0% found this document useful (0 votes)
1 views14 pages

Computer Networks - Unit 4

The document discusses the Network Layer (Layer 3) of computer networks, detailing its main functions such as routing, logical addressing, and packet forwarding. It explains the need for the Network Layer to facilitate data transmission across different networks, and outlines various routing algorithms like Dijkstra’s and Bellman-Ford. Additionally, it covers broadcast and multicast routing methods, IP address types, and the importance of IP headers for data routing.

Uploaded by

forgaming9955
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views14 pages

Computer Networks - Unit 4

The document discusses the Network Layer (Layer 3) of computer networks, detailing its main functions such as routing, logical addressing, and packet forwarding. It explains the need for the Network Layer to facilitate data transmission across different networks, and outlines various routing algorithms like Dijkstra’s and Bellman-Ford. Additionally, it covers broadcast and multicast routing methods, IP address types, and the importance of IP headers for data routing.

Uploaded by

forgaming9955
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Computer Networks - Unit 4

Network Layer (Layer 3)


Main Job: Finds the best path for data to travel from one computer to another.
How: It uses IP addresses to send data across different networks.
Key Tasks:
Routing: Chooses the best route for the data.
Logical Addressing: Uses IP addresses to identify devices.
Packet Forwarding: Sends data in small chunks called packets.

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)

Need of Network Layer:


We need the Network Layer because:

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.

Without the Network Layer:

Your data would get lost because it wouldn't know how to reach devices that are far
away or on other networks.

Services Provided by the Network Layer (OSI Layer 3)


The Network Layer provides the following key services:

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.

4. Fragmentation and Reassembly


Breaks large data into smaller packets (fragmentation).
Rebuilds them at the receiver’s end (reassembly), if needed.

5. Error Handling and Diagnostics


Uses protocols like ICMP to detect errors (e.g., unreachable destination).
Useful for tools like ping and traceroute.

In Simple Words:

The Network Layer makes sure your data knows:

Where to go (IP address)


How to get there (routing)
And gets there properly (packet forwarding, error checks)

Design Issues of the Network Layer


When building the Network Layer, designers face several challenges. Here are the main
design issues, explained simply:

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.

4. Fragmentation and Reassembly


Some networks only allow small packet sizes.
The challenge: How to split large packets into smaller ones and then rebuild
them at the destination.

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.

7. Quality of Service (QoS)


Some data (like video calls) needs faster and more reliable delivery.
The challenge: How to prioritize important traffic over less urgent data.

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.

Paths do not change automatically, even if the network changes.

Simple

Not flexible or smart

Used in small/simple networks

2. Dynamic Routing
Routers automatically choose and update the best path.

Adjusts to changes in the network (like traffic, broken links).

Smart and flexible

Needs more resources (CPU, memory)

Used in large/modern networks

Based on How They Work:


A. Distance Vector Routing
Routers share information with neighboring routers.
Chooses path based on distance (hops).
Example: RIP (Routing Information Protocol)

B. Link State Routing


Routers share info with all routers in the network.
Each router builds a full map of the network.
Example: OSPF (Open Shortest Path First)

Least Cost Routing Algorithm


The Least Cost Routing Algorithm is a method used to find the path with the lowest
cost between two points (like computers or routers) in a network.

What is "Cost"?
In networking, "cost" can mean:

Number of hops (routers)


Time delay
Bandwidth usage
Monetary cost

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.

Algorithms Based on Least Cost:


Dijkstra’s Algorithm: Uses link-state information to find the shortest (least
cost) path.
Bellman-Ford Algorithm: Uses distance vector method to calculate paths based on
neighbor info.

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

Path A → B → D has a cost of 2 + 2 = 4


Path A → C → D has a cost of 1 + 5 = 6
The Least Cost Path is A → B → 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.

Steps of Dijkstra’s Algorithm:

Let’s say we are finding the shortest path from source A.

1. Initialize:

Set the cost of source A = 0 .


Set cost of all other nodes to ∞ (infinity).
Mark all nodes as unvisited.

2. Visit the current node (start with A):

Check all its neighbors.


If a new cost to a neighbor is less than the current cost, update it.

3. Mark current node as visited (shortest path found).

4. Pick the unvisited node with the smallest cost and repeat.

5. Stop when all nodes are visited or the destination is reached.

Time Complexity:

O(V²) for simple implementation


O((V + E) log V) with priority queue (heap)

Advantages

1. Always finds the shortest path


→ It guarantees the least-cost path from the source to all other nodes.

2. Efficient for sparse graphs


→ Especially when used with priority queues (like min-heaps).

3. Works well in link-state routing protocols


→ Used in real-world protocols like OSPF.

4. Supports multiple destinations


→ Can find shortest paths to all nodes in one run.

5. Simple and well understood


→ Easy to implement and use in both learning and real systems.

Disadvantages
1. Doesn’t handle negative edge weights
→ Fails if any link has a negative cost. (Use Bellman-Ford instead)

2. Can be slow for large graphs


→ Time-consuming if not optimized, especially in dense networks.

3. Needs complete network knowledge


→ Each node must know the cost to every other node, which may not be realistic
in dynamic networks.

4. More memory usage


→ Needs extra data structures (like cost tables and visited lists), which
increases memory use.

5. Not suitable for dynamic changes


→ If the network changes frequently, the algorithm has to be rerun from
scratch.

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).

2. Repeat (V - 1) times (where V = number of vertices):

For every edge (u → v) with cost w , update:


if cost[v] > cost[u] + w then cost[v] = cost[u] + w
3. Optional Step: Check for negative weight cycles:

Do one more pass:


if you can still update a distance → negative cycle exists.

Advantages of Bellman-Ford Algorithm

1. Handles negative weights


→ Can find shortest paths even when some edge costs are negative.

2. Detects negative weight cycles


→ Alerts if a loop keeps reducing cost infinitely (helps avoid routing errors).

3. Simpler to implement than Dijkstra


→ Uses basic loops and no complex data structures like heaps.

4. Used in distance vector routing protocols


→ Example: RIP (Routing Information Protocol).

5. Works on both directed and undirected graphs


→ As long as edge directions are properly handled.

Disadvantages of Bellman-Ford Algorithm


1. Slower than Dijkstra
→ Time complexity is O(V × E), which is inefficient for large networks.

2. Does not guarantee fastest execution


→ Even if a shorter path is found early, it still runs for V - 1 rounds.

3. Less efficient in real-time routing


→ Not ideal for networks that change frequently.

4. Can give incorrect results if negative cycles are not handled properly
→ Must explicitly check for negative weight cycles.

5. Consumes more CPU resources


→ Especially when run frequently on large networks.

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.

Why Use It?

In large networks, like the internet or big company networks:

Having one big routing table is inefficient.


Routers can't store info about every other router in the world.

So, we divide the network into regions or layers to reduce complexity.

How It Works:
1. Network is divided into regions or groups (like cities, countries, continents).

2. Each router:

Knows full details of its own region.


Knows only summary information about other regions (like a route to
"Region 2", not each router inside it).

3. Routes are calculated within regions and between regions separately.

Example:

Internet (Top Level)



├── Region 1 (e.g., India)
│ ├── Sub-region: Mumbai
│ └── Sub-region: Delhi

├── Region 2 (e.g., USA)
├── Sub-region: New York
└── Sub-region: Texas

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.

Methods of Broadcast Routing:

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

Adds multiple destination addresses in a single packet.


Routers send the packet to each address.

3. Spanning Tree Broadcast

Creates a tree structure to avoid loops.


Sends packet along this tree only once per path.

4. Reverse Path Forwarding (RPF)

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:

Build a tree that connects the sender to all receivers.


Two types:
Source-Based Tree (one tree per sender)
Shared Tree (one tree for all senders)

2. Reverse Path Forwarding (RPF):

Router forwards the multicast packet only if it came from the shortest
path to the source.

3. Protocols:

IGMP (Internet Group Management Protocol) – lets devices join/leave


multicast groups.
PIM (Protocol Independent Multicast) – builds multicast routing trees.

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

2. IPv6 (Internet Protocol version 6)


Format: 8 groups of hexadecimal numbers
Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Supports trillions of addresses (used as IPv4 gets exhausted)

Types Based on Use:

Type Description Example

Public IP Unique on the entire internet 8.8.8.8 (Google)

Private IP Used inside homes/offices (local networks) 192.168.1.1

Static IP Doesn’t change Servers, websites

Dynamic IP Changes each time you connect Most home users

IP Address Classes (IPv4):

Class Range Usage

A 1.0.0.0 – 126.0.0.0 Large networks

B 128.0.0.0 – 191.255.0.0 Medium networks

C 192.0.0.0 – 223.255.255.0 Small networks

(Note: 127.x.x.x is reserved for loopback)

Key Functions:
1. Identifies devices on a network
2. Helps route data from source to destination
3. Used by routers to deliver packets correctly

IP Header Format (IPv4)


An IP header contains important control information required for routing and delivery
of packets in the network.

Basic Format (20 to 60 bytes)

Field Size Description

Version 4 bits IP version (usually 4)

IHL (Header Length) 4 bits Length of header in 32-bit words

Type of Service 8 bits Specifies priority of the packet

Total Length 16 bits Total length of the packet (header + data)


Identification 16 bits Unique ID for fragmentation

Flags 3 bits Control flags (e.g., Don’t Fragment)

Position of this fragment in the original


Fragment Offset 13 bits
packet

Time to Live (TTL) 8 bits Limits the lifetime of a packet (in hops)

Indicates the protocol (e.g., TCP = 6, UDP =


Protocol 8 bits
17)

Header Checksum 16 bits Error checking of header

Source IP Address 32 bits IP address of the sender

Destination IP
32 bits IP address of the receiver
Address

Options + Padding Variable Optional field for extra features

Key Points
Ensures proper routing and delivery.
TTL prevents infinite loops.
Checksum helps detect errors.
Fragmentation fields support packet splitting for transmission.

Packet Forwarding – Exam-Like Answer

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:

When a data packet arrives at a router, the router:

1. Reads the destination IP address from the packet.


2. Looks up the routing table to find the best next hop.
3. Sends the packet to the next router or final destination.

Steps in Packet Forwarding:


1. Packet received at a router.
2. Header analyzed for destination IP.
3. Routing table consulted.
4. Packet sent to appropriate output port.

Types of Forwarding:

Type Description

Direct Forwarding Destination is in the same network.

Indirect Forwarding Packet is forwarded via other routers.

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.

Fragmentation & Reassembly:


Fragmentation is the process of breaking a large IP packet into smaller fragments so
they can pass through networks that have a smaller Maximum Transmission Unit (MTU).

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.

When Fragmentation Happens:


When a router receives a packet larger than the MTU of the next link.
Common in IPv4 (IPv6 avoids it by using Path MTU Discovery).

Fields Used in Fragmentation:

Field Purpose

Identification Identifies which fragments belong to which original packet

Flags Tells if more fragments follow (MF = More Fragments)

Fragment Offset Position of this fragment in the original packet

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.

It is used for diagnosing network problems, reporting errors, and checking


connectivity.

Key Characteristics:
Works with IP (part of the IP suite).
Used by tools like ping and traceroute.
Not used to transfer data.

Main Purposes of ICMP:

1. Error Reporting

E.g., Destination unreachable, Time exceeded, etc.

2. Network Diagnostics

E.g., Ping (checks if host is reachable), Traceroute (shows path to


destination)

Common ICMP Message Types:

Type Message Purpose

0 Echo Reply Reply to ping

3 Destination Unreachable Host or network cannot be reached

5 Redirect Suggest better route

8 Echo Request Ping request

11 Time Exceeded Packet TTL expired

#### Example:

When you type ping google.com :

Your system sends an ICMP Echo Request.


If Google responds, it sends back an ICMP Echo Reply.

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).

Comparative Study: IPv4 vs IPv6


Feature IPv4 IPv6

Internet Protocol
Full Form Internet Protocol version 6
version 4

Address Size 32 bits 128 bits

Decimal (e.g.,
Address Format Hexadecimal (e.g., 2001:0db8::1)
192.168.1.1)

3.4 × 10³ addresses (virtually


Address Space ~4.3 billion addresses
unlimited)

Header Size 20–60 bytes Fixed 40 bytes

Auto-configuration
Configuration Manual or DHCP
(Stateless/SLAAC)

Security Optional (via IPSec) Built-in (IPSec is mandatory)

Packet Done by sender and


Done only by sender
Fragmentation routers

Not supported (uses


Broadcasting Supported
multicast/anycast)

Routing
Less efficient More efficient (simpler headers)
Efficiency

Checksum Field Present Removed (handled by upper layers)

Widely used, older


Compatibility Newer, not fully adopted everywhere
technology

#### Conclusion:

IPv4 is still widely used but running out of addresses.


IPv6 is designed for the future – more secure, scalable, and efficient.

You might also like