Sub topic 10
Topology changes and MAC table aging
This chapter assumes you know how a switch learns MAC addresses into its forwarding table and floods unknown unicast frames. It also assumes you can read the output of show spanning-tree. You should already understand port roles and the classic 802.1D port states from earlier chapters.
Why a topology change is a problem
A switch forwards a frame by looking up the destination MAC address in its MAC address table. Each entry maps a MAC address to the port where that address was last seen. Entries age out after 300 seconds by default on Cisco IOS.
That works while the topology is stable. When a link fails or a blocked port starts forwarding, the path to some hosts changes. The old entries can then point at the wrong port.
Consider this case:
- Host A is reached through switch SW3 via port Gi0/1.
- The link on Gi0/1 fails, and spanning tree unblocks Gi0/2, which gives a new path.
- SW1 and SW2 still hold entries that send frames for host A toward the dead path.
Those frames are dropped until the stale entries expire or are replaced. With a 300-second aging time, host A could be unreachable for up to five minutes even though spanning tree has already reconverged. Spanning tree needs a way to tell every switch to discard its old entries quickly. That mechanism is the topology change notification.
What counts as a topology change
The rules differ between classic STP and RSTP.
| Protocol | Events that trigger a topology change |
|---|---|
| 802.1D | A port moves to forwarding, or a port that was forwarding moves to blocking. |
| 802.1w (RSTP) | A non-edge port moves to forwarding. A port moving to discarding does not trigger one. |
Edge ports (PortFast) never trigger a topology change in either case. A host powering on or off should not make the whole network flush its tables. This is one of the main reasons to configure PortFast on host-facing ports.
The RSTP rule makes sense. When a port goes down, the switches that lost a path still hold the stale entries, but they learn of the problem through the loss of the link itself. A newly forwarding port is what creates the chance that traffic now arrives from a different direction, so that event is what has to be announced.
Classic 802.1D: TCN and the TC flag
In 802.1D, only the root bridge can tell all switches to shorten their aging time. A non-root switch that detects a change must get the news to the root first. The process has these steps:
- The switch that detects the change sends a Topology Change Notification (TCN) BPDU out its root port. A TCN BPDU is a short BPDU with no configuration information.
- The upstream switch acknowledges it by setting the Topology Change Acknowledgment (TCA) flag in the configuration BPDUs it sends downstream. It then forwards the TCN out its own root port.
- This repeats hop by hop until the TCN reaches the root bridge.
- The root sets the Topology Change (TC) flag in all the configuration BPDUs it sends. It keeps the flag set for max age plus forward delay, which is 35 seconds with default timers.
- Every switch that receives a BPDU with the TC flag set reduces its MAC table aging time to the forward delay, 15 seconds by default, for the duration of the flag.
The effect is that stale entries expire within about 15 seconds, and entries for hosts that are still active are relearned as soon as they send traffic.
RSTP: flushing instead of waiting
RSTP handles topology changes differently, and the difference is faster. There is no separate TCN BPDU. Instead:
- The switch that detects a change sets the TC flag in its own BPDUs and sends them out all its designated ports and its root port. It does this for twice the hello time, which is 4 seconds by default.
- The switch immediately flushes the MAC entries learned on all its non-edge ports, except the port on which the change was detected. It does not wait for a shortened aging timer.
- A neighbor that receives a BPDU with the TC flag flushes its own entries on its other ports and propagates the flag onward.
The change spreads across the network from the point of origin in every direction. It does not have to travel to the root and back, so convergence of the forwarding tables takes a few seconds instead of tens of seconds.
Seeing topology changes
The show spanning-tree detail command reports how many topology changes a switch has seen and where the latest one came from.
! Cisco IOS
show spanning-tree vlan 10 detailA typical excerpt looks like this:
VLAN0010 is executing the rstp compatible Spanning Tree protocol
Bridge Identifier has priority 32768, sysid 10, address 0011.2233.4401
Number of topology changes 14 last change occurred 00:00:42 ago
from GigabitEthernet0/7
Times: hold 1, topology change 35, notification 2
hello 2, max age 20, forward delay 15The line to watch is "last change occurred ... ago from ...". It names the port that caused the most recent change. On a healthy network the counter rises rarely, and only when a real link comes up or fails.
Common causes of repeated topology changes
If the counter keeps climbing, the network is flushing MAC tables over and over. The effect is a burst of unknown-unicast flooding each time, which can saturate links and hurt performance. These are the usual causes:
- Host ports without PortFast. In classic STP, a PC that reboots makes its port go to forwarding and then to blocking, and each change sends a TCN. In RSTP, a port that is not configured as an edge port and is not recognized as one acts the same way.
- A flapping link. A bad cable, a failing transceiver, or a duplex mismatch causes the port to go up and down. Each transition may cause a change.
- A device that bridges or sends BPDUs. A small unmanaged switch added by a user can create changes when its links come and go.
The "from" port in the output leads you directly to the source. Run the command again on the switch connected to that port, and repeat until you reach the switch where the change started.
Tuning the aging time
The aging time can be changed per VLAN:
! Cisco IOS
configure terminal
mac address-table aging-time 600 vlan 10
end
show mac address-table aging-timeLowering it frees table space sooner, and raising it reduces flooding for hosts that talk rarely. Do not use a short aging time as a substitute for fixing topology changes. Spanning tree already shortens it when it matters.
Edge cases
- Different protocol versions. If an RSTP switch receives a classic 802.1D BPDU on a port, it falls back to 802.1D behavior on that port, including the TCN process. Mixed networks therefore keep some of the slower behavior.
- Non-root change sources in 802.1D. If the root bridge itself detects the change, it sets the TC flag directly without waiting for a TCN.
- Per-VLAN scope. With PVST+ and Rapid PVST+, each VLAN has its own spanning tree, so a topology change in VLAN 10 flushes entries only for VLAN 10.
Exercise
In a network running classic 802.1D, a user reboots a PC that is connected to an access port with no PortFast configured. What happens in the network, and what single change prevents it?
Show answer
The port goes to forwarding when the PC starts and to blocking or down when it stops. Each transition counts as a topology change, so the switch sends a TCN toward the root. The root sets the TC flag, and every switch shortens its MAC aging time to 15 seconds. This causes unnecessary flushing and unknown-unicast flooding. Configuring spanning-tree portfast on the port makes it an edge port, and edge ports do not generate topology changes.
Exercise
The output of show spanning-tree vlan 20 detail shows "Number of topology changes 380 last change occurred 00:00:03 ago from GigabitEthernet0/12". What do you do next?
Show answer
Treat Gi0/12 as the source. Check whether it faces a host, in which case PortFast is missing, or another switch, in which case you run the same command on the neighbor and follow the "from" port until you find where the change starts. Also check the interface for flaps in the logs and for errors with show interfaces, because a bad cable or transceiver commonly causes repeated changes.