How Spanning Tree Protocol Works – Fully Explained

How Spanning Tree Protocol Works – Fully Explained

Ethernet networks are vulnerable to broadcast storms. However, loops are necessary in an Ethernet network because they offer backup routes in the event that a link fails.Both of these problems are solved by spanning-tree protocols because they offer link redundancy while also avoiding loops.

Through the use of the Spanning Tree Protocol (STP), Rapid Spanning Tree Protocol (RSTP), Multiple Spanning Tree Protocol (MSTP), and VLAN Spanning Tree Protocol, Juniper Networks devices provide Layer 2 loop prevention (VSTP). On Ethernet networks, RSTP is the standard spanning-tree protocol used to avoid loops. If you want to What is Spanning Tree Protocol here’s an ultimate guide for it.

Spanning Tree Protocols: Advantages

The advantages of spanning tree protocols are as follows:

  • Link redundancy is provided while avoiding undesirable loops.
  • Keep broadcast storms at bay
  • Uses edge ports to connect to non-STP-capable devices like PCs, servers, routers, and hubs that are not connected to other switches.

Broadcast storm prevention is aided by spanning tree protocols.

By building a tree topology (spanning tree) of the entire bridged network with only one accessible path connecting the tree root and a leaf, spanning-tree protocols cleverly avoid loops in a network. 

All alternate routes are compelled to go into standby. The spanning-tree algorithm (STA) chooses the network switch known as the tree root to use when determining the best route between bridges located throughout the network and the root bridge. Frames move along branches of the network to their destination, a leaf like an end-user PC. A network link between bridges is represented by a tree branch. Designated bridges are switches that forward frames through a STP spanning tree.


By setting force-version to the original IEEE 802.1D Spanning Tree Protocol (STP) version rather than RSTP or VSTP, the Junos OS for EX Series and QFX Series switches with support for the Enhanced Layer 2 Software (ELS) configuration style will run in place of RSTP or VSTP.

Participation in the Spanning Tree Is Determined by Port Roles
Each port has a state as well as a role. How a port participates in the spanning tree depends on its role. The five port roles that RSTP employs are:

  • The root bridge’s nearest port is known as the root port (has the lowest path cost from a bridge). Only this port is capable of receiving frames from and sending them to the root bridge.
  • The port that directs traffic away from the root bridge and toward a leaf is known as a designated port. Every link connection that a designated bridge serves has a corresponding designated port. Frames from all of the root bridge’s ports, which act as designated ports, are forwarded.
  • Alternate port: A port that offers a different route to the root bridge in the event that the root port fails and enters the discarding state. Although this port is not a part of the active spanning tree, it takes over right away if the root port fails.
  • In the event that a designated port fails and enters the discarding state, a backup port acts as a fallback path toward the spanning tree’s leaves. Only when two or more bridge ports are connected to the same LAN and the bridge is acting as the designated bridge can there be a backup port. If a designated port fails, a backup port takes over right away.
  • Port that has been disabled is not a part of the active spanning tree.

Port States Control a Port’s Frame Processing.

Every port has a role and a state. How a port handles a frame depends on its state.  Each port of a specific bridge is assigned to one of three states by RSTP:

  • Discarding – All BPDUs are discarded by the port. A port in this state does not learn MAC addresses and discards every frame it receives
  •  Learning—The port builds its MAC address table by examining received frames for location data as it gets ready to forward traffic.
  • Forwarding – Filtering and frame forwarding are both done by the port. The active spanning tree includes a port that is in the forwarding state.

Devices that Cannot Be Part of a Spanning Tree Are Connected by Edge Ports
An edge port is a designated port that connects to non-STP-capable devices like PCs, servers, routers, or hubs that are not connected to other switches, according to the definition of spanning tree. Edge ports can instantly switch to the forwarding state because they are directly connected to end stations, which prevents them from forming network loops. Edge ports can be manually configured, and a switch can also identify edge ports by observing when the end stations aren’t communicating.

In fact, BPDUs are sent to the spanning tree by the edge ports themselves. If you want to change RSTP on the edge port interface and are aware of the effects it will have on your network.

BPDUs upkeep of the spanning tree

Bridge protocol data units (BPDUs), which are frames, are used by spanning-tree protocols to establish and maintain the spanning tree. A BPDU frame is a message that switches send to each other to exchange data about themselves, including their bridge IDs, root path costs, and port MAC addresses. The root bridge is decided by the initial BPDU exchange between switches. The cost of each link between branch devices is simultaneously communicated using BPDUs and is dependent on port speed or user configuration. By calculating the best path for data frames to take between two leaves using this path cost, RSTP can then block all other options. A regular RSTP port is automatically switched to when an edge port receives a BPDU.
When all ports are in either a forwarding or blocking state and the spanning-tree algorithm (STA) identifies the root and designated bridges, the network is in a steady state, at which point the spanning tree converges. The root bridge keeps sending BPDUs at a hello time interval to maintain the tree (default 2 seconds). The current tree topology is still being communicated by these BPDUs. A port compares the data from a hello BPDU with the data already saved for the receiving port. When a switch receives a BPDU, one of three things happens:

  • The port resets a counter called max age to zero and then sends a new BPDU with information about the most recent active topology to the following port in the spanning tree if the BPDU data matches an existing entry in the MAC address table.
  • If the topology in the BPDU has changed, the MAC address table is updated, max age is reset to 0, and a new BPDU is forwarded to the following port in the spanning tree with the information from the active topology at that time.
  • One of two responses occurs when a port does not receive a BPDU after three hellos. The spanning tree is completely reworked if the port is the root port—see RSTP Root Bridge Failure. The connected device cannot send BPDUs if the bridge is any non-root bridge, so RSTP transforms that port into an edge port.

Failure of a Root Bridge

A flag known as a topology change notification (TCN) is added to the BPDU when a link to the root port fails. The MAC address table is flushed and the BPDU is sent to the following bridge when this BPDU reaches the following port in the VLAN. All of the VLAN’s ports have finally flushed their MAC address tables. The new root port is then configured by RSTP. After an exchange of BPDUs known as the proposal-agreement handshake, the alternate or backup port takes control when a root port or a designated port fails. Point-to-point links, which are dedicated connections between two network nodes or switches that connect one port to another, are how RSTP propagates this handshake. To ensure a loop-free topology, if a local port changes to a new root or designated port, it negotiates a quick transition with the receiving port on the closest neighbouring switch using the proposal-agreement handshake.

MAC Addresses Must Be Relearned by Devices Following a Link Failure

The network might be slower as it floods to relearn the MAC addresses because a link failure forces all associated ports to flush their MAC address tables. This relearning procedure can be sped up. The Layer 2 forwarding table of switches is flushed during TCN propagation, causing a deluge of data packets. The switch sends proactive ARP requests for IP addresses in the ARP cache thanks to the Address Resolution Protocol (ARP) feature (present because of Layer 3 VLAN interface). As the response comes in, switches with ARP on STP enabled build up the Layer 2 forwarding table, preventing flooding later. The best way to avoid excessive flooding in expansive Layer 2 networks using RVIs is to enable ARP on STP.


For EX Series switches that support the Enhanced Layer 2 Software (ELS) configuration style, the ARP feature is not available on the Junos OS.

Leave a Reply

Your email address will not be published.