STP stands for spanning tree protocol. STP is used to reduce layer 2 loops. By default, STP is running in all manageable switches.
For a good network design and to ensure network availability, some extra links are added to the network (redundancy). If any active link fails then traffic shifts to these redundant links. It means these links are used for backup purpose. The process of adding extra links is known as network redundancy.
As we know everything has its pros and cons, same here, redundant links are good for backup purpose, but they also create layer 2 loops. To avoid these loops STP is used. STP allows the network design to use redundancy without causing other problems (loops).
STP prevents layer 2 loops by placing redundant ports in a blocking state. These extra links acts as a backup that can enter in a forwarding state if an active interface fails.
Interface in a forwarding state behave normally. They send and receive all normal traffic. While interface in blocking mode only send/receive BPDU messages (Bridge Protocol data units).
By selecting which ports are in forward mode and which are in blocking mode, STP creates a single path between each point. This way, STP prevents from layer 2 loops.
Why we need STP?
- To reduce broadcast storm.
- MAC table instability- As MAC table keep changing because frames with same source MAC arrives on different ports.
- Due to loops, multiple copies of the frame arrive at the destination.
How does a root bridge elect?
Switches use bridge-ID to select the root bridge. Bridge-ID consist two parameters one is bridge priority and another is MAC address. The switch which has lowest bridge-ID is selected as a root bridge. First priority field is compared, if there is a tie, then MAC address is compared.
How process starts?
- ALL STP-enabled switches sends Hello BPDU message to each other.
- Before sending BPDU message next time, switch compares it’s BID with received BID (inside BPDU message), when received BPDU has lower BID, it stops advertising itself.
- The same process repeats, and the switch which has lowest BID become root bridge.