The Routing Problem — Why Packets Need a Map
Each strategy is a routing algorithm. None is universally "best" — they trade off how much each router knows against how much they need to communicate. The entire Internet runs on all three, layered on top of each other.
Every time you load a webpage, your data travels across dozens of routers — physical devices that forward packets hop-by-hop toward the destination. Each router must answer one question: where do I send this packet next? Routing algorithms decide that answer.
RIP (Distance Vector) — lightweight, each router only knows costs to neighbours.
OSPF (Link State) — each router knows the entire network map and computes shortest paths.
BGP (Path Vector) — glues autonomous systems together using policy-based routing.
Distance Vector Routing — RIP
Distance Vector is the oldest and simplest approach to routing. Each router maintains a routing table containing the best-known distance to every destination, and which neighbour to use to get there. Routers share their entire table with direct neighbours only — they never see the whole network.
Next morning you update your table and share it again. Slowly, correct information spreads across the network — but only as fast as the morning gossip rounds. And if a road closes, you might keep recommending it for a long time before the bad news reaches you. This is called count-to-infinity.
The Bellman-Ford Equation
Distance Vector is based on the Bellman-Ford algorithm. The core update rule every router uses:
🏭 Animated: How Distance Vectors Converge
💡 Click "Next Step" to watch distance vectors exchange and routing tables converge.
RIP — The Protocol in Practice
If a link fails, a router stops advertising it. But its neighbour might still be advertising a route through that router. The failing router picks up that stale route and adds 1. The count bounces back and forth until it hits 16 (infinity). This is slow convergence by design — a fundamental weakness of Distance Vector. Fixes include split horizon, poison reverse, and triggered updates.
Real-World RIP: Router Configuration Snapshot
! Cisco IOS — Enabling RIPv2 on a small branch router
Router(config)# router rip
Router(config-router)# version 2
Router(config-router)# network 192.168.10.0
Router(config-router)# network 10.0.0.0
Router(config-router)# no auto-summary ! Required for VLSM/CIDR
Router(config-router)# passive-interface GigabitEthernet0/1 ! Don't send RIP on LAN
! Verify: show routing table
Router# show ip route rip
! Output:
! R 10.0.1.0/24 [120/1] via 192.168.10.2, 00:00:07, GigabitEthernet0/0
! R 10.0.2.0/24 [120/2] via 192.168.10.2, 00:00:07, GigabitEthernet0/0
! [AD=120, metric=hop count]
Link State Routing — OSPF
Link State routing gives every router a complete map of the network. Instead of sharing routing tables, routers share Link State Advertisements (LSAs) — small packets that describe each router's direct connections and their costs. Every router floods LSAs across the network, builds an identical topology database, and then runs Dijkstra's Shortest Path First algorithm locally.
The trade-off: OSPF converges much faster than RIP and supports complex topologies — but it's significantly more complex to configure and more demanding on CPU and memory.
OSPF Key Concepts
🏭 Animated: Dijkstra's Algorithm on an OSPF Network
💡 Dijkstra visits the lowest-cost unvisited node at each step. Green = settled, amber = in queue.
OSPF Areas — The Scalability Answer
ABR = Area Border Router. It sits in two areas and summarises routes between them, shrinking the LSDB within each area.
OSPF Metric — Cost = 10⁸ / Bandwidth
OSPF — Cisco IOS Configuration
! OSPF multi-area configuration — Cisco IOS
Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1 ! Unique 32-bit ID
Router(config-router)# auto-cost reference-bandwidth 10000 ! 10Gbps ref for modern nets
Router(config-router)# network 192.168.1.0 0.0.0.255 area 0
Router(config-router)# network 10.10.0.0 0.0.255.255 area 1
Router(config-router)# passive-interface GigabitEthernet0/2
! Verify OSPF neighbours and database
Router# show ip ospf neighbor
Router# show ip ospf database
Router# show ip route ospf
On a broadcast segment (e.g., Ethernet switch), N routers would form N(N-1)/2 adjacencies — an O(N²) problem. OSPF elects a Designated Router (DR) and Backup DR (BDR). All others form adjacencies only with DR/BDR, reducing the problem to O(N). The DR floods LSAs on behalf of the segment. DR is elected by highest OSPF priority (default 1), then highest Router-ID.
Path Vector Routing — BGP
BGP (Border Gateway Protocol) is the routing protocol of the Internet. It connects Autonomous Systems (AS) — the ~75,000+ independent networks operated by ISPs, cloud providers, enterprises, and governments. BGP is fundamentally different from RIP and OSPF: it does not try to find the shortest path. It finds the best policy-compliant path.
BGP works the same way. An ISP in the US might prefer to route traffic through its own network rather than a competitor's, even if the competitor's path is physically shorter. BGP encodes business relationships and policy, not just geography.
BGP: Path Vector vs. Distance Vector
| Destination | Cost | Next Hop |
|---|---|---|
| 10.0.1.0/24 | 3 | 192.168.1.1 |
| 10.0.2.0/24 | 5 | 192.168.1.1 |
Only knows cost and next hop. Can't detect loops — the path is opaque.
| Prefix | AS Path | Next Hop |
|---|---|---|
| 10.0.1.0/24 | AS64500 AS64501 | 203.0.113.1 |
| 10.0.2.0/24 | AS64500 AS64502 AS64503 | 203.0.113.1 |
Knows the full AS path. Loop detection is trivial: if your own AS number appears in the path, discard it.
BGP Message Types
🏭 Animated: AS-Path in Action
💡 Watch an UPDATE message travel from AS64500 (origin) to AS64503, accumulating AS numbers in the path attribute at each hop.
BGP Path Selection — The Decision Process
When BGP receives multiple paths to the same prefix, it applies a decision process in order. The first attribute that differs determines the winner:
iBGP vs eBGP
| Property | Value |
|---|---|
| Between | Different AS routers |
| TTL | 1 (directly connected peers) |
| NEXT_HOP | Changed to own address |
| LOCAL_PREF | Set on ingress from eBGP |
| Property | Value |
|---|---|
| Between | Same AS routers |
| TTL | 255 (can span multiple hops) |
| NEXT_HOP | Preserved from eBGP peer |
| Full Mesh | Required (or use Route Reflectors) |
iBGP does not re-advertise routes learned from one iBGP peer to another — it prevents loops within the AS. This means all iBGP routers must be in a full mesh: N(N-1)/2 sessions. With 100 routers that's 4,950 sessions. Route Reflectors (RFC 4456) solve this: a designated RR re-advertises routes to its clients, breaking the full-mesh requirement.
BGP Configuration — Cisco IOS
! BGP peering setup — Router in AS 64500
Router(config)# router bgp 64500
Router(config-router)# bgp router-id 1.1.1.1
Router(config-router)# bgp log-neighbor-changes
! eBGP peer in AS 64501
Router(config-router)# neighbor 203.0.113.2 remote-as 64501
Router(config-router)# neighbor 203.0.113.2 description eBGP-to-AS64501
! iBGP peer in same AS (loopback-based, TTL update needed)
Router(config-router)# neighbor 10.0.0.2 remote-as 64500
Router(config-router)# neighbor 10.0.0.2 update-source Loopback0
! Originate our prefix into BGP
Router(config-router)# network 198.51.100.0 mask 255.255.255.0
! Verify
Router# show bgp ipv4 unicast summary
Router# show bgp ipv4 unicast 198.51.100.0/24
RIP vs OSPF vs BGP — Side-by-Side
| Property | RIP | OSPF | BGP |
|---|---|---|---|
| Algorithm Type | Distance Vector | Link State | Path Vector |
| Algorithm | Bellman-Ford | Dijkstra (SPF) | Policy-based selection |
| Scope | IGP (within AS) | IGP (within AS) | EGP (between AS) |
| Metric | Hop count (max 15) | Cost (bandwidth-based) | AS_PATH + policy attributes |
| Network scale | Small (<15 hops) | Medium–large (1,000s of routers) | Entire Internet (~900,000 prefixes) |
| Convergence speed | Slow (minutes) | Fast (seconds) | Very slow (minutes to hours) |
| Loop prevention | Split horizon / Poison reverse | SPF (topology is fully known) | AS_PATH loop detection |
| Transport | UDP port 520 | IP Protocol 89 | TCP port 179 |
| Config complexity | Very simple | Moderate–complex | Complex (policy-heavy) |
| Supports VLSM/CIDR | v2 only | Yes | Yes |
| Authentication | MD5 (v2) | MD5 / SHA | MD5 / TCP-AO |
| Typical use today | Legacy / embedded | Enterprise LAN / WAN core | ISP peering / data centres |
When Routing Goes Wrong — Real Incidents
Resource Public Key Infrastructure (RPKI) is a cryptographic framework that lets IP address holders digitally sign which AS is authorised to originate their prefixes. Routers receiving a BGP route can validate it against the RPKI. As of 2024, about 50% of the global routing table is covered by RPKI ROAs (Route Origin Authorizations). Major ISPs including AT&T, Comcast, Deutsche Telekom, and NTT now enforce RPKI route origin validation.
Where Each Protocol Lives — The Protocol Ecosystem
IGPs (OSPF/RIP) run inside each AS for internal reachability. BGP runs between ASes, exchanging reachability information about the prefixes each AS can reach.
Golden Rules & Practitioner Checklist
RIP: Small branch networks, embedded routers, legacy environments.
Simple config, poor scalability, slow convergence — use only when OSPF is too complex to justify.
OSPF: The go-to IGP for enterprise and ISP internal networks. Fast convergence,
hierarchical with areas, bandwidth-aware metrics. More complex to configure but far more robust.
BGP: The protocol of the Internet. Required whenever you have multiple
upstream ISPs, run a data centre, or operate a CDN. Policy-rich but demands careful design —
a misconfiguration can impact millions of users worldwide.