Spanning Tree Protocol (STP)

ccnp-switching
Reviews spanning tree fundamentals, BPDU types and timers, and shows how to set the root bridge and tune STP timers on Cisco switches.
Published

Nov 19, 2017

The specification for STP is IEEE 802.1D.

Requirements: CCNA-level STP knowledge.

What is a tree? Any acyclic connected graph is a tree. A tree is an undirected graph G that satisfies any of the following equivalent conditions if G has finitely many vertices:

Therefore, to prevent a loop, we have to have n-1 links. (n = number of switches participating in STP)

Three switches in a triangle with their bridge MAC addresses, the topology used for the root bridge election that follows
SW1#show version | inc MAC
Base ethernet MAC Address       : 00:1D:70:7B:42:00
SW2#show version | inc MAC
Base ethernet MAC Address       : 00:22:0D:EC:12:00
SW3#show version | inc MAC
Base ethernet MAC Address       : 00:22:BE:5A:06:80
SW1#show spanning-tree

VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     001d.707b.4200
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     001d.707b.4200
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Fa1/0/1             Desg FWD 19        128.3    P2p
Fa1/0/12            Desg FWD 19        128.14   P2p
Fa1/0/13            Desg FWD 19        128.15   P2p

An example of how to change the root bridge to SW2:

SW2(config)#spanning-tree vlan 1 root primary

Verification

SW1#show spanning-tree

VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     0022.0dec.1200
             Cost        19
             Port        14 (FastEthernet1/0/12)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     001d.707b.4200
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Fa1/0/1             Desg FWD 19        128.3    P2p
Fa1/0/12            Root FWD 19        128.14   P2p
Fa1/0/13            Desg FWD 19        128.15   P2p

To check whether BPDUs are actually being sent

SW1#show spanning-tree interface fastEthernet 1/0/12 detail
 Port 14 (FastEthernet1/0/12) of VLAN0001 is designated forwarding
   Port path cost 19, Port priority 128, Port Identifier 128.14.
   Designated root has priority 32769, address 001d.707b.4200
   Designated bridge has priority 32769, address 001d.707b.4200
   Designated port id is 128.14, designated path cost 0
   Timers: message age 0, forward delay 0, hold 0
   Number of transitions to forwarding state: 1
   Link type is point-to-point by default
   BPDU: sent 39, received 2

BPDUs are sent every 2 seconds on trunk ports:

SW1#debug spanning-tree bpdu
SW1#
*Mar  1 04:51:00.761: STP: VLAN0001 rx BPDU: config protocol = ieee, packet from FastEthernet1/0/12  , linktype IEEE_SPANNING , enctype 2, encsize 17
*Mar  1 04:51:00.761: STP: enc 01 80 C2 00 00 00 00 22 0D EC 12 0E 00 26 42 42 03
*Mar  1 04:51:00.761: STP: Data     0000000000600100220DEC120000000000600100220DEC1200800E0000140002000F00
*Mar  1 04:51:00.761: STP: VLAN0001 Fa1/0/12:0000 00 00 00 600100220DEC1200 00000000 600100220DEC1200 800E 0000 1400 0200 0F00
*Mar  1 04:51:00.761: STP(1) port Fa1/0/12 supersedes 0

*Mar  1 04:51:02.766: STP: VLAN0001 rx BPDU: config protocol = ieee, packet from FastEthernet1/0/12  , linktype IEEE_SPANNING , enctype 2, encsize 17
*Mar  1 04:51:02.766: STP: enc 01 80 C2 00 00 00 00 22 0D EC 12 0E 00 26 42 42 03
*Mar  1 04:51:02.766: STP: Data     0000000000600100220DEC120000000000600100220DEC1200800E0000140002000F00
*Mar  1 04:51:02.766: STP: VLAN0001 Fa1/0/12:0000 00 00 00 600100220DEC1200 00000000 600100220DEC1200 800E 0000 1400 0200 0F00
*Mar  1 04:51:02.766: STP(1) port Fa1/0/12 supersedes 0

Sample BPDU frame captured by Wireshark

Frame 169: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
    Interface id: 0 (eno1)
    Encapsulation type: Ethernet (1)
    Arrival Time: Nov 11, 2017 15:53:51.971857596 EST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1510433631.971857596 seconds
    [Time delta from previous captured frame: 0.288136052 seconds]
    [Time delta from previous displayed frame: 0.288136052 seconds]
    [Time since reference or first frame: 82.922480439 seconds]
    Frame Number: 169
    Frame Length: 60 bytes (480 bits)
    Capture Length: 60 bytes (480 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:llc:stp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
IEEE 802.3 Ethernet
    Destination: Spanning-tree-(for-bridges)_00 (01:80:c2:00:00:00)
        Address: Spanning-tree-(for-bridges)_00 (01:80:c2:00:00:00)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Cisco_7b:42:1a (00:1d:70:7b:42:1a)
        Address: Cisco_7b:42:1a (00:1d:70:7b:42:1a)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Length: 38
    Padding: 0000000000000000
Logical-Link Control
    DSAP: Spanning Tree BPDU (0x42)
        0100 001. = SAP: Spanning Tree BPDU
        .... ...0 = IG Bit: Individual
    SSAP: Spanning Tree BPDU (0x42)
        0100 001. = SAP: Spanning Tree BPDU
        .... ...0 = CR Bit: Command
    Control field: U, func=UI (0x03)
        000. 00.. = Command: Unnumbered Information (0x00)
        .... ..11 = Frame type: Unnumbered frame (0x3)
Spanning Tree Protocol
    Protocol Identifier: Spanning Tree Protocol (0x0000)
    Protocol Version Identifier: Spanning Tree (0)
    BPDU Type: Configuration (0x00)
    BPDU flags: 0x01, Topology Change
        0... .... = Topology Change Acknowledgment: No
        .... ...1 = Topology Change: Yes
    Root Identifier: 24576 / 1 / 00:22:0d:ec:12:00
        Root Bridge Priority: 24576
        Root Bridge System ID Extension: 1
        Root Bridge System ID: Cisco_ec:12:00 (00:22:0d:ec:12:00)
    Root Path Cost: 19
    Bridge Identifier: 32768 / 1 / 00:1d:70:7b:42:00
        Bridge Priority: 32768
        Bridge System ID Extension: 1
        Bridge System ID: Cisco_7b:42:00 (00:1d:70:7b:42:00)
    Port identifier: 0x801a
    Message Age: 1
    Max Age: 20
    Hello Time: 2
    Forward Delay: 15

There are three kinds of BPDUs:

  • Configuration BPDU, used by Spanning tree protocol to provide information to all switches.
  • TCN (Topology Change Notification), tell about changes in the topology.
  • TCA (Topology Change Acknowledgment), confirm the reception of the TCN.

By default the BPDUs are sent every 2 seconds.

Spanning Tree Protocol Timers

  • hello: The hello time is the time between each bridge protocol data unit (BPDU) that is sent on a port. This time is equal to 2 seconds (sec) by default, but you can tune the time to be between 1 and 10 sec.
  • forward delay: The forward delay is the time that is spent in the listening and learning state. This time is equal to 15 sec by default, but you can tune the time to be between 4 and 30 sec.
  • max age: The max age timer controls the maximum length of time that passes before a bridge port saves its configuration BPDU information. This time is 20 sec by default, but you can tune the time to be between 6 and 40 sec.

How to customize STP timers

  • Manually:
SW1(config)#spanning-tree vlan 1 hello-time ?
  <1-10>  number of seconds between generation of config BPDUs

hello-time default value is: 2 seconds

SW1(config)#spanning-tree vlan 1 forward-time ?
  <4-30>  number of seconds for the forward delay timer

forward-time default value is: 15 seconds

SW1(config)#spanning-tree vlan 1 max-age ?
  <6-40>  maximum number of seconds the information in a BPDU is valid

max-age default value is: 20 seconds

  • Automatically:
  1. We have to determine the diameter of your network. In a well-designed network the diameter is usually equal to 3. (Core, Distribution, and Access).
  2. Optionally we determine the hello-time, then the switch calculates the forward-time and max-age
SW1(config)#spanning-tree vlan 1 root primary diameter 3 hello-time 3

To verify:

SW1#show spanning-tree

VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     001d.707b.4200
             This bridge is the root
             Hello Time   3 sec  Max Age 17 sec  Forward Delay 12 sec

  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     001d.707b.4200
             Hello Time   3 sec  Max Age 17 sec  Forward Delay 12 sec
             Aging Time 300

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Fa1/0/1             Desg FWD 19        128.3    P2p
Fa1/0/12            Desg FWD 19        128.14   P2p
Fa1/0/13            Desg FWD 19        128.15   P2p
Back to top