Skip to main content
← All posts

Part 6: Routing Packets Across the Internet: Autonomous Systems, BGP & OSPF

Md. Harun-Or-RoshidNov 5, 20263 min readArticle
Part 6: Routing Packets Across the Internet: Autonomous Systems, BGP & OSPF

Lesson Overview & Learning Objectives

The internet is not a single monolith, but a federation of over 100,000 independently operated networks called Autonomous Systems (AS). For a packet to navigate from an end user to a server on another continent, routers must dynamically compute the optimal path across multiple administrative domains. In this guide, we demystify packet routing versus forwarding, analyze Interior Gateway Protocols like OSPF (powered by Dijkstra's algorithm), examine the glue of the global internet—Border Gateway Protocol (BGP-4)—and explore CIDR prefix matching.

1. Routing vs. Forwarding: Control Plane vs. Data Plane

Routing (The Control Plane)

The network-wide logic that determines the end-to-end paths packets take from source to destination. Routers run routing protocols (BGP, OSPF) to exchange topology updates and build a Routing Information Base (RIB) in software memory.

Forwarding (The Data Plane)

The local, router-internal action of transferring a packet from an inbound interface to the appropriate outbound interface in nanoseconds. Forwarding is executed entirely in hardware using a Forwarding Information Base (FIB) programmed into ASIC/TCAM chips.

2. Autonomous Systems (AS) and Border Gateway Protocol (BGP)

An Autonomous System (AS) is a collection of connected IP routing prefixes under the control of a single administrative entity (such as Google AS15169, Cloudflare AS13335, or Comcast AS7922) that presents a common routing policy to the internet.

Between autonomous systems, routers speak Border Gateway Protocol (BGP). Unlike internal routing protocols that prioritize the mathematically shortest path, BGP is a Path Vector Protocol heavily driven by business economics and transit peering contracts:

How BGP Determines Route Selection (Best Path Algorithm):

  1. Weight: Highest local proprietary weight (Cisco specific).
  2. Local Preference: Prefers customer routes (revenue generating) over peer routes or paid transit routes.
  3. Locally Originated: Prefers routes created by the router itself.
  4. Shortest AS-Path: Prefers the path with the fewest Autonomous System hops.
  5. Origin Code: Prefers IGP over EGP or incomplete routes.
  6. Lowest Multi-Exit Discriminator (MED): Prefers lowest entry point advertised by neighbor AS.
  7. eBGP over iBGP: Prefers external BGP learned routes over internal BGP learned routes.

3. Interior Routing: OSPF and Dijkstra's Algorithm

While BGP glues different networks together, internal traffic within an organization's datacenter or campus network is managed by an Interior Gateway Protocol (IGP), predominantly Open Shortest Path First (OSPF).

OSPF is a Link-State Protocol. Every router broadcasts Link-State Advertisements (LSAs) describing its attached links and costs. Every router in the OSPF area constructs an identical topological graph of the network and independently runs Dijkstra's Shortest Path First (SPF) Algorithm to compute the shortest tree of paths rooted at itself.

4. Longest Prefix Match & CIDR

When a destination IP like 198.51.100.45 arrives at a core router, the router's table may contain multiple overlapping subnet routes:

Prefix EntryPrefix LengthOutbound InterfaceMatching Decision
198.0.0.0/88 bitseth0Matches, but broad
198.51.0.0/1616 bitseth1Matches, more specific
198.51.100.0/2424 bitseth2✓ WINNER: Longest Prefix Match (Most specific route)
Share:
Share on X
Share on LinkedIn
Share on Facebook
Share on Reddit
Share on WhatsApp
Share on Telegram
Copy link

Related reading

Routing Packets: BGP, OSPF & Internet Core | Draftsbook · Draftsbook