In this article, I am going to explain all the terms, concepts and working of Spanning Tree Protocol (STP) with the example, I have tried to clear all the concepts and doubts which usually rises in the Spanning Tree Protocol so, if you are interested to know something more about Spanning Tree Protocol keep reading this article till the end.
Spanning Tree Protocol (STP)
- A protocol which creates redundancy in Network topology like inverted Tree Structure.
- An inverted Tree has no loops and every branch connect to its Root
- Same like Tree structure in spanning Tree enables network all devices are connected to its main device like Root Bridge by its Root Port.
- STP used in switches to turn on redundancy in topology
- Block unwanted links /ports
- By default Switches run STP, no needed any configuration
- STP Uses an algorithm called Spanning Tree Algorithm (STA) to make the selection of which port should be shutdown.
- STA also decide some more selection using by STP
- Select a switch to “Root Bridge”
- Select port as “Root Port “to each switch towards Root Bridge.
- Select ports as “Designated Ports “–active ports getting data downwards from Root Bridge.
- Take the decision of which unwanted ports should be in Block state to prevent a loop in topology .means select Non-designated/Backup Ports in topology.
How STP Select Root Bridge/Main Switch in topology using STA (Spanning-Tree Algorithm)
- Root Bridge/Switch can be chosen from other switches in topology by identifying Bridge ID
- Bridge ID contains Priority Number, Extended System id, Mac address of every switch
- By default, all Cisco switches have Priority number is 32768.
- Extend system Id also called Vlan number, by default every switch has VLAN 1.Stp can be run according to VLAN, we can choose Root Bridge separate as per VLAN.
- So by default priority of all switches become the same as per VLAN 1. (32768+vlan 1=32769).
- Network Administrator can be set/modify Priority as per need.
- When by default all switches priority becomes the same STA (Spanning-Tree Algorithm) compares Mac address that must be unique of every switch.
- Switches compare Bridge Id to each other by sending frames called BPDU ( Bridge Protocol Data Unit ) after every two seconds to compare whose lowest bridge id to make Root Bridge.
- Finally, Lowest Bridge id becomes Root Bridge/Switch.
How STP Selects Root Port
A port from non-root Bridge/switch which has lowest and its only one port towards Root Bridge.
STP selects Root port by two steps
1-STP calculates the root path cost of all ports from all switches going towards selected Root Bridge.
2-If all ports cost becomes the same equal-cost then STP compares Bridge id (BID) of switches in the topology.
How Spanning Tree Protocol (STP) selects Designated Port
- Root Bridge/Switch doesn’t have a root port.
- It has always forward port called designated port towards in –root Bridge.
- Designated Port selection depends upon root port selection which is the lowest port cost if the same then lowest BID identification.
- From root port, there is always a designated port coming from Root Bridge.
Difference between Root Port and Designated Port
- Root port always selects by-election of non-root Bridges/ switches whose ports path cost is lowest and it is a single port coming from Root Bridge.
- Root port always coming from Root Bridge & Designated ports going towards Root Bridge.
- Both Root Bridge and Designated port are in forwarding/active mode.
- After selection of Root Port, selection of Designated ports held by non-root Bridges in topology
- Designated or active ports by which Root Bridge does communication to non-root bridges/switches and it is done by identification of lowest cost if same then STP checks Bridge Id (BID) to select the active port.
- After the selection of designated ports, other ports will be blocked to avoid loop in topology.
STP Port States-Journey of orange lights to green lights in switches:-
- As soon as you put the cable in switches you will go into LISTENING Mode, here you just send & receive BPDUs only. It takes 15 seconds
- After 15 seconds we move to another state called LEARNING Mode, It also takes 15 seconds, here you also send & receive BPDUs and also learning MAC Address from incoming BPDUs to fill the Mac address table of the switch.
- After 30 seconds port becomes in FORWARDING Mode, here the port becomes ready to send data frames, actual data start sending to switches.30 seconds are huge to wait for the state, if you enable port-fast on your switches interfaces, you can skip two first states of ports.
- If your port is non designated/backup port in Blocking Mode if STP topology changes then it takes 20 seconds to wait to come in forwarding mode.
How BPDU is generated and works
Bridge Protocol Data Units (BPDUs) to build the topology database. BPDUs have forwarded out all ports every two seconds to a dedicated MAC multicast address of 0180.c200.0000. All switches selection depends on the exchange of BPDUs, including Root Bridge, root port, designated port. BPDU packets contain information on ports, addresses, priorities, and costs and ensure that the data ends up where it was intended to go.
Important Spanning Tree Protocol (STP) Timers and default values
Hello: the interval between Configuration BPDUs, it takes 2 seconds
Forward delay: Time spent in listening and Learning states before moving towards forwarding State.
Max age: Maximum Length of time. A BPDU can be store without receiving an update. It takes 20 seconds.
Also read these articles.
Download What is Spanning Tree Protocol (STP) and its types in pdf- Click here