02

Network Layer

Chapter 2 • Intermediate

70 min

Network Layer

Network Layer provides routing and forwarding of packets across networks.

IP Addressing

IPv4 Address

IPv4 address is 32-bit (4 bytes), written as dotted decimal.

Format: A.B.C.D (each 0-255)

Example: 192.168.1.1

IP Address Classes

Class A:

  • Range: 1.0.0.0 to 126.255.255.255
  • Network bits: 8
  • Host bits: 24
  • Subnet mask: 255.0.0.0

Class B:

  • Range: 128.0.0.0 to 191.255.255.255
  • Network bits: 16
  • Host bits: 16
  • Subnet mask: 255.255.0.0

Class C:

  • Range: 192.0.0.0 to 223.255.255.255
  • Network bits: 24
  • Host bits: 8
  • Subnet mask: 255.255.255.0

Class D: Multicast (224.0.0.0 to 239.255.255.255)

Class E: Reserved (240.0.0.0 to 255.255.255.255)

Subnetting

Subnetting divides network into smaller subnets.

CIDR Notation: IP/prefix_length

Example: 192.168.1.0/24

  • Network: 192.168.1.0
  • Subnet mask: 255.255.255.0
  • Hosts: 2^8 - 2 = 254 (excluding network and broadcast)

Subnet Calculation:

  • Network address: IP AND subnet mask
  • Broadcast address: Network address OR inverted subnet mask
  • First host: Network address + 1
  • Last host: Broadcast address - 1

Special IP Addresses

Loopback: 127.0.0.0/8 (127.0.0.1)

Private IPs:

  • Class A: 10.0.0.0/8
  • Class B: 172.16.0.0/12
  • Class C: 192.168.0.0/16

Broadcast: 255.255.255.255

IPv6

IPv6 address is 128-bit (16 bytes), written in hexadecimal.

Format: 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Shortened: 2001:db8:85a3::8a2e:370:7334

Advantages:

  • Larger address space
  • Better security
  • Simplified header

Routing

Routing determines path for packets.

Routing Algorithms

1. Distance Vector

Principle: Each router maintains distance to all destinations.

Algorithm:

  • Bellman-Ford
  • Periodic updates
  • Example: RIP

Problems:

  • Count-to-infinity
  • Slow convergence

2. Link State

Principle: Each router knows entire network topology.

Algorithm:

  • Dijkstra's shortest path
  • Flooding of link state
  • Example: OSPF

Advantages:

  • Faster convergence
  • No count-to-infinity

3. Path Vector

Principle: Maintains path information.

Example: BGP

Routing Table

Routing Table contains:

  • Destination network
  • Next hop
  • Interface
  • Metric

Fragmentation

Fragmentation divides packets when MTU is smaller.

MTU (Maximum Transmission Unit): Maximum packet size.

Fragmentation Fields:

  • Identification
  • Flags (MF, DF)
  • Fragment offset

Reassembly: Done at destination.

GATE CS Important Points

  1. IP Addressing: Classes, subnetting, CIDR
  2. Subnet Calculation: Network, broadcast, host addresses
  3. Routing Algorithms: Distance vector, link state
  4. IPv6: Format, advantages
  5. Fragmentation: MTU, fragmentation fields

Practice Tips

  1. Subnetting: Practice calculating subnets
  2. IP Classes: Know ranges and subnet masks
  3. Routing: Understand distance vector vs link state
  4. CIDR: Practice CIDR notation
  5. Previous Year Questions: Solve GATE network layer questions