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):
- Weight: Highest local proprietary weight (Cisco specific).
- Local Preference: Prefers customer routes (revenue generating) over peer routes or paid transit routes.
- Locally Originated: Prefers routes created by the router itself.
- Shortest AS-Path: Prefers the path with the fewest Autonomous System hops.
- Origin Code: Prefers IGP over EGP or incomplete routes.
- Lowest Multi-Exit Discriminator (MED): Prefers lowest entry point advertised by neighbor AS.
- 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 Entry | Prefix Length | Outbound Interface | Matching Decision |
|---|---|---|---|
| 198.0.0.0/8 | 8 bits | eth0 | Matches, but broad |
| 198.51.0.0/16 | 16 bits | eth1 | Matches, more specific |
| 198.51.100.0/24 | 24 bits | eth2 | ✓ WINNER: Longest Prefix Match (Most specific route) |
Related reading
How to Give Google Antigravity Direct SSH Access to Remote Servers (Proxmox & Linux)
Connect Google Antigravity directly to Proxmox and Linux servers using the Model Context Protocol (MCP), dedicated Ed25519 keys, and automated updates.
By Md. Harun-Or-Roshid
Part 10: Cloud to Fog & Edge: Architecting the Distributed Continuum
Explore the distributed computing continuum: compare centralized cloud, fog computing gateways, and real-time edge nodes for latency-critical IoT systems.
By Md. Harun-Or-Roshid
Part 10: Distributed Databases: Partitioning, Sharding, 2PC & CAP Theorem
Master distributed database architecture: horizontal sharding, consistent hashing, two-phase commit (2PC), CAP theorem trade-offs, and NewSQL engines.
By Md. Harun-Or-Roshid
Part 9: Load Balancing: Layer 4 vs Layer 7, Algorithms, Reverse Proxies & High Availability
Master high-availability load balancing, comparing Layer 4 transport vs Layer 7 application routing, consistent hashing rings, and health checks.
By Md. Harun-Or-Roshid