Sub topic 15
Q-in-Q: Stacking Tags
This chapter assumes you know how 802.1Q tags work, how access and trunk ports behave, and what the native VLAN is. It covers the stacked-tag format (802.1ad, Q-in-Q), when to use it, and the errors that come with it.
The problem Q-in-Q solves
A single 802.1Q tag has a 12-bit VLAN ID, so a network has at most 4094 usable VLANs. A service provider that carries traffic for many customers can run out of IDs. Customers also choose their own VLAN numbers, so two customers may both use VLAN 10.
Q-in-Q solves both problems. The provider adds a second tag, the outer tag, in front of the customer's tag. The provider switches forward on the outer tag only. The customer's inner tag passes through unchanged.
The stacked frame
IEEE 802.1ad defines the format. The outer tag is the service tag (S-tag). The customer's own tag is the customer tag (C-tag).
| Layer | Name | TPID | Set by |
|---|---|---|---|
| Outer | S-tag | 0x88A8 | Provider |
| Inner | C-tag | 0x8100 | Customer |
Both tags are 4 bytes. The S-tag has the same layout as the C-tag: 3-bit priority, 1-bit drop eligible indicator, and 12-bit VLAN ID. Only the TPID differs. A switch that sees 0x88A8 after the source MAC address knows a service tag follows.
Some older equipment uses 0x8100 for the outer tag as well. This is the original "Q-in-Q" behavior and predates the standard. Both ends of a link must agree on the outer TPID.
How the provider edge works
The customer-facing port on the provider switch is a tunnel port. Frames arrive from the customer, tagged or untagged. The switch pushes one S-tag on each frame. The S-tag's VLAN ID identifies the customer's service. On the way out of the provider network, the egress switch removes the S-tag and the customer sees the original frames.
Here is an example on a Cisco Catalyst switch:
vlan 100
name CUSTOMER-A
!
interface GigabitEthernet0/5
switchport access vlan 100
switchport mode dot1q-tunnel
l2protocol-tunnel cdp
l2protocol-tunnel stp
!
interface GigabitEthernet0/24
switchport mode trunkPort Gi0/5 faces customer A. Every frame it receives leaves on the provider trunk with outer VLAN 100. The provider trunk Gi0/24 carries the S-tagged frames.
MTU and the extra four bytes
Each tag adds 4 bytes. A standard frame with one tag is 1522 bytes. With two tags it is 1526 bytes. Provider links must accept these larger frames. If they do not, full-size customer frames are dropped, while small packets such as pings still work. On Cisco switches that support it, raise the system MTU:
system mtu 1504On many platforms the value depends on the model, so check what yours supports. Also, a customer who sends 1500-byte IP packets needs the provider path to carry at least 1526-byte frames.
Common errors
- Provider links with a small MTU. Large frames vanish and small ones pass. Check the MTU on every hop.
- Control protocols consumed or leaked. By default a tunnel port may handle CDP, STP and VTP frames locally. Use Layer 2 protocol tunneling if the customer needs them carried across the provider network.
- TPID mismatch. If one side expects 0x88A8 and the other sends 0x8100 as the outer tag, the frames are misread.
- Customer VLANs overlapping with the native VLAN. Be careful with native VLAN settings on the provider trunk. Untagged frames receive no S-tag handling on some platforms.
Reading the tags in code
You can extend the earlier parser to handle two tags:
import struct
def parse_tags(frame: bytes):
"""Return a list of (tpid, pcp, dei, vid) for each VLAN tag in a frame."""
tags = []
offset = 12
while offset + 4 <= len(frame):
tpid, tci = struct.unpack("!HH", frame[offset:offset + 4])
if tpid not in (0x8100, 0x88A8):
break
tags.append((tpid, tci >> 13, (tci >> 12) & 1, tci & 0x0FFF))
offset += 4
return tagsFor a Q-in-Q frame the function returns two entries: the S-tag first, then the C-tag.
Exercise
A customer sends a frame tagged with VLAN 10 into a provider tunnel port assigned to VLAN 100. What tags does the frame carry inside the provider network, and in what order? What is the frame's size if the original tagged frame was 1522 bytes?
Show answer
The frame carries the outer S-tag (VLAN 100, TPID 0x88A8) first, then the customer's C-tag (VLAN 10, TPID 0x8100). The provider switches forward on VLAN 100 only. The frame grows by 4 bytes, so it is 1526 bytes.
Exercise
Customer A can ping across the provider network, but file transfers with full-size frames stall. What is the likely cause, and what do you check?
Show answer
The provider path probably does not accept the extra 4 bytes from the S-tag, so full-size frames are dropped while small pings pass. Check the MTU on every provider link and raise it to carry at least 1526-byte frames.