Computer NetworksUnit 612 min read
Network Layer & IP Addressing: Routing, IPV4/IPV6, Subnetting, NAT, ICMP
Unit 6 of Computer Networks covers the network layer’s core functions—IP addressing (IPv4/IPv6), subnetting, routing protocols (RIP, OSPF), NAT, ICMP, and congestion control—with real-world examples from eSewa, Ncell, and Daraz, plus visual packet traces and topology diagrams.
TAKEAWAYS:
- IPv4 vs. IPv6: IPv4’s 32-bit addresses are exhausted; IPv6’s 128-bit addresses solve this but require new protocols (e.g., ICMPv6).
- Subnetting: Divides a network into smaller subnets using CIDR notation (e.g.,
192.168.1.0/24) to optimize routing and reduce broadcast traffic. - Routing Protocols: RIP (distance-vector) and OSPF (link-state) determine the best path between networks; OSPF is faster for large networks.
- NAT: Translates private IP addresses (e.g.,
192.168.x.x) to a single public IP, enabling millions of devices to share internet access (used by ISPs like NTC). - ICMP: Handles error messages (e.g., "Destination Unreachable") and diagnostics (ping uses ICMP Echo Request/Reply).
- Congestion Control: TCP’s slow-start and AIMD algorithms prevent network overload (critical for apps like Pathao’s real-time ride-matching).
1. The Network Layer: Core Functions
The network layer (Layer 3 of the OSI model) is responsible for:
- Logical addressing: Assigning unique IP addresses to devices (e.g.,
192.168.1.1). - Routing: Forwarding packets between networks using routers.
- Congestion control: Managing traffic to avoid network collapse.
- Fragmentation/reassembly: Breaking large packets into smaller ones for transmission (IPv4 only).
Layer 7: Application
Layer 6: Presentation
Layer 5: Session
Layer 4: Transport (TCP/UDP)
Layer 3: Network (IP, Routing)
Layer 2: Data Link (MAC, Switches)
Layer 1: Physical (Cables, Signals)
Why it matters: Without the network layer, devices couldn’t communicate across different networks (e.g., your laptop to a Daraz server in Kathmandu).
2. IP Addressing: IPv4 and IPv6
IPv4 Addressing
- Format: 32-bit address divided into network and host parts (e.g.,
192.168.1.1). - Classes: Divided into Class A (0–127), Class B (128–191), Class C (192–223), Class D (multicast), and Class E (reserved).
- Subnetting: Splits a network into smaller subnets using a subnet mask (e.g.,
/24for255.255.255.0).
Example: A company with IP 10.0.0.0/8 can subnet it into /16 blocks:
10.0.0.0/16→10.0.0.0to10.0.255.25510.1.0.0/16→10.1.0.0to10.1.255.255
Drawbacks of IPv4:
| Limitation | Impact |
|---|---|
| Address exhaustion | Only ~4.3 billion addresses. |
| No built-in security | Vulnerable to spoofing. |
| No QoS support | No priority for voice/video. |
| Complex subnetting | Manual calculations error-prone. |
IPv6 Addressing
- Format: 128-bit address (e.g.,
2001:0db8:85a3::8a2e:0370:7334). - Advantages:
- No NAT needed (plenty of addresses).
- Built-in security (IPsec mandatory).
- Simpler header (faster routing).
- Autoconfiguration (devices assign their own IP).
Example: IPv6 in Nepal’s Ncell network enables seamless 4G/5G roaming without NAT translation.
IPv4 Header (20–60 bytes):
- Version (4 bits)
- IHL (Internet Header Length)
- Type of Service (ToS)
- Total Length (16 bits)
- Identification, Flags, Fragment Offset
- Time to Live (TTL)
- Protocol (TCP/UDP/ICMP)
- Header Checksum
- Source/Destination IP (32 bits each)
IPv6 Header (40 bytes):
- Version (4 bits)
- Traffic Class (8 bits)
- Flow Label (20 bits)
- Payload Length (16 bits)
- Next Header (8 bits)
- Hop Limit (8 bits)
- Source/Destination IP (128 bits each)
3. Subnetting and CIDR
Classless Inter-Domain Routing (CIDR) replaces fixed class boundaries with variable-length subnet masks (VLSM).
Steps to Subnet:
- Determine required hosts per subnet (e.g., 30 hosts → need 5 bits for hosts:
2^5 – 2 = 30). - Calculate subnet mask:
- Default Class C mask:
/24(255.255.255.0). - Need 5 host bits → borrow 3 bits from network → new mask:
/27(255.255.255.224).
- Default Class C mask:
- List subnets:
- First subnet:
192.168.1.0/27(hosts:192.168.1.1to192.168.1.30). - Second subnet:
192.168.1.32/27(hosts:192.168.1.33to192.168.1.62).
- First subnet:
Real-World Example: Daraz’s warehouse network uses subnetting to isolate:
10.1.0.0/16→ Order processing servers.10.2.0.0/16→ Inventory databases.10.3.0.0/16→ Employee workstations.
192.168.1.0/27 → 192.168.1.0 – 192.168.1.30 (Subnet 1)
192.168.1.32/27 → 192.168.1.32 – 192.168.1.62 (Subnet 2)
192.168.1.64/27 → 192.168.1.64 – 192.168.1.94 (Subnet 3)
...
192.168.1.224/27→ 192.168.1.224–192.168.1.254 (Subnet 8)
4. Routing Protocols
Routers use routing protocols to share network topology info. Two key types:
| Protocol | Type | How It Works | Example Use Case |
|---|---|---|---|
| RIP | Distance-vector | Routers share full routing tables every 30 sec. | Small office networks. |
| OSPF | Link-state | Routers exchange link-state ads (LSAs) to build a full map. | ISPs like NTC, large enterprises. |
RIP Example:
- Router A knows:
- Network
10.0.0.0/8is 1 hop away. - Network
192.168.1.0/24is 2 hops away.
- Network
- If a link fails, RIP takes 180 seconds to update routes (slow for large networks).
OSPF Example:
- Nepal Telecom (NTC) uses OSPF to route traffic between Kathmandu, Pokhara, and Biratnagar.
- Routers flood Link-State Advertisements (LSAs) to all nodes, creating a shortest-path tree using Dijkstra’s algorithm.
5. Network Address Translation (NAT)
Problem: IPv4 addresses are scarce, but private networks (e.g., homes, offices) need many IPs.
Solution: NAT translates private IPs (e.g., 192.168.1.5) to a single public IP (e.g., 203.123.45.6).
Types of NAT:
| Type | Description | Example |
|---|---|---|
| Static | One private IP maps to one public IP (1:1). | Corporate VPN access. |
| Dynamic | Many private IPs share one public IP (many:1). | Home internet via ISP. |
| PAT | Port Address Translation (many:1 with port numbers). | Most home routers use PAT. |
Example: Your home router uses PAT to let:
192.168.1.2:54321(your laptop) →203.123.45.6:12345(public).192.168.1.3:65432(your phone) →203.123.45.6:23456(public).
Private IP:Port → Public IP:Port
192.168.1.2:54321 → 203.123.45.6:12345 (YouTube)
192.168.1.3:65432 → 203.123.45.6:23456 (WhatsApp)
192.168.1.4:7890 → 203.123.45.6:34567 (eSewa)
Why NAT is used by ISPs:
- NTC uses NAT to let thousands of users share a few public IPs.
- Khalti uses NAT to route payments securely between banks and merchants.
6. Internet Control Message Protocol (ICMP)
ICMP is used for error reporting and diagnostics (not for carrying user data).
Key ICMP Messages:
| Type | Code | Description | Example Command |
|---|---|---|---|
| Echo Request | 0 | Ping request. | ping 8.8.8.8 |
| Echo Reply | 0 | Ping response. | |
| Destination Unreachable | 3 | Host/network unreachable. | traceroute failure. |
| Time Exceeded | 11 | TTL expired (packet loop). | traceroute hops. |
Example: Nepal’s NEPSE stock exchange uses ICMP to monitor server health:
- If a server is down, ICMP "Destination Unreachable" alerts admins.
sequenceDiagram
participant A as Your PC
participant B as Router
participant C as Google DNS
A->>B: ICMP Echo Request (ping)
B->>C: ICMP Echo Request
C->>B: ICMP Echo Reply
B->>A: ICMP Echo Reply
Note over A,B: Round-trip time (RTT) = 20ms7. Congestion Control in Networks
Congestion occurs when too many packets flood the network, causing delays or packet loss.
TCP Congestion Control Mechanisms:
- Slow Start: Exponentially increase window size until loss occurs.
- AIMD (Additive Increase, Multiplicative Decrease):
- Increase window by 1 MSS (Maximum Segment Size) per RTT.
- If loss detected, halve the window.
- Fast Retransmit: Resend lost packets without waiting for timeout.
Example: Pathao’s ride-matching system uses TCP congestion control to:
- Prioritize ride requests during peak hours (e.g., 7–9 PM).
- Avoid network overload when thousands of users request drivers simultaneously.
Time →
| | | | |
|-------|-------|-------|-------|
1 2 3 4 5
| | | |
|-------|-------|-------|
Slow Start: 1 → 2 → 4 → 8 MSS
|-------|-------|-------|
AIMD: +1 per RTT until loss
|-------|-------|
Loss → Window / 2
In the Real World
eSewa Payments:
- Uses IPv4 with NAT to route transactions between banks (e.g., NMB, Global IME) and merchant servers.
- Routing: OSPF ensures low-latency payment processing across Nepal’s data centers.
Ncell 4G/5G Network:
- IPv6 adoption enables seamless handover between towers without NAT.
- ICMP monitors tower health; if a tower fails, ICMP alerts trigger failover.
Daraz Order Fulfillment:
- Subnetting: Isolates warehouse zones (e.g.,
10.1.0.0/16for orders,10.2.0.0/16for inventory). - Congestion Control: TCP’s AIMD prevents order-processing delays during sales (e.g., Dashain).
- Subnetting: Isolates warehouse zones (e.g.,
Exam Tip
What Examiners Look For
- IPv4/IPv6 Comparison: Always mention address size, NAT need, header size, and security.
- Subnetting Calculations: Show step-by-step borrowing of bits and list subnets in order.
- Routing Protocols: Differentiate RIP (slow, hop-count) vs. OSPF (fast, link-state).
- NAT: Explain PAT vs. static NAT and why it’s used (address conservation).
- ICMP: Relate to ping/traceroute and error messages.
- Congestion Control: Draw the TCP window growth graph and explain AIMD.
Common Mistakes to Avoid
- Forgetting to exclude network/broadcast addresses in subnet calculations.
- Confusing MAC (Layer 2) vs. IP (Layer 3) addresses.
- Not labeling fields in packet headers (e.g., TTL, Protocol).
- Ignoring real-world examples (examiners love Ncell, eSewa, or Daraz cases).
High-Score Strategy
- Draw diagrams: Always include:
- A subnetting table (with first/last usable IPs).
- A routing table (next-hop, metric).
- A NAT translation table.
- Use numbers: "RIP has a 15-hop limit; OSPF uses Dijkstra’s algorithm."
- Link to Nepal: "NTC uses OSPF for backbone routing; NAT in home routers saves public IPs."
Based on the PU BE Computer (PU) syllabus for Computer Networks, unit 6.
Discussion
Loading…