Computer Networks

date
May 1, 2025
type
Post
AI summary
slug
computer-networks
status
Published
tags
Networks
summary

OSI Model

Layer 2: Data Link Layer

The Data Link Layer is the second layer of the OSI model and provides reliable, structured communication over the physical medium. It ensures that data sent from one device on a local network can be correctly received by another device on the same network. Below is a breakdown of its key responsibilities and features:

1. Framing (Data Packaging)

The Data Link Layer groups raw bits from the Physical Layer into frames, which are structured units of data. Each frame typically includes:
  • Header: Contains control information, such as source and destination MAC addresses.
  • Payload: The actual data to be transmitted.
  • Trailer: Often includes error-checking data, such as a Cyclic Redundancy Check (CRC).
Framing allows the receiver to identify the beginning and end of each data unit, ensuring proper data segmentation and synchronization.

2. MAC Addressing (Hardware Identification)

The Data Link Layer uses MAC (Media Access Control) addresses, which are unique hardware identifiers assigned to network interfaces:
  • These addresses are used for local delivery of frames between devices on the same LAN.
  • Switches use MAC addresses to determine the correct port to forward a frame, enabling efficient frame delivery.

3. Error Detection and Correction

This layer helps ensure data integrity by detecting transmission errors:
  • Most commonly, it uses Frame Check Sequences (FCS) or CRC codes appended to the frame.
  • If a receiving device detects an error, it may discard the frame. Some protocols at higher layers handle retransmission.

4. Flow Control and Access Control

In shared networks, the Data Link Layer prevents data collisions and regulates transmission timing:
  • Media Access Control protocols like CSMA/CD (used in Ethernet) allow devices to detect whether the medium is free before sending data.
  • Wireless networks use CSMA/CA (Collision Avoidance) to minimize simultaneous transmissions.
These mechanisms help avoid congestion and data loss in busy networks.

5. Switch and Bridge Operation

Devices that operate at Layer 2 include network switches and bridges:
  • Switches read MAC addresses to forward frames to the correct device on the appropriate port.
  • Bridges connect different LAN segments and help reduce broadcast domains by making forwarding decisions based on MAC addresses.

6. Common Layer 2 Protocols

Several protocols function at the Data Link Layer:
  • Ethernet: Defines frame format and media access control for wired LANs.
  • ARP (Address Resolution Protocol): Resolves IP addresses to MAC addresses (though it bridges Layers 2 and 3).
  • PPP (Point-to-Point Protocol): Used in direct communication between two nodes, such as routers.
  • 802.11 (Wi-Fi): Defines wireless LAN frame handling and access control.

Layer 3: Network Layer

The Network Layer enables communication between devices that are not on the same local network. It ensures that data packets are properly routed across multiple networks to reach their final destination. This layer sits above the Data Link Layer and below the Transport Layer.

1. Logical Addressing (IP Addressing)

The Network Layer uses IP addresses to identify devices across different networks:
  • Unlike MAC addresses (which are tied to hardware), IP addresses are logical and can change depending on the network.
  • Each device on a network has a unique IP address, enabling global identification.

2. Routing (Path Determination)

The Network Layer is responsible for determining the best path for data to travel across networks. This process is handled by routers, which rely on two distinct operational planes:

a. Control Plane vs. Data Plane

  • Control Plane:
    • Responsible for building and maintaining the routing table.
    • Runs routing protocols such as OSPF, BGP, and RIP to learn network topology and exchange reachability information.
    • Makes decisions about the best path to each destination.
    • Operates in software (CPU).
  • Data Plane (also called Forwarding Plane):
    • Responsible for the actual forwarding of packets based on the routing table.
    • Performs a simple lookup in the forwarding information base (FIB) to decide which interface to send the packet out.
    • Operates in hardware or fast-path optimized software (e.g., ASICs in routers).
This separation allows routers to make intelligent decisions (control plane) while efficiently forwarding high volumes of traffic (data plane).

b. Routing Protocol Categories

Routing protocols are typically grouped into the following categories based on how they share and compute routing information:
i. Link-State Protocols
  • Examples: OSPF (Open Shortest Path First), IS-IS (Intermediate System to Intermediate System)
  • Each router independently builds a full map of the network topology by exchanging link-state advertisements (LSAs).
  • Once the map is complete, the router runs a shortest-path algorithm (typically Dijkstra’s algorithm) to compute the best routes.
  • Advantages:
    • Fast convergence.
    • More scalable and stable than distance-vector protocols.
  • Use case: Enterprise networks and internal segments of ISPs.
ii. Distance-Vector Protocols
  • Example: RIP (Routing Information Protocol)
  • Routers exchange only distance metrics (e.g., hop count) to reach destinations, not full topology.
  • Routing decisions are based on the information from direct neighbors.
  • Drawbacks:
    • Slower convergence.
    • Prone to routing loops without additional mechanisms (e.g., split horizon, hold-down timers).
iii. Path-Vector Protocols
  • Example: BGP (Border Gateway Protocol)
  • Used between autonomous systems (ASes) on the Internet.
  • Each route advertisement includes the entire path (AS path), which helps in loop prevention and policy control.
  • Routers make decisions based not just on shortest path but also on routing policies and attributes (e.g., AS path length, local preference).
  • BGP is the backbone protocol of the global Internet.

These routing protocols enable the control plane to populate the routing table, which the data plane then uses to forward packets efficiently across diverse and interconnected networks.

3. Packet Forwarding

After determining the best path, the Network Layer forwards packets to the next hop toward the destination:
  • Each packet has a header that includes source and destination IP addresses.
  • Routers examine these headers to determine how to forward the packet.

4. Fragmentation and Reassembly

Some data packets may exceed the maximum transmission unit (MTU) of a network:
  • The Network Layer can fragment packets into smaller pieces.
  • The receiving device reassembles the fragments to reconstruct the original packet.

5. Error Reporting and Diagnostics

Protocols at this layer support network troubleshooting and reporting:
  • ICMP (Internet Control Message Protocol) is used by tools like ping and traceroute.
  • These tools help diagnose routing issues and measure connectivity between devices.

6. Common Network Layer Protocols

Key protocols at Layer 3 include:
  • IPv4/IPv6: Core protocols for assigning and routing logical addresses.
  • ICMP: Used for control messages and error reporting.
  • IGMP: Used for managing multicast group memberships.
  • IPSec: Provides secure IP communication through encryption and authentication.

Devices that operate at this layer include routers, layer-3 switches, and firewalls that inspect or manipulate IP headers.

Layer 4: Transport Layer

The Transport Layer sits between the Network Layer (Layer 3) and the Application Layer (Layer 7). Its core mission is to provide end‑to‑end communication services for applications, hiding the details of the underlying network and ensuring that data arrives intact, in order, and at an acceptable pace.

1. Segmentation and Reassembly

The Transport Layer breaks large application messages into smaller segments that fit within the network’s Maximum Transmission Unit (MTU). Each segment receives a sequence number so the receiving host can:
  • Detect lost or out‑of‑order segments.
  • Reassemble segments into the original application payload.
This process allows applications to transmit arbitrarily large data streams without worrying about lower‑layer size limits.

2. Port Addressing and Multiplexing

To let many applications share a single host, the Transport Layer uses port numbers:
  • Source Port / Destination Port fields in the header identify the sending and receiving processes.
  • Ports enable multiplexing (multiple conversations over one IP) and demultiplexing (delivering the right data to the right socket).
  • Well‑known ports (0‑1023) are reserved for common services (e.g., 80 for HTTP, 443 for HTTPS), while 1024‑65535 are used for dynamic or private allocations.

3. Connection Establishment and Termination

Some transport protocols create a virtual circuit between hosts:
  • TCP uses a three‑way handshake (SYN → SYN‑ACK → ACK) to establish state on both ends, then a four‑step FIN/ACK exchange to close gracefully.
  • UDP is connectionless—it adds minimal header overhead and sends datagrams without setup, trading reliability for speed and simplicity.

4. Reliability and Error Recovery

Reliable protocols (notably TCP) guarantee that data arrives uncorrupted and in order:
  • Acknowledgments (ACKs) confirm receipt of segments.
  • Retransmission timers trigger resends when ACKs are missing.
  • Checksums in the header detect bit errors.
If a segment is lost or damaged, the sender retransmits until an ACK is received, shielding the application from network hiccups.

5. Flow Control

Flow control protects a slower receiver from being overwhelmed by a faster sender:
  • TCP’s sliding‑window advertises how many bytes the receiver can accept (the receive window).
  • The sender may transmit only ≤ window size before pausing for ACKs, matching the data rate to the receiver’s buffer capacity.

6. Congestion Control

While flow control manages the endpoint → endpoint pace, congestion control protects the network itself:
  • Algorithms such as Slow Start, Congestion Avoidance, Fast Retransmit, and Fast Recovery probe available bandwidth and back off when packet loss suggests congestion.
  • Modern variants—CUBIC, BBR, QUIC’s congestion controller—improve throughput and fairness under diverse conditions.

7. Common Transport‑Layer Protocols

Protocol
Key Features
Typical Use Cases
TCP
Reliable, connection‑oriented, ordered delivery, congestion & flow control
Web traffic, email, file transfer
UDP
Unreliable, connectionless, minimal overhead
Streaming media, VoIP, DNS, gaming
SCTP
Multi‑streaming, multi‑homing, message boundaries
Telecom signaling, industrial control
QUIC
Runs over UDP, integrates TLS 1.3, multiplexed streams, 0‑RTT
Modern web (HTTP/3), mobile apps
These protocols give application developers a spectrum—from maximum reliability (TCP) to minimal latency (UDP/QUIC)—to match transport behavior to the needs of each service.

With segmentation, port multiplexing, connection management, reliability mechanisms, and sophisticated congestion algorithms, the Transport Layer is the workhorse that turns best‑effort IP delivery into dependable, application‑friendly communication.

© Qiwei Mao 2024 - 2025