Sub topic 9
Aging Out Stale Entries
This chapter assumes you know how source learning fills the MAC address table and how the forwarding decision uses it. Here we cover what happens to entries that stop being useful.
Why entries must expire
A switch learns an address when it sees a frame from it. It has no signal for when a host leaves. A laptop may be unplugged, a VM may be deleted, or a phone may roam to another access point. If the switch kept the old entry forever, it would send frames to a port where nobody is listening. The table would also fill with addresses that no longer exist.
Aging solves both problems. Each entry records when its source address was last seen. If no frame from that address arrives within the aging time, the switch deletes the entry.
How aging works
Two rules govern an entry's lifetime:
- Refresh on source. Every frame received from a known source address resets that entry's timer. Only frames sent by the host refresh it. Frames sent to the host do not.
- Expire on silence. When the timer exceeds the aging time, the entry is removed.
After removal, a frame addressed to that host is treated as unknown unicast and flooded. When the host replies, the switch learns the address again and returns to forwarding to a single port.
Seeing it in code
The learning switch from the previous chapters checks the age of an entry when it looks up a destination. This run reuses the LearningSwitch class:
sw = LearningSwitch(ports=[1, 2, 3])
A = '00:00:00:00:00:0a'
B = '00:00:00:00:00:0b'
print(sw.handle(1, A, B, now=0)) # B unknown: flood -> [2, 3]
print(sw.handle(2, B, A, now=1)) # A was learned on port 1 -> [1]
print(sw.handle(1, A, B, now=2)) # B was learned on port 2 -> [2]
print(sw.handle(1, A, B, now=400)) # B aged out (400 - 1 > 300): flood -> [2, 3]B last sent a frame at time 1. By time 400 it has been silent for 399 seconds, which is more than the 300-second limit. The entry is deleted and the frame floods. In the last call A's own entry is refreshed, because A is the source.
Real switches usually scan the table in the background instead of checking at lookup time. The visible result is the same.
Choosing the aging time
Many switches default to 300 seconds. You can change it, and the trade-off runs in two directions:
| Aging time | Benefit | Cost |
|---|---|---|
| Short | Stale entries disappear quickly. The table stays small. | Idle but active hosts are forgotten, so more frames flood. |
| Long | Less flooding and fewer relearning events. | Dead entries linger. After a host moves silently, frames may go to the wrong port. |
Aging is per entry, not per switch
Each entry has its own timer. Busy hosts stay in the table, and idle ones drop out. Static entries, covered in a later chapter, are exempt from aging.
On a Cisco IOS-style switch, show mac address-table aging-time prints the current value. On Linux, the bridge's value is a property of the bridge device, and bridge fdb show br br0 lists entries.
Exercise
Host X sends one frame at t=0 and then stays silent. Host Y sends X a frame every 10 seconds. The aging time is 300 seconds. What does the switch do with Y's frames after t=300, and why?
Show answer
After t=300 the switch removes X's entry because X has sent nothing for longer than the aging time. Y's frames are only destination lookups, which do not refresh X's entry. Each of Y's frames to X is then flooded as unknown unicast until X transmits again and is relearned.