Skip to content

Spanning Tree

Spanning Tree Protocol (STP) is a Layer 2 loop prevention mechanism that ensures a loop-free topology in Ethernet networks by selectively blocking redundant paths while maintaining network connectivity and providing automatic failover capabilities. It supports multiple implementations including Per-VLAN Spanning Tree Plus (PVST+), Rapid Per-VLAN Spanning Tree Plus (RPVST+), and Multiple Spanning Tree (MST) protocol, each offering different approaches to VLAN-aware loop prevention and convergence optimization. Spanning Tree configuration includes features like PortFast for edge ports, BPDU Guard for security, root bridge selection, and path cost manipulation to optimize network topology and ensure rapid recovery from link failures while preventing broadcast storms and network instability.

Diagram
NameTypeConstraintMandatoryDefault Value
spanning_treeClass[spanning_tree]No

spanning_tree (iosxe.devices.configuration)

Section titled “spanning_tree (iosxe.devices.configuration)”
NameTypeConstraintMandatoryDefault Value
modeChoicemst, pvst, rapid-pvstNo
loggingBooleantrue, falseNo
loopguard_defaultBooleantrue, falseNo
portfast_defaultBooleantrue, falseNo
portfast_bpduguard_defaultBooleantrue, falseNo
extend_system_idBooleantrue, falseNo
mst_instancesList[mst_instances]No
vlansList[vlans]No

mst_instances (iosxe.devices.configuration.spanning_tree)

Section titled “mst_instances (iosxe.devices.configuration.spanning_tree)”
NameTypeConstraintMandatoryDefault Value
idIntegermin: 0, max: 4094Yes
vlansClass[vlans]No

vlans (iosxe.devices.configuration.spanning_tree)

Section titled “vlans (iosxe.devices.configuration.spanning_tree)”
NameTypeConstraintMandatoryDefault Value
idIntegermin: 1, max: 4094Yes
priorityIntegermin: 0, max: 61440No

vlans (iosxe.devices.configuration.spanning_tree.mst_instances)

Section titled “vlans (iosxe.devices.configuration.spanning_tree.mst_instances)”
NameTypeConstraintMandatoryDefault Value
idsListInteger[min: 1, max: 4094]No
rangesList[ranges]No

ranges (iosxe.devices.configuration.spanning_tree.mst_instances.vlans)

Section titled “ranges (iosxe.devices.configuration.spanning_tree.mst_instances.vlans)”
NameTypeConstraintMandatoryDefault Value
fromIntegermin: 1, max: 4094Yes
toIntegermin: 1, max: 4094Yes

By preventing Layer 2 loops, Spanning Tree Protocol (STP) ensures network stability and rapid recovery from link failures.

Key Components:

  • STP Mode (mode): Selects the spanning tree protocol (PVST+, Rapid-PVST+, MST).

  • Logging (logging): Enables STP logging for topology changes and root bridge elections.

  • Bridge Priority (priority): Sets the priority for root bridge election.

  • VLANs (vlans): Configures per-VLAN STP settings including bridge priority for individual VLANs in PVST+/Rapid-PVST+ mode.

  • MST Instance ID and VLAN Mappings (mst_instances): Configures MST instances and their associated VLANs.

  • Port Priority (port_priority): Sets the priority for individual ports.

  • Path Cost (path_cost): Adjusts the cost for spanning tree path selection.

  • PortFast (portfast_default, portfast): Enables PortFast globally or per interface.

  • BPDU Guard (portfast_bpduguard_default, bpduguard): Enables BPDU Guard globally or per interface.

  • BPDU Filter (bpdufilter): Enables BPDU Filter globally or per interface.

  • Root Guard (rootguard): Protects the root bridge role.

  • Loop Guard (loopguard_default, loopguard): Prevents loops caused by unidirectional links.

  • EtherChannel Guard (etherchannel_guard): Protects EtherChannel links.

  • Max Age, Forward Delay, Hello Time (max_age, forward_delay, hello_time): Sets STP timers.

  • Extend System ID (extend_system_id): Enables extended system ID for bridge priority.

Key Parameters Briefly Explained:

  • mode: STP protocol selection.
  • logging: Enable STP event logging.
  • priority: Bridge priority.
  • vlans: Per-VLAN STP configuration with id and priority.
  • mst_instances: MST instance configuration.
  • port_priority, path_cost: Port-specific settings.
  • portfast_default, portfast: PortFast settings.
  • portfast_bpduguard_default, bpduguard: BPDU Guard settings.
  • bpdufilter, rootguard, loopguard_default, loopguard, etherchannel_guard: Protective features.
  • max_age, forward_delay, hello_time: STP timers.
  • extend_system_id: Extended system ID.

You can use these Spanning Tree parameters to control loop prevention, optimize convergence, and enhance the security of your Layer 2 network. Customize the STP mode, bridge priorities, port settings, and protective features to fit your network’s topology, performance requirements, and resilience needs. Adjusting these parameters lets you tailor how your network handles redundancy and prevents loops.

The following configuration describes how to set up Spanning Tree Protocol on a Cisco IOS-XE device, including STP mode, logging, global PortFast and BPDU Guard, per-VLAN priority, MST configuration, and instance mapping for robust Layer 2 loop prevention and optimized convergence.

spanning-tree mode rapid-pvst
spanning-tree logging
spanning-tree loopguard default
spanning-tree portfast default
spanning-tree portfast bpduguard default
spanning-tree extend system-id
!
spanning-tree vlan 10 priority 4096
spanning-tree vlan 20 priority 8192
spanning-tree vlan 30 priority 4096
!
interface GigabitEthernet0/1
spanning-tree portfast
spanning-tree bpduguard enable
spanning-tree mode mst
spanning-tree logging
spanning-tree loopguard default
spanning-tree portfast default
spanning-tree portfast bpduguard default
spanning-tree extend system-id
!
spanning-tree mst configuration
name MY_MST_REGION
revision 1
instance 0 vlan 1,10,20,30
instance 1 vlan 100,200,300
instance 2 vlan 400,500,600
exit
!
spanning-tree mst 0 priority 4096
spanning-tree mst 1 priority 8192

The following YAML code defines Spanning Tree Protocol configuration on an IOS-XE device, including global settings for mode, logging, loopguard, portfast, BPDU guard, extend system ID, per-VLAN priority configuration, and MST instance configuration.

iosxe:
devices:
- name: AccessSwitch1
configuration:
spanning_tree:
mode: rapid-pvst
logging: true
loopguard_default: true
portfast_default: true
portfast_bpduguard_default: true
vlans:
- id: 10
priority: 4096
- id: 20
priority: 8192
- id: 30
priority: 4096
iosxe:
devices:
- name: CoreSwitch1
configuration:
spanning_tree:
mode: mst
logging: true
loopguard_default: true
portfast_default: false
portfast_bpduguard_default: true
extend_system_id: true
mst_instances:
- id: 0
vlans:
ids: [1, 10, 20, 30]
- id: 1
vlans:
ids: [100, 200, 300]
ranges:
- from: 350
to: 360
- id: 2
vlans:
ranges:
- from: 400
to: 500
- from: 550
to: 600