Explained Network layer in OSI model.


The network layer is the third layer in the OSI model. It uses the services of the data link layer and provides services to the transport layer.

The role of the network layer is to route the packet from source to destination hope by hope.  Source and destination may be directly connected or may connect via many intermediate sub-networks.

On the source node, upon receiving the packet from the transport layer, the network layer chooses the outgoing link towards the destination. While on an intermediate node, it receives packets on the incoming links, does a routing table lookup, and sends the packet out towards the destination.

For example, we use the internet in our home via wifi connection.  On one side a wifi router connects to the laptop over a wireless channel, and the other side connects to the internet service provider over a WAN port.

Our laptop and wifi router both have a network layer. When a user enters an URL address in a web browser address bar and hits the enter key, the application layer protocol HTTP ( web browser uses HTTP) sends a request to the transport layer. The transport layer sends the request message to the network layer of the laptop.

The Laptop network layer sends the message to the wifi router over the wireless medium. The network layer of the WiFi Router checks the destination IP and finds that it belongs to a web server on the Internet. The wifi router sends the message to the ISP over the DSL line.

Till now there is only a single outgoing link. But on ISP (Internet service provider), there can be multiple outgoing links. One suitable link is chosen.

Functions of network Layer:

Interworking of networks: The network layer connects to different types of networks.  The networks could be VLANs or any other network. Like in our example, the IP layer is doing interworking between the internal LAN and the public internet.

Fragmentation and assembly of user data:   Fragmentation is the process of breaking a larger packet into smaller packets before sending it to the underlying network.  Assembly is the process to build the original packet from the fragment on the receiver side.  The network layer has to do the fragmentation to fulfill the underlying network data unit’s carrying capacity.  The frames may travel via multiple paths, but network layers wait for all segments and deliver the complete message to the transport layer after assembly.

Addressing: The network layer does the end-to-end logical addressing.  Before sending a packet to the underlying data link layer, the network layer adds a header in front of user data. The header has source and destination logical addresses. Two addresses may be directly connected or maybe multiple hopes apart.

Network Interworking:  Interwoking means enabling communication between different types of networks to each other.  The types of networks could be VLANs, Public, Private networks, and Networks with different subnet masks.

The IP layer only looks for the destination IP address for the next network hope, so that kind of IP does not matter for forwarding packets from any type of network to any other type of network.