Unit 4: Network layer

CAP7001 — Data Communication And Networking 9 min read

I. Orientation — Logical Addressing and Packet Delivery

The network layer, Layer 3 of the OSI model, provides logical addressing and transfers packets across interconnected networks. Internet Protocol version 4 (IPv4) uses 32-bit addresses, while routers select paths and forward packets toward destination networks.

  • Primary data unit: The network-layer protocol data unit is an IP packet, also called a datagram.
  • Logical addressing: An IPv4 address contains 32 bits, written as four decimal octets, such as 192.168.1.20.
  • Routing and forwarding:
    • Routing: Builds knowledge of paths to destination networks.
    • Forwarding: Sends each packet through the appropriate router interface.
  • Router decision: A router compares the packet’s destination IP address with routing-table entries and applies longest-prefix matching.
  • Delivery scope:
    • Direct delivery: Source and destination are on the same network.
    • Indirect delivery: One or more routers connect the source to the destination.
  • Core routing-table fields: Destination network, subnet mask or prefix, next-hop address, outgoing interface, route source, and metric.
  • Control principle: Static routes are entered administratively; dynamic routes are learned and updated through routing protocols.

II. Classful Addressing — Fixed IPv4 Network Boundaries

A. Classful addressing

Classful addressing divides the IPv4 address space into classes with fixed boundaries between network and host portions.

  • Address classes:
    • Class A: First bit 0; first octet 1–126; default mask 255.0.0.0 or /8.
    • Class B: First bits 10; first octet 128–191; default mask 255.255.0.0 or /16.
    • Class C: First bits 110; first octet 192–223; default mask 255.255.255.0 or /24.
    • Class D: First bits 1110; range 224.0.0.0–239.255.255.255; used for multicast.
    • Class E: Range 240.0.0.0–255.255.255.255; reserved or experimental.
  • Special range: 127.0.0.0/8 is reserved for loopback; for example, 127.0.0.1 identifies the local host.
  • Host calculation: For a network with h host bits, traditional usable host addresses equal:
    TEXT
    Usable hosts = 2^h - 2

    Here, one address represents the network and one represents the directed broadcast.
  • Example: 172.16.5.10 is Class B under classful rules, so its default network is 172.16.0.0/16.
  • Limitation: Fixed classes waste addresses and do not represent arbitrary prefix lengths; classless inter-domain routing largely replaced them.

III. Public and Private Addresses — Controlling Global Reachability

A. Public and private addresses

Public addresses are globally routable and unique, whereas private addresses are reserved for internal networks and are not routed across the public Internet.

  1. Public addresses:

    • Allocation: Address blocks ultimately originate with the Internet Assigned Numbers Authority and are distributed through regional registries and service providers.
    • Reachability: A public server may be reached across the Internet if routing and security policies permit it.
    • Uniqueness: Simultaneous global use requires a unique public address.
  2. Private addresses:

    • Reserved blocks:
      • 10.0.0.0/8
      • 172.16.0.0/12
      • 192.168.0.0/16
    • Reuse: Separate organizations may both use 192.168.1.0/24 because the networks are not globally routed.
    • Requirement: A private-addressed host normally needs NAT or an application proxy to communicate with public Internet systems.
    • Distinction: Private does not mean secure; firewalls, authentication, and access controls remain necessary.

IV. Network Address Translation (NAT) — Rewriting Packet Addresses

A. Network address translation (NAT)

NAT allows a translating router or firewall to replace IP addresses, and sometimes transport-layer ports, as packets cross an address-domain boundary.

  • Static NAT: Maintains a fixed one-to-one mapping, such as private 10.0.0.10 to public 203.0.113.10.
  • Dynamic NAT: Temporarily maps internal addresses to available addresses from a public pool.
  • PAT or NAT overload: Maps many private hosts to one public address by assigning distinct TCP or UDP source ports.
  • Translation record: A NAT table may associate:
    TEXT
    Inside local  192.168.1.5:49160
    Inside global 203.0.113.8:30001
    Destination   198.51.100.20:443
  • Packet processing: Outbound translation changes the source address or port; return traffic is matched to the table and translated back.
  • Benefits: NAT conserves public IPv4 addresses and permits private internal addressing.
  • Limitations: It weakens end-to-end connectivity, complicates unsolicited inbound sessions, and may disrupt protocols that embed IP addresses in payloads.

V. Static Routing — Administrator-Defined Paths

A. Static routing

Static routing uses manually configured routes that remain unchanged until an administrator modifies or removes them.

  • Route components: A static route identifies a destination prefix and either a next-hop address or outgoing interface.
    TEXT
    Destination prefix → Next hop / Exit interface
  • Example: To reach 192.168.20.0/24, Router A may forward packets to neighboring router 10.0.0.2.
  • Advantages: Static routes are predictable, consume no routing-update bandwidth, and reduce exposure to false routing advertisements.
  • Suitable uses: Small stable networks, stub networks with one exit, management paths, and backup routes.
  • Administrative distance: A floating static route can be assigned a less-preferred administrative distance so that it activates only when a primary dynamic route disappears.
  • Limitations: Manual configuration scales poorly, topology changes are not discovered automatically, and incorrect entries can create loops or unreachable networks.

VI. Dynamic Routing — Automatic Route Exchange

A. Dynamic routing

Dynamic routing protocols allow routers to discover networks, exchange path information, and adapt routes when the topology changes.

  • Main operations: Routers discover neighbors, advertise reachable prefixes, calculate best paths, install routes, and update them after failures.
  • Metric: A protocol compares routes through quantities such as hop count, cost, bandwidth, or delay.
  • Convergence: Convergence occurs when routers reach a consistent view after a topology change; faster convergence reduces packet loss and loops.
  • Protocol categories:
    • Interior gateway protocols: Operate within an autonomous system; RIP and OSPF are examples.
    • Exterior gateway protocols: Exchange reachability between autonomous systems; BGP is the principal example.
  • Advantages: Dynamic routing supports redundant paths, larger topologies, and automatic failure response.
  • Costs: It consumes processing, memory, and link capacity and requires safeguards against instability or unauthorized updates.

VII. Distance Vector Routing — Learning from Neighbors

A. Distance vector routing

Distance vector routing makes each router advertise to neighbors its estimated distance and direction to destination networks.

  • Bellman–Ford principle: Router x computes its distance to destination y through each neighbor v:
    TEXT
    Dₓ(y) = minᵥ { c(x,v) + Dᵥ(y) }

    Dₓ(y) is the best known cost from x to y, c(x,v) is the cost to neighbor v, and Dᵥ(y) is that neighbor’s advertised cost.
  • Information scope: A router generally knows a destination, metric, and next hop rather than the complete topology.
  • Update behavior: Routing tables are sent periodically or when significant changes occur.
  • Loop problem: Routers may repeatedly increase a metric for an unreachable destination, producing the count-to-infinity problem.
  • Controls: Split horizon, route poisoning, poison reverse, triggered updates, and hold-down timers reduce loops.
  • Trade-off: The method is relatively simple but typically converges more slowly than link-state routing.

VIII. RIP — Hop-Count Distance Vector Protocol

A. RIP

The Routing Information Protocol is an interior distance-vector protocol that chooses routes by hop count.

  • Metric rule: Each router traversed adds one hop; the lowest-hop route is preferred.
  • Infinity value: A metric of 16 means unreachable, so the maximum usable path is 15 hops.
  • Updates: RIP commonly sends the full routing table every 30 seconds using UDP port 520.
  • Versions:
    • RIPv1: Classful; does not carry subnet-mask information and uses broadcast updates.
    • RIPv2: Classless; carries prefix information, supports authentication, and uses multicast address 224.0.0.9.
  • Failure handling: Route poisoning advertises a failed route with metric 16, while triggered updates distribute the change without waiting for the next periodic cycle.
  • Strength: RIP is easy to configure and understand in small networks.
  • Limitation: The 15-hop ceiling, periodic traffic, and slow convergence make it unsuitable for large modern networks.

IX. Link State Routing — Building a Topology Map

A. Link state routing

Link-state routing enables every router in an area to construct a synchronized topology database and independently calculate shortest paths.

  • Process:
    • Discover directly connected neighbors.
    • Measure or assign link costs.
    • Create link-state advertisements.
    • Flood advertisements throughout the area.
    • Build a link-state database.
    • Run the shortest-path-first algorithm.
  • Dijkstra principle: Starting with itself as the root, a router repeatedly selects the lowest-cost unconfirmed node and updates costs to adjacent nodes.
  • Result: The shortest-path tree determines next hops for routing-table entries.
  • Sequence control: Sequence numbers and aging distinguish recent advertisements from stale information.
  • Advantages: Routers obtain a detailed topology view, converge quickly, and avoid many distance-vector loop problems.
  • Costs: Database storage, flooding, and shortest-path calculations require greater memory and processing.

X. OSPF — Hierarchical Link-State Routing

A. OSPF

Open Shortest Path First is a classless link-state interior gateway protocol that computes routes using cost and supports hierarchical network design.

  • Cost metric: OSPF interface cost is commonly derived from reference bandwidth:
    TEXT
    Cost = Reference bandwidth / Interface bandwidth

    Both bandwidth values must use the same unit; implementations may allow the reference value to be changed.
  • Areas: Area 0 is the backbone; other areas normally exchange inter-area traffic through the backbone.
  • Router roles: Internal routers remain within one area, area border routers connect areas, and autonomous system boundary routers redistribute external routes.
  • Neighbor formation: Routers exchange Hello packets and form adjacencies when parameters such as area ID and timers agree.
  • Database exchange: OSPF uses link-state advertisements and runs Dijkstra’s algorithm after relevant topology changes.
  • Multi-access networks: A designated router and backup designated router reduce adjacency and flooding overhead.
  • Protocol detail: OSPF runs directly over IP using protocol number 89, not TCP or UDP.
  • Value: It supports variable-length subnet masks, route summarization, authentication, fast convergence, and scalable design.

XI. Default Routing — The Route of Last Resort

A. Default routing

Default routing provides a fallback path when no more specific destination prefix matches a packet.

  • IPv4 notation: The default route is 0.0.0.0/0; its zero-length prefix matches every IPv4 destination.
  • Selection rule: Longest-prefix matching gives specific routes priority, so 192.168.1.0/24 is selected before 0.0.0.0/0.
  • Typical use: A stub router forwards all unknown destinations to an Internet service provider or upstream router.
    TEXT
    0.0.0.0/0 → Upstream next hop
  • Sources: A default route may be configured statically or learned and advertised through a dynamic routing protocol.
  • Default gateway: An end host similarly sends off-network packets to its configured local router.
  • Benefit: One entry replaces numerous external-network routes, reducing routing-table size and administrative effort.
  • Risk: An incorrect default can cause packet loss or routing loops; more specific routes and return paths must still be valid.