Sub topic 15
Q-in-Q: Stacking Tags
This chapter assumes you can configure access and trunk ports, you know the 802.1Q tag layout (TPID, PCP, DEI, VID), and you know that a trunk adds 4 bytes to the frame. Q-in-Q builds on the tag format from the earlier chapters and needs no new commands beyond a few port modes.
The problem Q-in-Q solves
A VLAN ID is 12 bits, so one network has at most 4094 usable VLANs. That is plenty for one company. It is not enough for a service provider that carries Layer 2 traffic for hundreds of customers, because each customer already uses its own VLAN numbers. Two customers might both use VLAN 10 and VLAN 20, and the provider cannot map them onto one shared VLAN space without conflicts.
Q-in-Q solves this by stacking a second tag on the frame. The customer's tag is left untouched and travels as payload. The provider adds an outer tag that identifies the customer. Inside the provider network, switches forward on the outer tag only.
Two names are used for this:
- Q-in-Q is the informal name. It often means a second tag using the ordinary 802.1Q TPID
0x8100. - 802.1ad is the IEEE standard, also called provider bridging. It defines the outer tag with its own TPID,
0x88A8.
Terminology
| Term | Meaning |
|---|---|
| C-TAG, C-VLAN | The customer's tag and VLAN ID. TPID `0x8100`. |
| S-TAG, S-VLAN | The service provider's tag and VLAN ID. TPID `0x88A8` in 802.1ad. |
| Provider edge (PE) port | The provider switch port facing the customer. It adds or removes the S-TAG. |
| Provider core port | A trunk between provider switches. It carries S-tagged frames. |
What the frame looks like
With 802.1ad, the S-TAG goes first, directly after the source MAC address. The C-TAG follows it, then the original EtherType.
| Frame type | Bytes after source MAC | Added size |
|---|---|---|
| Untagged | EtherType, payload | 0 |
| 802.1Q | `8100` + TCI, EtherType, payload | 4 bytes |
| 802.1ad (Q-in-Q) | `88A8` + S-TCI, `8100` + C-TCI, EtherType, payload | 8 bytes |
The S-TAG has the same 16-bit TCI layout as an 802.1Q tag: 3-bit PCP, 1-bit DEI, 12-bit VID. In 802.1ad the DEI matters more than it does in a campus network. A provider can mark frames that exceed a customer's contracted rate as drop eligible. Congested core links then discard those frames first.
The number of possible combinations is large. There are up to 4094 S-VLANs, and each can carry up to 4094 C-VLANs. That is about 16.7 million service identifiers.
Configuring a provider edge port
On Cisco IOS switches, the customer-facing port uses the mode dot1q-tunnel. The port is assigned to the S-VLAN as if it were an access port.
vlan 100
name CUSTOMER-A
!
interface GigabitEthernet0/1
description Customer A uplink
switchport access vlan 100
switchport mode dot1q-tunnel
l2protocol-tunnel cdp
l2protocol-tunnel stp
l2protocol-tunnel vtp
!
interface GigabitEthernet0/24
description Provider core trunk
switchport mode trunk
switchport trunk allowed vlan 100
switchport nonegotiateThe tunnel port does not care whether incoming frames are tagged. It treats every frame as payload and pushes S-VLAN 100 on top. The customer can therefore send any C-VLANs it likes, and the provider never needs to learn them.
The core trunk is an ordinary trunk whose "VLANs" are S-VLANs. The allowed list and nonegotiate rules from earlier chapters apply unchanged.
Platform differences
- Some platforms always use
0x8100for the outer tag. Others let you set the outer TPID to0x88A8or another value. Both ends of a link must agree, so check the platform documentation. - Switch syntax differs between vendors. Juniper, Arista and Linux bridges each have their own way to express "push an S-TAG on this port".
- Do not rely on
dot1q-tunnelfor every platform. Some call it "QinQ port", "customer edge" or "service interface".
Frame size and MTU
A double-tagged frame is 4 bytes larger than a single-tagged one. A full-size customer frame of 1518 bytes (1522 with its C-TAG) becomes 1526 bytes. Many switches default to a maximum of 1500 bytes of payload and may drop the larger frames, usually counted as giants or oversize errors.
The symptoms are specific. Ping and small TCP exchanges work, but large transfers stall, because only full-size frames are dropped. Raise the system MTU on every provider switch in the path, and check it with the platform's command (on many Catalyst switches, show system mtu). A change often needs a reload.
Control protocols: Layer 2 protocol tunneling
Customer switches send control frames such as STP BPDUs, CDP, VTP and LACP to reserved multicast addresses. A provider switch normally consumes or drops these on the edge port. The customer's two sites then cannot see each other as neighbors. Two customer sites might even build separate spanning trees by accident.
Layer 2 protocol tunneling changes this. The edge port encapsulates the control frame, usually by rewriting its destination MAC to a provider-specific multicast address. The far edge port restores the original address and delivers it. The l2protocol-tunnel lines in the example above do this for CDP, STP and VTP.
Tunneling control traffic has a cost. A customer misconfiguration can send many control frames through the provider network, so protocol tunneling is usually combined with a rate threshold on the port.
MAC learning in the provider network
Provider switches learn the customer MAC addresses, keyed on the S-VLAN. A customer with a large Layer 2 network can fill the MAC table of every core switch. Two customers can also have the same MAC address, and that causes no conflict because the entries are in different S-VLANs. Provider backbone bridging (802.1ah, MAC-in-MAC) fixes the table-size problem by hiding customer MACs behind provider MACs. It is a separate technology and is not covered here.
Inspecting stacked tags
This Python program builds a double-tagged frame and parses it. Any number of tags is handled by looping while the next two bytes are a known TPID.
import struct
TPIDS = {0x8100: "C-TAG (802.1Q)", 0x88A8: "S-TAG (802.1ad)"}
def build_frame(dst: bytes, src: bytes, tags, ethertype: int, payload: bytes) -> bytes:
"""tags is a list of (tpid, pcp, dei, vid) tuples, outermost first."""
frame = dst + src
for tpid, pcp, dei, vid in tags:
tci = (pcp << 13) | (dei << 12) | vid
frame += struct.pack("!HH", tpid, tci)
return frame + struct.pack("!H", ethertype) + payload
def parse_tags(frame: bytes):
"""Return (list of tag dicts, offset of the real EtherType)."""
tags = []
offset = 12
while len(frame) >= offset + 4:
tpid, tci = struct.unpack("!HH", frame[offset:offset + 4])
if tpid not in TPIDS:
break
tags.append({
"kind": TPIDS[tpid],
"pcp": tci >> 13,
"dei": (tci >> 12) & 0x1,
"vid": tci & 0x0FFF,
})
offset += 4
return tags, offset
frame = build_frame(
dst=bytes.fromhex("ffffffffffff"),
src=bytes.fromhex("020000000001"),
tags=[(0x88A8, 0, 0, 100), (0x8100, 0, 0, 10)],
ethertype=0x0800,
payload=b"\x00" * 46,
)
tags, offset = parse_tags(frame)
for tag in tags:
print(tag)
print("EtherType offset:", offset, "frame length:", len(frame))The output shows the S-TAG with VID 100 first, then the C-TAG with VID 10, and the EtherType at byte offset 20. Note that the single-tag parser from the 802.1Q chapter would read only the outer tag. It would then treat the inner 0x8100 as the EtherType.
Common faults
- Large frames dropped. The provider MTU was not raised for the extra 4 bytes.
- Customer CDP or STP neighbors not seen. Layer 2 protocol tunneling is missing on the edge port.
- Outer TPID mismatch. One end sends
0x88A8and the other expects0x8100. The receiver does not recognize the outer tag, so it treats the frame as untagged or drops it. - Wrong port mode. A customer-facing port left as a normal trunk accepts the customer's tags into the provider VLAN space. VLAN numbers then collide with the provider's own.
- MAC table exhaustion. One customer with thousands of hosts fills the core tables. Limit the learned addresses per port with port security.
Exercise
A provider receives a customer frame tagged with C-VLAN 30 on an edge port assigned to S-VLAN 200. Which tags does the frame carry in the provider core, and how many bytes larger is it than the original frame?
Show answer
It carries two tags: an outer S-TAG with VID 200 and the inner C-TAG with VID 30, which the provider does not modify. The frame is 4 bytes larger than the customer's tagged frame (8 bytes larger than an untagged one).
Exercise
Large file transfers across a new Q-in-Q service fail, but small pings succeed and every VLAN setting is correct. What is the most likely cause, and what do you check?
Show answer
The provider switches probably have the default MTU and drop the 1526-byte double-tagged frames. Check the system MTU on every switch in the path (for example with show system mtu), raise it, and look for giant or oversize counters on the interfaces.
Exercise
Two customers both use VLANs 10 and 20 on their own networks. Why can the provider carry both over the same core without conflict?
Show answer
The core forwards on the S-VLAN only. Each customer is given its own S-VLAN, and its C-VLAN numbers stay inside the payload. Customer MAC addresses are also learned per S-VLAN, so identical C-VLANs or MACs in different S-VLANs do not collide.