COMP — Link Layer & LANs (Week 7)
Week 7 – Data/Link Layer & Local Area Networks (LANs)
Administrative Announcements
Trimester break has finished – welcome back.
Assignment 2 (second assignment) due Friday of this week
• All info already given (see ~15 min of Week 6 lecture start).
• Nothing from today is required to complete A2.
• Contact lecturer early for misunderstandings / extension requests.
1 OSI Context & Why the Link Layer Matters
Layer ordering reminder:
• Layer 1 Physical (cables, radio).
• Layer 2 Data-Link (today’s focus).
• Layer 3 Network/IP (last week).
• Above: Transport, Application.
For network engineers, Layer 3 (routing) and Layer 2 (link/LAN) are where you spend most “logical” time; Layer 1 = pure hardware.
Link-layer = direct interface between host’s NIC and the medium.
• It transfers a network-layer datagram one hop to a physically‐adjacent node (same “segment”).
Terminology mapping:
• L3 packet → Frame at L2.
• “Subnet” (IP) ≈ “segment/collision domain” (Ethernet).
• Two hosts in same subnet normally talk using MAC, not IP, on the wire.
2 Frames & Encapsulation
Encapsulation: IP datagram ⟶ encapsulated in a link-layer frame with:
• Link Header (MAC src/dst, type, etc.)
• Payload (IP datagram)
• Link Trailer (CRC, End-of-Frame delimiters).
At this layer we always add both header and trailer (unlike TCP/UDP that add only a header).
Trailer roles:
• Mark end of frame for sniffers.
• Store error-checking codes (e.g.xC FCS) for reliability.
3 Network Interface Cards (NICs)
Still called NIC for historical reasons (once plug-in cards).
• Today integrated in laptop motherboard / SoC / Wi-Fi chip.
• Implements Link & Physical layers: hardware + firmware + driver software.
Connects to host via various buses (PCIe, USB, SPI/I²C on embedded).
• Signal modulation different for Cat5 vs Antenna, emphasising hardware nature.
4 Link-Layer Services
• Framing
• Medium Access Control (MAC) – rules for placing bits on medium.
– Crucial in Wi-Fi (different modulations).
• Optional Reliable Delivery
– Often enabled on error-prone links (wireless, dial-up, LoRaWAN).
– Not needed for very low-error fibre.
• Flow Control (protect limited switch/host buffers).
• Error Detection (always) & Error Correction (sometimes).
– Link-layer algorithms more powerful than higher-layer Internet Checksum because can be hardware-accelerated.
5 Error‐Handling Algorithms
5.1 Parity
Even parity bit: choose p such that Sum from i=1 to n of b_i + p is congruent to 0 (mod 2).
• Detects one-bit errors but cannot locate which bit.
2-D Array parity: rows + columns parity bits.
• Detects & corrects single-bit flips (intersection reveals error).
• Fails on multi-bit patterns.
5.2 CRC (Cyclic Redundancy Check)
Sender treats bits as polynomial G(x), appends R(x) s.t. divisible by generator.
Receiver divides; non-zero remainder ⇒ error.
Ethernet uses 32-bit CRC, Wi-Fi varies, classical modems used 16-bit.
Detects:
• all 1- & 2-bit errors,
• all odd-bit errors,
• burst ≤16 bits with 16-bit CRC (larger for 32-bit).
Cheap hardware: XOR gates + shift register.
6 Duplex & Physical Characteristics
Simplex: one-way only (rare in networks).
Half-duplex: both can send, but not simultaneously (Wi-Fi, walkie-talkie).
Full-duplex: simultaneous send/receive (modern Ethernet pairs, most fibre pairs).
7 Link Types
7.1 Point-to-Point (P2P)
Exactly two nodes share link (router ↔ router serial, dial-up, microwave link).
Media access trivial; historically common in Cisco serial labs.
7.2 Multiple Access / Broadcast
Shared medium: collisions possible.
Need MAC protocols to coordinate.
Channel partitioning techniques
TDMA (Time-division): predictable slots, wasted if node idle.
FDMA (Freq-division): distinct sub-carriers; used in WDM fibre.
Token (taking turns): e.g.xC IBM Token Ring; deterministic but non-scalable.
Random access (dominant): allow collisions, recover (Ethernet CSMA/CD); or try to avoid (Wi-Fi CSMA/CA).
8 Evolution of Ethernet
8.1 Coax Bus Ethernet (802.3 original)
Thick/Yellow coax; 500 m segment, min 3 m tap spacing.
10 Mb/s; shared collision domain.
8.2 Hubs (Layer-1 Repeaters)
Multi-port device that electrically replicates incoming bits to all ports.
• Still one collision domain.
• Cheap ($≈5), dumb; uncommon today.
8.3 Repeaters & Length limits
Amplify/regen signals, extend segment but still part of same collision domain.
Limited count—propagation delay must stay < “slot time” so collisions detectable.
8.4 Bridges (2-port Layer-2)
Listen promiscuously on each attached segment.
Forward only complete, error-free frames whose destination lies on other segment.
Effect: break up collision domains; localise traffic.
8.5 Switches (Multi-port Bridges)
Every port = its own segment ⇒ virtually zero collisions.
Internally a matrix of bridges; store-and-forward, optional buffering.
Can still attach hubs or cascaded switches → hierarchical LAN.
Collision Domain Recap
Segment(s) where simultaneous transmissions may collide.
Bridges/switches create separate collision domains even inside one IP subnet.
9 CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
Host wishing to send listens; if idle send immediately.
If busy, waits random back-off (exponential after each collision).
While sending, keeps sensing: collision detected ⇒ transmit 32-bit Jam signal, abort.
Everybody hearing jam backs off random slot.
Efficiency acceptable; disappears entirely if every host on its own switch port.
10 MAC (LAN) Addressing
48-bit globally unique address burned into NIC (can be overridden).
Format: six octets hex, e.g.
64:6E:0C:12:A4:FE
.First 3 octets = OUI (Organisationally Unique ID) purchased from IEEE.
• Lookup tools map OUI → vendor.
Bits of first octet:
• b0 (I/G) 0 = unicast, 1 = group.
• b1 (U/L) 0 = globally administered, 1 = locally (randomised) address.
MAC addresses are portable (unlike IP) and only significant on local segment.
11 Address Resolution Protocol (ARP)
Needed because L3 IP ↔ L2 MAC mapping not implicit.
Steps (IPv4 only):
If destination IP within same subnet, sender broadcasts ARP Request: "Who has 192.168.0.5?".
Owner replies ARP Reply unicast with its MAC.
Sender caches entry in ARP table (timeout ageing).
If dest IP remote, host ARPs only for default-gateway’s MAC.
IPv6 replaces ARP with Neighbour Discovery / ICMPv6.
Commands:
arp -a
(Windows) shows table.
12 Ethernet II Frame Format
| Preamble 7B | SFD 1B | Dest MAC 6B | Src MAC 6B | Type 2B |
| Payload 46–1500B ( + optional 4B 802.1Q VLAN tag ) |
| CRC/FCS 4B |
Preamble:
101010…
(7 bytes) + Start-of-Frame‐Delimiter10101011
(1 byte) for clock sync.Type/Length field: e.g.
0x0800
= IPv4,0x86DD
= IPv6,0x0806
= ARP.Min payload 46 bytes (pads if shorter).
Max payload 1500 B (standard MTU); jumbo ≈ 9000 possible in DC.
CRC-32 trailer checks integrity + marks end.
Optional 802.1Q VLAN tag (4 bytes) inserted after Src MAC (see next lecture).
13 Switch Operation in Detail
Learning: on every received frame the source MAC is stored in CAM/TCAM table with ingress port, timer reset.
Forwarding/Filtering:
• If Dest MAC known → send out associated port only.
• If unknown / multicast / broadcast → Flood out all ports except incoming.
Aging: entries expire (default 5 min Cisco) so moved hosts are relearned.
Store-and-forward: entire frame buffered, CRC checked, then forwarded; allows speed mismatches (1 Gb port ↔ 100 Mb printer).
14 Switches vs Routers
Aspect | Switch (Layer 2) | Router (Layer 3) |
---|---|---|
Operates on | MAC addresses & Frame header | IP addresses & Datagram header |
Table built by | Automated learning + flooding | Routing protocols, static routes |
Collision handling | Eliminated per-port | Not applicable (next-hop decision only) |
Typical speed | Very high (ASIC) | Slightly lower; more processing |
Scope | Single broadcast domain (subnet) | Interconnects multiple subnets |
Terminology | CAM/TCAM, FDB | RIB/FIB, routing table |
Multilayer (L3) switches incorporate both behaviours: ASIC switching within VLAN, routing between VLANs.
15 Full Summary / Key Takeaways
Link-layer frames move one hop; routers forward datagrams hop-by-hop.
Ethernet dominates wired LANs; evolved from coax → hubs → switches.
CSMA/CD allows efficient random access on shared media; modern switched Ethernet removes collisions entirely.
NICs integrate hardware error detection (CRC), signalling, buffering.
MAC addresses are global, 48-bit, vendor-assigned; ARP binds them to IPv4 addresses.
Switches learn MAC→port mappings, flood unknowns, and age tables to adapt.
Error detection parity/CRCs give high reliability before upper layers even see data.
Conceptual mapping:
• Segment/collision-domain ≈ VLAN broadcast domain.
• Subnet (IP) commonly maps 1 : 1 to broadcast domain, but virtualisation (VLANs) can break this (next lecture).
Practical CLI Nuggets (for lab)
Show NICs:
ipconfig /all
(Win) /ip a
(Linux).View ARP cache:
arp -a
(Win) /ip neigh
(Linux).Change duplex on NIC (Windows Advanced tab /
ethtool
Linux).OUI lookup online reveals vendor (e.g.xD Dell, Intel, Cisco).
Packet capture requires promiscuous mode (e.g.xD Wireshark) to see non-destined frames.
Next lecture/lab: VLAN tagging, trunk links, switch-router interoperation, hands-on flooding/learning demos.