Spanning tree protocol (STP) is a Layer 2 network protocol used to prevent looping within a network topology. STP was created to avoid the problems that arise when computers compete for the ability to use the shared telecommunications path on a local area network (LAN). When too many computers try to send at the same time, overall network performance is affected and can bring all traffic to a near halt.
STP prevents the condition known as bridge looping. To reduce the likelihood of looping, a LAN can be divided into two or more network segments with a device called a bridge connecting any two segments. Each message (called a frame) goes through the bridge before being sent to the intended destination. The bridge determines whether the message is for a destination within the same segment as the sender's or for the other segment, and forwards accordingly. A bridge looks at the destination address and, based on its understanding of the two segments (which computers are on which segments), forwards it on the right path (which means to the correct outgoing port). The benefit of network segmentation (and the bridge) is that the amount of competition for use of the network path is reduced by half (assuming each segment has the same number of computers) and the possibility of the network coming to a halt is significantly reduced.Content Continues Below
Each bridge learns which computers are on which segment by sending any first-time message to both segments (this is known as flooding) and then noticing and recording the segment from which a computer replied to the message. Gradually, the bridge builds a picture for itself of which computers are in which segments. When a second and subsequent messages are sent, the bridge can use its table to determine which segment to forward it to. The approach of allowing the bridge to learn the network through experience is known as transparent bridging (meaning that bridging does not require setup by an administrator).
In order to build into a network, it is typical to add a second bridge between two segments as a backup in case the primary bridge fails. Both bridges need to continually understand the topography of the network, even though only one is actually forwarding messages. And both bridges need to have some way to understand which bridge is the primary one. To do this, they have a separate path connection just between the bridges in which they exchange information, using bridge protocol data units (BPDUs). BPDUs are data messages exchanged across switches within an extended LAN that uses a spanning tree protocol.
The program in each bridge that allows it to determine how to use the protocol is known as the spanning tree algorithm. The algorithm is specifically constructed to avoid bridge loops (multiple paths linking one segment to another, resulting in an infinite loop situation). The algorithm is responsible for a bridge using only the most efficient path when faced with multiple paths. If the best path fails, the algorithm recalculates the network and finds the next best route.
How STP works
The spanning tree algorithm determines the network (which computer hosts are in which segment) and this data is exchanged using BPDUs. It is broken down into two steps:
Step 1: The algorithm determines the best message a bridge can send by evaluating the configuration messages it has received and choosing the best option.
Step 2: Once it selects the top message for a particular bridge to send, it compares its choice with possible configuration messages from the non-root-connections it has. If the best option from step 1 isn't better than what it receives from the non-root-connections, it will prune that port.
The spanning tree protocol and algorithm were developed by a committee of the Institute of Electrical and Electronics Engineers (IEEE). As of 2019, the six STPs are:
STP/ IEEE 802.1D - The original STP version. Sometimes referred to as Common Spanning Tree (CST).
Per-VLAN Spanning Tree (PVST+) - Cisco’s improvement of STP that operates a separate 802.1D spanning-tree instance for each VLAN configured in the network.
802.1D-2004 - An updated version of the STP standard that incorporates IEEE 802.1w.
Rapid Spanning Tree Protocol (RSTP) or IEEE 802.1w - An evolution of STP 802.1D that addresses the STP convergence time gap issue with enhanced BPDU exchange.
Rapid PVST+ - Cisco’s improvement of RSTP. Rapid PVST+ provides a separate instance of 802.1w per VLAN, allowing for faster convergence times.
Multiple Spanning Tree Protocol (MSTP) or 802.1s - MSTP maps multiple VLANs into the same spanning tree to reduce processing on the switch.
To enable STP on a switch, an administrator connects to the switch by typing spanning-tree mode <selected mode> in global configuration mode. The network administrator then adjusts spanning tree operation to control its behavior by first electing a root bridge, which becomes the central reference point for STP. Next, the administrator will identify root ports and designated ports.
The MicroNugget video: How to Configure Spanning Tree Protocol offers an overview of STP configuration.
- Easy to use.
- Proven technology.
- Offers wide support for bridges and switches.
- Provides link redundancy while simultaneously preventing undesirable loops.
- Offers various backups that become active if the main connection experiences hiccups.
- As data centers increase use of virtualization technology, STP may not be able to handle increased input/output (I/O) demands.
- Full network capacity is not realized when using STP. Even when there are equal-cost multiple paths on a network, all traffic flows along a single path as defined by a spanning tree. This restriction of traffic means alternative, and perhaps more direct, paths are blocked.
Alternatives to spanning tree protocol
TRILL is an Internet Engineering Task Force (IETF) protocol standard that uses Layer 3 (network layer) routing techniques to create a cloud of links that appear to Internet Protocol (IP) nodes as a single IP subnet. TRILL uses shortest path routing protocols and can be used at the same time as STP. The main benefit of TRILL is that it frees up network capacity. Shortest path routing improves efficiency and decreases the cost-to-benefit ratio. Data centers running a cloud computing infrastructure may choose TRILL because it provides faster recovery time than STP should hardware fail.
Similar to TRILL, the other key alternative to STP is Shortest Path Bridging. SPB (802.1aq) was co-developed by the IEEE and the IETF, and combines the effectiveness of Multiprotocol Label Switching (MPLS) with the efficiency of Ethernet. SPB is backwards compatible with spanning tree.