5.3 Network Layer

Before Starting Network Layer we need to understand two important points.

  • When the sender and receiver are on different networks, the Data Link Layer does not directly handle communication between the sender and receiver as a whole. Instead, each local network (or network segment) handles communication between devices on that specific network. The Data Link Layer operates locally within each network segment.

  • When the sender and receiver are in the same network (local network), the Data Link Layer is responsible for directly transmitting frames between them, using their MAC addresses.

The Network Layer (Layer 3) in the OSI model is responsible for routing packets from the source device to the destination device across different networks. It ensures that data is sent across multiple hops from the source to the destination and provides logical addressing, routing, and forwarding of packets.

Key functions of the Network Layer include:

  • Logical addressing

  • Packet forwarding

  • Routing

  • Fragmentation and reassembly

The Network Layer is integral in ensuring that data can travel across different networks, typically using IP (Internet Protocol) as the underlying protocol. Let's dive into the specifics of the topics related to the Network Layer.


1. Addressing

Addressing in the Network Layer involves assigning logical addresses that uniquely identify devices on a network.

Internet Address:

  • The Internet address typically refers to the IP address (Internet Protocol address), which uniquely identifies a device on a network. IP addresses can either be IPv4 (32-bit) or IPv6 (128-bit).

Classful Addressing:

Historically, Classful IP Addressing divided IP addresses into five classes (A, B, C, D, E), where:

Class A:

  • Purpose: Used for very large networks, typically organizations with vast numbers of devices, such as ISPs or multinational corporations.

  • Address Range: 0.0.0.0 to 127.255.255.255.

  • Subnet Mask (Default): 255.0.0.0 or /8 (8 bits reserved for the network portion).

  • Network/Host Division:

    • First 8 bits (1st octet) are for the network identifier.

    • Remaining 24 bits are for host identifiers

  • Special Notes:

    • Addresses starting with 127 (e.g., 127.0.0.1) are reserved for loopback testing and are not assignable.


Class B:

  • Purpose: Used for medium-sized networks, such as university campuses or regional organizations.

  • Address Range: 128.0.0.0 to 191.255.255.255.

  • Subnet Mask (Default): 255.255.0.0 or /16 (16 bits reserved for the network portion).

  • Network/Host Division:

    • First 16 bits (1st and 2nd octet) are for the network identifier.

    • Remaining 16 bits are for host identifiers


Class C:

  • Purpose: Used for small networks, such as small businesses or branch offices.

  • Address Range: 192.0.0.0 to 223.255.255.255.

  • Subnet Mask (Default): 255.255.255.0 or /24 (24 bits reserved for the network portion).

  • Network/Host Division:

    • First 24 bits (1st, 2nd, and 3rd octet) are for the network identifier.

    • Remaining 8 bits are for host identifiers


Class D:

  • Purpose: Reserved for multicast applications, which involve one-to-many communication (e.g., streaming video or audio).

  • Address Range: 224.0.0.0 to 239.255.255.255.

  • Subnet Mask: Not applicable since Class D addresses are used for groups rather than individual devices.

  • Special Notes:

    • Devices subscribe to a multicast group and receive packets addressed to that group.

    • Often used in applications like IPTV, conferencing, and real-time updates.


Class E:

  • Purpose: Reserved for experimental purposes and research. Not assignable for public use.

  • Address Range: 240.0.0.0 to 255.255.255.255.

  • Special Notes:

    • Originally intended for future use but is mostly unused in practice.

    • Addresses in this range are not routable on the internet.

By understanding these classes, network administrators could assign IP addresses based on the size and needs of their networks. However, in modern networking, CIDR has largely replaced the class-based approach. CIDR is integral to modern networking, particularly in IPv4 to conserve address space. It also simplifies IPv6 addressing, which inherently uses a similar system but with a much larger address space.


2. Subnetting

Subnetting is the process of dividing a larger network into smaller, more manageable subnetworks (subnets). It helps in optimizing IP address usage and improves network performance by reducing the size of broadcast domains.

  1. Subnet Mask: A subnet mask determines the network and host portions of an IP address.

    • For example, a subnet mask 255.255.255.0 means the first three octets represent the network portion, and the last octet represents the host portion.

  2. Subnetting Example:

  • Class C Network

Scenario

  • You are given the IP address: 192.168.1.0/24

  • Task: Divide this network into 4 subnets.

Step 1: Borrowing Host Bits for Subnetting

  • The default subnet mask for Class C is 255.255.255.0, which corresponds to /24.

    • This means 24 bits are for the network portion, and 8 bits are for the host portion.

    • The host portion is used to assign addresses to devices in the network.

  • To create 4 subnets, we need at least 22=42^2 = 422=4.

    • This requires borrowing 2 bits from the host portion to create subnets.

  • New Subnet Mask:

    • After borrowing 2 bits, the first 26 bits are used for the network, leaving only 6 bits for the host portion.

    • This changes the subnet mask to 255.255.255.192, which corresponds to /26.

Step 2: Calculating Usable Hosts

  • Where n is the number of bits left for the host portion, and we subtract 2 for:

    • 1 IP reserved for the network address.

    • 1 IP reserved for the broadcast address.

Example Calculation:

  • Bits left for the host portion: 6

Thus, each subnet supports 62 usable hosts.

Step 3: Calculating Usable Hosts

Subnet

Subnet Mask

Network Address

Broadcast Address

Usable Host Range

Usable Hosts

Subnet 1

255.255.255.192 (/26)

192.168.1.0

192.168.1.63

192.168.1.1 - 192.168.1.62

62

Subnet 2

255.255.255.192 (/26)

192.168.1.64

192.168.1.127

192.168.1.65 - 192.168.1.126

62

Subnet 3

255.255.255.192 (/26)

192.168.1.128

192.168.1.191

192.168.1.129 - 192.168.1.190

62

Subnet 4

255.255.255.192 (/26)

192.168.1.192

192.168.1.255

192.168.1.193 - 192.168.1.254

62

Step 4: Total Information

  • New Subnet Mask: 255.255.255.192 (/26).

  • Number of Subnets: 4.

  • Total Usable Hosts per Subnet: 62.


3. Routing Protocols

Routing protocols determine the best path for data to travel across a network. Their primary function is to ensure that data can efficiently reach its destination by choosing the most optimal route. Routing protocols come in various types, each designed for different use cases. These include distance vector, link-state, and hybrid protocols.

  1. RIP (Routing Information Protocol):

    • Type: Distance Vector Protocol

    • How it works: RIP is one of the oldest routing protocols, using the distance vector algorithm. In this method, routers exchange routing tables to determine the best path, with the "distance" represented by the hop count. The metric used by RIP to decide the best route is the number of hops.

    • Limitations: The hop count is limited to 15, which means it cannot support networks with more than 15 routers. This makes RIP unsuitable for larger networks.

    • Versions:

      • RIP v1 (Classful): Does not support subnetting and assumes a classful network.

      • RIP v2 (Classless): Supports subnetting and allows more flexible routing configurations.

  2. OSPF (Open Shortest Path First):

    • Type: Link-State Protocol

    • How it works: OSPF is a link-state routing protocol. It uses the Dijkstra algorithm to calculate the shortest path from one router to another, considering factors such as the network's topology and link costs. Each router in the network maintains an identical database, and routers periodically send updates to ensure all routers have the most current view of the network.

    • Advantages: OSPF is more scalable than RIP, can handle large networks, and is quicker to converge after a network change.

  3. BGP (Border Gateway Protocol):

    • Type: Path Vector Protocol

    • How it works: BGP is the primary routing protocol used for routing between autonomous systems (AS) on the Internet. Unlike RIP and OSPF, BGP doesn't rely on the traditional "shortest path" metric. Instead, it uses path attributes like AS path, prefix length, and other policies to determine the best route.

    • Use Case: BGP is most commonly used for inter-domain (inter-AS) routing, making it essential for the global Internet routing infrastructure. BGP can be policy-based, allowing administrators to manipulate routing decisions.

  4. Unicast and Multicast Routing Protocols:

    • Unicast Routing:

      • Definition: Involves sending data from one sender to one receiver.

      • Protocols: Unicast is the most common type of routing for general Internet traffic. Protocols such as RIP, OSPF, and BGP handle unicast routing.

    • Multicast Routing:

      • Definition: Involves sending data from one sender to multiple receivers.

      • Protocols: Protocols like PIM (Protocol Independent Multicast) handle multicast routing. Multicast is used for applications like streaming media, where the same data needs to be sent to multiple clients. It reduces the overall bandwidth used for such transmissions compared to unicast.


4. Routing Algorithms

Routing algorithms are the foundation of how routers decide the best path for data to travel. Common routing algorithms include:

1. Shortest Path Algorithm (Dijkstra's Algorithm)

  • How it works:

    • Calculates the shortest path from a source node to all other nodes in a network.

    • Maintains a list of visited and unvisited nodes and iteratively updates the shortest distance for each node.

  • Usage:

    • Used in link-state protocols like OSPF (Open Shortest Path First).

    • Ideal for complex networks where accurate and efficient pathfinding is crucial.

  • Advantages:

    • Provides a clear and efficient route.

    • Scales well for large networks.


2. Flooding

  • How it works:

    • A simple, non-optimized method where each router sends incoming packets to all its neighbors, ensuring that data eventually reaches its destination.

  • Usage:

    • Rarely used in practice due to its inefficiency and tendency to cause network congestion.

    • Sometimes used in special cases, like broadcasting or ensuring reliable delivery in small, controlled networks.

  • Disadvantages:

    • High resource consumption and potential for overwhelming the network with redundant data.


3. Distance Vector Routing

  • How it works:

    • Each router maintains a routing table containing the distance (or cost) to reach other nodes.

    • Routers periodically share their routing tables with immediate neighbors.

    • The best route to a destination is calculated based on the total cost (e.g., hop count).

  • Example Protocol: RIP (Routing Information Protocol).

  • Advantages:

    • Simple and easy to implement.

  • Disadvantages:

    • Slower convergence and potential for routing loops in larger or dynamic networks.


4. Link State Routing

  • How it works:

    • Each router builds a detailed map of the entire network by exchanging Link-State Advertisements (LSAs) with other routers.

    • Using algorithms like Dijkstra, each router independently calculates the best path to every destination.

  • Example Protocol: OSPF (Open Shortest Path First).

  • Advantages:

    • Faster convergence and more accurate routing decisions.

    • Scales better for larger networks compared to distance vector routing.

  • Disadvantages:

    • More complex and requires more computational resources than distance vector routing.


5. Network Layer Protocols (ARP, RARP, IP, ICMP)

  1. ARP (Address Resolution Protocol):

    • ARP is used to map IPv4 addresses to MAC addresses in a local network. It is used when a device knows the IP address but needs the corresponding MAC address to send data on the local network.

    • Example: If a device with IP 192.168.1.1 is connected to the network, ARP is used to find its MAC address.

  2. RARP (Reverse Address Resolution Protocol):

    • RARP is the reverse of ARP. It is used by a device to find its IP address when it knows its MAC address.

    • RARP is rarely used today, as it has been replaced by DHCP (Dynamic Host Configuration Protocol).

  3. IP (Internet Protocol):

    • IP is the core protocol of the Network Layer. It provides logical addressing, fragmentation, and reassembly of packets.

    • IPv4: The most commonly used version of IP (32-bit addresses).

    • IPv6: The newer version of IP (128-bit addresses) designed to overcome the limitations of IPv4 (address exhaustion).

  4. ICMP (Internet Control Message Protocol):

    • ICMP is used for sending error messages and operational information related to IP processing. Ping and Traceroute are common utilities that use ICMP.


6. IPv6 (Packet Formats, Extension Headers, Transition from IPv4 to IPv6, and Multicasting)

IPv6 is the successor to IPv4, designed to address issues like address exhaustion, security, and configuration.

Key Features of IPv6

  1. Expanded Address Space:

    • IPv6 uses 128-bit addresses, compared to the 32-bit addresses of IPv4.

    • Provides 2^128 (approximately 3.4×10^38) unique addresses, effectively eliminating address exhaustion.

  2. Simplified Header Structure:

    • IPv6 headers are more streamlined and efficient.

    • Reduces processing overhead and improves routing performance.

  3. Elimination of NAT (Network Address Translation):

    • With a vast address space, IPv6 eliminates the need for NAT, allowing for true end-to-end communication.

  4. Built-in Security:

    • IPv6 includes IPSec as a mandatory feature for authentication, encryption, and data integrity.

  5. Improved Multicasting:

    • IPv6 natively supports multicasting, allowing efficient one-to-many communication.

    • Reduces bandwidth usage in applications like video streaming.

  6. Auto-Configuration:

    • IPv6 supports both stateful (via DHCPv6) and stateless (via SLAAC) auto-configuration.

    • Devices can generate their own addresses without manual intervention.

  7. Improved QoS (Quality of Service):

    • The Traffic Class field in the IPv6 header enables better prioritization of critical data packets.

  8. No Broadcasts:

    • IPv6 uses multicast and Anycast instead of broadcast, reducing unnecessary network traffic.


IPv6 Address Structure

An IPv6 address consists of 128 bits divided into 8 groups of 16 bits each, separated by colons (:). Example:

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

Abbreviating IPv6 Addresses:

  1. Leading Zeros Omission:

    • 2001:0db8:85a3:0000:0000:8a2e:0370:7334 becomes 2001:db8:85a3:0:0:8a2e:370:7334

  2. Consecutive Zero Compression:

    • Replace consecutive groups of 0000 with :: (only once in an address). Example: 2001:db8:85a3::8a2e:370:7334


Types of IPv6 Addresses

  1. Unicast:

    • Identifies a single interface.

    • Traffic destined for a unicast address is delivered to the specified interface.

  2. Multicast:

    • Identifies multiple interfaces.

    • Traffic sent to a multicast address is delivered to all interfaces identified by that address.

  3. Anycast:

    • Identifies multiple interfaces, but traffic is delivered to the nearest (in terms of routing) interface.

  4. Reserved Addresses:

    • Loopback Address: ::1 Used by a device to send packets to itself.

    • Unspecified Address: :: Indicates the absence of an address.

IPv6 packet format

The IPv6 packet format is designed to streamline processing and improve efficiency. It consists of a fixed header and optional extension headers, followed by the payload.


IPv6 Packet Structure

|--------------------------|
| IPv6 Fixed Header (40B)  |
|--------------------------|
| Extension Headers        |
|--------------------------|
| Payload Data             |
|--------------------------|

Here’s a detailed diagram:

1. Fixed Header (40 Bytes)

The fixed header is always 40 bytes long and contains essential information for routing and delivering the packet. The fields in the IPv6 header are as follows:

Field

Size (bits)

Description

Version

4

IP version, set to 6 for IPv6.

Traffic Class

8

Defines the packet priority and QoS.

Flow Label

20

Identifies packet flows for special handling (e.g., real-time traffic).

Payload Length

16

Specifies the size (in bytes) of the payload, including extension headers but excluding the fixed header.

Next Header

8

Indicates the type of the next header (e.g., TCP, UDP, or an extension header).

Hop Limit

8

Number of hops the packet can traverse before being discarded (similar to TTL in IPv4).

Source Address

128

The IPv6 address of the sender.

Destination Address

128

The IPv6 address of the intended receiver.


2. Extension Headers

IPv6 uses extension headers to provide additional functionality, such as security or routing. These headers are optional and only included when necessary, making IPv6 packets more efficient than IPv4.

Common extension headers include:

Extension Header

Next Header Value

Purpose

Hop-by-Hop Options

0

Contains options to be processed by every router.

Routing Header

43

Specifies routing information for intermediate nodes.

Fragment Header

44

Handles fragmentation of large packets.

Authentication Header (AH)

51

Ensures data integrity and authenticity.

Encapsulating Security Payload (ESP)

50

Provides encryption for packet data.

Destination Options

60

Contains options processed only by the destination node.


3. Payload

The payload contains the actual data being transmitted and is passed to the upper-layer protocols (e.g., TCP, UDP, or an application-specific protocol). The payload size is determined by the Payload Length field in the fixed header.


Transition from IPv4 to IPv6:

The transition from IPv4 to IPv6 is necessary due to the exhaustion of IPv4 addresses and the increasing demands of modern networks. IPv6 provides a much larger address space and other enhancements. However, the transition is complex because IPv4 and IPv6 are not directly interoperable. Several techniques and strategies are employed to ensure a smooth transition.


Challenges of Transition

  1. Compatibility: IPv4 and IPv6 are fundamentally different, making direct communication impossible without special mechanisms.

  2. Infrastructure Costs: Upgrading existing systems and networks to support IPv6 can be expensive.

  3. Coexistence: IPv4 networks will remain operational for many years, requiring dual-stack systems during the transition period.


Transition Strategies

1. Dual-Stack Implementation

  • Description: Devices run both IPv4 and IPv6 protocols simultaneously, allowing communication over both protocols.

  • Advantages:

    • Gradual transition without immediate need to disable IPv4.

    • Ensures compatibility with both IPv4 and IPv6 networks.


2. Tunneling

  • Description: IPv6 packets are encapsulated within IPv4 packets to traverse IPv4-only networks.

  • Advantages:

    • No need to replace IPv4 infrastructure immediately.

    • Enables IPv6 connectivity over existing IPv4 networks.


3. Translation

  • Description: Translation mechanisms enable direct communication between IPv4 and IPv6 devices by translating between the two protocols.

  • Advantages:

    • Facilitates communication between IPv4 and IPv6 systems.


Conclusion

  • When the sender and receiver are on different networks, the Data Link Layer does not directly handle communication between the sender and receiver as a whole. Instead, each local network (or network segment) handles communication between devices on that specific network. The Data Link Layer operates locally within each network segment.

  • When the sender and receiver are in the same network (local network), the Data Link Layer is responsible for directly transmitting frames between them, using their MAC addresses.

The Network Layer plays a crucial role in ensuring that data can be routed and delivered across different networks efficiently and reliably.

Last updated