Computer Networks Essentials / Network Layer

Routing Algorithms

๐Ÿค” What is a Routing Algorithm? (Basic Idea)

A routing algorithm is a set of rules and calculations used by routers to:

  • Find the best path

  • Decide where to forward packets

  • Update routing tables automatically

๐Ÿ“Œ In simple words:

Routing algorithms help routers choose the smartest route for data.


๐Ÿง  Real-Life Analogy

๐Ÿ—บ๏ธ Google Maps Navigation

  • Many routes available

  • Shortest, fastest, or least traffic route chosen

  • Route changes if traffic changes

๐Ÿ‘‰ Routers use routing algorithms the same way.


๐ŸŽฏ Why Routing Algorithms Are Needed

Routing algorithms help to:

  • ๐Ÿš€ Deliver data efficiently

  • ๐Ÿ”„ Adapt to network changes

  • โŒ Avoid routing loops

  • ๐Ÿ“‰ Reduce congestion

  • ๐ŸŒ Scale to large networks (Internet)

Without routing algorithms:

  • Routers cannot decide paths โŒ

  • Network becomes unreliable โŒ


๐Ÿ“ Where Are Routing Algorithms Used?

  • Implemented in routing protocols

  • Used at the Network Layer

  • Executed inside routers


๐Ÿงฉ Key Properties of a Good Routing Algorithm

A good routing algorithm should be:

  • โœ”๏ธ Correct

  • โšก Fast convergence

  • ๐Ÿ“ˆ Scalable

  • ๐Ÿ” Loop-free

  • ๐Ÿง  Adaptive to failures


๐Ÿงญ Types of Routing Algorithms

Routing algorithms are mainly classified into:

1๏ธโƒฃ Shortest Path Algorithm

2๏ธโƒฃ Distance Vector Routing Algorithm

3๏ธโƒฃ Link State Routing Algorithm

4๏ธโƒฃ Flooding Algorithm

Weโ€™ll explain each one clearly ๐Ÿ‘‡


๐Ÿ›ฃ๏ธ 1. Shortest Path Routing Algorithm

๐Ÿ”น Basic Idea

Selects the path with the minimum cost between source and destination.

๐Ÿ“Œ Cost can be based on:

  • Distance

  • Delay

  • Bandwidth

  • Hop count


๐Ÿง  Example

If:

  • Path A โ†’ Cost = 10

  • Path B โ†’ Cost = 5

๐Ÿ‘‰ Path B is selected.


โญ Advantages

  • Simple concept

  • Efficient routing

  • Optimal path selection

๐Ÿ“Œ Used as the foundation of other algorithms.


๐Ÿ” 2. Distance Vector Routing Algorithm

๐Ÿ”น Basic Idea

Each router knows:

  • Distance to destination

  • Direction (next hop)

๐Ÿ“Œ Routers share routing tables with neighbors only.


๐Ÿง  How It Works (Step-by-Step)

1๏ธโƒฃ Router initializes its table

2๏ธโƒฃ Shares table with neighbors

3๏ธโƒฃ Receives neighborsโ€™ tables

4๏ธโƒฃ Updates routes if shorter path found

5๏ธโƒฃ Repeats periodically


๐Ÿงฎ Metric Used

  • Hop count (mostly)

๐Ÿ“Œ Example protocol: RIP


โŒ Problems

  • Slow convergence

  • Routing loops

  • Count-to-infinity problem


๐Ÿ› ๏ธ Solutions

  • Split horizon

  • Poison reverse

  • Hold-down timers


โœ… Advantages

  • Simple

  • Low computation


๐ŸŒ 3. Link State Routing Algorithm

๐Ÿ”น Basic Idea

Each router knows the entire network topology.

๐Ÿ“Œ Routers exchange link state information instead of full tables.


๐Ÿง  How It Works (Step-by-Step)

1๏ธโƒฃ Discover neighbors

2๏ธโƒฃ Measure link cost

3๏ธโƒฃ Flood link state packets (LSPs)

4๏ธโƒฃ Build topology map

5๏ธโƒฃ Run shortest path algorithm


๐Ÿงฎ Algorithm Used

  • Dijkstraโ€™s Algorithm

๐Ÿ“Œ Example protocol: OSPF


โœ… Advantages

  • Fast convergence โšก

  • Accurate routing

  • No routing loops


โŒ Disadvantages

  • High memory usage

  • Complex implementation

  • High CPU usage


๐ŸŒŠ 4. Flooding Algorithm

๐Ÿ”น Basic Idea

Every incoming packet is sent on all outgoing links except the one it arrived on.

๐Ÿ“Œ No routing table required.


๐Ÿง  Use Cases

  • Network discovery

  • Emergency message delivery


โŒ Problems

  • Heavy traffic

  • Duplicate packets

  • Congestion

๐Ÿ“Œ Controlled using:

  • Hop count

  • Sequence numbers


๐Ÿ“Š Comparison of Routing Algorithms

Algorithm

Knowledge

Speed

Loop Issue

Example

Shortest Path

Partial

Fast

No

Dijkstra

Distance Vector

Neighbor only

Slow

Yes

RIP

Link State

Full topology

Fast

No

OSPF

Flooding

None

โ€“

No

Discovery


๐Ÿง  Distance Vector vs Link State (Very Important)

Feature

Distance Vector

Link State

Information Shared

Routing table

Link states

Knowledge

Partial

Complete

Convergence

Slow

Fast

Complexity

Low

High

Example

RIP

OSPF


๐Ÿ”„ Routing Algorithm & Routing Protocol Relationship

๐Ÿ“Œ Routing Algorithm โ†’ Logic / method

๐Ÿ“Œ Routing Protocol โ†’ Implementation

Example:

  • Algorithm โ†’ Link State

  • Protocol โ†’ OSPF


๐Ÿง  Routing Algorithm Selection Depends On

  • Network size

  • Traffic load

  • Speed requirement

  • Hardware capacity

  • Reliability needs


โญ One-Line Summary

๐Ÿ”น Routing algorithms determine the most efficient path for data packets across networks by using metrics and network information.