Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Routing Basics & Algorithms
CN

Routing Basics & Algorithms

How routers find the best path: Master Distance Vector (RIP) vs Link State (OSPF) algorithms.

Routing is the process of forwarding packets from source to destination across intermediate routers. Each router maintains a routing table that tells it which interface to forward a packet through for each destination network.

Static vs Dynamic Routing

StaticDynamic
ConfigurationManualAutomatic via routing protocols
AdaptabilityDoesn’t adapt to failuresAutomatically recovers from failures
OverheadNoneProtocol traffic, CPU usage
Use caseSmall, stable networksLarge, changing networks

Distance Vector (e.g., RIP)

Each router periodically shares its entire routing table with directly connected neighbors.

  • Metric: hop count (max 16 = unreachable)
  • Algorithm: Bellman-Ford
  • Update frequency: Every 30 seconds
  • Problems: Slow convergence (count to infinity), routing loops

Count-to-infinity: Router A loses link to X. Router B says “I can reach X in 2 hops” (stale info). A updates to 3 hops via B. B now sees “A can reach X in 3 hops” → B updates to 4. The number increases until it reaches ∞ (16 for RIP).

Each router floods information about its directly connected links to all routers in the area. Every router builds a complete map of the network and runs Dijkstra’s algorithm.

  • Metric: Cost (typically based on bandwidth)
  • Algorithm: Dijkstra’s Shortest Path First (SPF)
  • Update: Only when a link state changes (triggered updates)
  • Convergence: Fast — milliseconds to seconds

EGP vs IGP

TypePurposeExamples
IGP (Interior Gateway Protocol)Routing within an Autonomous SystemRIP, OSPF, EIGRP
EGP (Exterior Gateway Protocol)Routing between Autonomous SystemsBGP

BGP is the routing protocol of the internet — ISPs use it to exchange routes globally.

Q: Compare RIP and OSPF.

A: RIP is distance vector — shares entire table with neighbors, uses hop count (max 15), slow convergence. OSPF is link state — floods link info to all routers, uses cost metric, runs Dijkstra, fast convergence. Use RIP for small/simple networks; OSPF for larger enterprise networks.

Q: What is an Autonomous System (AS)?

A: A collection of IP networks under a single administrative domain — e.g., an ISP, a university, or a company like Google. Each AS has a unique ASN (16-bit or 32-bit number) used in BGP routing.

Q: What is a default route?

A: 0.0.0.0/0 — the “catch-all” entry. If no more specific route matches, the router forwards the packet via the default route (usually toward the internet gateway).

Q: What is the count-to-infinity problem?

A: In distance vector routing, when a link fails, routers can form a loop where each thinks the other has a path. The hop count increments until it reaches infinity (16 in RIP), causing slow convergence. Solved by split horizon, route poisoning, and hold-down timers.

My Private Notes

Notes are auto-saved locally to this device.