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
loopguard_defaultBooleantrue, falseNo
portfast_defaultBooleantrue, falseNo
portfast_bpduguard_defaultBooleantrue, falseNo
extend_system_idBooleantrue, falseNo
mst_instancesList[mst_instances]No

mst_instances (iosxe.devices.configuration.spanning_tree)

Section titled “mst_instances (iosxe.devices.configuration.spanning_tree)”
NameTypeConstraintMandatoryDefault Value
idIntegermin: 0, max: 4094Yes
vlan_idsListIntegerNo

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).

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

  • VLANs (vlan_ids): Specifies VLANs for PVST+/Rapid-PVST+ or maps VLANs to MST instances.

  • 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.
  • priority: Bridge priority.
  • vlan_ids: VLANs for STP.
  • 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, global PortFast and BPDU Guard, MST configuration, and instance mapping for robust Layer 2 loop prevention and optimized convergence.

spanning-tree mode rapid-pvst
spanning-tree loopguard default
spanning-tree portfast default
spanning-tree portfast bpduguard default
spanning-tree extend system-id
!
spanning-tree vlan 1,10,20,30 root primary
spanning-tree vlan 100,200,300 root secondary
!
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
!
interface GigabitEthernet0/1
spanning-tree portfast
spanning-tree bpduguard enable

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

iosxe:
devices:
- name: Device1
configuration:
spanning_tree:
mode: rapid-pvst
loopguard_default: true
portfast_default: true
portfast_bpduguard_default: true
extend_system_id: true
- name: Device2
configuration:
spanning_tree:
mode: mst
loopguard_default: true
portfast_default: false
portfast_bpduguard_default: true
extend_system_id: true
mst_instances:
- id: 0
vlan_ids: [1, 10, 20, 30]
- id: 1
vlan_ids: [100, 200, 300]
- id: 2
vlan_ids: [400, 500, 600]