Computer NetworksUnit 716 min read
Routing Protocols: Algorithms, Protocols & VLSM
Unit 7 of Computer Networks covers routing protocols (interior/exterior), distance-vector vs. link-state algorithms, VLSM/subnetting, and real-world applications like Ncell’s network or eSewa’s load balancing. Learn how routers exchange routes, solve the count-to-infinity problem, and design efficient IP address alloca
TAKEAWAYS:
- Routing protocols dynamically exchange route information between routers to forward packets efficiently, classified into interior (IGP) and exterior (EGP) based on network scope.
- Distance-vector (e.g., RIP) and link-state (e.g., OSPF) algorithms differ in how they calculate shortest paths and share updates, with trade-offs in convergence speed and overhead.
- Variable Length Subnet Masking (VLSM) optimizes IP address allocation by assigning smaller subnets to networks with fewer hosts, reducing waste (e.g., NTC’s branch offices).
- The count-to-infinity problem in distance-vector protocols causes routing loops, solved by techniques like split horizon, poison reverse, or triggered updates.
- Hierarchical routing (e.g., BGP for ISPs like Ncell) scales large networks by dividing them into autonomous systems (AS) and using policy-based routing.
- Real-world systems (e.g., WhatsApp’s CDN routing, Khalti’s payment gateway load balancing) rely on routing protocols to ensure low-latency, reliable communication.
1. Introduction to Routing Protocols
Routing protocols are the rules and algorithms that routers use to exchange route information and determine the best path for forwarding packets across networks. They operate at the Network Layer (Layer 3) of the OSI model and are essential for internetworking.
Why Routing Protocols?
Without routing protocols, routers would rely on static routes (manually configured), which are:
- Inflexible: Require manual updates if the network topology changes.
- Scalable: Impractical for large networks (e.g., Ncell’s backbone).
- Error-prone: Human mistakes can cause outages.
Routing protocols automatically adapt to network changes (e.g., link failures) and optimize path selection based on metrics like:
- Hop count (number of routers traversed).
- Bandwidth (link speed).
- Delay (propagation + processing time).
- Cost (administrative or monetary).
2. Classification of Routing Protocols
Routing protocols are categorized based on:
Scope:
- Interior Gateway Protocols (IGP): Used within an autonomous system (AS) (e.g., a company’s network like Nepal Telecom’s backbone). Examples: RIP, OSPF, EIGRP.
- Exterior Gateway Protocols (EGP): Used between autonomous systems (e.g., Ncell ↔ NTC ↔ Internet). Example: Border Gateway Protocol (BGP).
Algorithm Type:
- Distance-Vector (DV): Routers share distance (cost) to destinations with neighbors (e.g., RIP).
- Link-State (LS): Routers share complete topology and compute shortest paths independently (e.g., OSPF).
- Path-Vector (PV): Used in BGP to track AS path and prevent loops.
3. Distance-Vector Routing Protocols
How It Works
- Each router maintains a routing table with:
- Destination network.
- Next hop (router to forward to).
- Metric (e.g., hop count).
- Routers periodically exchange their entire routing table with direct neighbors.
- Bellman-Ford algorithm is used to compute shortest paths.
Example: RIP (Routing Information Protocol)
- Metric: Hop count (max 15 hops; 16 = unreachable).
- Update interval: Every 30 seconds.
- Convergence time: Slow (takes time to propagate updates).
Worked Example: RIP Routing Table Update Assume a simple network:
Router A -- Router B -- Router C
- Initial state: All routers know directly connected networks.
- After 1st update:
- A learns
C/24via B (distance = 2). - B learns
A/24andC/24(distance = 1). - C learns
B/24andA/24via B (distance = 2).
- A learns
Mermaid Diagram: RIP Update Process
sequenceDiagram
participant A as Router A
participant B as Router B
participant C as Router C
A->>B: Sends routing table (A/24, distance=0)
B->>C: Sends routing table (B/24, A/24 via A, distance=1)
C->>B: Sends routing table (C/24, B/24, A/24 via B, distance=1)
B->>A: Sends updated table (A/24, B/24, C/24 via C, distance=2)Problems with Distance-Vector
Count-to-Infinity Problem:
- If a link fails, routers keep incrementing the hop count until it reaches 16 (infinite).
- Example: If A-B link fails, A thinks B is 16 hops away and stops sending updates to B. But B still thinks A is 2 hops away (via C), causing a routing loop.
Mermaid Diagram: Count-to-Infinity Loop
flowchart TD A["Router A"] -->|"B/24 via B"| B["Router B"] B -->|"A/24 via A"| A C["Router C"] -->|"A/24 via B"| B B -->|"C/24 via C"| C
Slow Convergence:
- Updates are periodic, so failures take time to propagate.
Solutions to Count-to-Infinity
| Technique | Description | Example |
|---|---|---|
| Split Horizon | Prevents a router from sending info back to where it came from. | A won’t send A/24 to B. |
| Poison Reverse | Sends infinite metric (16) for a route back to the neighbor. | A sends B/24 as 16 hops to B. |
| Triggered Updates | Sends updates immediately when a change is detected (instead of waiting 30s). | RIPv2 supports this. |
4. Link-State Routing Protocols
How It Works
- Each router floods the entire network with Link-State Advertisements (LSAs) containing:
- Neighbor routers.
- Link costs (e.g., bandwidth).
- Every router builds a complete topology map and runs Dijkstra’s algorithm to compute shortest paths.
Example: OSPF (Open Shortest Path First)
- Metric: Cost (based on bandwidth; lower cost = faster link).
- Formula:
Cost = Reference Bandwidth / Interface Bandwidth. - Default reference bandwidth = 100 Mbps.
- Example: A 100 Mbps link has cost
100/100 = 1; a 10 Mbps link has cost100/10 = 10.
- Formula:
- Areas: Divides large networks into hierarchical regions to reduce overhead.
- Convergence: Faster than RIP (seconds vs. minutes).
Worked Example: OSPF Cost Calculation Assume:
- Link A-B: 100 Mbps → Cost =
100/100 = 1. - Link B-C: 10 Mbps → Cost =
100/10 = 10. - Link A-C: 10 Mbps → Cost =
10.
Shortest path from A to C:
- A → B → C: Cost =
1 + 10 = 11. - A → C: Cost =
10. → A chooses A → C (lower cost).
Mermaid Diagram: OSPF Topology Flooding
sequenceDiagram
participant A as Router A
participant B as Router B
participant C as Router C
A->>B: Floods LSA (A-B cost=1)
B->>C: Floods LSA (B-C cost=10, A-B cost=1)
C->>A: Floods LSA (A-C cost=10, B-C cost=10)
A->>A: Runs Dijkstra: A→C (cost=10) is bestAdvantages of Link-State
- Faster convergence (no periodic updates; changes propagate immediately).
- No count-to-infinity (complete topology known).
- Scalable (hierarchical areas reduce flooding).
Disadvantages
- High memory usage (stores full topology).
- High CPU usage (runs Dijkstra’s algorithm).
- Complex configuration (areas, authentication).
5. Variable Length Subnet Masking (VLSM)
What is VLSM?
- Traditional subnetting assigns equal-sized subnets, wasting IP addresses.
- VLSM assigns different subnet mask lengths based on host requirements:
- Networks with few hosts get smaller subnets (e.g.,
/28for 14 hosts). - Networks with many hosts get larger subnets (e.g.,
/24for 254 hosts).
- Networks with few hosts get smaller subnets (e.g.,
Why Use VLSM?
- Conserves IP addresses (critical for IPv4 exhaustion).
- Reduces routing table size (smaller subnets aggregate better).
Worked Example: VLSM Subnetting
Given: 192.168.0.0/24 (CIDR 24).
Requirements:
- LAN 1: 30 hosts → Needs 6 bits for hosts (
2^6 - 2 = 62hosts). → Subnet mask:/26(32 - 6 = 26). - LAN 2: 10 hosts → Needs 4 bits for hosts (
2^4 - 2 = 14hosts). → Subnet mask:/28(32 - 4 = 28). - LAN 3: 5 hosts → Needs 3 bits for hosts (
2^3 - 2 = 6hosts). → Subnet mask:/29(32 - 3 = 29).
Step-by-Step Subnetting:
- Start with
192.168.0.0/24(subnet0, usable range192.168.0.1–254). - Allocate LAN 1 (/26):
- Subnet
0:192.168.0.0/26(wasted; avoid using0). - Next available:
192.168.0.64/26(LAN 1).- Usable hosts:
192.168.0.65–94.
- Usable hosts:
- Subnet
- Allocate LAN 2 (/28):
- Next subnet:
192.168.0.96/28.- Usable hosts:
192.168.0.97–110.
- Usable hosts:
- Next subnet:
- Allocate LAN 3 (/29):
- Next subnet:
192.168.0.112/29.- Usable hosts:
192.168.0.113–118.
- Usable hosts:
- Next subnet:
Mermaid Diagram: VLSM Subnet Allocation
5+3 VLSM Rule
- 5 bits for subnets, 3 bits for hosts →
/27(default for VLSM). - Used when no specific host requirements are given.
- Example:
192.168.0.0/27gives:- Subnet bits: 5 →
2^5 = 32 subnets. - Host bits: 3 →
2^3 - 2 = 6 hosts per subnet.
- Subnet bits: 5 →
Why Use 5+3?
- Balances subnet count and host capacity.
- Ensures no wasted subnets for small networks.
6. Exterior Gateway Protocol: BGP (Border Gateway Protocol)
What is BGP?
- The de facto standard for inter-domain routing (between ISPs like Ncell ↔ NTC ↔ Internet).
- Operates between autonomous systems (AS) (e.g., AS1234 for Ncell, AS5678 for NTC).
- Uses path-vector algorithm (extends distance-vector with AS path tracking).
How BGP Works
- Peering: Routers in different ASes establish BGP sessions (e.g., Ncell’s router ↔ NTC’s router).
- Route Advertisement:
- Routers exchange network prefixes (e.g.,
103.0.0.0/8for Ncell). - Each update includes the AS path (e.g.,
AS1234 → AS5678).
- Routers exchange network prefixes (e.g.,
- Policy-Based Routing:
- ISPs use BGP attributes (e.g.,
AS_PATH,NEXT_HOP,LOCAL_PREF) to enforce policies like:- Prefer local routes (e.g., Ncell prefers its own routes over competitors).
- Avoid loops (if a route’s AS path contains its own AS, discard it).
- ISPs use BGP attributes (e.g.,
Example: BGP Route Selection
Assume:
- AS1 (Ncell) advertises
192.168.1.0/24to AS2 (NTC). - AS2 receives two paths to
192.168.1.0/24:- Via AS1 (AS path:
AS1). - Via AS3 → AS1 (AS path:
AS3 AS1).
- Via AS1 (AS path:
BGP selects the path with the shortest AS path → AS1 (shorter path).
Mermaid Diagram: BGP AS Path
sequenceDiagram
participant Ncell as AS1234 (Ncell)
participant NTC as AS5678 (NTC)
participant Internet as AS7890 (Internet)
Ncell->>NTC: Advertises 192.168.1.0/24 (AS_PATH: AS1234)
NTC->>Internet: Advertises 192.168.1.0/24 (AS_PATH: AS5678 AS1234)
note "NTC prefers the path with fewer AS hops."BGP Attributes
| Attribute | Description |
|---|---|
| AS_PATH | List of ASes traversed (e.g., AS1234 AS5678). |
| NEXT_HOP | IP of the next router in the path. |
| LOCAL_PREF | Preference for routes within the same AS (higher = preferred). |
| MED | Multi-Exit Discriminator (influences inbound traffic from neighbors). |
| COMMUNITY | Used for routing policies (e.g., "do not export to customers"). |
BGP vs. IGP
| Feature | BGP (EGP) | IGP (RIP/OSPF) |
|---|---|---|
| Scope | Between ASes (Internet) | Within an AS (e.g., Ncell’s network) |
| Algorithm | Path-vector | Distance-vector or Link-state |
| Metric | AS path length, policies | Hop count or cost |
| Convergence | Slow (minutes) | Fast (seconds) |
| Scalability | High (millions of routes) | Limited to single AS |
7. Real-World Applications
1. Ncell’s Backbone Network
- Uses OSPF for interior routing (within Ncell’s AS) to efficiently route calls/data between towers.
- Uses BGP for exterior routing to exchange routes with other ISPs (e.g., NTC, Smart).
- VLSM optimizes IP allocation for different-sized cell sites.
2. eSewa’s Payment Gateway
- Load balancing: Uses OSPF or BGP to distribute traffic across multiple servers to prevent overload.
- Redundancy: If one payment server fails, OSPF quickly reroutes traffic to another.
3. WhatsApp’s CDN Routing
- Anycast DNS: Uses BGP to route users to the nearest WhatsApp server (e.g., Kathmandu user → Ncell’s nearest CDN node).
- VLSM: Efficiently allocates IPs to CDN nodes worldwide.
4. Daraz’s Order Fulfillment
- Hierarchical routing: Daraz’s warehouse network uses OSPF areas to separate regional hubs (e.g., Kathmandu, Pokhara) from the central database.
- RIP for small branches: Remote pickup points use RIP due to low traffic.
5. NTC’s Fiber Optic Backbone
- Uses MPLS (Multi-Protocol Label Switching) on top of OSPF for fast traffic engineering.
- VLSM ensures minimal IP waste across thousands of exchange points.
8. Exam Tips
Memorize Key Protocols and Their Features:
- RIP: Distance-vector, hop count ≤ 15, slow convergence.
- OSPF: Link-state, cost-based, hierarchical areas.
- BGP: Path-vector, AS path, policy-based.
Practice VLSM Subnetting:
- Always draw the subnet table (network, broadcast, usable hosts).
- Use the 5+3 rule when no host count is given.
Understand Count-to-Infinity:
- Explain why it happens (no poison reverse) and how to fix it (split horizon, triggered updates).
Compare IGP vs. EGP:
- IGP = within AS (OSPF, RIP).
- EGP = between ASes (BGP).
Real-World Scenarios:
- Relate VLSM to NTC’s branches (small subnets for remote offices).
- Relate BGP to Ncell ↔ NTC peering (AS path selection).
Diagrams Are Key:
- Always draw:
- Routing table updates (RIP).
- Topology flooding (OSPF).
- AS path diagrams (BGP).
- Label metrics, costs, and next hops.
- Always draw:
Common Pitfalls:
- Forgetting broadcast addresses in subnetting.
- Misapplying split horizon (e.g., sending updates back to the source).
- Confusing OSPF cost with RIP hop count.
9. Summary Table: Routing Protocols
| Protocol | Type | Algorithm | Metric | Scope | Max Hops | Convergence | Notes |
|---|---|---|---|---|---|---|---|
| RIP | IGP | Distance-vector | Hop count | Single AS | 15 | Slow | Count-to-infinity problem |
| OSPF | IGP | Link-state | Cost (bandwidth) | Single AS | N/A | Fast | Hierarchical areas |
| EIGRP | IGP | Advanced DV | Composite | Single AS | 100 | Fast | Cisco proprietary |
| BGP | EGP | Path-vector | AS path | Between ASes | N/A | Slow | Policy-based routing |
10. Practice Questions
Subnetting:
- Subnet
172.16.0.0/16using VLSM for:- LAN 1: 20 hosts.
- LAN 2: 50 hosts.
- LAN 3: 100 hosts.
- Show the subnet allocation table.
- Subnet
Routing Loops:
- Explain how split horizon and poison reverse prevent count-to-infinity in RIP.
OSPF Cost:
- Calculate the cost of a 10 Mbps and 1 Gbps link (reference bandwidth = 100 Mbps).
BGP Policy:
- Why might Ncell prefer routes from NTC over Smart even if Smart’s path is shorter?
VLSM vs. Traditional:
- Given
10.0.0.0/8, allocate subnets for:- 3 networks with 50 hosts each.
- 1 network with 5 hosts.
- Compare IP usage in VLSM vs. traditional subnetting.
- Given
Based on the PU BE Computer (PU) syllabus for Computer Networks, unit 7.
Discussion
Loading…