Sub topic 4
The MAC address table: what it stores
This chapter assumes you know how a MAC address differs from an IP address, which fields an Ethernet frame carries (destination MAC, source MAC, EtherType), and the high-level roles of a hub, a switch and a router. Here you will see what the switch keeps in memory. Later chapters cover how entries get there and how they are used.
The table in one sentence
The MAC address table maps a MAC address to the switch port where that address was last seen. Switch vendors often call it the CAM table. CAM is content-addressable memory, hardware that finds a match by comparing the search key against all stored entries at once. A lookup therefore takes about the same time whether the table holds ten entries or ten thousand.
What each entry holds
| Field | Meaning |
|---|---|
| MAC address | The unicast address of a device, taken from the source field of a frame |
| VLAN | The VLAN in which the address was seen |
| Port | The single port through which that address is reachable |
| Type | Dynamic (learned automatically) or static (configured by an administrator) |
| Age | Time since the entry was last refreshed, used to remove idle entries |
On a VLAN-aware switch the lookup key is the pair of VLAN and MAC address, not the MAC address alone. The same address can therefore appear in two VLANs with different ports. The VLANs chapter covers this in detail.
Rules that shape the table
- Each key maps to exactly one port at a time. A switch cannot send a unicast frame "somewhere around" two ports.
- One port can appear in many entries. A port that leads to another switch usually has many addresses behind it.
- Only unicast addresses are stored. Broadcast and multicast addresses appear in the destination field but never as a frame's source, so they are not learned this way.
- The table holds Layer 2 information only. It has no IP addresses. Mapping an IP address to a MAC address is the job of ARP, which runs on the hosts.
Dynamic and static entries
Dynamic entries are created by the switch and removed after they sit idle. Static entries are typed in by an administrator and stay until removed. They are used for fixed devices or for security, as the static-entries chapter explains.
The same idea as a data structure
A dictionary is a good model of the table. This sketch uses the VLAN and MAC pair as the key.
table = {}
table[(1, "00:11:22:33:44:55")] = {"port": "Gi0/1", "type": "dynamic", "last_seen": 0.0}
table[(1, "00:11:22:33:44:66")] = {"port": "Gi0/2", "type": "dynamic", "last_seen": 3.5}
table[(10, "00:11:22:33:44:55")] = {"port": "Gi0/7", "type": "static", "last_seen": 0.0}
for (vlan, mac), entry in table.items():
print(vlan, mac, entry["port"], entry["type"])The same MAC address appears twice, once in VLAN 1 and once in VLAN 10. The entries are independent because their keys differ.
How it looks on real devices
A Cisco IOS-style switch prints the table like this:
Switch# show mac address-table
Mac Address Table
-------------------------------------------
Vlan Mac Address Type Ports
---- ----------- -------- -----
1 0011.2233.4455 DYNAMIC Gi0/1
1 0011.2233.4466 DYNAMIC Gi0/2
Total Mac Addresses for this criterion: 2Each row has the VLAN, the address, the type and the port. A Linux bridge shows the same information with this command:
bridge fdb show br br0Each line gives a MAC address, the port after dev, and flags such as permanent for static entries. Linux calls the table the forwarding database (FDB).
Exercise
A switch has the entries (VLAN 1, 00:aa) on Gi0/1 and (VLAN 20, 00:aa) on Gi0/5. Is this a contradiction, and does the table store any IP addresses?
Show answer
It is not a contradiction. The lookup key is the VLAN plus the MAC address, so the two entries are different keys, each mapping to one port. The table stores no IP addresses. It holds only Layer 2 data: MAC address, VLAN, port, type and age.