Network Kings, India’s Leading IT Career Training Academy
Redundancy in any network is necessary to provide a backup path if one link goes down, but it may also lead to a loop in a network and hence network congestion.
Networks get configured with redundant paths. Although redundancy is a crucial aspect of network design, it may also lead to form a loop. The loop can occur when data travels from source to destination but gets stuck in a circle due to the redundant link provided. To avoid data looping, the Spanning Tree Protocol gets used.
Spanning Tree Protocol (STP) works on Layer 2 of the OSI Model and prevents loops in network topology and prevents ethernet network loops while providing redundancy.
Let us take an example of the above Network Topology.
Switches S1 and S2 are connected via link 1.
S3 is a redundant switch providing redundancy in a network.
If the link between S1 and S2 goes down for any reason, Data can travel to S2 via S3.
Suppose S1 sends data to S2 via link 1.
Data will also travel to S3 via link 2, then to S2 via link 3, and again back to S1.
Hence a loop is formed where data travels from S1 to S3 to S2 and again to S1.
Hence in the absence of STP, there would be no redundancy. STP blocks some ports of switches with the help of STP election to prevent looping. The blocked port can enable itself when there is a change in topology or case of link failure and hence providing redundancy.
NOTE: To understand how STP Election works, how the port is blocked, which port to block, and dive into the world of STP, we need to understand some basic terminologies and concepts used in Spanning Tree Protocol.
Bridge ID is a combination of Bridge Priority and MAC Address which is unique for every switch. Bridge ID is a numerical value that ranges from 0 to 65535.
MAC Address also called Media Access Control Address is a unique number assigned to the Network Interface Controller (NIC) of a device. It is a sort of Hardware address and is used at the data link layer. It is a 48-bit address.
The switch with the lowest priority becomes a Root Bridge. If, in case, the priority of 2 or more than 2 switches is the same, then the switch with the lowest Bridge ID becomes Root Bridge.
The port roles are as follows-
A non-root switch always has at least 1 root port.
3 types of STP timers help in loop prevention, namely-
BPDU also known as Bridge Protocol Data Unit is an essential component of the Spanning Tree Protocol. BPDU is a message transmitted by each switch which helps to exchange information about the network topology and hence helps in STP Election.
There are two types of BPDU, namely-
Configuration BPDU – This BPDU gets exchanged when switches are connected or enabled. It is the primary BPDU which includes information about network topology and some following important network information: –
Topology Change Notification BPDU (TCN) – TCN is transmitted when there is any change in the topology of a network such as a link failure, the addition of a new switch, link recovery, etc. When a switch detects a change in a network, it generates TCN and broadcast it to a neighbouring switch. Another switch will respond according to the changes occurred in a network.
For example: – If a link goes down, Switches will reconverge the path to the backup link.
Hence exchange of Configuration BPDU and TCN BPDU helps switches to maintain a loop-free path along with responding to changes in the network’s topology. The Multicast Destination MAC address used by BPDU is 01:80:C2:00:00:00.
Let’s understand how the Spanning Tree Protocol election work and how and which port is blocked to prevent the looping of the network.
Let’s take an example of the above topology.
Switches S1, S2 and S3 have MAC ADDRESS: – 00.00.00.00.00.01, 00.00.00.00.00.02, 00.00.00.00.00.03 respectively.
The priority of all the 3 switches is 32768. (By default, Cisco Switches has priority set to 32768 but it can also be changed and configured manually).
Steps involved in the (Spanning Tree Protocol) STP Election process: –
1. Bridge Priority Determination: –
When Switches are turned on, they will start sending Configuration BPDU containing Bridge ID, Cost to the Root Bridge, and STP Timers (Hello Timer, Max Age Timer, Forward Delay Timer)
The bridge ID is 8 bytes.
It is a combination of Bridge Priority and MAC ADDRESS.
2. Root Bridge and Root Port Election: –
Initially Every Switch consider itself to be a ROOT BRIDGE. When Switch receives BDPU with a lower Bridge ID (Superior BPDU), it will stop its configuration BPDU and start forwarding Superior BPDU to its neighbours.
Bridge ID (Bridge Priority + MAC ADDRESS) starts with Priority hence Switches with a lower Priority value (Lower the Priority Value, Higher the Priority of the switch) become ROOT BRIDGE.
Suppose the Priority of 2 or more switches is the same, the Switch with a Lower MAC ADDRESS becomes the ROOT BRIDGE.
In our example, Switch has the same priority but the MAC ADDRESS OF S1 is lowest, hence it will become ROOT BRIDGE.
Also, the ports on the ROOT BRIDGE become ROOT PORTS.
ROOT PORTS never comes to a blocking state and always forwards the ethernet frames.
These ports do not block traffic.
3. Designated Port Election: –
When the Root port Is elected, Designated ports are identified on the NON-ROOT BRIDGE.
Designated ports are those which are connected via a link having the lowest cost to reach the root port of the root bridge.
Costs are determined by the type of Link switches that are connected. Some default costs of links are given below: –
|
Speed |
Link Cost |
|
10 Mbps |
100 |
|
100 Mbps |
19 |
|
1Gbps |
4 |
|
10Gbps |
2 |
4. Blocking Port Election: –
We now know how root ports and designated ports are elected. Let us now talk about how to select a port that will be blocked.
Port connected via a link having the highest cost to reach the ROOT BRIDGE will be blocked and it will not transmit any ethernet frame unless a change in the topology takes place.
All the links Connecting Switches have the same cost.
In the above Topology, Switches are connected via a 1gbps link which has a cost equal to 4.
The direct cost of Switch 2 to reach ROOT BRIDGE i.e., S1 is 4 and the indirect cost to reach Switch 1 is 8
For S3 also, the direct cost to reach ROOT BRIDGE i.e., S1 is 4 and the indirect cost to reach Switch 1 is 8.
Indirect and direct costs for both the switch are equal and hence there is a tie.
In such cases where there is a tie between direct and indirect costs, the Election process again happens based on Bridge ID.
Priority of S2 and S3 is equal but the MAC ADDRESS of S2 is lower i.e., 00.00.00.00.00.02
And hence S2 wins the STP election and it will become Designated Switch on both the port of S2 will become Designated Port.
Now the port on S3 will be blocked to avoid the loop.
To decide which port will be blocked, the Cost of both the link to reach S1 i.e., Root Bridge is calculated again.
The direct cost to reach S1 is 4 which is lower than the indirect cost
Hence Port connected via a link that has a higher cost will be blocked.
S1 becomes the Root bridge because the Bridge ID of S1 is the lowest
S2 becomes a Designated Switch although the cost to reach S1 is the same but because its Bridge ID of it is lower than S3
S3 has 1 port as the designated port while the other port is blocked.
Links have different costs.
S1 and S2 are connected with 100 Mbps link which has a cost equal to 19.
S1 and S3 are connected with 1Gbps which has a cost equal to 4.
S3 and S2 are connected with 100 Mbps link which has a cost equal to 19.
The direct cost of S2 to reach S1 is 19.
The direct cost of S3 to reach S1 is 4.
Since the Direct cost of S3 is lower hence Ports on S3 will not be blocked and ports on it will become Designated Ports.
The direct cost of S2 to reach S1 is 19 and the Indirect cost to reach S1 is 23 hence port that has a higher cost path will be blocked.
In this way, by determining Root Bridge, Root Ports, Designated Ports, and Blocking Ports, the Spanning Tree Protocol creates a loop-free network.
Traffic flows along the designated paths, ensuring redundancy and fault tolerance in the network.
The higher the Speed of the link, Lower the cost, and vice versa.
If a port with a higher speed is blocked, then the network will become slow and inefficient.
Also, if a port with a higher speed is blocked, then there is no sense to invest in a higher-speed link which is also expensive.
As network engineers, our goal is to make network communication more efficient and hassle-free.
Spanning Tree Protocol is one such protocol that helps to make a loop-free path and remove network congestion at the Data link layer (Layer 2).
The concept behind blocking a port is to elect a ROOT BRIDGE first and then find the path which has the least cost to reach the ROOT BRIDGE. The port connected to a link with the higher total cost to reach the ROOT BRIDGE is blocked.
The least cost implies the higher speed of the link and hence it is favourable to block the port with a lower speed (i.e., higher cost) to make the network faster.
(Please note that the cost mentioned here does not signify the monetary cost but it is a parameter used to find the shortest path.)