Module 3 -- Network Layer -- Computer Networks


Index

  1. Introduction to the Network Layer
  2. Switching
  3. Logical Addressing and IPv4 vs IPv6
  4. Physical Address vs Logical Address in Networking
  5. 2. IPv4 (Internet Protocol Version 4)
  6. 3. IPv6 (Internet Protocol Version 6)
  7. Address Mapping and it's Protocols
  8. 1. ARP (Address Resolution Protocol)
  9. 2. RARP (Reverse ARP) (or Inverse ARP)
  10. 3. BOOTP Protocol (Bootstrap Protocol)
  11. 4. DHCP Protocol
  12. Routing, Forwarding, Unicast Routing and it's protocols
  13. 1. Distance Vector Routing
  14. 2. Link State Routing

Introduction to the Network Layer


1. Host-to-Host (Source-to-Destination) Delivery


2. Routing


3. Fragmentation


4. Congestion Control (to a Lesser Extent)


Switching

Switching is a fundamental process in networking that directs data from a source to its destination. It involves making decisions about which path or channel a data packet should take as it moves through the network.

1. What is Switching?

Switching is the process of transferring data packets between different network segments or devices. It determines the route that data takes from the sender to the receiver. The key goals of switching are:


2. Types of Switching

https://www.geeksforgeeks.org/what-is-switching/

There are three primary types of switching techniques, each with its own method and applications:

Pasted image 20250328113649.png

A. Circuit Switching

Pasted image 20250328112506.png


B. Packet Switching

Pasted image 20250328113202.png


C. Virtual-Circuit Switching


D. Message Switching

This is an older switching technique that has become obsolete. In message switching technique, the entire data block/message is forwarded across the entire network thus, making it highly inefficient.

Pasted image 20250328113702.png


3. How Switching Works: Key Components and Processes

A. Switching Devices

B. Switching Techniques

C. Decision Process


4. Practical Considerations and Applications


Logical Addressing and IPv4 vs IPv6

1. Overview of Logical Addressing


Physical Address vs Logical Address in Networking

https://www.geeksforgeeks.org/what-is-physical-address-and-logical-address-in-networking/

A physical address is a unique identifier given to network interfaces for communication over a physical network segment. A logical address is a unique address assigned to each networked device to identify its location and enable routing

What is a Physical Address?

The physical address is also known as the MAC (Media Access Control) address or link address. It is the address of a node which is defined by its LAN or WAN. It is used by the data link layer and is the lowest level of addresses. MAC address is the unique address of a device. The size of a physical address is 48 bits (6 bytes). Below is the format for representing a physical address:

XX : XX : XX : YY : YY : YY, where 1 octant = 8 bits.

Example:

16 : 1A : BB : 6F : 90 : E5

Note: Sometimes an octant is also called octet.

In the context of IP addresses (specifically IPv4), an octet refers to each of the four 8-bit (or 1 byte) sections of an IP address, separated by periods.

The first 24 bits of a MAC address XX : XX: XX is decided by OUI (Organizationally Unique Identifier). It represents the identity of the manufacturer. The next 24 bits of a MAC address YY : YY : YY represents the unique identity of the device. It is assigned by the manufacturer. They represent NIC (Network Interface Card).

So the MAC address is basically :

manufacturer : device

each segment having 24 bits each. So the total size of a physical address is 48 bits.

Pasted image 20250328115801.png

In the above diagram, we can see that there are two networks - Network 1 and Network 2. A1 is the sender and there are two receivers - D1 and D2. In case of physical address, receiver D1 receives the data but receiver D2 is unable to receive data. This is because receiver D2 does not belong to the same network as the sender A1 belongs to. Physical address can only be passed in the same network and not in different networks. The purpose of using Physical address is to identify devices in the same network.

Advantages

Disadvantages


Logical Address

Pasted image 20250328120009.png

As we have seen previously in Operating Systems, Logical Addresses are purely for the CPU to allocate data into the registers/virtual memory which is then translated to physical address by a translation-lookaside buffer of the MMU to send/retrieve data to the actual physical memory.

In the context of Computer Networking, the concept stays similar:

Logical address also referred to as IP (Internet Protocol) address is an universal addressing system. It is used in the Network layer. This address facilitates universal communication that are not dependent on the underlying physical networks. There are two types of IP addresses - IPv4 and IPv6.

The size of IPv4 is 32 bits. For example ,

192 : 180 : 210 where, 1 octant = 8 bits.

So the logical address space of IPv4 is 232.

The size of IPv6 is 128 bits. For example ,

1C18 : 1B32 : C450 : 62A5 : 34DC : AE24 : 15BC : 6A5D where , 1 octant = 16 bits.

So the logical address space of IPv6 is 2128.

As you can see this is the main difference in Logical Addresses from Physical Addresses.

Pasted image 20250328120818.png

In the above diagram , we can see that there are two networks - Network 1 and Network 2. A1 is the sender and there are two receivers - D1 and D2. In case of logical address, receiver D1 as well as D2 receives the data. This is because logical address can be passed in different networks. The purpose of using logical address is to send the data across networks.


Advantages

Disadvantages


Differences between Physical Address and Logical Address

Physical Address Logical Address
Physical Address is the address of a node which is defined by its LAN or WAN Logical address also referred to as IP (Internet Protocol) address is an universal addressing system
Physical Address is computed bu MMU. Logical Address is generated by CPU.
Found on Data Link Layer. Found on Network Layer.
Format is 48-bit address in hexadecimal. Format is IPv4: 32-bit
IPv6: 128-bit
Physical address is not visible to users. Logical address is visible to users.

2. IPv4 (Internet Protocol Version 4)

https://www.geeksforgeeks.org/what-is-an-ip-address/

Pasted image 20250328120622.png

Address Format

Advantages and Limitations


3. IPv6 (Internet Protocol Version 6)

Address Format

Advantages and Improvements


4. Comparison: IPv4 vs. IPv6

Feature IPv4 IPv6
Address Length 32 bits (dotted-decimal notation) 128 bits (hexadecimal notation)
Address Space ~4.3 billion addresses Vast address space (2^128 addresses)
Header Complexity More fields, some optional fragmentation Simplified header with fixed fields, no fragmentation at routers
Security IPsec is optional IPsec is a fundamental part of the protocol
Configuration Typically requires DHCP or manual assignment Supports stateless autoconfiguration (SLAAC) and DHCPv6
Mobility Limited built-in support for mobile devices Enhanced mobility support with streamlined protocols

5. Practical Implications and Use Cases


Based on Usage: Public vs Private IP Addresses

Public IP Addresses

A Public IP address is assigned to every device that directly accesses the internet. This address is unique across the entire internet. Here are the key characteristics and uses of public IP addresses:

Private IP Addresses

Private IP addresses are used within private networks (such as home networks, office networks, etc.) and are not routable on the internet. This means that devices with private IP addresses cannot directly communicate with devices on the internet without a translating mechanism like a router performing Network Address Translation (NAT). Key features include:

Pasted image 20250328121448.png


Based on Assignment Method (Static vs. Dynamic)

Static IP Addresses:

Dynamic IP Addresses:


Address Mapping and it's Protocols

Address mapping protocols are crucial for resolving logical addresses (IP addresses) to physical addresses (MAC addresses) so that packets can be correctly forwarded on a local network.

1. ARP (Address Resolution Protocol)

https://www.geeksforgeeks.org/arp-protocol/

1. Purpose of ARP


2. How ARP Works

ARP Request

ARP Reply

Pasted image 20250328122700.png


3. ARP Cache and Maintenance


4. Issues and Considerations


Types of ARP

There are four types of ARP protocol they are as follows:-

  1. Proxy ARP
  2. Gratuitous ARP
  3. Reverse ARP
  4. Inverse ARP

1. Proxy ARP

This is a technique through which proxy ARP in a network can answer ARP queries of IP addresses that are not in that network. That is, if we understand it in simple language, the Proxy server can also respond to queries of IP-address of other networks.

Through this we can fool the other person because instead of the MAC address of the destination device, the MAC address of the proxy server is used and the other person does not even know.


2. Gratuitous ARP

This is an arp request of a host, which we use to check duplicate ip-address. And we can also use it to update the arp table of other devices. That is, through this we can check whether the host is using its original IP-address, or is using a duplicate IP-address.


3. Reverse ARP

This is also a networking protocol, which we can use through client computer. That is, it is used to obtain information about one's own network from the computer network.


4. Inverse ARP (InARP)

Inverse ARP, it is the opposite of ARP, that is, we use it to know the IP address of our device through MAC Address, that is, it is such a networking technology, through this we convert MAC Address into IP address. It is mainly used in ATM machines.


Advantages of ARP Protocol

There are many Advantages of ARP protocol but below we have told you about some important advantages.


2. RARP (Reverse ARP) (or Inverse ARP)

1. Purpose of RARP


2. How RARP Works

RARP Request

RARP Reply


3. RARP Server and Operation


4. Limitations and Evolution


Disadvantages of RARP


3. BOOTP Protocol (Bootstrap Protocol)

BOOTP is a more advanced version of RARP.

1. Purpose of BOOTP


2. Key Functions of BOOTP


3. How BOOTP Works

A. BOOTP Client Process

  1. Client Initialization:

    • When a device boots up, it doesn’t have an IP address.

    • The client creates a BOOTP Request packet that contains its MAC address and possibly a requested boot file name.

  2. Broadcast Request:

    • Since the client doesn't have an IP address yet, it broadcasts the BOOTP Request on the local network.

    • The broadcast ensures that any BOOTP server on the network can receive the request.

B. BOOTP Server Process

  1. Request Reception:

    • A BOOTP server listens for BOOTP Requests.

    • When it receives a request, it checks its configuration table for a matching MAC address.

  2. Formulating a Response:

    • If a match is found, the server prepares a BOOTP Reply packet that includes the assigned IP address and any additional network configuration information (like the subnet mask, default gateway, and boot file details).
  3. Sending the Reply:

    • The BOOTP Reply is sent as a unicast message directly to the requesting client’s MAC address.

C. Client Configuration


4. Advantages and Limitations

Advantages

Limitations


5. Evolution to DHCP


6. Summary


4. DHCP Protocol

DHCP is a more advanced version and an upgrade from the BOOTP protocol. It is also an Application Layer Protocol besides operating on the Network Layer.

1. Purpose of DHCP


2. How DHCP Works

DHCP operates through a sequence of message exchanges between the DHCP client and the DHCP server. The process is often summarized by the acronym DORA (Discover-Offer-Request-Acknowledgement):

A. DHCP Discover

B. DHCP Offer

C. DHCP Request

D. DHCP Acknowledgment


There are a few more DHCP messages as well which are not part of the DORA but still used.

E. DHCP Negative Acknowledgment Message:

Whenever a DHCP server receives a request for an IP address that is invalid according to the scopes that are configured, it sends a DHCP Nak (Negative Acknowledgement / Not Acknowledged) message to the client. Eg-when the server has no IP address unused or the pool is empty, then this message is sent by the server to the client.


F. DHCP Decline

If the DHCP client determines the offered configuration parameters are different or invalid, it sends a DHCP decline message to the server. When there is a reply to the gratuitous ARP by any host to the client, the client sends a DHCP decline message to the server showing the offered IP address is already in use.


G. DHCP Release:

A DHCP client sends a DHCP release packet to the server to release the IP address and cancel any remaining lease time.


H. DHCP Inform

If a client address has obtained an IP address manually then the client uses DHCP information to obtain other local configuration parameters, such as domain name. In reply to the DHCP inform message, the DHCP server generates a DHCP Ack message with a local configuration suitable for the client without allocating a new IP address. This DHCP ack message is unicast to the client.

Note – All the messages can be unicast also by the DHCP relay agent if the server is present in a different network.


3. Lease and Renewal Process


4. Advantages and Security Considerations

Advantages

Security Considerations


5. DHCP in Modern Networks


Routing, Forwarding, Unicast Routing and it's protocols

1. What is Routing?

Routing is the process of determining the optimal path that data packets should take from a source to a destination across interconnected networks. This process involves:


2. What is Forwarding?

Forwarding (sometimes called packet switching) is the process by which a router or switch takes an incoming packet and sends it out on the correct outgoing interface, as determined by its routing table. Key points include:


3. What is Unicast Routing?

https://www.geeksforgeeks.org/unicast-routing-link-state-routing/

Unicast Routing is a specific type of routing where a data packet is sent from a single source to a single destination.

Pasted image 20250329120937.png

There are various unicast protocols such as TCP, HTTP, etc.

Characteristics include:


Protocols of Routing

1. Distance Vector Routing

https://www.geeksforgeeks.org/distance-vector-routing-dvr-protocol/

https://www.youtube.com/watch?v=5ZuP5qjbKSI&list=PLxCzCOWd7aiGFBD2-2joCpWOLUrDLvVV_&index=59 (must watch)

https://www.youtube.com/watch?v=UYASPR4jEkk&list=PLxCzCOWd7aiGFBD2-2joCpWOLUrDLvVV_&index=60 (Count to infinity problem in DVR)

Concept and Operation


Bellman-Ford Basics

(recapping from semester 4)

The Bellman-Ford Algorithm is the same as Dijkastra's algorithm, except that it works for negative edges which Dijkastra's cannot do so.

The Bellman-Ford Algorithm works by repeatedly relaxing the edges. Relaxation is the process of updating the shortest distance to each vertex by simply visiting it.

Step-by-Step Explanation

  1. Initialization: Start by setting the distance to source vertex as 0 and the distance to the rest of the vertices as infinity.
  2. Relaxation: For each edge, if the distance to the destination vertex can be shortened by taking the edge, updating the distance to the destination vertex.
  3. Check for negative cycles: After (V-1) iterations, V being the total number of vertices in the graph, check once more for any shorter paths available. If any more distances can be updated, this means there is a negative weight(or more) in the graph.

Example

Pasted image 20240619214118.png

Pasted image 20240619214142.png

Pasted image 20240619214150.png

Each router maintains a Distance Vector table containing the distance between itself and All possible destination nodes. Distances, based on a chosen metric, are computed using information from the neighbors’ distance vectors.

Information kept by DV router:

- Each router has an ID
- Associated with each link connected to a router,  
    there is a link cost (static or dynamic).
- Intermediate hops

  
Distance Vector Table Initialization:

- Distance to itself = 0
- Distance to ALL other routers = infinity number.

covers these protocols extensively.


Metrics and Cost Calculation


How Distance Vector Algorithm works?

The DV calculation is based on minimizing the cost to each destination

Dx(y) = Estimate of least cost from x to y   
C(x,v) =  Node x knows cost to each neighbor v  
Dx   =  [Dx(y): y ? N ] = Node x maintains distance vector  
Node x also maintains its neighbors' distance vectors  
– For each neighbor v, x maintains Dv = [Dv(y): y ? N ]

Note:

    
    Dx(y) = min { C(x,v) + Dv(y), Dx(y) } for each node y ? N

Example :

Consider 3-routers X, Y and Z as shown in figure. Each router have their routing table. Every routing table will contain distance to the destination nodes.

Pasted image 20250329120458.png

Consider router X , X will share it's routing table to neighbors and neighbors will share their routing tables to X and distance from node X to destination will be calculated using bellman-ford equation.

 Dx(y) = min { C(x,v) + Dv(y)} for each node y ? N  

As we can see that distance will be less going from X to Z when Y is intermediate node(hop) so it will be update in routing table X.

Pasted image 20250329120623.png

Similarly for Z also –

Pasted image 20250329120632.png

Finally the routing table for all –

Pasted image 20250329120643.png

Here's how this happened:

First X sent it's distance vector it's neighbor Y.

0 --> X
1 --> Y
5 --> Z

Now there's already a known path from X to Z of cost 5.

This is the case for both X --> Z and Z --> X.

Once Y receives the distance vector of X, it updates it's own distance vector and sends to both X and Z

The distance vector is updated for Y as follows :

1 --> X
0 --> Y
2 --> Z

Now, when X and Z receive the distance vector from Y, their vectors are updated as follows.

For X :

0 --> X
1 --> Y
3 --> Z

For Z :

3 --> X
2 --> Y
0 --> Z

How did this updating take place? How did both X and Z decide to settle for the shorter path by hopping through Y?

Due to the B-F algorithm :

We take the minimum of the two distances.

So both X and Z had an initial path distance of 5.

And now after getting the distance vector from Y both X and Y see that a new distance is possible from X to Z and Z to X by hopping through Y which has a total cost of (1 + 2 = 3 or 2 + 1 = 3)

So they take the min(3,5) which results in 3 as it's lesser than 5, thus updating their routing tables accordingly.


Advantages


Disadvantages


Real-World Examples


https://www.youtube.com/watch?v=kW6zV-040SY&list=PLxCzCOWd7aiGFBD2-2joCpWOLUrDLvVV_&index=61 (must watch)

Concept and Operation


Calculation of Shortest Path

To find the shortest path, each node needs to run the famous Dijkstra algorithm.

Let's do a recap of Dijkastra's algorithm from semester 4.

Purpose: Dijkstra's algorithm is used to find the shortest path from a starting node (also called the source) to all other nodes in a weighted graph.

Step-by-Step Explanation:

  1. Initialization:

    • Start with a graph with nodes and weighted edges (weights represent the distance between nodes).
    • Set the distance to the source node to 0 and all other nodes to infinity.
    • Mark all nodes as unvisited and create a set of all the unvisited nodes.
  2. Processing:

    • While there are unvisited nodes:
      1. Select the unvisited node with the smallest distance (let's call this node u).
      2. For the current node u, consider all its unvisited neighbors. Calculate their tentative distances through u (i.e., the distance to u plus the distance from u to the neighbor).
      3. If the calculated tentative distance is less than the known distance, update the shortest distance to that neighbor.
      4. Mark the current node u as visited (it will not be checked again).
  3. Completion:

    • The algorithm completes when all nodes have been visited. The shortest path to each node is now known.

Example

Let's take this graph

Pasted image 20240619190253.png

Pasted image 20240619190308.png

Pasted image 20240619190455.png

Advantages


Disadvantages


Real-World Examples