Spanning Tree Protocol (STP)

Spanning Tree Protocol (STP) is a Data link layer (layer 2) protocol that is used to discover and maintain a valid loop-free path for the switched network. It is also used to analyze the port speed in the topology and determine which port should be open and which port should be closed in order to provide a loop-free network.

Note: Switching loops are called as "bridging loops", even for those networks also that do not have a bridge.

We need to avoid the loops because due to loops, MAC address table entries continuously change which results that some or all packets never reach to their intended destination. Loops also generate an unnecessary strain on our switched CPUs.

Note: In real-world networking, switching loops do not often occur, because for preventing the loops, STP uses Spanning-tree algorithm.

Spanning Tree Terms

There are the following spanning tree terms that we used within layer 2 switched networks:

Root Bridge

A Root Bridge is the starting point of the STP topology. To elect a Root Bridge from all switches of the network, STP uses two parameters:

  • A variable known as bridge priority
  • The MAC addresses of participating switches

A switch that has the lowest priority values is elected as the Root Bridge. If the priority values are the same in all switches, then the switch which has the lowest MAC address is elected as the Root Bridge.

Non-Root Bridge

Except Root Bridge, all switches in the network are known as the Non-Root Bridge. These Bridges receive updates from the Root Bridges.

BPDU

BPDU stands for Bridge Protocol Data Unit. It protects the port from receiving STP BPDUs.

Bridge ID (BID)

BID is used to identify each bridge/switch on the network.

Bridge ID = Bridge Priority (16-bits) + MAC Address (48-bits)

Nonroot bridges

Nonroot bridges are used for exchanging BPDUs with all bridges, updating the STP topology database on all switches, preventing loops, and providing a measure of defence against link failure.

Port cost

Port cost is used to determine the best path when multiple links are used between two switches. It is a local value and not advertised to upstream or downstream switches.

The following table shows the port cost value:

Bandwidth Old Cost Value New Cost Value
10 Gbps 1 2
1 Gbps 1 4
100 Mbps 10 19
10 Mbps 100 100

Root port

The Root port is directly connected to the Root Bridge. It has the lowest path cost. If more than one links are connected to the root bridge, then the port cost is determined by checking the bandwidth of each link.

Designated port

A designated port is used to the best (lowest) cost to the root bridge via its root port. The designated port will be marked as a forwarding port.

Nondesignated port

A Nondesignated port has a higher cost than a designated port.

Forwarding port

A forwarding port forward and receive frames, send and receive BPDUs, and continuously learn the MAC addresses.

Blocked port

A blocking port is a port in which no frame is forwarded, no frame is received, and therefore no dynamic learning of the MAC addresses. A blocked port will always accept BPDUs from neighboring switches.

Spanning Tree Operations

Spanning-Tree Port States

There are the following Spanning tree port states:

Blocking

A blocked port does not forward the frames. It only listens to the BPDUs. The main purpose of the blocking state is to prevent the use of looped paths. When we power ON the switch, all ports are in the blocking state by default.

Listening

A listening port is neither forwarding the frames nor learning the MAC addresses.

Learning

A learning port is not forwarding the frames, but it is learning the MAC addresses.

Forwarding

A forwarding port forward and receive frames, send and receive BPDUs, and continuously learn the MAC addresses.

Disable

A port is in the disable state if it does not participate in the frame forwarding or STP.

Convergence

Spanning Tree PortFast

The Spanning Tree PortFast is introduced to avoid the network connectivity issues. Enabling the PortFast causes the switch or trunk port to enter the STP forwarding-state immediately.

Spanning Tree UplinkFast

UplinkFast is used to improve the convergence time of STP in case of a link failure. The spanning-tree UplinkFast feature is designed to run in a switched environment when the switch has at least one alternate backup root port.

It allows a switch to find alternate paths for the root bridge. If the primary link fails, the secondary link will come up more quickly.

Spanning Tree BackboneFast

Spanning tree BackboneFast is used for speeding up the convergence when a link is not directly connected to the switch. If a switch running in the BackboneFast receives an inferior BPDU from its designated bridge, it knows that a link on the path to the root has failed. BackboneFast is also beneficial because it starts the spanning tree configuration more quickly.