Sunday, January 22, 2012

802.1q trunk native vlan concept

IEEE 802.1q trunk has the concept of native vlans. The standard also provides less overhead to the ethernet frames (just 4 bytes) by shim vlan tag compare to Cisco's ISL (26 bytes) which encapsulates the entire frame and adds new CRC trailer.

So what is native vlan, and when do i use it ?

Native VLAN is relevant only when there is 802.1q trunking between switches or a switch and a router ( in case of router on stick). Native VLAN has no significance when ISL trunking is used OR all vlans are tagged.

In 802.1q trunking each frame is being tagged by 4 bytes field in the ethernet header and before IP header (assume IP traffic). The 4 bytes tag field contains vlan number (12 bit), 3 bit field for layer 2 QoS, TPID (16 bits) field in order to identified the tagged frame(this is set to 0x8100 for 802.1q) etc.
The native VLAN does not have the 4 bytes tag in the frame. When one switch sends native vlan traffic to the other switch over the 802.1q trunk, the receving switch must also have same native vlan configure in order to accept the native vlan from other switch. If the receiving switch has different native vlan than what it is receiving in that case this switch may leak the received native vlan traffic in to its own native valn traffic. Switches have protection mechanisms in order to prevent this to happen by throughing error messages saying "native vlan mismatch" these error came out because negotiation of native vlan between the switches is a part of DTP and CDP. If these two protocols are disabled this error message will not appear but traffic can still leak. However there is a special mechanism in STP which brings ports in blocking state (*PVID_Inc) if native vlans are mismatched. It show this errors
%SPANTREE-2-BLOCK_PVID_LOCAL
%SPANTREE-2-RECV_PVID_ERR
STP moves these ports out of blocking states as soon as vlans are tagged on both sides using vlan dot1q tag native global command. However CDP will still shows native vlan mismatch but traffic will flow as normal because now all vlans are tagged and native vlan has no significance in that case.
By default VLAN 1 is the native VLAN in CISCO switches and can be configured to any vlan as native. It is normally used for management traffic.
if a device on the path does not understand untagged frames, Native VLAN should be disabled. To do so, use the VLAN dot1q tag native global command which will affect all trunk ports and cause Native VLAN frames to be tagged. 

Now enough theory lets try this
!
!
!
!
Answer goes something like this


R5 should able to ping R1. Both R1 and R5 do not know anything about the tagging. The reason being 
when R5 sends a a echo packet towards R1 it first reaches to CAT2 's port f0/6, now CAT2 knows that this belongs to VLAN 10 which is supposed to be tagged while sending it to CAT1 through the trunk between them because this trunk sends all vlan as tagged except its native vlan which is vlan 20.
Now CAT1 received this echo packed with a tagged vlan 10. This packet now goes through another trunk to the R1. When CAT1 sends this packet to this trunk it will untagged this frame because vlan 10 is the native vlan for this trunk to R1.
Now when R1 receives this untagged frame it will assume that this belongs to its native vlan which is vlan 20. On receiving this packet R1 will reply to the echo with the echo reply back to R5 with untagged frame. 
The return packet from R1 to R5 first reaches on CAT1's fa0/1 it will assume that this frame belongs to its native vlan 10. when CAT1 sends this frame through the trunk f0/13 it will tag this frame because this trunk sends all frame tagged except the native vlan 20 frames. Now when CAT2 receives this vlan 10 tagged frame it will send to the port which is assiged for vlan 10 i.e fa0/6 hence at the end R5 will receive the echo reply from R1.