layer-2.wiki

knowledge infrastructure // data-link layer

Data-Link Protocols

The data-link layer is the second layer of the OSI model, responsible for node-to-node data transfer between two directly connected nodes. It handles the packaging of data into frames, error detection, and flow control across the physical medium. Unlike higher layers that deal with logical addressing and routing, Layer 2 operates with the raw urgency of direct physical communication.

Protocols at this layer define the rules of engagement for how devices share a common transmission medium. Ethernet, the dominant LAN protocol, uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection) to manage simultaneous access. Token Ring, its historical counterpart, employed a deterministic token-passing mechanism that guaranteed orderly access but at the cost of latency.

Modern data-link protocols have evolved beyond simple medium access. Point-to-Point Protocol (PPP) provides authentication, encryption, and compression for serial links. The IEEE 802.11 family governs wireless LAN communication, introducing complex handshake sequences and power management that would have seemed science fiction to the engineers who designed the original Ethernet specification on a yellow coaxial cable in 1973.

Key Insight

Layer 2 is where the abstract world of software first touches the physical world of electrical signals, light pulses, and radio waves. Every higher-layer protocol depends on this translation working flawlessly.

The invisible architecture of communication

Network Topology

Network topology describes the arrangement of nodes and connections in a network. At Layer 2, topology is not merely an abstract diagram -- it directly determines how frames propagate, how collisions are managed, and how redundancy is achieved. The physical and logical topologies may differ: a network that physically resembles a star (all nodes connected to a central switch) operates logically as a series of point-to-point links at Layer 2.

Bus topologies, where all devices share a single communication backbone, were foundational to early networking. The original 10BASE5 Ethernet used a thick coaxial cable as a shared bus, with vampire taps physically piercing the cable sheath to attach devices. This elegant brutality gave way to star topologies centered on hubs and later switches, which isolated collision domains and dramatically improved throughput.

Ring topologies persist in specialized environments. Fiber Distributed Data Interface (FDDI) used a dual counter-rotating ring that could heal itself when a link failed, wrapping traffic onto the secondary ring within milliseconds. This self-healing property made FDDI the backbone of choice for campus networks throughout the 1990s before Gigabit Ethernet rendered it obsolete.

Historical Note

The shift from shared-medium to switched topologies in the mid-1990s was the most significant architectural change in LAN history, enabling full-duplex communication and eliminating the collision domain that had constrained network performance since Ethernet's inception.

Frame Structure

The frame is the fundamental unit of data at Layer 2. It encapsulates the payload from higher layers within a precisely structured envelope of header and trailer fields. An Ethernet II frame begins with a 7-byte preamble of alternating 1s and 0s -- a synchronization signal that allows the receiving device to lock onto the incoming bitstream -- followed by a 1-byte Start Frame Delimiter that marks the beginning of the actual frame content.

The header carries the destination and source MAC addresses (6 bytes each) and a 2-byte EtherType field that identifies the protocol of the encapsulated payload. The payload itself ranges from 46 to 1500 bytes in standard Ethernet, with jumbo frames extending this to 9000 bytes for high-performance environments. A 4-byte Frame Check Sequence (FCS) using CRC-32 polynomial division provides error detection at the trailer.

This frame structure has remained remarkably stable since its standardization. While the speeds have increased from 10 Mbps to 400 Gbps, the fundamental frame format has endured -- a testament to the elegance of the original design. VLAN tagging (802.1Q) inserts a 4-byte tag between the source address and EtherType, enabling logical network segmentation without altering the core structure.

Technical Detail

The minimum frame size of 64 bytes (including header and FCS) was not arbitrary -- it was calculated to ensure that a collision would be detected before the transmitting station finished sending the frame on a maximum-length Ethernet segment.

Where bits become meaning

Layer 2 Switching

A Layer 2 switch is the central intelligence of a modern local area network. Unlike the passive hubs it replaced, a switch examines the destination MAC address of each incoming frame and forwards it only to the port where that destination resides. This targeted forwarding eliminates unnecessary traffic on other ports and allows simultaneous communication between multiple port pairs -- a capability called wire-speed switching.

Switches maintain a MAC address table (also called a CAM table -- Content Addressable Memory) that maps MAC addresses to physical ports. This table is built dynamically through a learning process: when a frame arrives on a port, the switch records the source MAC address and the port number. When the destination is unknown, the switch floods the frame to all ports except the source -- a process that naturally resolves as the table populates.

Modern switches implement sophisticated features that extend far beyond basic forwarding. Spanning Tree Protocol (STP) prevents broadcast storms in networks with redundant links by logically disabling loop-creating paths. Quality of Service (QoS) mechanisms allow switches to prioritize time-sensitive traffic like voice and video. Port security features can lock ports to specific MAC addresses, preventing unauthorized device connections.

Architecture Note

The evolution from store-and-forward switching (buffer the entire frame, check FCS, then forward) to cut-through switching (begin forwarding after reading just the destination MAC) reduced latency from microseconds to nanoseconds, enabling the real-time applications that define modern networking.

MAC Addressing

The Media Access Control (MAC) address is the identity of a network interface at Layer 2. It is a 48-bit address, conventionally written as six pairs of hexadecimal digits separated by colons or hyphens. The first three octets identify the manufacturer (the Organizationally Unique Identifier, assigned by IEEE), while the last three are assigned by the manufacturer to ensure global uniqueness.

Unlike IP addresses, which are logically assigned and can change, MAC addresses are burned into the hardware -- or at least they were originally. Modern network interfaces allow MAC address modification in software, a capability exploited by both legitimate use cases (virtual machine networking, privacy-preserving MAC randomization) and malicious ones (MAC spoofing to bypass access controls).

Special MAC addresses serve specific functions: FF:FF:FF:FF:FF:FF is the broadcast address, reaching all devices on a network segment. Multicast addresses (identified by the least significant bit of the first octet being set to 1) enable one-to-many communication for protocols like STP and link-layer discovery. The Address Resolution Protocol (ARP) bridges Layer 2 and Layer 3 by resolving IP addresses to MAC addresses through a broadcast-and-reply mechanism.

Design Philosophy

The 48-bit address space provides approximately 281 trillion unique addresses -- a number that seemed inexhaustible in 1980. With the explosion of IoT devices, the move to 64-bit Extended Unique Identifiers (EUI-64) ensures addressing will scale for decades to come.

Every device has a name. Every frame knows its destination.

Bridging & VLANs

Bridges were the original devices for connecting separate Layer 2 network segments. A bridge operates by learning which MAC addresses exist on each of its ports and selectively forwarding frames between segments only when necessary. This simple intelligence transformed networking: suddenly, a building could have multiple Ethernet segments that appeared to be a single network, with the bridge filtering unnecessary traffic at the boundaries.

Virtual LANs (VLANs) abstracted this concept further, allowing a single physical switch to operate as multiple independent broadcast domains. By tagging frames with a VLAN identifier (the 802.1Q standard inserts a 4-byte tag into the Ethernet frame), network administrators can create logical network boundaries that have nothing to do with physical location. A device in one building can be on the same VLAN as a device in another, sharing a broadcast domain across trunk links.

VLAN trunking protocols automate VLAN configuration across switch fabrics, while inter-VLAN routing at Layer 3 allows controlled communication between these isolated domains. The combination of VLANs, Spanning Tree Protocol, and link aggregation (802.3ad) creates a resilient, segmented, high-bandwidth Layer 2 fabric that forms the foundation of modern enterprise networks and data center architectures.

Evolution

Software-Defined Networking (SDN) represents the latest evolution of Layer 2, separating the control plane from the data plane and enabling programmatic control of switching behavior through protocols like OpenFlow -- transforming rigid hardware configuration into fluid, software-defined infrastructure.