In switched networks with a physical loop, switches run STP to automatically generate a loop-free topology. Such a topology is known as an STP tree. The STP tree can contain only one root bridge; each of the other bridges connects to this root bridge through only one active path (which is the optimal path). In the STP tree generation process, a root bridge is first elected, then a root port (RP) and a designated port (DP) are elected, and then the alternate port (AP) is blocked. If the network topology changes, STP automatically updates the tree accordingly.
Byte 1
Bridge priority Bridge MAC address
BID
Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 Byte 7 Byte 8
Fig. 4.2 BID structure
Byte 1
Port priority Port No.
PID
Bits 1to 4
Port priority Port No.
PID
Bits 5 to 16 Byte 2 Definition 1
Definition 2
Fig. 4.3 PID composition
4.2.1
Root Bridge Election
Before an STP tree can be generated, a root bridge must be elected. A root bridge is the logical (not necessarily the physical) center of an entire switched network. Changes to the network topology may change the root bridge.
Switches running STP (we’ll refer to such switches as STP switches) exchange STP frames, the payload data of which is known as bridge protocol data units (BPDUs). A BPDU contains STP-specific information, including the BID. However, despite STP frames carrying this data unit, a BPDU is not a network layer unit of data (We’ll describe BPDUs in Sect.4.3). The BPDU producer, receiver, and processor are all STP switches rather than computers.
After bootup, all STP switches assume that they are the root bridge. They announce this assumption in the BPUDs that they send to other switches. Upon receiving such a BPDU, the switch compares its own BID with that of the root bridge specified in the BPDU. The switches continue to exchange and compare BPDUs until the switch with the smallest BID is elected as the root bridge.
In Fig.4.4, switches S1, S2, and S3 all use the default bridge priority of 32,768. However, because S1’s BID is the smallest, it will be elected as the root bridge.
GE0/0/1 GE0/0/2 GE0/0/1 GE0/0/1 GE0/0/2 GE0/0/2 S3 S2 S1 BPDU Default priority: 32768
Bridge MAC address: 0016-0016-3333 BID: 8000-0016-0016-3333
Default priority: 32768
Bridge MAC address: 0016-0016-2222 BID: 8000-0016-0016-2222
Default priority: 32768
Bridge MAC address: 0016-0016-1111 BID: 8000-0016-0016-1111
Fig. 4.4 Root bridge election
4.2.2
Root Port Election
Bridges other than the root bridge are known as non-root bridges. Each non-root bridge may have multiple ports connected to the network, so to ensure that each non-root bridge has only one active path (the optimal path) to the root bridge, one “root port” must be elected per non-root bridge. The non-root bridge uses the root port to exchange packets with the root bridge.
STP elects the root port based on root path cost (RPC), which is the total cost of all the links along the path from a port to the root bridge. Path cost is related to the port rate, and the faster the port forwarding, the lower the path cost. Table4.1lists this relationship.
NOTE
The values and their relationship specified in this table are defined in IEEE 802.1t. However, the values used in real-world scenarios may differ from vendor to vendor. Based on Fig.4.5, assume that S1 is the root bridge and that the path cost adheres to IEEE 802.1t. S3 must elect either GE0/0/1 or GE0/0/2 as the root port. Because the RPC of GE0/0/1 is 20000 and that of GE0/0/2 is 200,000 + 20,000 = 220,000, S1 elects GE0/0/1 as its root port.
However, different ports on a non-root bridge device may have the same RPC. In such a scenario, the process shown in Fig.4.6is used to elect the root port.
In Fig.4.7, S1 is the root bridge. Assume that the RPC of S4’s GE0/0/1 and GE0/0/2 are the same. S4 compares the BID of S2 and S3. If S2’s BID is smaller
Table 4.1 Port rate to path
cost relationship Port rate Path cost (IEEE 802.1t standard)
10 Mbps 2,000,000 100 Mbps 200,000 1 Gbps 20,000 10 Gbps 2000 GE0/0/2 GE0/0/1 GE0/0/1 GE0/0/2 GE0/0/2 S3 S2 S1 Port rate 1 Gbps Port rate 1 Gbps Port rate 100 Mbps Root bridge Path 1 Path 2 GE0/0/1
Fig. 4.5 Root port election (different RPCs)
than S3’s BID, S4 elects GE0/0/1 as its root port; or, if S3’s BID is smaller than S2’s BID, S4 elects GE0/0/2 as its root port. For S5, assume that the RPC of its GE0/0/1 and GE0/0/2 are the same. Because these two ports are connected to the same device (S4), S5 compares the PID of S4’s GE0/0/3 and GE0/0/4. If the PID of GE0/0/3 is smaller than that of GE0/0/4, S5 elects GE0/0/1 as its root port; or, if the PID of S4’s GE0/0/4 is smaller than that of S4’s GE0/0/3, S5 elects GE0/0/2 as its root port.
4.2.3
Designated Port Election
A root port ensures that a switch has only one active path (the optimal path) to the root bridge. To prevent loops, each network segment must have only one active path (the optimal path) to the root bridge. If a network segment has two or more such paths (for example, the network segment is connected to different switches or different ports on the same switch), the corresponding switch or switches must have only one designated port.
The designated port is elected by comparing RPC. The port with the smallest RPC is elected as such. If the RPC is the same, the BID and PID must be compared. For details, see Fig.4.8.
Equal RPC
Different BIDs Compare the BID of the upstream device
The port connected to an upstream device with a smaller PID is elected as the root port. Equal BID
The port connected to an upstream device with a smaller BID is elected as the root port.
Fig. 4.6 Root port election process (same RPC)
S1 S2 S3 S4 S5 GE0/0/1 GE0/0/1 GE0/0/2 GE0/0/2 GE0/0/3 GE0/0/4 Path 1 Path 2 Root bridge GE0/0/1 GE0/0/2
Fig. 4.7 Root port election (same RPC)
Based on Fig.4.9, assume that S1 is the root bridge and that the costs of all links are the same. S3’s GE0/0/1 has a smaller RPC than that of GE0/0/2, so S3 elects GE0/0/1as its root port. Similarly, S2’s GE0/0/1 has a smaller RPC than that of GE0/0/2, so S2 elects GE0/0/1 as its root port.
For the network segment between S3’s GE0/0/2 and S2’s GE0/0/2, S3’s GE0/0/2 and S2’s GE0/0/2 have the same RPC, so S3’s BID and S2’s BID must be compared. If S2’s BID is smaller than S3’s BID, S2’s GE0/0/2 will be elected as the designated port for the network segment between S3’s GE0/0/2 and S2’s GE0/0/2. Network segment LAN1 is connected only to S2. As such, only the PIDs of S2’s GE0/0/3 and GE0/0/4 need to be compared. If GE0/0/3 has a smaller PID than GE0/0/4, S2’s GE0/0/3 will be elected as the designated port for the network segment LAN1.
Finally, it must be noted that there are no root ports on the root bridge and only designated ports. Consider for a moment why this might be.
Equal RPC Alternate port Designated port Smaller PID Larger BID Compare BID Equal BID Compare PID Designated port Smaller BID Alternate port Larger PID
Fig. 4.8 Designated port election (same RPC)
GE0/0/3 GE0/0/1 GE0/0/2 GE0/0/1 GE0/0/1 GE0/0/2 GE0/0/2 S3 S2 S1 Designated port Root port Root bridge Designated port Root port Designated port LAN1 GE0/0/4 Designated port
Fig. 4.9 Designated port election (same RPC)
4.2.4
Alternate Port Blocking
All ports other than the root port and designated port on a switch are collectively known as alternate ports. STP logically blocks these alternate ports, which prevents them from forwarding user frames (frames generated and sent from computers). However, these ports can receive and process STP frames. The root and designated ports can forward user data frames in addition to sending and receiving STP frames. Logically blocking the alternate ports completes the STP tree (loop-free topol- ogy) generation process. Figure4.10 shows the blocked ports.