Computer Networks - Unit 4
Computer Networks - Unit 4
Example:
If you send a message from your phone to someone in another city, the Network Layer
figures out how the message should travel through different routers and networks to
reach the destination.
Protocols Used:
IP (Internet Protocol)
ICMP (used for ping)
ARP (helps find MAC address from IP)
Devices are not always on the same network. → The Network Layer helps data
travel between different networks.
It finds the best path for data to reach the correct destination.
→ Like Google Maps for data packets.
It uses IP addresses to know where to send the data.
Your data would get lost because it wouldn't know how to reach devices that are far
away or on other networks.
1. Logical Addressing
Assigns IP addresses to devices.
Helps in identifying source and destination across different networks.
2. Routing
Chooses the best path for data to travel.
Uses routers to move data from one network to another.
3. Packet Forwarding
Sends data in small packets from one device to another.
Forwards packets through multiple devices (routers) until it reaches the
destination.
In Simple Words:
1. Addressing
Every device on a network must have a unique address (like an IP address).
The challenge: How to assign and manage these addresses correctly.
2. Routing
The network must decide the best path for data to travel.
The challenge: How to choose fast, reliable, and efficient routes.
3. Packet Forwarding
Once the route is selected, the packet must be sent to the next device.
The challenge: How to quickly and accurately forward packets.
5. Error Handling
Data can get lost or corrupted on the way.
The challenge: How to detect and sometimes fix errors or notify higher layers.
6. Congestion Control
If too many packets are sent at once, the network can become overloaded.
The challenge: How to avoid congestion and keep data flowing smoothly.
Routing Algorithms
Routing algorithms are used in the Network Layer to find the best path for data to
travel from source to destination across a network.
Two Main Types of Routing Algorithms:
1. Static Routing
Fixed paths decided manually.
Simple
2. Dynamic Routing
Routers automatically choose and update the best path.
What is "Cost"?
In networking, "cost" can mean:
The algorithm selects the path that has the least total cost.
How It Works:
Each link in the network has a cost value.
The algorithm calculates the total cost of all possible paths.
It then chooses the path with the smallest total cost.
Example:
If you want to send data from Router A to Router D, and there are multiple paths:
A —(2)— B —(2)— D
A —(1)— C —(5)— D
Dijkstra’s Algorithm
Dijkstra’s Algorithm is a popular routing algorithm used to find the shortest path
(least cost) from a source node to all other nodes in a network.
Where is it used?
In Link-State Routing protocols like OSPF (Open Shortest Path First).
Goal:
To find the minimum total cost path from the source to each destination.
Key Idea:
Each link has a cost (e.g., delay, hop count).
Start from the source node.
Always pick the nearest unvisited node.
Repeat until all nodes are visited.
1. Initialize:
4. Pick the unvisited node with the smallest cost and repeat.
Time Complexity:
Advantages
Disadvantages
1. Doesn’t handle negative edge weights
→ Fails if any link has a negative cost. (Use Bellman-Ford instead)
Bellman-Ford Algorithm
The Bellman-Ford algorithm is used to find the shortest path from a source node to all
other nodes in a weighted graph.
Key Features:
Works for graphs with negative edge weights
Can detect negative weight cycles
Used in Distance Vector Routing Protocols like RIP
How It Works:
1. Initialize the cost of the source node to 0, and all others to ∞ (infinity).
4. Can give incorrect results if negative cycles are not handled properly
→ Must explicitly check for negative weight cycles.
Time Complexity:
O(V × E)
(V = vertices, E = edges)
Used In:
RIP (Routing Information Protocol)
Any system where negative weights are possible
Hierarchical Routing
Hierarchical Routing is a method of organizing large networks into smaller, manageable
regions (or levels) to make routing more efficient.
How It Works:
1. Network is divided into regions or groups (like cities, countries, continents).
2. Each router:
Example:
A router in Mumbai doesn’t need to know the exact routers in Texas, just how to reach
the USA region.
Advantages:
1. Reduces routing table size
2. Improves routing efficiency
3. Scalable for large networks
4. Reduces bandwidth usage for routing updates
Disadvantages:
1. Path may not be optimal (shortest path may be missed due to abstraction).
2. More complex design and configuration
3. Troubleshooting is harder across levels
Real-Life Usage:
Internet Service Providers (ISPs) use it.
OSPF (Open Shortest Path First) supports area-based hierarchical routing.
Broadcast Routing
Broadcast Routing is a method where a packet is sent from one source to all other
nodes in the network.
Goal:
To deliver the same data to every device on the network — like making a public
announcement!
Example:
When a router sends a message like:
"Who is 192.168.1.5?" (ARP Request)
→ It’s broadcasted to all nearby devices.
1. Flooding
Send the packet to all neighbors, who forward it to all their neighbors
(except the sender).
Simple, but can cause duplicate packets and network congestion.
2. Multi-Destination Routing
Sends packet only if it arrives on the shortest path back to the source.
Reduces unnecessary traffic.
Advantages:
Easy way to discover devices or send data to all nodes.
Required for ARP, network announcements, etc.
Disadvantages:
Consumes bandwidth (sent to everyone).
Not scalable in large networks.
May cause broadcast storms (network overload).
Used In:
ARP (Address Resolution Protocol)
DHCP Discovery
Routing updates in Distance Vector protocols (e.g., RIP)
Multicast Routing
Multicast Routing is a method of sending one copy of a message from a source to
multiple selected receivers, not to all.
Purpose:
To efficiently deliver data to a group of interested receivers, without sending
multiple copies.
Real-life Example:
Watching a live video stream (e.g., an online class or cricket match)
→ One stream is sent, and only the users who joined the group receive it.
How It Works:
1. Devices join a multicast group (e.g., Group ID: 224.0.0.9).
2. The sender sends one packet addressed to the group.
3. Routers create a multicast tree to forward that packet only to:
Routers with group members.
Paths that lead to group members.
Techniques Used:
1. Multicast Trees:
Router forwards the multicast packet only if it came from the shortest
path to the source.
3. Protocols:
Advantages:
Saves bandwidth – sends only one copy of data.
Efficient for group communication (e.g., video conferencing, gaming).
Scalable – works well with many receivers.
Disadvantages:
Complex setup – routers need to manage group memberships and trees.
Requires multicast support in hardware and network.
Harder to manage and secure than unicast/broadcast.
Used In:
Online classes / webinars
Live video streaming
Multiplayer online games
Stock market updates
IP Addresses
An IP address (Internet Protocol address) is like a unique home address for every
device connected to a network or the internet. It helps devices identify and
communicate with each other.
Why Is It Needed?
When you send data (like opening a website), your computer needs to know where to send
it and the receiver needs to know where it came from — IP addresses make that
possible.
Types of IP Addresses:
1. IPv4 (Internet Protocol version 4)
Format: x.x.x.x → 4 numbers separated by dots
Each number ranges from 0 to 255
Example: 192.168.1.1
Total: About 4.3 billion addresses
Key Functions:
1. Identifies devices on a network
2. Helps route data from source to destination
3. Used by routers to deliver packets correctly
Time to Live (TTL) 8 bits Limits the lifetime of a packet (in hops)
Destination IP
32 bits IP address of the receiver
Address
Key Points
Ensures proper routing and delivery.
TTL prevents infinite loops.
Checksum helps detect errors.
Fragmentation fields support packet splitting for transmission.
Definition:
Packet forwarding is the process of moving packets from the source to the destination
by passing them through intermediate routers in a network.
Explanation:
Types of Forwarding:
Type Description
Key Concepts:
Based on destination IP address.
Uses routing tables.
Follows best path determined by routing algorithms.
Example:
If a packet from 192.168.1.1 wants to reach 8.8.8.8 , the router forwards it based on
the best available route in its table.
Reassembly is the process of combining those fragments back into the original packet
at the destination.
Why Needed?
Different networks support different maximum packet sizes (MTU).
If a packet is larger than the MTU, it must be fragmented to pass through.
Field Purpose
Fragmentation Example:
1. Original Packet: 4000 bytes
2. MTU: 1500 bytes
3. Packet is split into:
Fragment 1: bytes 0–1479
Fragment 2: bytes 1480–2959
Fragment 3: bytes 2960–3999
Reassembly:
Happens only at the destination host.
Uses Identification , Fragment Offset , and MF flag to rejoin fragments.
Advantages:
Allows large packets to travel through networks with small MTUs.
Disadvantages:
Increases processing overhead.
If one fragment is lost, the whole packet must be retransmitted.
Security risk if fragments are used to bypass firewalls.
ICMP – Internet Control Message Protocol
Definition:
ICMP (Internet Control Message Protocol) is a network layer protocol used by devices
(like routers and hosts) to send error messages and operational information.
Key Characteristics:
Works with IP (part of the IP suite).
Used by tools like ping and traceroute.
Not used to transfer data.
1. Error Reporting
2. Network Diagnostics
#### Example:
Advantages:
Helps in troubleshooting network issues.
Useful for network monitoring.
Lightweight and widely supported.
Disadvantages:
Can be blocked by firewalls (for security).
Does not fix errors, only reports them.
Can be misused in DDoS attacks (e.g., ICMP flood).
Internet Protocol
Full Form Internet Protocol version 6
version 4
Decimal (e.g.,
Address Format Hexadecimal (e.g., 2001:0db8::1)
192.168.1.1)
Auto-configuration
Configuration Manual or DHCP
(Stateless/SLAAC)
Routing
Less efficient More efficient (simpler headers)
Efficiency
#### Conclusion: