Site is Under Maintenance
Please come back again in...
00 Days
00 Hours
00 Minutes
00 Seconds

Spanning-Tree Cost Calculation

As we learned from the previous tutorial, "Introduction to Spanning-Tree Protocol (STP)," non-root bridges must identify the shortest path to the root bridge, but what happens when there's a mix of different interface types, such as Ethernet, FastEthernet, and Gigabit? Let's explore this scenario together!

In the following topology, we'll examine how Spanning-Tree calculates the cost associated with each interface type, which ultimately influences the path select to the root bridge. By understanding these cost calculations, you can effectively manage and optimize your network's spanning-tree configuration. Let's take a look, shall we?



In the diagram above, we have a larger network comprising multiple switches, each with different interface types: Ethernet (10 Mbit), FastEthernet (100 Mbit), and Gigabit (1000 Mbit). SW1 at the top is the root bridge, while all other switches are non-root and need to determine the shortest path to it.

The Spanning-Tree Protocol (STP) assigns costs to interfaces based on their bandwidth allocations, as follows:
  • Bandwidth: 10 Mbit / Cost = 100
  • Bandwidth: 100 Mbit / Cost = 19
  • Bandwidth: 1000Mbit / Cost = 4
Spanning-Tree uses these costs to calculate the shortest path to the root bridge, with slower interfaces having higher costs to get there. The path with the lowest total cost is selected for communications with the root bridge.

The cost value can be found in the BPDU, specifically in the "root path cost" field. Each switch inserts the cost of its shortest path to the root bridge here. Once the switches identify which one is the root bridge, they will determine the shortest paths, with BPDUs flowing from the root bridge down to all other switches.

If you've ever studied for the CCNA or CCNP, you might find the concept of the Spanning-Tree cost familiar. Similar to Spanning-Tree, OSFP (Open Shortest Path First) also uses cost to determine the shortest path to its destination; however, there's a significant difference between the two protocols. Allow me to explain:

You see, OSPF builds a topology database called the Link-State Database, or LSDB, that allows all routers to have a comprehensive view of the network's structure. In contrast, Spanning-Tree is more reactive in that switches do not have a complete understanding of the topology. Instead, BPDUs flow from the root bridge down to all switches, which then make their decisions based on the information contained in the received BPDUs. This means that STP relies on local information rather than a global overview of the network as does OSPF.

The way STP operates without a complete overview of the network topology makes it crucial for switches to respond quickly to changes. When a network topology change occurs, such as a new switch being added or a link going down, the switches rely on the BPDUs to reevaluate their roles and port states.

When a switch receives a BPDU, it updates its information based on the cost metrics that are included within it. This can trigger recalculations of the shortest paths to the root bridge, potentially leading to a new election of designated ports or even a new root bridge if the current root fails.

In environments where rapid changes are common, such as in large networks or those with many redundant links, enhancements to the original STP, like Rapid Spanning-Tree Protocol (RSTP) or Multiple Spanning-Tree Protocol (MSTP) (which will be covered in subsequent tutorials), can be beneficial. Why? Because these protocols reduce convergence times significantly, allowing networks to adapt more quickly and more swiftly to changes while maintaining and avoiding loop-free technologies.

By understanding the many nuances of STP and its cost calculations, as well as its limitations compared to protocols like OSPF, you can better manage and design resilient and efficient networks. This knowledge is invaluable for troubleshooting and optimizing network performance in real-world scenarios.

Let's take a look at the different STP costs for our topology:



SW2 will choose the direct link to SW1 as its root port because it's a 100 Mbit interface, which has a cost of 19. As a result, SW2 will forward BPDUs towards SW4, and the root path cost field in the BPDU will reflect a cost of 19.

Meanwhile, SW3 is also receiving BPDUs from SW1. Given the current configuration above, SW3 may select its 10 Mbit interface as its root port, despite its higher cost of 100. This decision is based on the available BPDUs and the paths being assessed.

As BPDUs continue to propagate throughout the network, each switch will intelligently make decisions based on the costs and roles assigned. This iterative process ensures that all switches eventually converge on a stable topology, with the optimal paths to the root bridge established. Let's proceed to analyze the next steps in the STP process!


Let's break down the above diagram for brevity and clarity:

1. SW3 receives BPDUs on its two interfaces: a 10 Mbit interface (cost 100) and a 1000 Mbit interface (cost 4). It will select the 1000 Mbit interface as its root port since it provides the shortest path to the root bridge, resulting in a cumulative root path cost of 42 (19 from SW2 + 19 to SW1 + 4 to SW3).

2. SW3 forwards BPDUs to SW4 with a root path cost of 100.

3. SW4 receives two BPDUs:
  • One from SW2 with a root path cost of 19.
  • One from SW3 with a root path cost of 100.
Since the path through SW2 is shorter, SW4 will select SW2 as its root port.

4. SW4 then forwards BPDUs towards SW3 and SW5. In the root path cost field of the BPDU sent to SW3, the cost will be 38 (its root path cost of 19 plus the interface cost of 19).

5. SW3 forwards BPDUs towards SW5, including a root path cost of 42 (19 from SW2 + 19 to SW3 + 4 to SW5).

This is how BPDUs propagate throughout the network, allowing each switch to determine its optimal path to the root bridge based on the accumulated costs. The resulting topology will ensure efficient and loop-free communications across the network.

The complete picture will look like this:


SW5 receives BPDUs from both SW3 and SW4. In the BPDU, we can observe the following information in the root path cost field:
  • BPDU from SW3: cost 42
  • BPDU from SW4: cost 38
To determine its root port, SW5 will calculate the total cost to reach the root bridge via each switch. It adds the cost of its interface towards SW4 (19 for the 100 Mbit interface), resulting in a total cost of 57 (38 from SW4 + 19 for its interface).

Conversely, for SW3, the total cost is significantly higher: 42 (from SW3) plus 100 (for the 10 Mbit interface), totaling 142. Consequently, SW5 selects the interface towards SW4 as its root port due to the lower cost.

Are you following along? It's important to remember that switches base their intelligent decision-making solely on the BPDUs they receive. They lack a complete view of the network topology (keep that in mind). The best BPDU is simply the one that indicates the shortest path to the root bridge.

Now, what happens if the costs are equal?

In that case, the switch will break the tie using the MAC addresses of the switches sending the BPDUs. The switch will prefer the BPDU from the switch with the lower MAC address, ensuring a consistent decision-making process even when the costs are not the same.



In the diagram above, SW1 is the root bridge, and SW2 is a non-root bridge with two links connecting to SW1, creating redundancy and potential loops. Since STP needs to prevent looping, it will block one of the interfaces on SW2. 

When SW2 receives BPDUs on both interfaces, the root path cost field will be identical for both links. Since the costs are equal, STP will use port priority as the next criterion for determining which interface to block. By default, all interfaces typically have the same priority, leading to a tie.

In this case, the interface number becomes the deciding factor. The interface with the higher number will be blocked. For example, if Fa0/1 and Fa0/2 are the two interfaces, SW2 will block Fa0/2 since it has a higher number. This method ensures that the STP effectively manages redundancy while maintaining a loop-free topology.

The lowest interface number will indeed be chosen, so in this case, Fa0/2 will be blocked. Port priority is a configurable value, allowing you to dictate which interface will be blocked based on your network design preferences, and I'll demonstrate how to adjust this in subsequent STP tutorials.

Whenever STP needs to make a decision, it follows this hierarchy:

1. Lowest Bridge ID: The switch with the lowest bridge ID is elected as the root bridge.

2. Lowest Path Cost to Root Bridge: If a switch receives multiple BPDUs, it will select the interface with the lowest cost to reach the root bridge as its root port.

3. Lowest Sender Bridge ID: If two switches connect to a switch and both paths have the same cost to the root bridge, the switch will choose the interface leading to the switch with the lowest bridge ID.

4. Lowest Sender Port ID: If there are two interfaces connecting to the same switch with equal cost to the root bridge, the switch will prefer the interface with the lower number as the root port.

This decision-making process on behalf of the switches is essential for, again, maintaining a loop-free topology. It's worth noting and remembering these criteria, as they form the foundation of STP functionality. I hope this clarifies the STP cost calculation for you!

Happy STP Cost Calculating!


Rate This Article

Thanks for reading: Spanning-Tree Cost Calculation, Sorry, my English is bad:)

Getting Info...

About the Author

I'm Aevon...Just a gal with an insane passion for all things cybersecurity. 17 years in the industry and still love what I'm doing.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.