Spanning Tree Protocol (STP) helps prevent loops which would otherwise disrupt network connectivity. It also contributes to improved network resiliency by enabling multiple switches to be connected together redundantly in case one of them stops working.
UniFi switches support both 802.1D Spanning Tree Protocol (STP), as well as 802.1W Rapid Spanning Tree Protocol (RSTP). Spanning Tree is automatically enabled on UniFi Switches to protect against network loops.
RSTP is enabled by default on all UniFi switches. This is typically recommended instead of STP, because it provides a quicker response when network loops are detected. Spanning Tree can be enabled and disabled per switch, per port or globally:
- Globally: Navigate to Settings > Networks > Spanning Tree.
- Per Switch: Navigate to UniFi Devices > Select a switch > Settings > Spanning Tree.
- Per Port: Navigate to UniFi Devices > Select a switch > Port Manager > Select a port > Spanning Tree Protocol.
Note: We do not recommend disabling Spanning Tree.
Switch Priority and Root Bridge Assignment
Each switch has a configurable priority which is used to determine the root bridge. The root bridge is largely determined by the switch with the lowest priority value. If all switches have the same priority, then the root bridge is assigned to the switch whose MAC address' hex value is the lowest. All switches are assigned a priority of 32,768 by default, but this can be changed by navigating to UniFi Devices > Select a switch > Settings > Priority.
Most small-to-medium sized networks can remain on the default values. However, as networks become larger, it is usually a good idea to configure priorities so that the root bridge role is assigned to a central, highly-capable switch that is unlikely to fail. The UniFi Professional Aggregation is an excellent candidate for the root bridge.
Discarding (Blocking) State
When a loop is detected on a switch, certain ports will enter a discarding (blocking) state, while the others will remain in a forwarding (working) state. These states are assigned automatically based on the 'cost' of a certain port to reach the root bridge switch. Cost is a function of link speeds, so ports with a higher speed take priority to remain in a forwarding state.
Switch port states are indicated in UniFi Network by navigating to UniFi Devices > Select a switch > Port Manager.
Spanning Tree Example
The diagram above shows a basic three-switch topology with a redundant 1 Gbps link between access switches. In normal operation with RSTP, the link between Access-01 and Access-02 would be in a discarding state. Whether the port on Access-01 or Access-02 went into the discarding state would determine on the priority set for each switch.
If a cable were to become inoperable between Core-01 and Access-01, Access-01 would transition its root port over to the port between Access-01 and Access-02. This would allow the redundant link to pass traffic until the link between Core-01 and Access-01 was restored.
The topology change would end up looking like the diagram below: