Layer 2 - Data Link Layer

Data Link Layer (Layer 2 of OSI Model)

Importance of Layer 2

  • The data link layer is critical for device-to-device communication.
  • Everything above layer 2 relies on its functionality.
  • It supports data transfer to and from the internet.

Fundamentals

  • Layer 2 operates over Layer 1, requiring a functional Layer 1 network.
  • Higher layers build on lower layers, adding features.
  • Layer 2 can run on different Layer 1 types (copper, fiber, WiFi) while providing the same capabilities.
  • Focus will be on Ethernet, commonly used in local networks (homes, offices).

Frames

  • Layer 2 introduces the concept of frames for sending information.

MAC Addresses

  • Layer 2 introduces MAC addresses, unique hardware addresses for each device.
  • MAC addresses are hexadecimal and 48 bits long (e.g., 3E:22:FB:…).
  • They are generally NOT software-assigned for physical networking.
  • Composition:
    • OUI (Organizationally Unique Identifier): Assigned to manufacturers of network devices.
    • NIC Specific: Unique to the Network Interface Controller.
  • Together, the MAC address should be globally unique.

Layer 1 and Layer 2 Interaction

  • Layer 2 (Ethernet) frames are transmitted onto the shared physical medium by Layer 1.
  • Layer 1 converts the frame into voltages, RF, or light.
  • Layer 1 transmits raw data without understanding the frame's content.

Frame Structure

  • A frame is a container with several components:
    • Preamble and Start Frame Delimiter:
      • Indicates the start of the frame, allowing devices to identify frame parts.
    • Destination and Source MAC Addresses:
      • Every device has a unique MAC address.
      • Destination MAC: Specifies the recipient device. Using all Fs signifies a broadcast to all devices.
      • Source MAC: Set to the transmitter's MAC address to allow replies.
    • EtherType (ET):
      • Specifies the Layer 3 protocol encapsulating data within the frame (e.g., IP).
    • MAC Header: These three fields (Destination MAC, Source MAC, EtherType) are collectively the MAC header, controlling destination, indicating source, and specifying function.
    • Payload:
      • Contains the data being sent, typically from a Layer 3 protocol.
      • Size: 46 to 1500 bytes for standard frames.
    • Encapsulation: Layer 3 data (e.g., IP packet) is placed inside the Ethernet frame.
    • The EtherType field indicates which Layer 3 protocol should receive the data at the destination.
    • Frame Check Sequence (FCS):
      • Used for error detection via a CRC (Cyclic Redundancy Check).
      • Allows the destination to check for data corruption during transmission.

Frame Transmission Process

  • Layer 2 software generates a frame.
  • The frame is passed to Layer 1.
  • Layer 1 transmits the raw data onto the physical medium.
  • At the destination, Layer 1 receives the raw data.
  • The data is passed to Layer 2 software, which interprets the frame and passes the data to Layer 3.

Addressing Layer 1 Limitations: Media Access Control

  • Problem with Layer 1 only:
    • Two devices connected via a single cable (shared physical medium) experience collisions.
    • Layer 1 transmits any data it receives without media access control.
    • If both devices transmit simultaneously, their signals interfere, corrupting the data.
    • Layer 2 solves this problem by providing controlled access to the physical medium to prevent collisions.