Saturday, May 12, 2012

Spanning Tree Protocol (STP)


Redundancy can make a network more reliable but more administrative overhead is needed. In a switching environment, redundant paths can mean reliable connectivity or dreadful switching loops. Below is a diagram of a redundant switch design. A switching loop will cause extensive degradedation of network performance due to broadcast storms, duplicate frames and filling a MAC table.



Spanning tree protocol (802.1d) allows switches to be in a redundant topology without switching loops by blocking redundant  paths until the best path is lost. An election process is started when the switches are first powered on and each switch believes to be the Root Bridge. There can only be one root bridge so each switch sends its BID (bridge id )in a BPDU (bridge protocol data unti)frame announcing to other switches that it should be root bridge. The BID is made of a combination of bridge priority (default 32,768) and base MAC address. A switch receives a BPDU and compares its BID with the sender's BID, if sender's BID is lower than the switches it will understand it's not the root bridge and start advertising the sender's BID as root bridge. If the switches BID is lower it will continuce to delcare itself as root bridge.

After a root bridge has won the election, all other switches calcuate the best path to the root bridge. The port with the best path (highest bandwidth= low cost) to the root bridge will be called the root port. There can only be one root port per switch . Designated ports are ports with the lowest cost via the root port and all other ports are non-designated ports and are in blocking mode.

STP Modes

  • Blocking- frames are not forwarded but BPDU are accepted (still part of STP election)
  • Listening- frames aren't forwarded and MAC table hasn't been built
  • Learning - frames are forwarded but MAC address are being learned and table is being built
  • Forwarding- frames are being forwarded and MAC addresses are still being learned
  • Disabled - no frames forwarded or BPDU accepted (dead)


The show spanning tree command displays who is root bridge, the local switches BID , version of STP and which mode STP ports are in. S1 one is the root bridge because it has a lower MAC address than S2, their bridge priorities are the same.

S1#show spanning-tree
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     0003.E470.423D
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0003.E470.423D
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/5            Desg FWD 19        128.5    P2p
Fa0/10           Desg FWD 19        128.10   P2p


S2#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     0003.E470.423D
             Cost        19
             Port        5(FastEthernet0/5)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     00D0.FF41.B99B
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role    Sts  Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/5            Root FWD 19        128.5    P2p
Fa0/10           Altn BLK  19        128.10   P2p

Data can not be sent until all switches have converged. After the election process each switch understands its role in the network. STP will use timers to keep the track of the topology for any changes.

Choosing the switch in the middle of a redundant topology is a good way to speed up convergence. Using the spanning-tree vlan priority command  I can rig the election to guarantee the root bridge. The lower the priority the better in a STP election. I can also configure a secondary root  bridge in case the primary one goes down.

 Switch(config)#spanning-tree vlan 10,20,30 priority 4096

or

Switch(config)#spanning-tree vlan 10,20,30 root primary

Hello BPDUs are sent every two seconds as an heartbeat for each link, when a switch hasn't heard a hello it will start the Max Age timer giving 20 seconds before it declares a topology change. Then a forward delay is used for both the listening and learning modes (15 seconds each mode). That is a total of about 50 seconds before a port can start forwarding again. There is a way to cut down on this mintune of downtime using portfast.

Portfast is used when a port will only be used with a host machine (server,PC)and not to another switch. A warning is introduce after the command to remind the implications on this command.



Switch(config)#int fastEthernet 0/7
Switch(config-if)#spanning-tree portfast
%Warning: portfast should only be enabled on ports connected to a single
host. Connecting hubs, concentrators, switches, bridges, etc... to this
interface  when portfast is enabled, can cause temporary bridging loops.
Use with CAUTION

%Portfast has been configured on FastEthernet0/7 but will only
have effect when the interface is in a non-trunking mode.


BPDUGuard is also a great command to use on a portfast port to prevent a switch from being plugged into it, if one is detected it will disable the port.

Switch(config-if)#spanning-tree bpduguard enable 


Rapid Spanning Tree Protocol 802.1w

There is a new revised version of STP called RSTP and it can coverge a lot faster because it only has three modes. RSTP can be used between different vendor switches. Everything else works exactly the same as STP which makes it backwards compatible with 802.1d


  • Discarding- frames aren't forwarded and MAC table hasn't been built
  • Learning - frames are forwarded but MAC address are being learned and table is being built
  • Forwarding- frames are being forwarded and MAC addresses are still being learned

To enable RSTP, use the follow command in  global configuration mode

Switch(config)#spanning-tree mode rapid-pvst


No comments:

Post a Comment