Spanning Tree Protocol
Spanning Tree Protocol
Section titled “Spanning Tree Protocol”Summary
Section titled “Summary”Spanning Tree Protocol (STP) is a network protocol that prevents loops in bridged networks by dynamically blocking redundant paths. RouterOS bridge interfaces support STP, RSTP, and MSTP to ensure a loop-free and redundant topology.
For small networks with just 2 bridges, STP does not bring many benefits. However, for larger networks, properly configured STP is crucial. To achieve a proper loop-free and redundant topology, you must properly set bridge priorities, port path costs, and port priorities.
RSTP (Rapid Spanning Tree Protocol) is enabled by default on new bridges in RouterOS v7. RSTP converges faster than classic STP and is recommended for most deployments.
STP and RSTP
Section titled “STP and RSTP”Enabling STP/RSTP
Section titled “Enabling STP/RSTP”To enable STP or RSTP on a bridge, set the protocol-mode parameter:
/interface bridgeadd name=bridge1 protocol-mode=rstpAvailable protocol modes:
none- STP disabled (default for legacy configurations)stp- Classic Spanning Tree Protocol (slow convergence)rstp- Rapid Spanning Tree Protocol (fast convergence, recommended)mstp- Multiple Spanning Tree Protocol (VLAN-aware)
Default Values
Section titled “Default Values”RouterOS uses the following default values for STP:
| Parameter | Default Value |
|---|---|
| Bridge Priority | 32768 (0x8000) |
| Port Path Cost | Auto (depends on port speed) |
| Port Priority | 128 |
| Forward Delay | 15 seconds |
| Max Age | 20 seconds |
| Hello Time | 2 seconds |
The default bridge priority of 32768 means bridges with lower priority values will become root bridges.
Port Path Cost Defaults
Section titled “Port Path Cost Defaults”| Interface Speed | STP Cost | RSTP Cost |
|---|---|---|
| 10 Mbps | 100 | 2,000,000 |
| 100 Mbps | 19 | 200,000 |
| 1 Gbps | 4 | 20,000 |
| 10 Gbps | 2 | 2,000 |
| 20 Gbps | 1 | 1,000 |
Election Process
Section titled “Election Process”When STP is enabled, bridges exchange BPDU (Bridge Protocol Data Unit) frames to elect:
- Root Bridge - The bridge with the lowest bridge ID (priority + MAC address)
- Root Ports - The port on each non-root bridge with the lowest path cost to the root
- Designated Ports - Ports on each segment that forward traffic toward the root
- Blocked Ports - Redundant ports that are blocked to prevent loops
Bridge ID Calculation
Section titled “Bridge ID Calculation”The Bridge ID is composed of:
- Priority: Configurable (default 32768), must be divisible by 4096
- MAC Address: The bridge’s internal MAC
Lower priority values win the root bridge election. If priorities are equal, the lowest MAC address wins.
# Set bridge priority to make it the root bridge/interface bridgeset [find name=bridge1] priority=4096Path Cost Calculation
Section titled “Path Cost Calculation”The root path cost is the sum of port path costs from a given port to the root bridge. Lower path costs are preferred.
# Set custom port path cost/interface bridge portset [find interface=ether1] path-cost=10Configuration Examples
Section titled “Configuration Examples”Basic RSTP Configuration
Section titled “Basic RSTP Configuration”This example shows a simple RSTP setup with two MikroTik routers:
Router A (Root Bridge):
/interface bridgeadd name=bridge1 protocol-mode=rstp priority=4096
/interface bridge portadd bridge=bridge1 interface=ether1add bridge=bridge1 interface=ether2add bridge=bridge1 interface=ether3Router B (Secondary):
/interface bridgeadd name=bridge1 protocol-mode=rstp
/interface bridge portadd bridge=bridge1 interface=ether1add bridge=bridge1 interface=ether2add bridge=bridge1 interface=ether3Root Path Cost Example
Section titled “Root Path Cost Example”In this topology, Router A is the root bridge. Router B has two paths to reach Router A:
- Path 1: ether1 (1 Gbps) - cost 20,000
- Path 2: ether2 (100 Mbps) - cost 200,000
RSTP automatically selects the lower-cost path (ether1) as the root port and blocks ether2.
[Router A - Root Bridge] | +----+----+ | | ether1 ether2 | | | 100Mbps | |[Router B]Loop Prevention with Redundant Links
Section titled “Loop Prevention with Redundant Links”This configuration prevents loops in a network with redundant connections:
# On Router A/interface bridgeadd name=bridge1 protocol-mode=rstp priority=4096
/interface bridge portadd bridge=bridge1 interface=ether1add bridge=bridge1 interface=ether2add bridge=bridge1 interface=ether3
# On Router B/interface bridgeadd name=bridge1 protocol-mode=rstp
/interface bridge portadd bridge=bridge1 interface=ether1add bridge=bridge1 interface=ether2add bridge=bridge1 interface=ether3Per-Port STP
Section titled “Per-Port STP”RouterOS supports per-port STP settings for advanced control.
Edge Ports
Section titled “Edge Ports”Edge ports are ports that connect to end devices (computers, printers, etc.) and should never receive BPDUs. They transition to forwarding state immediately.
# Configure edge port/interface bridge portset [find interface=ether1] edge=yesWhen edge is set to auto (default), the port becomes an edge port if it doesn’t receive BPDUs within 3 seconds of becoming active.
BPDU Guard
Section titled “BPDU Guard”BPDU Guard shuts down a port if it receives a BPDU, preventing unauthorized switches from affecting the STP topology:
# Enable BPDU Guard on a port/interface bridge portset [find interface=ether1] bpdu-guard=yesWhen a port with BPDU Guard receives a BPDU, it enters the disabled state and must be manually re-enabled by disabling and re-enabling the port.
Multiple Spanning Tree Protocol (MSTP)
Section titled “Multiple Spanning Tree Protocol (MSTP)”MSTP allows mapping multiple VLANs into different spanning tree instances, providing better utilization of redundant links.
MSTP Regions
Section titled “MSTP Regions”All switches in an MSTP region must share the same:
- Region Name
- Revision Level
- VLAN-to-Instance Mapping
# Enable MSTP with VLAN filtering/interface bridgeadd name=bridge1 protocol-mode=mstp vlan-filtering=yes
# Configure MSTP region (set on the bridge itself)/interface bridgeset [find name=bridge1] region-name=CORP-REGION region-revision=1MST Instance
Section titled “MST Instance”Create MST instances and map VLANs to them:
# Create MST instance and map VLANs/interface bridge mstadd bridge=bridge1 identifier=1 vlan-mapping=10,20,30add bridge=bridge1 identifier=2 vlan-mapping=40,50MST Override
Section titled “MST Override”Use MST override to modify the bridge priority for specific instances:
# Set priority for MST instance/interface bridge mstset [find identifier=1] priority=4096Monitoring
Section titled “Monitoring”View STP Status
Section titled “View STP Status”Check the current STP status on a bridge:
/interface bridge print detailView Port Status
Section titled “View Port Status”Check STP state on individual ports:
/interface bridge port print detailView MSTP Instances
Section titled “View MSTP Instances”/interface bridge mst print detailTroubleshooting
Section titled “Troubleshooting”Port Stuck in Blocking State
Section titled “Port Stuck in Blocking State”If a port is stuck in blocking state:
- Check for physical loop conditions
- Verify all bridges have STP enabled
- Check port path costs - lower costs should become root ports
- Ensure BPDUs are not being filtered by firewall
STP Not Preventing Loops
Section titled “STP Not Preventing Loops”If STP is not preventing loops:
- Verify
protocol-modeis set torstpormstpon all bridges - Check that all switches in the network support RSTP/MSTP
- Verify no unmanaged switches are creating invisible loops
- Check for hardware offloading issues with STP
Common Issue: Cisco Interoperability
Section titled “Common Issue: Cisco Interoperability”When connecting MikroTik routers to Cisco switches:
- Both devices must use the same STP version
- Cisco uses PVST (Per-VLAN STP) by default - configure MSTP for compatibility
- Verify BPDU guard settings match on both sides
# Cisco config for MSTP compatibilityspanning-tree mode mstpSee Also
Section titled “See Also”- Bridge VLAN Filtering - Combining STP with VLAN filtering
- Bridge Hardware Offloading - Hardware-accelerated STP
- Basic VLAN Switching - VLAN configurations with STP