Switching – Spanning Tree Algorithm


In this post I will talk about a networking mechanism used to provide a loop-free network, the Spanning Tree Protocol (STP). I will show you the main elements that make up this protocol, their role and functionality. STP is used to maintain all the time at least one path active between two end points. Because there is the possibility that loops can occur, STP automatically deactivates one path if there are multiple paths for the same destination point. With a redundant design, there is always an alternative path if the main link becomes inactive. Remember from a previous post that the hierarchical network model uses multiple switches and links between one point to another. Even if a core switch fails, there is another one ready to forward packets outside the network.
STP sends frames between devices called BPDU (bridge protocol data unit) frames that contain information about the state of the network. By intentionally blocking paths between devices, STP ensures all the time that there are no network loops. The physical path will still exist and will be used as an alternative path if the main one fails. STP uses the Spanning Tree Algorithm to determine what paths should be deactivated. STA chooses the so called root bridge after BPDU frames are exchanged between devices. When BPDU frames are exchanged, STA selects the root bridge by looking at the lowest bridge ID (BID). Each BPDU frames contains the BID which is a combination between the MAC address, a priority value and extended system ID. At first, all switches act like root bridges and they exchange BPDU frames between each other. By comparing the BIDs from BPDU frames received, switches determine who’s the best root bridge switch. As an Administrator, you can influence the root bridge selection by changing the switch priority. By default the switch priority is 32768 but you can assign a priority between 1 and 65536 (it must be a value that is an increment of 4096). To change the switch priority, enter the global configuration mode and type spanning-tree vlan [id] priority [number]. For example, you can set the priority by typing spanning-tree vlan 1 priority 8192. If you try to assign a different value that is not an increment of 4096, you will receive a warning saying that “% Bridge Priority must be in increments of 4096.
% Allowed values are:
0     4096  8192  12288 16384 20480 24576 28672
32768 36864 40960 45056 49152 53248 57344 61440”
Here is an example of this output:

spanning-tree configuration

After the root bridge was chosen, STA will determine the best path to reach the root bridge for all switches in the network. The overall cost from one point to another is the cost of a path. After calculating the costs, STA will set all switch ports that participate in the STP algorithm to the appropriate mode, as follows:
designated ports – ports that will forward network traffic
non designated ports – ports that will be set in the blocking state. These ports will not forward traffic and they will be used if the main path fails. These ports are set in this state to prevent routing loops.
root ports – the ports that are the closest to the root bridge
Another way you can influence how ports are configured by the STP algorithm is by changing the port’s priority. This is a value that is by default set to 128 but can be changed to a value between 0 and 240. To change a port’s priority, use the spanning-tree port-priority [number] command from the interface configuration mode.
I’ve told you previously that STP will choose best paths by comparing the overall cost from one point to another. This means that STP will sum all the costs from all paths that a packet must travel through, to reach it’s destination. The default cost is determined by the path’s bandwidth. For example, a path with the speed of 1 Gb/s will have a cost of 4, one with 100 Mb/s will have the cost of 19 and so on. The path with the lowest cost is desired. You can let STP chose paths by checking the link’s cost or you can configure manually a cost for a certain path. To configure the cost of a path, simply enter the interface configuration mode and type spanning-tree cost [number], for example, spanning-tree cost 10. To verify your spanning tree configuration type show spanning-tree.
Switch ports that participate in the spanning-tree algorithm must transition to several states before they are able to fully integrate in the STP process. By changing the ports state, STA ensures that there are no loops occurring in the network. There are five states that a port can transition to:
Disable – the port will not participate in the spanning-tree process and it will not forward data.
Blocking – the port will not forward frames received but it will process BPDU frames to determine other switches states.
Listening – the port will participate in the STP algorithm, it will receive and forward BPDU frames.
Learning – the port will receive and forward BPDU frames and it will also add entries to the MAC address table
Forwarding – the port is fully participating in the STP process, it will forward/receive frames and BPDU frames.
There are some timers created to manage how long a port will stay in a certain state. The hello time is the interval between BPDU frames (the time it must pass before another BPDU frame is sent), by default it is 2 seconds but this can be easily changed to a value between 1 and 10 seconds. The forward delay time is the time that a port will require to reach the learning state. By default, the forward delay time is set to 15 seconds , but it can be changed to a value between 4 and 30. Usually, you will not have to change these timers because they have been configured to a network diameter of 7 which is usually enough for most network implementations. If you really want to change the spanning tree network diameter, use the command spanning-tree vlan [number] root primary/secondary diameter [number], for example spanning-tree vlan 10 root primary diameter 9.
 Portfast ports will transition from the blocking state to the forwarding state immediately after a switch is powered on. Portfast ports can be configured on access ports because these ports are used to connect end devices such as computers/printers and do no participate in the STP convergence process. Also, it is recommended that you set these ports in the BPDU guard mode. A port in the BPDU guard mode will not forward BPDU packets to end devices because there is no need to. To enable the Portfast and the BPDU guard features, use the following commands:

BPDU guard
   To view the configured ports, use the show running-config command:
show running-config command
   In the end, I want to talk a little about the different STP versions. As you have probably seen, Cisco created some custom made versions of the Spanning Tree Protocol. Because this protocol became a standard, IEEE created their own version of STP that can be used by all networking devices.
   An older version of STP invented by Cisco is the Per-VLAN spanning tree protocol (PVST). This protocol stated that STP can run a different instance for every VLAN. What this means is that a switch can be elected as the root bridge for one VLAN and another switch can be elected as the root bridge for another VLAN. By implementing such a design, the redundancy is increased and also load balancing can be implemented because traffic is spread between different VLANs. in PVST, BPDU frames contain the VLAN ID to differentiate between different STP instances. You can set the root bridge for a VLAN by using the spanning-tree vlan [id] root primary/secondary command. For example, you can set the primary root bridge for VLAN 10 by typing spanning-tree vlan 10 root primary on a switch and spanning-tree vlan 10 root secondary on another switch. The same thing can be configured if you change the priority value using the spanning-tree vlan [id] priority [number] (a value incremented by 4096) command. I’ve created the following topology:
In this simple topology, I’ve selected the S2 switch to be the root bridge for vlan 10 and S3 the secondary root bridge for vlan 10. Also, I’ve selected S1 to be the root bridge for vlan 20 by changing the priority value below the default value. The following are the commands for each switch:
spanning-tree priority
spanning-tree priority
spanning-tree priority
   Another version of Cisco STP is the Rapid-PVST+ which is an implementation of the IEEE RSTP protocol. When Rapid spanning tree protocol was invented, it had some new features that didn’t existed before. RSTP had an increased speed in network convergence, it added more port state and roles and was also compatible with all the previous versions of STP. RSTP introduced edge ports which are somehow like Portfast ports because they connect end devices. Edge ports do not participate in the STP algorithm but unlike Portfast ports, if they receive a BPDU frame, their state is automatically changed to an active STP port (in the forwarding state). I will not talk too much about this protocol, you will have to know that it has only three port states: discarding, learning and forwarding. By using only three states, the STP speed is increased. The Rapid-PVST+ can be set on a Cisco switch by using the spanning-tree mode rapid-pvst command from the global configuration mode.
   There is much more to say about the STP protocol, I hope I’ve pointed out all the important aspects that make up this protocol. I hope you will find this post interesting, leave a comment/share. Thank you very much for reading this and have a wonderful day.
Advertisements

5 thoughts on “Switching – Spanning Tree Algorithm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s