By Stanislav Taran

OSI: Network Layer - Layer 3 (Part 6)


Definition

The Network layer is the third layer of the OSI model, responsible for routing packets from the source to the destination. It determines the best path for data to travel across the network, ensuring that packets are delivered efficiently and reliably.

Responsibilities

The Network layer has several key responsibilities:

  • Routing: The primary function of the Network layer is to route packets from the source to the destination. It determines the best path for data to travel across the network, taking into account factors like network congestion, latency, and reliability. Routing algorithms and protocols, such as RIP (Routing Information Protocol), OSPF (Open Shortest Path First), and BGP (Border Gateway Protocol), are implemented at this layer to make routing decisions.

  • Logical Addressing: The Network layer assigns logical addresses to devices on the network, such as IP addresses. These addresses are used to identify devices and route packets to their destinations. For this purpose, the Network layer uses the Internet Protocol (IP), which is a key protocol at this layer.

  • Packet Forwarding: The Network layer forwards packets between devices on the network, ensuring that data is delivered efficiently and reliably. It uses routing tables and algorithms to determine the best path for data to travel. It uses such protocols as IP (Internet Protocol) and ICMP (Internet Control Message Protocol) to manage packet forwarding.

  • Fragmentation and Reassembly: The Network layer can fragment large packets into smaller packets for transmission and reassemble them at the destination. This allows data to be transmitted efficiently over the network.

    Networks have a defined Maximum Transmission Unit (MTU), which specifies the largest size of a data packet that can be transmitted on that network. If a packet created by a higher layer application exceeds the MTU of the network it needs to traverse, fragmentation becomes necessary.

    In this case the Network layer will split the packet into smaller fragments that fit within the MTU. IP header will contain information about how to reassemble these fragments at the destination. Such as identification, flags, fragment offset, and checksum.

    When the fragments arrive at the destination, the Network layer reassembles them into the original packet before passing it to the Transport layer.

Protocols

The Network layer is primarily associated with the Internet Protocol (IP), which is responsible for logical addressing and routing of packets.

  • Internet Protocol (IP): specifies the origin and destination for each data packet. Routers inspect each packet’s IP header to identify where to send them. When a packet arrives at the network layer from the transport layer, the network layer prepends an IP header to the data. This header contains crucial information for routing, including:

    • Source IP Address: Identifies the device that sent the packet.

    • Destination IP Address: Specifies the intended recipient of the packet.

    • Other Control Information: This includes details like packet type, identification, and flags for fragmentation and options. On the image below you can see simplified schema of what packet headers are being added at each layer.

      Packet headers

    IP packets can be further classified into two types:

    • IPv4: The most widely used version of the Internet Protocol, which uses 32-bit addresses.
    • IPv6: The newer version of the Internet Protocol, which uses 128-bit addresses to accommodate the growing number of devices on the internet.

    We are not going to dive deep into differences between IPv4 and IPv6 in this series, but here is a simplified schema of how packets look different in these two versions. Keep in mind that TCP headers are being added at the Transport layer, so they have the same structure for both versions of IP.

    IPv4:

    IPv4 packet

    IPv6:

    IPv6 packet
  • Internet Control Message Protocol (ICMP): used for network management and troubleshooting. It allows devices to send error messages and control messages to other devices on the network.

    Here’s how it works:

    1. Error or Issue During Transmission: When a network issue occurs during data transmission (e.g., unreachable destination), a router or device encounters a problem with a specific data packet.
    2. Generating ICMP Message: The router or device encountering the issue creates an ICMP message relevant to the problem (e.g., Destination Unreachable).
    3. Encapsulation within IP Datagram: This ICMP message is then encapsulated within a new IP datagram. The source address in the IP header of this new datagram is typically the device that generated the ICMP message (router), and the destination address is the original sender’s IP address from the problematic data packet.
    4. Transmission via Network Layer: This new IP datagram containing the ICMP message is then transmitted through the network layer using the same routing mechanisms as regular data packets. ICMP packet can look like this:
    ICMP packet

    We will cover packet headers in more detail in separate post.

  • Routing Information Protocol (RIP): a distance-vector routing protocol that uses hop count as a metric to determine the best path to a destination. This protocol relies on a metric (distance) to determine the best path. In RIP’s case, the metric is the hop count, which represents the number of routers a packet needs to traverse to reach its destination.

  • Open Shortest Path First (OSPF): This protocol is also a routing protocol, but it uses a link-state algorithm to determine the best path to a destination. In this method, each router gathers information about the state of all links (connections) in the network, including the cost (metric) associated with each link. This cost can be based on factors like bandwidth, delay, or reliability.

  • Border Gateway Protocol (BGP): a path-vector routing protocol used between different autonomous systems (ASes) to exchange routing information. BGP is used to connect different networks on the internet and determine the best path for data to travel between them. It is essential for the global routing system and ensures that data is routed efficiently across the internet.

Conclusion

The Network layer of the OSI model plays a critical role in routing packets across the network, ensuring that data is delivered efficiently and reliably. By assigning logical addresses, managing packet forwarding, and implementing routing protocols, the Network layer enables devices to communicate with each other over the network.

That’s it for the Network layer! In the next post, we’ll explore the Data Link layer and its role in organizing data for transmission across a local area network (LAN). Stay tuned!