In order to understand the nuts and bolts of Spanning-Tree Protocol (STP), we need to get familiar with its terminology first.
Spanning-Tree Protocol Terminology
The ports participating in STP play different roles and those roles use different states of operation.
Spanning-Tree Port Roles
- Root Port (RP) - It is a port on a non-root switch, which is the shortest (the best) path towards the root bridge. Root bridge does NOT have any root ports. (no shortest path to itself ;-))
- Designated Port (DP) - It is a port that is in the forwarding state. All ports of the root bridge are designated ports (they are never in a blocking state). BPDU frames our sent out this port.
- Non-Designated Port (NDP) - It is a port that is in a blocking state in the STP topology.
Spanning-Tree Port States
- Disabled - The port in this state does not participate in the STP operation (it is shut down).
- Blocking - The port does NOT forward any Ethernet frames, does NOT accept any Ethernet frames (discards arriving frames), does NOT learn any MAC addresses. However, theport DOES process BPDU frames received from a neighboring switch. If the port transitions to this state (blocking), it can stay blocked for 20 seconds by default (max_age).
- Listening - The port in this state CAN send and receive the BPDU frames. However, the port in this state does NOT learn any MAC addresses, and does NOT forward or process incoming frames either. All Ethernet frames are being discarded. The computation of loop free topology takes place in this state. If the port transitions to this state (listening), it can stay in this state for 15 seconds by default (forward_delay).
- Learning - The port in this state already knows its role (root port or designated port ) in the STP domain. However, the port will not forward any Ethernet frames yet. It will be learning MAC addresses from the frames arriving at the port in order to populate MAC address table. This helps avoid too much flooding when the port transition to the forwarding state. If the port transitions to this state (learning), it can stay in this state for 15 seconds by default (forward_delay).
- Forwarding - The port in this state will forward all Ethernet frames as per switch operation. Also, the port will process all incoming Ethernet frames and will actively learn MAC addresses from the arriving traffic.
Bridges and switches are functionally the same devices. I will use both terms interchangeably.
As soon as you familiarize yourself with STP port roles and port states, it is time to explain how Spanning-Tree Protocol works.
Pic. 1 - STP Port Terminology
STP (IEEE 802.1d) Principles of Operation
STP will use three stages to compute loop free topology (pic. 2):
- Single root bridge election.
- Each non-root switch to select a single best port towards the root (root port).
- Each non-root switch to select a single forwarding port per segment (designated port).
Pic. 2 - STP Overview
Bridge Protocol Data Unit (BPDU)
All switches communicate with one another using special frames called BPDU. Those frames contain multiple parameters that switches are going to process in order to create and maintain loop free topology.
Root bridge is the switch that has all ports working in the designated role. It will be the reference point from which the loop free topology is computed. Root bridge will impose the timers that other switches will use such as:
- hello time - how often BPDUs are going to be sent/relayed (default timer=2 seconds),
- max age - how long the configuration is valid (default timer=20 seconds),
- forward delay - how long a port should be in listening/learning state (default timer=15 seconds).
1. Root Bridge Election
Only one switch in the layer 2 network becomes the root bridge. This is how standard was defined and is known as the Common Spanning-Tree approach (CST). Cisco changed that paradigm and introduced Per Vlan Spanning-Tree approach (PVST+). Cisco switches elect a single root switch per VLAN so, in theory each VLAN could have its own root bridge.
Root election is based on a single parameter that is found in the BPDU frame called: Bridge ID. The switch with the lowest Bridge ID becomes the root. Bridge ID has the following format:
Priority is configurable parameter that is used to elect the root bridge a device you want to be the root. The default value is: 32768. The lower the value is the more likely for a switch to become a root.
Base Mac Address is the unique mac address every switch has been given by the manufacturer. It is a tie breaker in case the priority on all switches is identical.
If you've understood everything so far, you're ready to look at the election process in more detail.
Pic. 3 - Root Bridge Election.
Imagine that we've just wired our topology in the pic. 3. Now, we start up all the switches and as soon as their ports transition to LISTENING state, they begin to send BPDU frames out of all active ports. In those frames both Bridge ID and Root ID parameters point to their own priority.base-mac-address value. In other words, each switch thinks it is the root bridge. It is like each switch is saying: "Hi there! This is my name (Bridge ID) and by the way I'm the root (Root ID the same as the Bridge ID value). Since they are processing the incoming BPDU's from the neighbors, SW2 and SW3 realize that SW1's Bridge ID is lower than theirs. From that point onwards, they begin to relay BPDU frames saying that SW1 as the root bridge.
In our example, SW3 upon receiving the BPDU from SW1, SW2 and SW4 compares their Bridge ID with its own and the conclusion is that SW1's Bridge ID has the lowest value (base-mac-address breaks the tie). From this point onwards, it relays the BPDU frame out of all its active ports with the following parameters:
Bridge ID = 32768.0000.3333.3333
Root ID = 32768.0000.1111.1111
Similarly, all the switches agree that SW1 is the root (their own Bridge ID is higher).
2. Root Port Selection
As soon as the root has been elected, all non-root switches begin to calculate which port is the best (the least cost) towards the root bridge. This port will be called the root port.
Pic. 4 - Root Port Selection
SW2, SW3 and SW4 receive BPDUs from different directions. For instance, SW2 will receive them on its port F0/1 and F0/2 (look at pic 4). The accumulative cost (the sum of the cost in the path towards the root), is taken into consideration. The lowest cost to reach the root becomes the root port.
How the cost of path is calculated?
Each speed has its arbitrarily assigned cost which is configurable. A few examples are below:
10 Mbps = 100
100 Mbps = 19
1 Gbps = 4
10 Gbps = 2
The root bridge (here SW1) is sending its BPDU frame every 2 seconds. It uses the parameter called: Root Path Cost in BPDU to advertise the cost to the root. It puts the value of '0' in it, as it is the root bridge and has no cost to itself. The frame is sent out its port F0/1 towards SW3 and F0/2 towards SW2. SW2, upon receiving it, adds the cost used to reach the sender of BPDU based on the predefined speed-to-cost value (all ports in our topology are FastEthernet=19).
Root Path Cost = 0 + 19 = 19 via F0/2
SW2 is going to advertise its best (as of now) cost out of F0/1 port towards SW3. SW3 will receive BPDU from SW1 with the Root Path Cost=0 on its F0/1 port. It will also receive BPDU from SW2 on its F0/2 interface with the Root Path Cost=19. As both ports have the cost of 19 towards those BPDU senders, the following math is done to choose the least cost path towards the root bridge:
Root Path Cost = 0 + 19 = 19 via F0/1
Root Path Cost = 19 + 19 = 38 via F0/2
It is clear that the direct connection towards root bridge via F0/1 is going to be selected as the root port.
SW3 has the least cost towards equal 19 (via F0/1 port). This cost is going to be added to Root Path Cost while it sends the BPDUs out F0/2, F0/3 and F0/4. Of course, SW2 also chooses its F0/2 port as the root port since the cost is smaller.
What if the Root Cost Path is identical?
We run into that situation on SW4. It receives BPDUs on its ports F0/1 and F0/2 with the following parameters:
Bridge ID = 32768.0000.3333.3333
Root ID = 32768.0000.1111.1111
Root Path Cost = 19
The cost clearly does not help to choose a single root port as both ports have the same cost:
19 + 19 = 38.
The following algorithm is used to determine the root port or designated port (in order):
- Prefer the lowest Root Path Cost.
- In case of the same Root Path Cost, prefer the lowest Bridge ID of the designated switch (the neighbor that sends BPDUs).
- In case of receiving BPDUs on multiple ports from the same designated switch (BPDU sender), prefer the lowest Port ID (known also as port priority) of the sender. That parameter has a default value 128 and is configurable.
- In case of all above are did not resolve the problem, prefer the lowest Port ID of the BPDU sender.
- SW4 receives BPDUs on port F0/1 and F0/2. The Root Path cost is the same: 19 + 19 = 38 on both ports.
- The designated switch (SW3), is the same switch i.e. the same Bridge ID (32768.0000.3333.3333).
- The designated switch (SW3) sends BPDUs out of its F0/3 and F0/4 ports with the same priority = 128 (Port ID).
- The tie breaker is the lowest Port ID where BPDU frames arrive on SW4. Port f0/1 becomes the root port since F0/3 is lower than F0/4 on SW3.
3. Designated Port Selection.
This procedure follows exactly the same algorithm used for root port selection.
Pic. 5 - Designate Port Selection
Icons designed by: Andrzej Szoblik - http://www.newo.plSince root port is the best port towards the root bridge it is going to be in the forwarding state (look at the beginning of this lesson). What is left to do, is to choose one of the ports between SW2 and SW3 as designated (forwarding) and the other as non-designated (blocked). The same applies between SW3 and SW4. Either SW3 will block its F0/4, or SW4 should block its F0/2 port.
SW3 will block its F0/2 (non-designated) and SW2 will make its F0/1 port designated (forwarding). The process will look as follows:
- Root Path Cost advertised by SW2 is 19 and so is the cost advertised by SW3.
- SW2 has lower Bridge ID (32768.0000.2222.2222) than SW3 (32768.0000.3333.3333). SW3 must block its F0/2.
- Root Path Cost Advertised by SW3 is 19, but SW4 advertises its cost as 38 (two hops via F0/1). SW4 blocks its port F0/2 (non-designated), the SW3 promotes its port F0/4 to designated role (forwarding).
Pic. 6 - Spanning-Tree Topology Computed
Icons designed by: Andrzej Szoblik - http://www.newo.pl
This process happens in the LISTENING state of all ports. Since the topology has been computed and does not have loops (blocking appropriate ports), it is safe to move to next states: learning and finally forwarding.
In the next post, we will look at this process one more time using command line interface and real equipment.
IoE for Kids
by Anna Janas · Cisco Marketing Lead for Central and Eastern Europe.
Who knows what IoE is?
My four-year-old daughter asked me one day, “Mummy, where do you work?” I thought, what’s the easiest way of explaining to a 4-year-old what Cisco is? Then it occurred to me that the easiest, yet the most universal way of telling the Cisco story so that it is understood even to a child is the Internet of Things.
Explaining to my daughter the Internet of Everything (IoE) concept and her enthusiastic reaction inspired me to reach out with this story to a larger audience. This led me to become a lecturer at the Children University in Poland.
Together with my colleague Jacek Lewandowski I reached out to the Children’s University, the oldest and largest institution of this kind in Poland. It’s a non-profit organization, carrying out modern educational programs for children aged 6-14, resembling university lectures, cooperating with more than a dozen Polish universities. It also serves as a platform with lesson scenarios for teachers. The idea of a lecture titled “Can Things Talk to Each Other?” was picked-up immediately, and before I knew it I was standing in front of hundreds of bright kids and explaining to them what IoE is and how it works.
Telling the IoE story in a manner that is not only understandable, but also interesting for children requires a specific approach, adjusted to the perception capabilities of a child. Routing or switching were obviously not words to be used here.
Can things talk to each other? Can an electric kettle make tea on its own? I use examples of people communicating using different tools and then the examples of things communicating: garbage bins communicating that they need to be emptied, street lamps turning on when a child approaches it, smart homes and in the future your refrigerator doing shopping when there are no eggs in it.
Oops...another difficult question!
Using as many real-life references and “speaking with pictures” I found was the best way of showing how IoE enables or will soon enable everyday objects to communicate with each other. I show Cisco films with a cat drinking milk and how milk is “getting” to the house—all using the Cisco network.
The enthusiasm from the children was brilliant and an unbelievable amount of questions were asked. Questions like can a robot do my homework for me in the future, as I hate it? Who invented Internet and when? How can lights turn on by themselves? Can a bus talk to a bus stop? Can a car talk to a parking lot?
Connecting the unconnected...how does that feel?
The first lecture had more than 300 children in the audience and will be repeated for children in other locations, reaching over 2,000 children. Additionally, the Cisco lecture, Internet of Everything-Connecting the Unconnected will be used as a lesson scenario, downloadable for teachers.
This experience is important to me on a professional and private level. Privately, it helped my daughter learn something important about me—what I do during the day. Professionally, it has taught me how to communicate even the most complicated aspects of technology in an easy and accessible way, making it comprehensive even for children whilst spreading Cisco’s leading thoughts on IoE among the future thought leaders. This opportunity has made me proud to be a Cisco employee.
Did you know? You can share this story using the social media icons on the upper left. Use the hashtag #WeAreCisco. You can also rate or comment on the story below.