STP / Spanning-Tree / IEEE 802.1D

Spanning-Tree is an algorithm to keep a switched network loopfree. This means if you have multiple redundant switching paths in a network, without spanning-tree i will happen, that there will be switching loops in the network, which could take the whole network down. So spanning-tree is a layer2 protocol, which algorithm is selecting one bridge as the root bridge and each port a certain role. These can be:

  • Root – elected forwarding port in the STP topology
  • Designated – elected forwarding port in every switched LAN segment
  • Alternate – providing an alternate path to the root bridge
  • Backup – loopback configuration of a blocked port

These are port states that are passed in the process of becoming a forwarding port:

  • Disabled – inactive port, does not participate the STP
  • Blocking – a port is at first in the blocking stage, not forwarding any frames
  • Listening – STP decided this port should participate in forwarding, but not forwarding any frames at now, takes 15 seconds and then goes into
  • Learning – prepares to forward frames, 15 seconds duration, after that goes into last state, which is forwarding
  • Forwarding – the interface is forwarding frames

An interface can be disabled at any state of the process to become a forwading port.
The root election is based by default on the switch with the lowest MAC address value. You can also set the root bridge by setting the prioority, so the it’s the lowest priority in the STP topology.

At first every switch assumes itself as the root bridge, when it’s first powered up. It communicates with BPDU’s send every two seconds to compute the spanning-tree topology.
A BPDU (Bridge Protocol Data Units) contains the following:

  • a unique ID which the switch sending the BPDU itself identifies as the root switch
  • the path cost to the root
  • the bridge ID of the sending switch
  • the age of the message
  • identifier of the sending interface
  • hello, forward dely, max-age timer values

A BPDU packet conversation does have the following consequences.

  • electing one switch as the root switch, counting priority (default 32768) fist and then if these are equal, the lowest MAC address
  • electing a root port an each switch, except the root switch
  • calculating the shortest distance to the root switch based on path cost. Path cost it based on the interface bandwidth
  • selecting a designated switch which has the so called designated port, as this is the port with the lowest path cost to the root switch

There are also TCN BPDU’s (topology change notification) messages send in a spanning-tree network.
Each configured VLAN has it’s own bridge ID. As each VLAN is it own bridge. Take a look at this with „show spanning tree“. You will see that each vlan has it’s own priority. So changing the priority for a vlan change the probability of the switch being elected as the root bridge

There are several possible configuration values to setup. If you want, for example to to change the election of the root port use the „port-cost“ variable for the local switch. To change the choosen root port for a downstream switch, take the „port-priority“ variable.

For Example: SW1 and SW2 are connected over 3 trunks SW1 is the root for vlan 7. To setup SW1 as the root for vlan 7: „spanning-tree vlan 7 root primary

Now you want to select a certain trunk for carrying the vlan 7 traffic. When you are on the root bridge use „port-priority“ to select the trunk and set a lower prio as on the others. Default is 128. If you are on the downstream switch, use „port-cost“ to let the downstream switch elect the root port, for example:

spanning-tree vlan 7 cost 20

Here are the STP costs for different link bandwidths:

  • 4 Mbps – 250
  • 10 Mbps – 100
  • 16 Mbps – 62
  • 45 Mbps – 39
  • 100 Mbps – 19
  • 155 Mbps – 14
  • 622 Mbps – 6
  • 1 Gbps – 4
  • 10 Gbps – 2

So after the root bridge is selected based upon the Bridge ID/MAC address and Bridge priority, the differnet types of ports are selected based upon the cost and path cost.

The root port of each bridge is selected upon path cost to the root bridge. Each path is summarized to a path cost and the port with the lowest path cost gets the root port.


Leave a Reply