STP - Spanning Tree Protocol Explained With Examples

A long ago, DCE developed the original version of STP (Spanning Tree Protocol). It is called DCE's STP. Later, IEEE developed an open-sourced version of STP. Cisco improved it for its switches. It is called PVST (Per VLAN Spanning Tree). PVST is similar to STP but has some additional features. Both use the same terminology and algorithm.

The main difference between STP and PVST is that PVST runs a separate instance for each VLAN. For example, if a network has five VLANs, PVST will run five instances, while STP will run only one instance. PVST is a Cisco-only feature. It runs only on Cisco switches. 

PVST/STP port states

Ports on a PVST/STP switch go through the following five states to reach convergency. 

  1. Disabled
  2. Blocking
  3. Listening
  4. Learning
  5. Forwarding

Disabled 

A disabled port is a port that is administratively disabled for various reasons. A disabled port does not participate in STP/PVST operation. A port in the disabled state is virtually nonoperational.

Blocking 

After excluding disabled ports, the switch starts all ports in the blocking state. In this state, the port does not accept user frames. It accepts only BPDUs. A BPDU is an STP frame. It includes all the information STP/PVST needs to learn and build the network topology. 

Listening 

In this state, the switch removes the old CAM table entries. Switches use CAM table entries to make forwarding decisions. Each CAM table entry has a default age-out timer. Once this timer is expired, the switch removes the entry. The switch uses this state to age out all old entries from the CAM table. In this state, the port only listens to BPDUs. It does not accept and forward user frames.

Learning

In this state, the switch builds the CAM table entries. In this state, the port accepts user frames but does not forward them. From the incoming frames, it learns the MAC addresses of the connected devices. It saves the learned MAC addresses in the CAM table.

Forwarding state

In the forwarding state, the switch accepts and forwards user frames.

Electing the root bridge

All STP/PVST running switches elect one switch as the root bridge. After electing the root bridge, they check all network paths. If a switch has more than one path to reach the root path, it chooses only one path to reach the root bridge. Apart from the root bridge, all other switches become non-bridge switches.

STP/PVST port types

There are three STP/PVST port types. These types are root, destinated, and disabled. A port can play only one role. A root port connects the non-root bridge switch to the root bridge switch. A designated port connects the non-root bridge switch to the local segment. A disabled port does not forward any user frames. It removes loops.

STP/PVST Packet Tracer LAB

Create a packet tracer lab, as shown in the following image.

packet tracer lab

Download Packet Tracer LAB

By default, all Cisco switches run STP. We can use the show spanning-tree command in privileged exec mode to verify it. The output of this command organizes information into four sections. 

First section

The first section contains two lines. It provides information about the VLAN. As mentioned earlier, Cisco switches run a separate STP instance for each VLAN. If you have more than one VLAN, the output will display information about each VLAN separately. The second line shows the STP variation. If you see IEEE in the output, it indicates the switch is running STP (if it is a non-Cisco switch) or PVST (if it is a Cisco switch).

Second section

The second section contains four lines. It provides information about the root bridge. The first line shows the priority value of the root bridge switch. The second line shows the MAC address of the root bridge switch. The third line shows the local switch's role in the topology. On a root bridge switch, it will show that this switch is a root bridge. On a non-root bridge switch, it will show the port's number that is connected to the root switch. The fourth line shows the STP timers.

Third section

The third section also contains four lines. It provides information about the local switch. The first line shows the priority value of the local switch. The second line shows the MAC address of the switch. On a root bridge switch, the first two lines of the first and second sections will be the same. The third line shows STP timers. The fourth line shows the aging time. The switch uses aging to age out old entries.

Fourth section

The fourth section provides information about the ports' state and their roles in the STP topology. 

The following image shows the output of this command on S1.

show spanning-tree

As we can see in the output, there is only one VLAN. The switch is running the PVST variation of STP. It is a root bridge.

The following image shows the output of this command on S2.

show spanning tree

As we can see in the above output, it is a non-root bridge. It is connected to the root bridge on the Gigabit 0/1 interface.

The following image shows the output of this command on S3.

show spanning tree

As we can see in the above output, it is also a non-root bridge. It is connected to the root bridge on the Gigabit 0/1 interface. The port 0/1 is disabled to remove the loop.

STP/PVST configuration

PVST is the default STP mode on all Cisco switches. In case you have changed it to RPVST, you can use the spanning-tree mode command to revert it. The following command changes the STP mode to PVST.

Router(config)#spanning-tree mode rapid-pvst

change stp mode

Conclusion

STP/PVST dynamically manages all links. If a link creates a loop, it blocks the connected port. If a link goes down, it automatically enables the backup link to maintain the connectivity.

ComputerNetworkingNotes CCNA Study Guide STP - Spanning Tree Protocol Explained With Examples