CSC263 Computer Networks

Computer NetworksUnit 48 min read

Network Layer – IP Addressing, Routing & Protocols

Unit 4 of Computer Networks: covers IP addressing, subnetting, routing fundamentals, routing protocols, and network layer services such as fragmentation, TTL, ICMP, NAT, and VPNs.

Key points

  • The Network Layer delivers logical addressing and routing between hosts.
  • IP addressing uses classful or CIDR notation; subnetting splits a network into smaller subnets.
  • Routing protocols (RIP, OSPF, EIGRP, BGP) differ in metric, convergence, and scalability.
  • Network layer functions include packet forwarding, fragmentation, TTL, and error reporting via ICMP.
  • NAT and VPNs extend network layer capabilities for address conservation and secure communication.

1. Introduction to the Network Layer

The Network Layer (Layer 3 of the OSI model) is responsible for logical addressing, routing, and forwarding of packets across multiple networks. It abstracts the physical medium and provides end‑to‑end connectivity. The most widely used protocol at this layer is the Internet Protocol (IP), which defines the packet format, addressing scheme, and routing mechanisms.

1.1 IP Addressing

An IP address is a 32‑bit binary number written in dotted‑decimal notation (IPv4). It is divided into a network portion and a host portion. The boundary is defined by the subnet mask or the CIDR prefix length.

Class Default Subnet Mask Typical Network Bits Typical Host Bits
A 255.0.0.0 8 24
B 255.255.0.0 16 16
C 255.255.255.0 24 8

CIDR (Classless Inter‑Domain Routing) replaces classful boundaries with a variable prefix length, e.g., 192.34.12.56/28.

1.2 IP Packet Structure

+--------+--------+--------+--------+--------+--------+--------+--------+
| 0-7    | 8-15   | 16-23  | 24-31  | 32-39  | 40-47  | 48-55  | 56-63  |
+--------+--------+--------+--------+--------+--------+--------+--------+
| Version| IHL    | TOS     | Total  | Identification | Flags | Fragment |
| (4)    | (4)    | (8)     | Length | (16)           | (3)   | Offset   |
+--------+--------+--------+--------+--------+--------+--------+--------+
| TTL    | Protocol | Header Checksum | Source IP Address |
| (8)    | (8)      | (16)           | (32)               |
+--------+--------+--------+--------+--------+--------+--------+--------+
| Destination IP Address | Options | Padding |
| (32)                    | (0‑40) | (0‑3)   |
+-------------------------+--------+--------+
  • Version – 4 for IPv4.
  • IHL – Internet Header Length (number of 32‑bit words).
  • TTL – Time To Live, decremented by each router.
  • Protocol – Indicates the transport layer protocol (TCP=6, UDP=17).
  • Flags & Fragment Offset – Used for fragmentation.

1.3 Fragmentation & Reassembly

When a packet’s size exceeds the Path MTU (Maximum Transmission Unit), the router fragments it. Each fragment carries the same Identification field and a Fragment Offset indicating its position. The receiver reassembles fragments when all are received.

2. Subnetting – Practical Example

2.1 Subnetting a Class C Network

Problem: Assume a class C network and divide it into three subnets. What is the value of the new subnet?
Solution:

  • Class C default mask: /24.
  • Need at least 3 subnets → use 2 bits for subnetting (2^2 = 4 ≥ 3).
  • New mask: /26 (24 + 2).
  • Each subnet has 2^(8-6) = 64 addresses, 62 usable hosts.

2.2 Detailed Worked Example – /28 Network

Given: IP 192.34.12.56/28.
Task: Find network address and broadcast address.

  1. Convert /28 to subnet mask: 255.255.255.240.
  2. Binary of IP:
    192  = 11000000
    34   = 00100010
    12   = 00001100
    56   = 00111000
    
  3. Apply mask to find network address:
    192.34.12.56
    & 255.255.255.240
    = 192.34.12.48
    
  4. Broadcast address = network address + 15 (since 2^4 – 1 = 15).
    192.34.12.48 + 15 = 192.34.12.63
    

Answer: Network address = 192.34.12.48; Broadcast address = 192.34.12.63.

2.3 Subnetting 172.16.0.0 into Two Subnets

Given: 172.16.0.0 (Class B, /16).
Goal: Divide into 2 subnets.

  • Need 1 bit for subnetting (2^1 = 2).
  • New mask: /17.
  • Subnet 1: 172.16.0.0/17
    • Network: 172.16.0.0
    • Broadcast: 172.16.127.255
    • Usable hosts: 2^(32-17) – 2 = 32,766
  • Subnet 2: 172.16.128.0/17
    • Network: 172.16.128.0
    • Broadcast: 172.16.255.255
    • Usable hosts: 32,766

Total usable hosts across both subnets: 65,532.

3. Routing Fundamentals

3.1 Routing Process

  1. Destination Lookup – Router checks its routing table for the longest prefix match.
  2. Next‑Hop Determination – The selected route provides the next hop IP and outgoing interface.
  3. Forwarding – Router decrements TTL, recalculates checksum, and forwards the packet.

3.2 Routing Metrics

  • Hop Count – Used by RIP.
  • Bandwidth, Delay, Load, MTU – Used by EIGRP.
  • AS‑Path, Local Preference – Used by BGP.

3.3 Routing Protocols – Comparison Table

Protocol Type Metric Convergence Scalability Typical Use
RIP Distance Vector Hop Count (≤15) Slow (15‑30 s) Small networks Small LANs
OSPF Link State Cost (inverse bandwidth) Fast (≤10 s) Large enterprise Enterprise backbone
EIGRP Hybrid (Distance Vector + Link State) Composite metric Fast (≤5 s) Medium‑large Cisco‑centric networks
BGP Path Vector AS‑Path, MED, Local Pref Slow (minutes) Internet‑scale Inter‑domain routing

3.4 Routing Table Entry Example

Destination      Next Hop        Interface   Metric
10.0.0.0/8       192.168.1.1     eth0        10
172.16.0.0/16    192.168.2.1     eth1        5
0.0.0.0/0        192.168.1.254   eth0        100

4. Network Layer Services

4.1 Time To Live (TTL)

  • Prevents infinite loops.
  • Each router decrements TTL; if it reaches zero, the packet is discarded and an ICMP Time Exceeded message is sent back.

4.2 ICMP (Internet Control Message Protocol)

  • Used for error reporting and diagnostics (e.g., ping, traceroute).
  • Common messages: Destination Unreachable, Time Exceeded, Echo Request/Reply.

4.3 NAT (Network Address Translation)

  • Translates private IP addresses to a public address.
  • Types: Static, Dynamic, PAT (Port Address Translation).
  • Advantages: Conserves public IPs, adds a layer of security.
  • Disadvantages: Breaks end‑to‑end connectivity, complicates inbound connections.

4.4 VPN (Virtual Private Network)

  • Extends a private network across a public network using encryption.
  • Types: IPsec, SSL/TLS, MPLS.
  • Applications: Remote access, site‑to‑site connectivity.

5. Advanced Topics

5.1 Quality of Service (QoS) at Network Layer

  • Differentiated services (DiffServ) marks packets with DSCP values.
  • Per‑hop behaviors (PHB) enforce priority, bandwidth guarantees.

5.2 Multicast Routing

  • Protocols: IGMP (host‑to‑router), PIM (router‑to‑router).
  • Enables efficient distribution of data to multiple receivers.

5.3 IPv6 Overview

  • 128‑bit addresses, eliminates NAT.
  • Stateless Address Autoconfiguration (SLAAC).
  • Simplified header for better performance.

6. ASCII Diagram – IP Packet Forwarding Flow

+-------------------+      +-------------------+      +-------------------+
| Source Host       |      | Router A          |      | Destination Host  |
| (IP: 10.0.0.5)    |      | (IP: 10.0.0.1)    |      | (IP: 10.0.1.5)    |
+--------+----------+      +--------+----------+      +--------+----------+
         |                          |                           |
         | 1. Encapsulate IP packet |                           |
         |-------------------------->|                           |
         |                          | 2. Lookup route for 10.0.1.0/24 |
         |                          |----------------------------->|
         |                          | 3. Decrement TTL, recalc checksum |
         |                          |<-----------------------------|
         |                          | 4. Forward to next hop (eth0)   |
         |                          |----------------------------->|
         |                          | 5. Repeat until destination     |
         |                          |<-----------------------------|
         |                          | 6. Deliver to host application |
         |                          |<-----------------------------|

7. Summary

  • The Network Layer provides logical addressing, routing, and forwarding.
  • IP addressing and subnetting are foundational skills; practice CIDR calculations.
  • Routing protocols differ in metric, convergence, and scalability; know when to use each.
  • Network layer services such as TTL, ICMP, NAT, and VPN extend functionality and security.
  • Understanding packet structure and routing processes is essential for troubleshooting and design.

Exam tip

  • Practice CIDR calculations: Given an IP and prefix, compute network, broadcast, and host ranges.
  • Compare routing protocols: Be ready to list key differences (metric, convergence, scalability).
  • Draw IP packet header: Label all fields and explain their purpose.
  • Explain NAT and VPN: Know types, advantages, and typical use cases.
  • Use diagrams: For routing and forwarding processes, an ASCII diagram often earns extra marks.

Based on the TU BSc CSIT syllabus for Computer Networks (CSC263), unit 4.

Discussion

Loading…