Routing Protocols (OSPF & BGP)

[!NOTE] This module explores the core principles of Routing Protocols (OSPF & BGP), deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.

The Hook: Navigating the Global City

Imagine you need to drive from New York to San Francisco. If you use a simple paper map (Static Routing), you might choose a direct highway. But what if there’s a massive blizzard in Colorado or a bridge collapsed in Ohio? You’d be stuck.

Instead, you use a GPS app like Waze or Google Maps (Dynamic Routing). The app constantly communicates with other drivers to learn about traffic, accidents, and road closures, automatically recalculating the fastest route. In the world of networking, routers are the traffic cops and GPS systems, using Routing Protocols to constantly share “traffic” updates and find the optimal path for your data packets.

1. What is a Router?

At its core, a router is a Layer 3 device responsible for forwarding data packets between distinct computer networks. While switches connect devices within the same network (Layer 2), routers connect different networks together.

A router logically operates in two distinct planes:

  • Control Plane (The Brains): Runs routing protocols (like OSPF or BGP) to learn the network topology and build the Routing Information Base (RIB). It figures out where packets should go.
  • Data Plane (The Muscle): Also known as the forwarding plane. It takes the best paths from the RIB and programs them into high-speed hardware memory called the Forwarding Information Base (FIB) to actually move the packets as fast as possible.

2. Static vs. Dynamic Routing

How does a router know where to send a packet?

  • Static Routing: An administrator manually types the routes into the router.
    • Analogy: Hardcoding directions to your house.
    • Pros: Zero CPU/bandwidth overhead, highly secure (no protocol to hack).
    • Cons: Does not adapt to link failures. If a cable is cut, traffic drops. Best for small “stub” networks with only one exit path.
  • Dynamic Routing: Routers speak a common protocol to automatically exchange network reachability information.
    • Analogy: Real-time crowdsourced GPS apps.
    • Pros: Automatically routes around failures and adds new networks dynamically.
    • Cons: Consumes CPU, memory, and link bandwidth to process updates.

3. Interior Gateway Protocols (IGP)

IGPs are used to route traffic inside a single organization’s administrative domain, formally known as an Autonomous System (AS).

Distance Vector (RIP - Routing Information Protocol)

  • How it works: Routers only share their routing tables with their immediate neighbors.
  • Analogy: The “Game of Telephone.” You ask your neighbor how to get to the store. They say “It’s 3 blocks away.” You don’t know the exact streets, you just trust your neighbor.
  • Metric: Hop Count (how many routers must be crossed).
  • Drawbacks: Slow convergence. If a link goes down, it takes a long time for the news to propagate. Highly prone to routing loops. (Mostly legacy today).
  • How it works: Every router floods the network with Link State Advertisements (LSAs) detailing its connected links and their states. Every router in the area uses these LSAs to build a complete, identical map (topology) of the network.
  • Analogy: Everyone has the exact same detailed city map and calculates their own directions.
  • The Algorithm: Uses Dijkstra’s Shortest Path Algorithm.
  • Metric: Cost, which is inversely proportional to bandwidth. A 10 Gbps fiber link has a much lower cost than a 100 Mbps copper link, making it the preferred path.
  • Scalability: To prevent routers from running out of memory from storing massive maps, OSPF splits networks into hierarchical Areas (e.g., Area 0 is the backbone).

4. Exterior Gateway Protocols (EGP)

EGPs are used to route traffic between different organizations (between different Autonomous Systems). This is how your ISP connects to Netflix, Google, or other ISPs.

Path Vector (BGP - Border Gateway Protocol)

  • The “Glue” of the Internet: BGP is the protocol that runs the global Internet.
  • How it works: Instead of looking for the fastest link, BGP looks at policies and business agreements.
  • Analogy: International shipping routes. A cargo ship might take a physically longer route to avoid high tariffs in a specific country’s waters or to favor a port owned by a partner company.
  • AS Path: To prevent loops, BGP tracks every Autonomous System Number (ASN) a route passes through. If a router sees its own ASN in the path, it drops the route.
  • eBGP vs. iBGP: eBGP runs between different ASes, while iBGP runs inside the same AS to distribute the external routes to internal routers.

5. Interactive: Dijkstra’s Path

Find the lowest cost path from Source (S) to Destination (D). OSPF calculates the path based on link cost, avoiding expensive routes even if they have fewer hops.

S
B
C
D
Cost: 10
Cost: 1
Cost: 2
Cost: 8
Waiting for Dijkstra...

6. Convergence

Convergence is the state where all routers in a network have a synchronized, consistent, and correct view of the network topology.

  • Fast Convergence is Critical: If a link is severed and routers aren’t updated quickly, they continue forwarding packets into a broken path.
  • Routing Black Hole: Packets arrive at a router that has lost its route to the destination. The router drops the packets silently, causing a total loss of connectivity for that session.
  • Routing Loop: Router A thinks the best path to a destination is through Router B. Router B thinks the best path is through Router A. Packets bounce back and forth until their Time-To-Live (TTL) expires.

When comparing protocols, OSPF converges in milliseconds to seconds, whereas BGP can take several minutes to converge fully, reflecting their different use cases (internal speed vs. external stability).