Thursday, March 26, 2009
STP Process: Step-by-step
STP or spanning tree protocol is used to prevent switching loops. STP will determine the most desirable path, and place that port in Forwarding mode ( to forward the traffic), while other less-desirable path ports will be in Blocking mode.
Redundancy is very important in networking, they are good because they help to prevent a complete failure of a network in case one of the links goes down.
STP allows a network design to include redundant links to provide automatic backup paths if an active link fails, while removing the danger of switching loops, or the need for manual intervention enabling these backup links.
** LAB Included!
Before we start, lets cover the STP terminology:
- Root Bridge (Switch): This is the switch with the best (smallest) BID or lowest MAC address . The root bridge becomes a key parameter when considering all other network decisions, like which port will be in BLOCKING mode and which will be in FORWARDING mode.
- BID (Bridge ID): Each bridge has a unique identifier (ID) and a configurable priority number (32768 is the default priority on Cisco switches) the bridge ID is combination of the priority and the MAC address of a switch. This is how STP tracks all the switches in the network. BID of a Switch looks as follows: PRIORITY.MAC-ADDRESS; 32768.AAAA:AAAA:AAA1
- Non root Bridges: Those are all the bridges that are not elected as the root bridge.
- BPDU: Those are special data frames the switches use to exchange STP information (BID, Cost to root) with other switches in the network for the selection of the root bridge and the port roles (root port, designated port, blocking port).
There are three types of BPDUs:
* Configuration BPDU (CBPDU), used for STP computation.
* Topology Change Notification (TCN) BPDU, used to announce changes in the network topology.
* Topology Change Notification Acknowledgment (TCA).
BPUD's are sent every 2 seconds by default, and they are used to track the network topology for any topology change.
STP Port modes:
- Blocking: User Frames aren't forwarded through that port; BPDU's are accepted; those ports used as backup paths, and they might go into forwarding mode if the other designated links in use were to fail.
- Listening: User Frames aren't forwarded through that state; MAC-address-table is NOT built yet; BPDUs are accpeted and the switch gathers new information regarding other switches in the topology.
- Learning: User Frames aren't forwarded yet but they are accepted by the switch to build the CAM table.The switch in this state tries to learn which mac address belongs to what port.
- Forwarding: User Frames are SENT and RECEIVED; STP still monitors incoming BPDUs that would indicate it change the mode to the blocking state to prevent a loop.
OK. Now let's have some fun.
I'll demonstrate the Root Bridge election process, then how Root ports are elected and last, how Designated / Blocking ports are decided.
- Root Bridge & Root ports election:
The switches exchange BPDUs, and each of the switches compare its own BID with the received BPDU. The bridge with the lowest priority will be elected as the root bridge. If the priority is equal on all the switches, the switch with the lowest MAC address will be elected. (Remeber how BIDs look like? - priority.MAC-ADDRESS, so if priority is equal, the MAC is used as tie-breaker!)
- After the Root bridge election, each of the switches in the network needs to choose its path to the root bridge. STP uses the term 'cost' to determine the speeds of the links. Lower cost - faster link, more bandwith!
The port with the shortest path to the root bridge (lowest cost to the root bridge) is elected as the ROOT PORT. If the switch has a directly connected to the root bridge, the cost to root value will be 0.
- If a switch has multiple links to the root bridge, and their costs are equal, the neighbors BID is used as the tie-breaker. The neighbor with the lower advertising BID is elected to be the shortest path to the root (and that port role is ROOT PORT).
- If redundancy is used, and multiple links are connected to the same switch, and costs are equal (MAC will be equal too because we are connecting to the same switch!) - the lowest interface priority is used as the root port. and if that's equal too, the lowest physical interface port will be elected as root port.
I'll demonstrate it now:
Root port process:
- Elect ROOT switch -> The switches exchanging BPDUs with each other, deciding which one of them will be the Root for that network. I've changed the priority of S1 to 24576 so it would be the Root bridge of our topology.
S1(config)#spanning-tree vlan 1 priority 24576. After that, I've changed the priority of S3 to 28672 so it will be the Root bridge in-case S1 falls. S3(config)#spanning-tree vlan 1 priority 28672
- Choose Root ports on every single switch -> Each one of the switches, determine its shortest path to the Root, and that port becomes the Root port. Since every switch is directly connected to the Root, and the speed of the links is equal, that connected port becomes the Root port.
- Choose Designated ports on every segment -> Now the switches needs to agree which of the NON-Root ports will be placed in blocking mode to prevent loops. On each segment (S2 -> S3, S3 -> S4 links) the switches compare their Cost to Root, since all the switches directly connected to the Root, their Costs are equal. So, now they are comparing their BIDs. Remember I changed S3's priority? so that it would be lower than the defaut? S3 BID is lower than both switches BID, so S3 places its ports in Designanted role and those ports are Forwarding traffic regulary. S2 & S4 switches both places their connected ports to S3 to Blocking role, and those ports are Blocking aby traffic except BPDUs. Now our STP enviornment is converged.
Here are the notes I took to my self to remember this whole thing about Root port election:
- Choose the path with the lowest cost to the root bridge, If equal --> Choose the neighboring switch with the lowest BID, If equal -->
that means multiple links go through the same switch, so choose the port with the lowest priority, If equal --> pick the lowest physical interface as the root port.
- Designated & Blocking ports:
After the root ports are set, each networking segment gotta have 1 port in FWD, and 1 port in BLK mode (to prevent loops!)
The designated port of a segment is decided upon which switch is closer to the root bridge? (has lower cost to Root..)
In our topology example:
S2, S3 and S4 has equal cost to the root bridge. that actually means in STP terms that none of them is actually closer to the root than the other. So in that case, they are comparing their BIDs with each other (for each link ofcourse, S2 and S3 and S3 and S4. since there is no link between S2 and S4 - there will be no comparison between those two!)
Because S3 priority is the lowest, S3 ports will be in DP role and S2 & S4 ports goes into BLK mode.
* the cost to the root is equal, you can already guess, the decision will be made upon the lower BID. The switch with the lower BID will be the DP (Designated port..) for this link.
* Once STP is converged, each NONROOT switch MUST have only ONE Root port, and each segment between 2 nonroot switches have 1 Designated port, and the other side of the link will be in BLK mode. This is a great rule to remember.
* STP root bridge ports will be ALL in Designated role and FWD state. And NON of the root ports will be in "Root" role!
** LAB for practicing is available @ STPLab.rar
** STP Questions is available @ http://ccna.certify.googlepages.com/stpquestions