Spanning Tree Protocol Concepts
Spanning Tree Protocol Concepts
Spanning Tree Protocol Concepts
The first thing to point out is that this article focuses on the original version of STP that is covered in IEEE 802.1D;
some of the material about the newer Rapid STP (RSTP-IEEE 802.1w) will also be briefly discussed.
The basic function of STP is to provide a loop free switched network; this is done by creating a topology of all
participating STP switches. The best loop free path through the switched network is then determined from this
topology information. The initial step taken by each STP is to elect a root switch; the root switch is used as a central
point in a switched network to determine the best route through the switched network. Initially, all switches act as if
they are the root switch and do this until they receive traffic from another superior switch (as determined by switch
priority); this is referred to as a root switch election.
Another thing that must be understood is that multiple root switches can exist in the network depending on what STP
mode is being used. By default, on Cisco switching equipment, each VLAN has its own STP instance and a root
switch is elected for each VLAN; this mode is called Per VLAN Spanning Tree Plus (PVST+). If implementing RSTP,
Rapid PVST+ is used.
Once the root switch is elected, each of the ports is given a role depending on its place within the STP topology; the
available port roles when using 802.1D spanning tree are shown below:
Root—The port given this role is the selected best path to reach the root switch
Designated—The port given this role is selected with the best path to a specific switched segment; there is
only one designated port per switched segment.
Alternate—The port given this role is selected as a backup to the root port; if the root port should have a
problem, this port would take over the root port role.
Backup—The port given this role is selected as a back to the designated port; if the designated port should
have a problem this port would take over the designated port role.
Once the best path is calculated and each of the ports has been given a role, all ports with the alternate or backup
STP roles will be blocked to prevent loops.
Each of the ports on a switch that are enabled participates in STP; each of these ports goes through a process of
interface states before they are allowed to forward traffic. The sequence of 802.1D interface states is shown in Figure
1.
As shown in Figure 1, there are five different states that a port can be in, described below:
Blocking State—Ports that are in the blocking state do not forward traffic; they simply listen to the network to
ensure that they should continue to block traffic. Should the state of the switched network change, the port
could transition to listening state. All ports start in blocking state after initial switch initialization.
Listening State—Ports that are in the listening state do not forward traffic. While in this state, the port will
only listen to traffic as they did when in blocking state. This is the first state that comes after the blocking
state after the port is set to start frame forwarding. The default time in the listening state is 15 seconds.
Learning State—Ports that are in the learning state do not forward traffic; while in this state the port will
listen to traffic and begin to learn addresses from the connected devices on a segment. The default time in
the learning state is 15 seconds.
Forwarding State—Ports that are in the forwarding state forward traffic as well as continue to learn
addresses from the segment.
Disabled State—Ports that are in the disabled state do not forward traffic or listen to the network traffic.
When implementing the RSTP, the time that a port takes to transition and the method used to transition has changed.
This provides the ability for a switched network to begin forwarding traffic sooner without unneeded delays; these
delays are a common complaint about the 802.1D version of STP.
When initially setting up STP, it is best to determine which of the switches on the network will become the root switch.
While it is possible for the network to determine this by itself, the election will simply come down to a question of who
has the lowest MAC address. By default, each switch begins with a priority of 32768; this priority is then combined
with the MAC address of the switch to create the bridge ID. During a root switch election, the switch with the lowest
bridge ID will be elected the root switch.
If the default Spanning Tree mode needs to be changed from the default of PVST+, use the commands shown in
Table 3.
Network Diagram
This document uses this network setup:
Concepts
STP runs on bridges and switches that are 802.1D-compliant. There are different flavors of STP, but
802.1D is the most popular and widely implemented. You implement STP on bridges and switches in
order to prevent loops in the network. Use STP in situations where you want redundant links, but not
loops. Redundant links are as important as backups in the case of a failover in a network. A failure of your
primary activates the backup links so that users can continue to use the network. Without STP on the
bridges and switches, such a failure can result in a loop. If two connected switches run different flavors of
STP, they require different timings to converge. When different flavors are used in the switches, it creates
timing issues between Blocking and Forwarding states. Therefore, it is recommended to use the same
flavors of STP. Consider this network:
In this network, a redundant link is planned between Switch A and Switch B. However, this setup creates
the possibility of a bridging loop. For example, a broadcast or multicast packet that transmits from Station
M and is destined for Station N simply continues to circulate between both switches.
However, when STP runs on both switches, the network logically looks like this:
STP Operation
Task
Prerequisites
Before you configure STP, select a switch to be the root of the spanning tree. This switch does not need
to be the most powerful switch, but choose the most centralized switch on the network. All data flow
across the network is from the perspective of this switch. Also, choose the least disturbed switch in the
network. The backbone switches often serve as the spanning tree root because these switches typically
do not connect to end stations. Also, moves and changes within the network are less likely to affect these
switches.
After you decide on the root switch, set the appropriate variables to designate the switch as the root
switch. The only variable that you must set is the bridge priority. If the switch has a bridge priority that is
lower than all the other switches, the other switches automatically select the switch as the root switch.
Clients (end stations) on Switch Ports
You can also issue the set spantree portfast command, on a per-port basis. When you enable
the portfast variable on a port, the port immediately switches from blocking mode to forwarding mode.
Enablement of portfast helps to prevent timeouts on clients who use Novell Netware or use DHCP in
order to obtain an IP address. However, do notuse this command when you have switch-to-switch
connection. In this case, the command can result in a loop. The 30- to 60-second delay that occurs during
the transition from blocking to forwarding mode prevents a temporal loop condition in the network when
you connect two switches.
Leave most other STP variables at their default values.
Rules of Operation
This section lists rules for how STP works. When the switches first come up, they start the root switch
selection process. Each switch transmits a BPDU to the directly connected switch on a per-VLAN basis.
As the BPDU goes out through the network, each switch compares the BPDU that the switch sends to the
BPDU that the switch receives from the neighbors. The switches then agree on which switch is the root
switch. The switch with the lowest bridge ID in the network wins this election process.
Note: Remember that one root switch is identified per-VLAN. After the root switch identification, the
switches adhere to these rules:
STP Rule 1—All ports of the root switch must be in forwarding mode.
Note: In some corner cases, which involve self-looped ports, there is an exception to this rule.
Next, each switch determines the best path to get to the root. The switches determine this path by a comparison of
the information in all the BPDUs that the switches receive on all ports. The switch uses the port with the least
amount of information in the BPDU in order to get to the root switch; the port with the least amount of
information in the BPDU is the root port. After a switch determines the root port, the switch proceeds to rule 2.
STP Rule 2—The root port must be set to forwarding mode.
In addition, the switches on each LAN segment communicate with each other to determine which switch is best
to use in order to move data from that segment to the root bridge. This switch is called the designated switch.
STP Rule 3—In a single LAN segment, the port of the designated switch that connects to that LAN segment
must be placed in forwarding mode.
STP Rule 4—All the other ports in all the switches (VLAN-specific) must be placed in blocking mode. The rule
only applies to ports that connect to other bridges or switches. STP does not affect ports that connect to
workstations or PCs. These ports remain forwarded.
Note: The addition or removal of VLANs when STP runs in per-VLAN spanning tree (PVST / PVST+) mode
triggers spanning tree recalculation for that VLAN instance and the traffic is disrupted only for that VLAN. The
other VLAN parts of a trunk link can forward traffic normally. The addition or removal of VLANs for a Multiple
Spanning Tree (MST) instance that exists triggers spanning tree recalculation for that instance and traffic is
disrupted for all the VLAN parts of that MST instance.
Note: By default, spanning tree runs on every port. The spanning tree feature cannot be turned off in
switches on a per-port basis. Although it is not recommended, you can turn off STP on a per-VLAN basis,
or globally on the switch. Extreme care should be taken whenever you disable spanning tree because this
creates Layer 2 loops within the network.
Step-by-Step Instructions
Complete these steps:
1. Issue the show version command in order to display the software version that the switch runs.
Note: All switches run the same software version.
Switch-15> (enable)show version
WS-C5505 Software, Version McpSW: 4.2(1) NmpSW: 4.2(1)
Copyright (c) 1995-1998 by Cisco Systems
NMP S/W compiled on Sep 8 1998, 10:30:21
MCP S/W compiled on Sep 08 1998, 10:26:29
Warning: Spantree port fast start should only be enabled on ports connected
to a single host. Connecting hubs, concentrators, switches, bridges, etc. to
a fast start port can cause temporary spanning-tree loops. Use with caution.
Warning: Spantree port fast start should only be enabled on ports connected
to a single host. Connecting hubs, concentrators, switches, bridges, etc. to
a fast start port can cause temporary spanning-tree loops. Use with caution.
!--- This is the MAC address of the root switch for VLAN 1.
!--- This is the MAC address of the root switch for VLAN 1.