Preventing network loops with Spanning-Tree Protocol (STP) 802.1d
Have you ever had a loop in your LAN? You don’t want one and neither do your users. A loop in your LAN can bring down the whole network. You can avoid a loop by using Spanning Tree protocol (STP). Let’s find out what Spanning Tree is, how it works, and how it can save your day by preventing a loop on your network.
What is Spanning Tree?
The Spanning Tree protocol is a networking standard, as defined by the IEEE in the 802.1d standard. The purpose of Spanning Tree is to prevent loops in the LAN and to select the fastest network links, if there are redundant links in the network. In the event that a link in the network goes down, Spanning Tree will failover to the alternate link, if one exists.
If this sounds like what a routing protocol does then you are on the right track. Routing protocols help devices route between WAN networks (prevent loops, use alternate paths, etc) at Layer 3. Spanning Tree could be termed a Layer 2 routing protocol for a LAN because it performs the same functions but for an Ethernet network, regardless of IP addresses. So, Spanning Tree is not an IP routing protocol but has some similar functions for the data-link layer (Layer 2).
How Spanning Tree works
Spanning Tree works by first using an algorithm to find redundant links in the LAN and selecting the best paths. Its initial goal is to put all links in either Forwarding or Blocking. In the end, the links without a redundant link and the best links with a redundant link would be in forwarding state. The redundant links that weren’t as good as the selected links would be in blocking state.
Spanning Tree cannot use multiple links to the same destination. There is no load-sharing feature with Spanning Tree. Any redundant link that is not as preferred is blocked (essentially shut down) until the primary link goes down.
Because Spanning Tree is a complex protocol, this article won’t cover every possible feature. We will, however, give you a solid overview of the protocol and its process.
The three criteria Spanning Tree uses to decide if an interface should be in forwarding state are:
All interfaces on the root bridge are put in forwarding state.
For other bridges that are not the root bridge, the port that is closest to the root bridge is put in forwarding state.
The bridge with the lowest administrative distance to the root bridge is called the designated bridge. The Ethernet interface on the designated bridge is called the designated port. That port is put into forwarding state.
But how is the root bridge elected? The root bridge is elected based on bridge ID (usually the MAC address) and a priority. By default, all priorities are the same so, by default, the switch with the lowest MAC address will become the root bridge.
How is the lowest administrative cost to the root bridge calculated? This is based on the speed of the links across the LAN, to get to that root bridge. STP uses default port costs to calculate this. These port costs can be overridden by an administrator. Here are the default STP port costs:
10Mb link – Cost is 100
100Mb link – Cost is 19
1Gb link – Cost is 4
10Gb link – Cost is 2
The costs shown are revised costs from the original STP default port costs. The IEEE did not anticipate the massive increase in speed now offered by Ethernet. Because of this 1Gb and 10Gb links could not be accommodated by the old default costs and the costs had to be revised.
How does STP prevent loops?
Because the “best ports” are put into forwarding state and the other ports are put into blocking state, there are no loops in the network. When a new switch is introduced to the network, the algorithm and port states are recalculated to prevent a new loop.
What happens when a link goes down?
Switches communicate with a BPDU (bridge protocol data unit) every 2 seconds. If the remote switch doesn’t respond, it is assumed that that switch (and its links) are down and the Spanning Tree algorithm is recalculated.
What are the STP port states?
Whenever a new port is enabled, Spanning Tree goes through the following port states to get that port to be either forwarding or blocking. They are:
Blocking – does not forward any frames but still receives BPDU’s from other switches
Listening – same as blocking but it is beginning its transition to forwarding frames. Unlike Blocking, in Listening mode, the port will send BPDU’s.
Learning – the second state in the transition to frame forwarding. In this state, the switch receives MAC address information from devices on this switch port.
Forwarding – transmits and receives frames. This is the normal state for a port.
Or, Disabled – the disabled state means that the switch port is administratively disabled.
Here is what we have learned:
STP is the Spanning Tree Protocol, also known as 802.1d
STP works on Ethernet LAN’s
STP prevents loops, selects the best LAN path, and provides redundancy if a link fails
Part of selecting the best path is calculating the best path to the root switch is calculating the link costs, based on the speed of the links.
A port can be in any of 5 states with STP – blocking, listening, learning, forwarding, and disabled.