Network layer, IP addressing, subnetting and routing notes — Unit 4
Free unit-wise study notes on network layer, ip addressing, subnetting and routing for Computer Networks, Semester 5 of B.Tech — Computer Science & Engineering — key concepts, examples, important questions and a revision checklist for semester exams.
An exhaustive exploration of the Network Layer, detailing IPv4 and IPv6 addressing, the intricacies of subnetting and CIDR, and the core routing algorithms (Distance Vector, Link State).
Notebook — 17 pages
Page 1
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
1. Introduction to the Network Layer
The Network Layer (Layer 3 in the OSI model) is responsible for the host-to-host delivery of packets across multiple distinct networks. While the Data Link Layer handles node-to-node delivery within a single network, the Network layer ensures data travels from the original source to the final destination.
⇒1.1 Key Responsibilities
Logical Addressing: Providing a universally unique IP address to every host on the internet to ensure cross-network identification.
Routing: Determining the optimal path for a packet to travel from the source to the destination through a web of routers.
Forwarding: The actual process of a router taking an incoming packet and moving it to the correct outgoing interface.
Fragmentation: Breaking large packets into smaller fragments if they exceed the Maximum Transmission Unit (MTU) of the underlying physical network.
Page 2
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
2. IPv4 Addressing: Overview
An IPv4 address is a 32-bit logical address that uniquely identifies a device on an IP network. The IPv4 address space allows for 2^32 (approx. 4.3 billion) unique addresses.
⇒2.1 Dotted Decimal Notation
To make IP addresses readable by humans, the 32 bits are divided into four 8-bit sections (octets). Each octet is converted to a decimal number ranging from 0 to 255, separated by dots (e.g., `192.168.1.10`).
⇒2.2 Network ID and Host ID
Every IP address is split into two parts:
Network ID: Identifies the specific network the device resides on. Routers use this to forward packets to the correct network.
Host ID: Identifies the specific machine within that local network.
Page 3
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
3. Classful Addressing
Historically, the IPv4 address space was divided into five distinct classes (A, B, C, D, E). The class of an address is determined by the leading bits of the first octet.
Class
Leading Bits
1st Octet Range
Default Mask
Application
A
`0`
1 - 126
`255.0.0.0` (/8)
Massive networks (millions of hosts)
B
`10`
128 - 191
`255.255.0.0` (/16)
Medium-to-large networks
C
`110`
192 - 223
`255.255.255.0` (/24)
Small networks (up to 254 hosts)
D
`1110`
224 - 239
N/A
Multicasting
E
`1111`
240 - 255
N/A
Reserved for R&D/Military
Note: `127` is missing from the table because the entire `127.x.x.x` range is reserved for loopback testing (localhost).
Page 4
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
4. Special IP Addresses
⇒4.1 Network and Broadcast Addresses
In any given network range, the very first and very last IP addresses cannot be assigned to individual devices.
Network Address: All Host ID bits are `0`. It represents the network itself (e.g., `192.168.1.0`).
Directed Broadcast Address: All Host ID bits are `1`. It targets all devices on that specific network (e.g., `192.168.1.255`).
Limited Broadcast Address: `255.255.255.255`. A packet sent here targets all hosts on the local network.
⇒4.2 Private IP Addresses
To conserve public IPs, certain ranges are reserved for internal, private use (LANs). They are not routable on the global internet. NAT (Network Address Translation) is required to access the internet.
Class A Private: `10.0.0.0` to `10.255.255.255`
Class B Private: `172.16.0.0` to `172.31.255.255`
Class C Private: `192.168.0.0` to `192.168.255.255`
Page 5
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
5. Introduction to Subnetting
Subnetting is the process of taking a single large network block and dividing it into multiple smaller, manageable logical networks (subnets).
⇒5.1 Why Subnet?
Reduce Broadcast Traffic: A broadcast sent on a massive network (like a Class A with 16 million hosts) would paralyze the network. Subnets contain broadcast domains.
Security: Subnetting allows administrators to isolate departments (e.g., HR vs. Engineering) using routers and firewalls.
Address Conservation: Prevents wasting large blocks of IP addresses on small sites.
⇒5.2 How Subnetting Works
Subnetting works by 'borrowing' bits from the Host ID portion of the IP address and reassigning them to the Network ID portion. This creates a new Subnet ID. The Subnet Mask dictates exactly how many bits have been borrowed.
Page 6
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
6. Subnetting Calculations
If we borrow `n` bits from the host portion, we can create 2^n subnets. The remaining `h` bits dictate the number of hosts.
⇒6.1 Number of Valid Hosts per Subnet
The formula for usable hosts per subnet is (2^h) - 2. We subtract 2 because the first address is the Network ID and the last address is the Broadcast ID.
⇒6.2 Example Calculation
Given a Class C network `192.168.1.0` with default mask `/24`. We want to create 4 subnets.
To get 4 subnets, we need `2^n >= 4`. Thus, `n = 2` bits borrowed.
Original mask: `11111111.11111111.11111111.00000000`
New mask: `11111111.11111111.11111111.11000000` (`255.255.255.192` or `/26`)
By the early 1990s, the rigid Class A/B/C system was causing IP addresses to run out rapidly. An organization needing 300 IPs had to be given a Class B (65,534 IPs), wasting over 65,000 addresses.
⇒7.1 The CIDR Solution
CIDR completely abandoned the concept of classes. The boundary between the Network ID and Host ID is no longer fixed at 8, 16, or 24 bits. It can be anywhere.
⇒7.2 Slash Notation
CIDR introduces slash notation (e.g., `192.168.1.15 /27`). The `/27` explicitly states that exactly 27 bits are used for the Network ID, leaving exactly 5 bits for the Host ID (`32 - 27`).
This allowed ISPs to allocate blocks of IPs that perfectly matched a customer's needs (e.g., an ISP could grant a `/23` block for exactly 510 hosts).
Page 8
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
8. The IPv4 Header
The Network layer encapsulates transport layer segments into IPv4 datagrams. The base IPv4 header is 20 bytes long.
⇒8.1 Key Header Fields
Version (4 bits): Identifies the IP version (value is 4).
Header Length (HLEN) (4 bits): Length of the header in 4-byte words.
Total Length (16 bits): Total size of the datagram (header + data).
Time to Live (TTL) (8 bits): Initialized to a value (e.g., 64 or 128) by the sender. Decremented by 1 at each router. If it hits 0, the packet is discarded (prevents infinite routing loops).
Identification, Flags, and Fragmentation Offset are used by routers to fragment a large datagram into smaller chunks if the next physical network has a smaller MTU.
Page 9
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
9. IPv6: The Next Generation
Despite CIDR and NAT, the 4.3 billion addresses of IPv4 eventually ran out. IPv6 was designed as the permanent solution.
⇒9.1 IPv6 Addressing
IPv6 uses 128-bit addresses, allowing for an astronomical 2^128 unique addresses.
Represented in hexadecimal notation, divided into eight 16-bit groups separated by colons (e.g., `2001:0db8:85a3:0000:0000:8a2e:0370:7334`).
Zero compression can be used to shorten addresses (e.g., replacing consecutive blocks of zeros with `::`).
⇒9.2 IPv6 Header Advantages
The IPv6 header is fixed at 40 bytes. Unlike IPv4, there is no header checksum (relying on Layer 2 and Layer 4 to handle errors), and fragmentation by intermediate routers is not allowed (improving router processing speed).
Page 10
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
10. Routing Concepts
Routing is the process of discovering network paths and forwarding packets along those paths.
⇒10.1 Forwarding vs. Routing
Forwarding: The localized action a router takes when a packet arrives at its input link. It looks at the destination IP, checks its routing table, and moves the packet to the correct output link. (Data Plane)
Routing: The network-wide process of routers communicating with each other to determine the best paths and build those routing tables. (Control Plane)
⇒10.2 Static vs. Dynamic Routing
Static Routing
Paths are manually entered into the router by an administrator.
Highly secure, no bandwidth overhead.
Cannot adapt if a link fails; terrible for large networks.
Dynamic Routing
Routers run algorithms to automatically discover networks and build tables.
Automatically reroutes traffic if a link fails.
Requires CPU/RAM overhead and consumes bandwidth for updates.
Page 11
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
11. Dynamic Routing: Distance Vector Algorithm
In Distance Vector routing, a router only knows the 'distance' (metric/cost) and the 'vector' (next-hop router) to a destination. It does not possess a map of the whole network.
⇒11.1 Mechanism
Each router periodically shares its entire routing table exclusively with its immediate neighbors.
When a router receives a table from a neighbor, it updates its own table if the neighbor offers a shorter path to a destination.
It uses the Bellman-Ford algorithm.
⇒11.2 Routing Information Protocol (RIP)
RIP is the most famous distance vector protocol. It uses 'hop count' as its metric. A maximum of 15 hops is allowed (16 is considered unreachable).
⇒11.3 Count-to-Infinity Problem
A major flaw in distance vector routing where a broken link causes routers to endlessly increment the cost to a destination, believing the other router has a valid path. Solved via 'Split Horizon' and 'Poison Reverse'.
Page 12
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
12. Dynamic Routing: Link State Algorithm
In Link State routing, every router builds a complete topological map (a graph) of the entire network.
⇒12.1 Mechanism
A router discovers its immediate neighbors and the cost of the link to them.
It generates a Link State Packet (LSP) containing this specific local knowledge.
It floods this LSP to every single router in the network.
Every router compiles all received LSPs to build an identical, complete database of the network.
Each router independently runs Dijkstra's Shortest Path Algorithm on this database to compute the best paths to all destinations.
⇒12.2 OSPF (Open Shortest Path First)
OSPF is the most widely used link-state protocol in enterprise networks. It is highly scalable, converges extremely fast after a failure, and doesn't suffer from the count-to-infinity problem.
Page 13
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
13. Path Vector Routing (BGP)
RIP and OSPF are Interior Gateway Protocols (IGPs), meant for routing inside an organization. But how do we route traffic between completely different organizations (ISPs, Tech Giants) across the globe?
⇒13.1 Border Gateway Protocol (BGP)
BGP is the 'protocol of the Internet'. It is an Exterior Gateway Protocol (EGP) based on the Path Vector algorithm.
⇒13.2 Mechanism
Instead of just sharing the 'distance' to a network, BGP routers share the exact sequence of Autonomous Systems (AS) a packet must traverse to reach the destination.
Example Path: `AS100 -> AS200 -> AS300`.
This explicit path completely prevents routing loops (if a router sees its own AS number in the path, it rejects the route).
BGP routing decisions are heavily influenced by business policies and ISP agreements, not just technical speed.
Page 14
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
14. Congestion Control in Network Layer
Congestion occurs when the number of packets being transmitted through the network approaches the packet handling capacity of the network. It leads to severe delays and packet loss.
⇒14.1 Open-Loop (Prevention) vs Closed-Loop (Removal)
Open-Loop: Policies applied before congestion occurs (e.g., Traffic Shaping).
Closed-Loop: Reactive mechanisms triggered after congestion occurs (e.g., router sending a Choke Packet to the sender to slow down).
⇒14.2 Traffic Shaping Algorithms
Leaky Bucket
Water (packets) pours into a bucket at a variable, bursty rate.
The bucket leaks out water from a hole at the bottom at a strict, constant rate.
If the bucket overflows, incoming packets are discarded.
Smooths out bursty traffic into a steady stream.
Token Bucket
Tokens are added to a bucket at a constant rate.
To transmit a packet, the sender must grab a token from the bucket.
Allows for bursty transmissions (up to the bucket's capacity) while maintaining an overall average rate.
Page 15
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
15. Internet Control Message Protocol (ICMP)
The IP protocol provides best-effort delivery but lacks built-in mechanisms for error reporting and host querying. ICMP acts as the companion protocol to IP to fulfill these needs.
⇒15.1 Error Reporting Messages
When a router discards an IP packet, it uses ICMP to send a warning back to the original source.
Destination Unreachable: Sent when a router cannot find a route to the final destination.
Time Exceeded: Sent when a packet's TTL reaches zero and is discarded (also the foundation of the `traceroute` utility).
Source Quench: An older congestion control mechanism asking a sender to slow down.
⇒15.2 Query Messages
Used for network diagnostics.
Echo Request and Reply: Used by the `ping` utility to test if a destination is alive and reachable.
Page 16
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
16. Network Address Translation (NAT)
NAT is a technology developed to dramatically slow the exhaustion of IPv4 addresses. It enables a large group of devices (a private LAN) to share a single public IP address to access the Internet.
⇒16.1 How NAT Works
A router is configured with a public IP on its internet-facing interface, while internal hosts use private IPs (e.g., `192.168.1.x`).
When an internal host sends a packet to the internet, the NAT router intercepts it, replaces the internal source IP with its own public IP, and records this translation in a NAT Table.
When the response returns from the internet, the router checks the NAT Table, swaps the destination IP back to the internal private IP, and forwards it to the host.
⇒16.2 PAT (Port Address Translation)
Also known as NAT Overload. If two internal hosts try to access the internet simultaneously, the router differentiates their traffic by modifying the Transport Layer source port numbers, allowing thousands of hosts to share just one public IP.
Page 17
Wink Notes
B.Tech CSE — 5th Semester
Computer Networks
— Unit - 4 —
17. IPv4 to IPv6 Transition Strategies
Because the internet is too massive for a 'flag day' where everyone switches to IPv6 simultaneously, several transition strategies were developed to allow IPv4 and IPv6 to coexist.
⇒17.1 Dual Stack
A node is configured to run both the IPv4 and IPv6 protocol stacks simultaneously. Before communicating, it uses DNS to check what the destination supports. If the destination has an IPv6 address, it uses IPv6; otherwise, it falls back to IPv4.
⇒17.2 Tunneling
Used when two IPv6 networks want to communicate but are separated by an older IPv4 infrastructure. The IPv6 packet is fully encapsulated inside an IPv4 packet at the edge router, carried across the IPv4 internet, and decapsulated at the destination edge router.
⇒17.3 Header Translation
Used when an IPv6-only host must communicate with an IPv4-only host. A specialized router actively translates the IPv6 header into an IPv4 header (similar to NAT) and vice versa.