Sub topic 9
Aging out stale entries
What this chapter assumes
You should already know how a switch learns a source address on the ingress port and how it uses the MAC address table to forward, flood or filter. This chapter covers the last part of an entry's life: how it expires, why that matters, and what goes wrong when the timer is badly matched to the traffic.
Why entries must expire
A switch never gets told when a host leaves. A laptop can be unplugged, a virtual machine can be migrated, or a cable can be moved to another switch, and the switch sees none of these directly. If entries lasted forever, two things would happen:
- The table would fill with addresses of devices that are gone. The table has a fixed size, so dead entries would eventually crowd out live ones.
- Frames for a host that moved silently would keep going to the old port, where nobody receives them.
Aging solves both problems with one rule: an entry that has not been refreshed for a set time is deleted.
How the aging timer works
Each entry stores the port and a timestamp of the last time the switch saw that address as a source. Two rules define the behavior:
- A frame whose source address matches an existing entry on the same port resets that entry's timer.
- If the idle time exceeds the aging time, the entry is removed. The default is 300 seconds (5 minutes) on Cisco IOS-style switches and on a Linux bridge.
Only frames sent by a host refresh its entry. A switch that forwards thousands of frames to a host does not refresh that host's entry, because lookups on the destination address do not touch the timer. A host that only receives traffic will age out even though it is busy.
Aging in code
The learning switch from earlier chapters stores (port, last_seen) for every address. Every source frame writes a fresh last_seen, and the destination lookup checks the age.
import time
AGING_SECONDS = 300
def is_group(mac):
# The least significant bit of the first octet marks multicast/broadcast.
return int(mac.split(':')[0], 16) & 1 == 1
class LearningSwitch:
def __init__(self, ports, aging=AGING_SECONDS):
self.ports = set(ports)
self.aging = aging
self.table = {} # mac -> (port, last_seen)
def handle(self, in_port, src, dst, now=None):
"""Return the list of ports the frame is sent out of."""
now = time.monotonic() if now is None else now
# 1. Learn or refresh the source address (this also handles host moves).
if not is_group(src):
self.table[src] = (in_port, now)
# 2. Look up the destination.
entry = None if is_group(dst) else self.table.get(dst)
if entry is not None and now - entry[1] > self.aging:
del self.table[dst] # expired entry
entry = None
if entry is None:
# Unknown unicast, broadcast or multicast: flood.
return sorted(self.ports - {in_port})
out_port = entry[0]
# Destination is behind the ingress port: filter the frame.
return [] if out_port == in_port else [out_port]The expiry check happens only when a frame is looked up. Real switches usually remove expired entries in the background, but the visible result is the same: after the timeout, the address is unknown.
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]In the last call, host A has sent frames the whole time, so its own entry stays fresh. Host B sent only one frame, at time 1, so its entry expired. Frames to B are flooded again until B transmits something.
What happens after expiry
Expiry does not break connectivity. The address becomes unknown, so the switch floods frames sent to it, exactly as for a host it has never seen. The host still receives them, and its reply re-creates the entry. The cost is extra traffic on every port in the VLAN, and any device on those ports can see the flooded frames.
The sequence for a one-way stream looks like this:
- Host B has been silent for more than the aging time, so its entry is gone.
- Host A keeps sending unicast frames to B.
- The switch floods each of them, because it has no entry for B.
- B replies, or sends anything. The switch learns B again and stops flooding.
Choosing an aging time
| Aging time | Benefit | Cost |
|---|---|---|
| Short (tens of seconds) | Frees table space quickly. Silently moved hosts become reachable sooner. | Idle but active hosts expire, and unknown unicast flooding increases. |
| Default (300 s) | Works for typical office traffic. | Silently moved hosts can be unreachable for up to 5 minutes. |
| Long (hours) | Little flooding for hosts that talk rarely. | Stale entries occupy the table. Moves are not noticed until the host transmits. |
| Disabled (0 on Cisco) | No expiry at all. | Dead entries accumulate, and moved hosts may stay unreachable. Rarely a good choice. |
No value is correct everywhere. Change the default only when you can point to a specific symptom.
Configuring and observing aging
On a Cisco IOS-style switch the aging time is set globally or per VLAN. Command names and ranges vary by platform and software version.
Switch# show mac address-table aging-time
Global Aging Time: 300
Switch# configure terminal
Switch(config)# mac address-table aging-time 600
Switch(config)# mac address-table aging-time 120 vlan 10On a Linux bridge the ageing time is a bridge property. The ip command takes it in hundredths of a second, so 30000 means 300 seconds.
# Show the current setting (look for "ageing_time")
ip -d link show br0
# Set the ageing time to 60 seconds (6000 centiseconds)
sudo ip link set dev br0 type bridge ageing_time 6000
# Watch entries; dynamic entries show a "used" timer, static ones are "permanent"
bridge fdb show br br0Run bridge fdb show br br0 several times while a host is idle. The dynamic entry's age grows and then the entry disappears. Static entries never age.
Common problems
Asymmetric traffic causes flooding
If traffic between two devices uses different paths in each direction, a switch on one path may see frames from only one of them. The other device never appears as a source there, so its entry never refreshes. The result is continuous unknown-unicast flooding, even though the table is mostly healthy. Load balancers, active/standby firewalls and equal-cost routing are common causes.
ARP cache outlives the MAC entry
A router or host can keep an IP-to-MAC mapping in its ARP cache for much longer than the switch keeps the MAC entry. Cisco routers use 4 hours by default, while the switch uses 5 minutes. If the destination host is quiet, the switch forgets it long before the router does. The router keeps sending unicast frames to the cached MAC address, and the switch floods every one of them. The usual fix is to make the two timers consistent: lower the ARP timeout below the MAC aging time, or raise the MAC aging time above the ARP timeout.
Silent moves leave a stale entry
When a virtual machine is live-migrated, or a host switches uplinks, the switch keeps the old entry until the new location sends a frame or the entry ages. Well-behaved migration tools send a gratuitous ARP or a reverse ARP frame so the new switch port is learned immediately. Without that frame, traffic keeps going to the old port for up to the aging time.
Topology changes shorten aging
When spanning tree reports a topology change, switches temporarily use a much shorter aging time so that entries pointing along the old paths disappear fast. A later chapter covers this in detail. The point here is that the configured aging time is not always the one in effect.
Exercises
Exercise
A switch has aging time 300 s. Host B sent one frame at t = 0 and has been silent since. Host A sends B a frame every 10 seconds, and the switch had learned B's address from that first frame. What does the switch do with A's frame at t = 290, and with A's frame at t = 310?
Show answer
At t = 290, B's entry is 290 seconds old, which is under 300, so the frame is forwarded out of B's port only. At t = 310 the entry is older than 300 s and has expired, so the switch floods the frame out of all other ports in the VLAN. A's frames do not refresh B's entry, because only frames with B as the source reset the timer.
Exercise
Users report that file transfers from a server to a client slow down every few minutes, and a packet capture on an unrelated host shows that host receiving unicast frames addressed to the client. The router's ARP timeout is 4 hours and the switch's MAC aging time is 5 minutes. Explain the cause and give one fix.
Show answer
The client sends little traffic, so its MAC entry on the switch expires after 5 minutes while the router's ARP entry stays valid. The router keeps sending unicast frames to the client's MAC address, and the switch floods them because the address is unknown. That is why the unrelated host sees them. Fixes include lowering the router's ARP timeout below the switch's MAC aging time (for example 4 minutes), or raising the switch's aging time above the ARP timeout.