Spanning Tree · Topic 1 of 3

STP and RSTP Concepts and BPDUs

Learn why Layer 2 loops need spanning tree, how the root bridge is elected from the bridge ID, and what configuration, TCN and RST BPDUs carry on Junos.

  • 5 min
In a nutshell
  • STP is 802.1D and RSTP is 802.1w; RSTP is the Junos EX default.
  • Bridge ID is priority plus MAC address; lowest wins. Default priority is 32768, in steps of 4096.
  • Best BPDU order: root ID, root path cost, sender bridge ID, sender port ID.

What it is

A Layer 2 network with redundant links has loops. Ethernet frames have no hop count, so a broadcast frame in a loop is copied and forwarded again and again until the links are full. This is a broadcast storm, and it can also corrupt MAC tables as the same source address appears on several ports.

The Spanning Tree Protocol (STP, IEEE 802.1D) stops this. Switches agree on a loop free tree, block the extra links and keep them in reserve. The Rapid Spanning Tree Protocol (RSTP, IEEE 802.1w) does the same job and recovers much faster. RSTP is the default on Junos EX switches and is backward compatible with STP.

Redundant linksLoop possibleBroadcast stormRedundant linksSTP or RSTPOne path activeothers blockedNo loop

How it works

The bridge ID and the root bridge

Every switch has a bridge ID of 8 bytes: a 2 byte priority followed by the 6 byte MAC address. The lowest bridge ID wins the election and becomes the root bridge. The default bridge priority on Junos is 32768, so with default priorities the switch with the lowest MAC address becomes root.

Priority values on Junos are set in steps of 4096, and a lower number is better. Set a priority on purpose rather than leave the choice to the MAC address.

ItemDefaultBetter value
Bridge priority32768Lower
Port priority128Lower
Hello time2 secondsNot a competition
Forward delay15 secondsNot a competition
Max age20 secondsNot a competition

How a switch chooses its best path

Each non-root switch looks at the BPDUs it receives and picks the best one. Comparison is made in this order, and the lowest value wins at each step.

  1. Lowest root bridge ID.
  2. Lowest root path cost, the sum of the port costs on the way to the root.
  3. Lowest sender bridge ID.
  4. Lowest sender port ID.

The port that receives the best BPDU becomes the root port. Port cost depends on link speed, using the standard values.

Link speedCost
10 Mbps2,000,000
100 Mbps200,000
1 Gbps20,000
10 Gbps2,000
Receive BPDUsCompare root bridge IDCompare root path costCompare sender bridge IDCompare sender port IDBest BPDU wins

BPDU types

Switches talk with bridge protocol data units (BPDUs). They are sent to the reserved multicast MAC address 01:80:C2:00:00:00, which a bridge does not forward like normal traffic.

BPDUUsed byPurpose
Configuration BPDUSTPCarries root bridge ID, root path cost, sender ID and timers; sent by the root and relayed by others
TCN BPDUSTPTopology change notification, sent toward the root when a topology change is seen
RST BPDURSTPCarries the same information plus port role and state flags; sent by every switch

The fields that matter most are:

  • Root bridge ID, the switch the sender believes is root.
  • Root path cost, the cost from the sender to that root.
  • Sender bridge ID and port ID.
  • Timers: hello, max age and forward delay.
  • Flags: topology change, and in RSTP the port role, proposal, agreement, learning and forwarding bits.

In STP only the root bridge originates configuration BPDUs, every hello time (2 seconds), and the others relay them. In RSTP every switch sends an RST BPDU on its designated ports every hello time, so a switch notices a lost neighbor after missing three hellos.

Topology changes

A topology change means MAC table entries may now be wrong. In STP the switch sends a TCN BPDU up to the root, and the root then sets the topology change flag in its configuration BPDUs. Switches shorten their MAC aging time while the flag is set, so old entries disappear fast.

In RSTP the switch that detects the change floods it itself, and each switch immediately flushes MAC entries learned on its other ports. A topology change is created only when a non edge port moves to forwarding, so a host connecting to an access port does not cause one.

Exam tip

A rapidly increasing topology change count in show spanning-tree bridge means something keeps flapping, typically a host port that is not configured as an edge port.

Protocol compatibility

An RSTP switch that receives an STP configuration BPDU on a port falls back to STP behavior on that port. It then has the slow timers and states on that segment. You can also force this with force-version stp under protocols rstp.

Common mistakes

Assuming the fastest switch becomes the root. Root is chosen by priority, then MAC address, not by speed or position.

Leaving the root to chance. With default priorities, an old switch with a low MAC address can become root, and traffic then takes poor paths.

Mixing up path cost and port priority. Path cost is compared first. Port priority matters only when everything before it ties.

Thinking BPDUs are forwarded like data. Switches process BPDUs themselves and generate their own for each segment.

Watch out

In STP only the root originates BPDUs, but in RSTP every switch does. Exam options often swap the two.

What to remember for the exam

  • STP is 802.1D and RSTP is 802.1w; RSTP is the Junos EX default.
  • Bridge ID is priority plus MAC address; lowest wins. Default priority is 32768, in steps of 4096.
  • Best BPDU order: root ID, root path cost, sender bridge ID, sender port ID.
  • Default timers: hello 2 seconds, forward delay 15 seconds, max age 20 seconds.
  • BPDU types: configuration and TCN for STP, RST for RSTP.
  • In RSTP every switch sends BPDUs; a neighbor is lost after three missed hellos.
  • RSTP falls back to STP on a port that receives an STP BPDU.

Check yourself

  • Two switches have the same priority. Which one becomes the root bridge?

    The one with the lower MAC address, because the lowest bridge ID wins.

  • Which BPDU does a switch send toward the root in STP to report a topology change?

    A topology change notification (TCN) BPDU.

  • What happens when an RSTP port receives an STP configuration BPDU?

    The port falls back to STP behavior and loses the rapid features on that segment.

Topic 1 of 3 in Spanning Tree

Test yourself on Spanning Tree

The full Juniper JNCIS-ENT JN0-352 question bank has 846 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.