Computer Networking › Section F · The link layer and LANs › Topic F.4
Switched LANs: MAC addresses, ARP, switches, and VLANs
Inside an office, a campus or a home, devices reach one another through Ethernet switches. Four ideas make this work: MAC addresses, the Address Resolution Protocol, self-learning switches and virtual LANs.
Two addresses for two jobs
An IP address says where a host sits in the internet and changes when the host moves to another network. A MAC address names a network interface on one link and is normally assigned when the interface is made. It is 48 bits, written as six pairs of hexadecimal digits such as 02:00:00:00:00:0a, so there are \(2^{48}\), about \(2.8 \times 10^{14}\), possible values. The IEEE assigns the first three bytes to manufacturers, who number their own interfaces. The all-ones address ff:ff:ff:ff:ff:ff means every node on the LAN. Phones now often use randomised MAC addresses on Wi-Fi so that they are harder to track.
The Address Resolution Protocol
To send a datagram, a host knows the next hop's IP address but needs its MAC address. ARP supplies it. Each host keeps an ARP table of IP-to-MAC entries, which expire after a time that varies from system to system. If an entry is missing, the host broadcasts an ARP request to ff:ff:ff:ff:ff:ff asking who owns that IP address. Only the owner answers, with a unicast reply, and the asker caches the result. ARP needs no configuration. Because it trusts any reply, a malicious node can claim another node's address, which is why some networks add checks on ARP traffic.
Worked example: ARP and the gateway
A host at 192.168.10.37 with mask 255.255.255.0 and gateway 192.168.10.1 sends a datagram to 198.51.100.7. 1. Compare prefixes: the destination is outside 192.168.10.0/24, so the next hop is the gateway. 2. The ARP table has no entry for 192.168.10.1, so the host broadcasts an ARP request: who has 192.168.10.1? 3. The gateway replies directly with its MAC address, and the host stores it. 4. The frame has the gateway's MAC as its destination but the IP datagram still has 198.51.100.7 as its destination. 5. Had the destination been 192.168.10.200, inside the subnet, the host would have ARPed for that machine itself.
The Ethernet frame
An Ethernet frame starts with eight bytes that let the receiver synchronise its clock, a 7-byte preamble and a 1-byte start-of-frame delimiter, then the destination and source MAC addresses (6 bytes each), a 2-byte type field, the payload, and a 4-byte CRC. The type field names the protocol inside: 0x0800 for IPv4, 0x0806 for ARP, 0x86DD for IPv6. The payload runs from 46 to 1,500 bytes, so a frame is 64 to 1,518 bytes excluding the preamble. Ethernet is connectionless, with no handshake, and unreliable: a frame that fails its CRC is dropped without comment. Speeds have grown from 10 Mbit/s to hundreds of Gbit/s, but the format is unchanged.
Switches filter, forward and learn
A switch receives frames and sends each one out of the right port, using a switch table of entries holding a MAC address, a port and a time. It builds the table itself. When a frame arrives, the switch records the source address against the arrival port. To forward, it looks up the destination: if the entry points to another port, the frame goes only there (forwarding); if it points to the arrival port, the frame is discarded (filtering); if there is no entry, or the destination is broadcast, the frame is flooded out of every port except the one it arrived on. Entries age out after a set time, often several minutes. Hosts never notice a switch, and it needs no configuration, which is why it is called plug and play.
Worked example: a switch learns
A 5-port switch starts with an empty table. A is on port 1, B on port 2, C on port 3, D on port 4. 1. A sends to B. The switch learns A is on port 1, has no entry for B, and floods the frame to ports 2, 3, 4 and 5. 2. B replies to A. It learns B is on port 2 and sends the reply only to port 1. 3. C sends to A. It learns C on port 3 and forwards to port 1 alone. 4. D sends to B. It learns D on port 4 and forwards to port 2 alone. The table now has four entries. 5. If B is then moved to port 5, frames for B still go to port 2 until the entry expires or B transmits again, which corrects the table.
Switches versus routers, and loops
A switch forwards by MAC address, learns by itself and needs no configuration, but broadcasts such as ARP requests reach every host, so one huge switched network scales poorly. A router forwards by IP prefix, must be configured, and does not pass broadcasts on, so each of its subnets is a separate broadcast domain. Redundant links between switches give resilience but create loops in which flooded frames circulate forever, a broadcast storm. The Spanning Tree Protocol, devised by Radia Perlman in the 1980s, lets switches agree on a loop-free tree by blocking some ports, and bring them back if a link fails.
Virtual LANs
A virtual LAN (VLAN) divides one physical switch into several logical ones. Each port is assigned to a VLAN, and frames only reach ports of the same VLAN, so staff, students and guests sit in separate broadcast domains even when plugged into the same switch. A link between switches carries all VLANs by adding an IEEE 802.1Q tag of four bytes to each frame, including a 12-bit VLAN ID. The 4,096 possible values lose two reserved ones, leaving 4,094 usable VLANs. Traffic between two VLANs must pass through a router, or a switch with routing ability, which also lets the network apply filtering rules.
Common mistakes to avoid
First, thinking the destination MAC in a frame is that of the final destination. Across a router it is the next hop's MAC. Second, ARPing for a host on another subnet; the host ARPs for the gateway. Third, assuming a switch broadcasts every frame, which a hub does; a switch floods only when it has no entry. Fourth, expecting VLANs to talk to each other without a router. Fifth, forgetting that the tag adds four bytes to the frame.
Key takeaways
A MAC address is a 48-bit interface identifier on one link, and ff:ff:ff:ff:ff:ff reaches all. ARP finds the MAC for a next-hop IP address by broadcasting a request, and off-subnet traffic goes to the gateway's MAC. Ethernet frames carry destination and source MAC, a type field, 46 to 1,500 payload bytes and a CRC. Switches learn source addresses, then filter, forward or flood. Routers separate broadcast domains; spanning tree prevents loops. VLANs create separate logical LANs, tagged with 802.1Q, up to 4,094 of them.
Flashcards
Flashcard
48-bit identifier of a network interface on one link
Test your understanding
Question 1 of 5
A host at 10.0.5.20 with mask 255.255.255.0 sends to 10.0.9.30. What destination MAC address does it put in the frame?
Question 2 of 5
A frame from X to Y arrives at port 3 of a switch that has no entry for Y. What does the switch do?
Question 3 of 5
How many VLANs can be distinguished by a 12-bit VLAN ID, if two IDs are reserved?
Question 4 of 5
Why does an ARP request use the broadcast destination ff:ff:ff:ff:ff:ff?
Question 5 of 5
Two hosts on different VLANs are plugged into the same switch. What is needed for them to exchange traffic?
