Solving Loops in the Network with STP (7 switch topology)

Meherchaitanya
6 min readJan 2, 2023

--

TL;DR

Looping is a problem caused by the configuration topology in the data link or the network layer. In the Data link layer, this is caused when switches are connected in a loop leading to multiple paths to reach a destination. Multiple paths can be caused either due to misconfiguration or to provide fault tolerance through redundancy. To eliminate loops, STP is a protocol that switches use. This article focuses on using a bigger topology to understand STP packets properly.

How Switch learns the network

The switch stores the MAC addresses learnt from the packets passing through the ports and in the forwarding table (also referred to as the CAM table). When a packet comes from a system, the source MAC address is stored in the forwarding table and, therefore, learns the ports associated with the MAC addresses.

But if there are multiple ports that the MAC address is associated with a standard switch would send the packets to both of its ports. In this process, if we have other switches connected in these ports, the

Looping in the switch that occurs when trying to send a packet from one switch to another in the presence of a loop

The above graphic shows that when a packet is supposed to reach a device in switch 2 from a device in switch 1, switch 1 has two ways to contact switch 2. So the switch sends the packet through both interfaces (ports). Once the packet reaches Switch 3, the packet can go back to Switch 1 and 2, leading to a packet being sent back to Switch 1.

With this, we reached our initial state and switch 1 sends the packet back to switch 3 leading to a loop in packets. This will cause inefficient bandwidth usage in the network; at some point, the switch will be overloaded and shut down.

Due to the TTL parameter in the network layer, the routers will drop the packets after some time, but there is no similar feature in the link layer and the data packet will be there in the network until restarted or the link is broken.

One simple solution is to remove these links not to have a loop. But this solution will remove the network fault tolerance feature for which we have multiple links. To solve this, a protocol called Spanning Tree Protocol (STP) exists. With the help of this protocol, the graph network of switches will be converted into an acyclic graph.

STP protocol with 7 switches

From the above topology of switches, if switch 1 is chosen the root Node assumes each link between switches is of the same cost (inversely proportional to bandwidth).

Once the root port is chosen, the ports connected to the root switch are set as designated port. The ports connected to the designated ports will be set as root port in this case meaning that this port is the connection link to the root switch with the lowest cost.

The same logic is extended to the neighbouring nodes with the root port

A loop that can be seen is that to reach the root switch from switch 3, it can directly go to switch 1 or switch 2 first and reach the root switch.

For tie-breaker, the path cost is first looked up, and it is obvious in this case the path to be chosen is the path directly connecting to the root switch as the path cost will be double the current path cost if the connection is maintained from switch 2.

For Switch 5, there is only one link so the Switch 3 port connecting to Switch 5 is set as the designated port, and the port in Switch 5 connection is set to the Root port.

Coming to switch 6, it has two paths, one from switch 4 and another from switch 3. The tiebreaker of the path cost fails in this case as both paths have the same propagation cost. In this case, the switch’s priority number is compared.

The priority numbers are written in the image under the switch name, and if the switch with a smaller cumulative value for the paths to be compared is low, that path is chosen.

So in this case, the switch 3 port is set as the designated port, and the switch 6 port connecting to switch 3 is set as the root port. The switch 4 port connecting to switch 6 will be set as the designated port, but the port of switch 6 connecting to switch 4 will be a blocked port meaning switch 6 won't forward (ignore) any packets being sent to this port.

Now it is the question for switch 7 and switch 8.

Switch 7 has two paths: switch 4 and switch 6, and switch 4 is a shorter path to the root switch. So the port connecting from switch 7 to switch 4 is set to the root port, and the port in switch 4 connecting to switch 7 is set as a designated port.

For switch 8, a similar question as switch 6 occurs as two paths have equal path costs (switch 3 → switch 6 or switch 4 → switch 7). So this tie-breaker fails, and the next tiebreaker is to compare the priority number, and the cumulative priority number leads to the port connecting switch 7 from switch 8 being the root port. So the port connecting switch 7 to switch 8 is set as the designated port. On the other hand port of switch 6 connecting to switch 8 is set as a designated port, but switch 8 connecting to switch 6 is set as the blocked port.

So the final topology will be devoid of loops virtually and in case a link breaks, the BDPU packets will stop coming to the switch, and the topology will change to a new spanning tree.

This summarizes the usage of the Spanning tree algorithm to block the switches from entering a networking loop. An example with more switches and complex linking between switches will better explain the logic of STP. Although this algorithm is simple, this is the basic protocol being discussed. Many of its disadvantages have been addressed by improved protocols like Rapid Spanning Tree Protocol (RSTP), Per VLAN Spanning Tree (PVST) and Rapid Per VLAN Spanning Tree (R-PVST+) that solves problems with the downtime of the links to recalculate the spanning tree and provide to allow multiple spanning trees for VLANs in a single switch.

References & other learning materials

--

--