› Module 5: The Network Layer › 5.3 Routing Algorithms: Distance Vector vs Link State
M O D U L E

Module 5: The Network Layer

Logical addressing, IPv4/IPv6, subnetting, packet headers, and routing protocols (OSPF, BGP)

5.1 IP Addressing, Classes, and Subnetting

The Network Layer (Layer 3) enables host-to-host packet delivery across multiple interconnected networks. An IPv4 Address is a 32-bit logical address represented in dotted-decimal format (e.g. 192.168.1.1).

Figure 5.1: Classical IPv4 Address Classes (A, B, C) 0 Network ID (7 bits) Class A (1.0.0.0 - 126.x) Host ID (24 bits = 16,777,214 hosts per network) 10 Network ID (14 bits) Class B (128.0.0.0 - 191.255.x) Host ID (16 bits = 65,534 hosts per network) 110 Network ID (21 bits) Class C (192.0.0.0 - 223.255.255.x) Host ID (8b = 254 hosts) Subnetting borrows bits from the Host portion to create multiple internal subnets without consuming new public IPs.

Figure 5.1: Structure of Class A, B, and C IPv4 addresses showing the shifting boundary between Network and Host bits.

5.2 The IPv4 Packet Header Structure

Every IPv4 packet carries a 20 to 60-byte header containing control metadata required by intermediate routers to verify, fragment, and route the payload to its destination.

Figure 5.2: The IPv4 Packet Header Format (32 Bits Wide) Version (4b) IHL (4b) Type of Service (8b) Total Length (16 bits) Identification (16 bits) Flags (3b) Fragment Offset (13 bits) Time to Live (TTL - 8b) Protocol (8b - TCP/UDP) Header Checksum (16 bits) Source IP Address (32 bits) Destination IP Address (32 bits) Options (0 to 40 bytes) + Padding

Figure 5.2: Field-by-field layout of the standard IPv4 packet header.

5.3 Routing Algorithms: Distance Vector vs Link State

Routing algorithms determine the optimal mathematical path for forwarding packets from origin to destination across interconnected networks of routers.

Figure 5.3: Distance Vector (Rumor) vs Link State (Full Map) Routing Distance Vector (Bellman-Ford) "Routing by Rumour" A B Shares full table with neighbor • Exchanges distance table with direct neighbors only • Slow convergence; count-to-infinity problem Example: RIP Protocol (Max 15 hops) Link State (Dijkstra SPF) "Full Topology Map Known to All" • Floods link state advertisements (LSAs) to ALL • Fast convergence; zero routing loops Example: OSPF Protocol (Dijkstra)

Figure 5.3: Distance Vector routers share full tables with immediate neighbours; Link State routers flood link states to reconstruct the global map.

5.4 Routing Protocols (RIP, OSPF, BGP) and NAT

Real-world networks use standardized protocols to dynamically populate router forwarding tables:

  • RIP (Routing Information Protocol): Distance-vector protocol using hop count metric (max 15 hops; 16 signifies infinity/unreachable). Sends updates every 30 seconds via UDP port 520.
  • OSPF (Open Shortest Path First): Interior Gateway Protocol (IGP) based on Link-State technology. Divides networks into hierarchical areas (Area 0 = Backbone Area) and calculates shortest paths using Dijkstra's algorithm.
  • BGP (Border Gateway Protocol): Path-Vector Exterior Gateway Protocol (EGP) that connects distinct Autonomous Systems (AS) and routes all global Internet inter-domain traffic.
  • Network Address Translation (NAT): Enables thousands of private RFC 1918 hosts (e.g. 192.168.x.x, 10.x.x.x) to share a single public routable IP address using Network Address Port Translation (NAPT/PAT).
MODULE COMPREHENSIVE QUIZ

Module 5 Final Quiz

Test your understanding across all 4 topics of this module with interview-grade questions, tricky edge cases, and code output predictions.

Take Module 5 Final Quiz →
Yukti Mascot