Network Layer Overview
Routing
Read aloud is unavailable in this browser.
Finding the Path
When you request a webpage from a server halfway around the world, your data doesn't travel in a straight line. It hops through perhaps 15-20 routers, each one making a decision: "Given where this packet needs to go, what's the best next step?"
These decisions happen billions of times per second across millions of routers worldwide. Each decision must be made in microseconds. And somehow, despite the Internet's vast complexity—with networks constantly failing, recovering, congesting, and changing—packets almost always find their way.
Routing is the network layer function responsible for this remarkable feat. It encompasses:
- Path Determination: Discovering routes through the network topology
- Route Selection: Choosing the best path when multiple options exist
- Route Distribution: Sharing routing information between routers
- Adaptation: Responding to network changes, failures, and congestion
This page introduces routing concepts at the network layer level. Subsequent chapters will explore specific routing protocols (RIP, OSPF, BGP) in exhaustive detail.
By the end of this page, you will understand the fundamental distinction between routing and forwarding, how routing tables are structured and used, the difference between static and dynamic routing, the categories of routing algorithms (distance vector, link state, path vector), and why routing at Internet scale is one of computing's greatest engineering achievements.
Routing vs. Forwarding: A Critical Distinction
Before diving into routing mechanisms, we must distinguish two related but fundamentally different network layer functions that are often confused: routing and forwarding.
Forwarding (Data Plane):
Forwarding is the per-packet operation of moving a packet from input to output:
- Packet arrives on an incoming interface
- Router reads the destination IP address from the header
- Router looks up the destination in its forwarding table
- Router transmits the packet on the specified outgoing interface
Forwarding happens for every packet and must be extremely fast—modern routers forward billions of packets per second. Forwarding is implemented in specialized hardware (ASICs, FPGAs) in high-end routers.
Routing (Control Plane):
Routing is the network-wide process of determining paths:
- Routers exchange information about reachable networks
- Each router builds a complete or partial view of the network topology
- Routing algorithms compute best paths to each destination
- Results are installed in the forwarding table
Routing happens in the background—not per-packet, but periodically or when topology changes. Routing is implemented in software, running on the router's general-purpose CPU.
| Aspect | Routing (Control Plane) | Forwarding (Data Plane) |
|---|---|---|
| Frequency | Periodic or event-driven | Per packet |
| Speed Required | Seconds to minutes acceptable | Microseconds required |
| Implementation | Software (general CPU) | Hardware (ASICs/TCAMs) |
| Scope | Network-wide process | Local to each router |
| Function | Compute and populate tables | Use tables to forward packets |
| Complexity | Complex algorithms, protocols | Simple table lookup |
| Failure Impact | Routes may be suboptimal | Packets dropped or lost |
The Relationship:
Routing Process Forwarding Process
│ │
├─→ Routing Table ─→ Forwarding Table ─→ Packet Switching
│ │ │
│ │ └─→ Outgoing Interface
│ │
│ └─→ Next Hop IP/Interface for each prefix
│
└─→ Routing Protocols (OSPF, BGP, etc.)
Routing produces the knowledge ("how do I reach this network?"); forwarding uses that knowledge for each packet ("which port does this packet exit?").
Routing is planning the trip; forwarding is driving each mile. You plan a route once (using maps and traffic data), but you make individual driving decisions at every intersection based on that plan. Similarly, routing computes paths; forwarding acts on them for each packet.
Routing Table Structure
The routing table is the data structure that stores the router's knowledge about how to reach destination networks. Understanding its structure is fundamental to understanding how routing works.
Core Routing Table Fields:
Every routing table entry contains (at minimum):
| Field | Purpose | Example Value |
|---|---|---|
| Destination Prefix | Network address and prefix length to match | 10.45.0.0/16 |
| Next Hop | IP address of the next router toward destination | 192.168.1.1 |
| Outgoing Interface | Physical/logical interface to transmit on | eth0, GigE0/1 |
| Metric/Cost | Measure of route quality (lower is better) | 10, 100, 65535 |
| Route Type | Source of this routing information | Connected, Static, OSPF, BGP |
| Administrative Distance | Preference when multiple protocols provide routes | 0-255 (lower preferred) |
Example Routing Table (Simplified):
Destination Next Hop Interface Metric Type
----------- -------- --------- ------ ----
0.0.0.0/0 203.0.113.1 eth0 1 Static
10.0.0.0/8 192.168.1.1 eth1 10 OSPF
10.45.0.0/16 192.168.1.2 eth1 5 OSPF
172.16.5.0/24 192.168.2.254 eth2 20 BGP
192.168.1.0/24 0.0.0.0 eth1 0 Connected
192.168.2.0/24 0.0.0.0 eth2 0 Connected
Route Types Explained:
-
Connected Routes: Networks directly attached to the router's interfaces. Next hop is 0.0.0.0 or implicit—packets are delivered directly.
-
Static Routes: Manually configured by administrators. Simple but don't adapt to failures.
-
Dynamic Routes: Learned from routing protocols (OSPF, RIP, BGP, etc.). Automatically adapt to network changes.
-
Default Route: 0.0.0.0/0 matches everything. Used when no more specific route exists—"gateway of last resort."
Longest Prefix Match:
When multiple entries match a destination, the router selects the one with the longest prefix (most specific match):
Destination IP: 10.45.99.50
0.0.0.0/0 → Matches (0 bits)
10.0.0.0/8 → Matches (8 bits)
10.45.0.0/16 → Matches (16 bits) ← SELECTED
This enables hierarchical routing: more specific routes override more general ones.
In large routers, the routing table (maintained by software, with all learned routes) is separate from the forwarding table (a hardware-optimized subset installed in fast lookup hardware). The routing process selects the best routes and installs them in the forwarding table. This separation allows routing computation without affecting forwarding speed.
Static vs. Dynamic Routing
Routes can be configured manually (static) or learned automatically (dynamic). Each approach has distinct advantages and trade-offs.
Static Routing:
Administrators manually configure routes on each router:
# Cisco IOS
ip route 10.45.0.0 255.255.0.0 192.168.1.1
# Linux
ip route add 10.45.0.0/16 via 192.168.1.1
- •Predictable: Routes don't change unexpectedly
- •Secure: No routing protocol packets to attack
- •Low Overhead: No routing protocol CPU/bandwidth
- •Simple: Easy to understand and troubleshoot
- •Full Control: Administrator dictates exact paths
- •No Adaptation: Doesn't respond to link failures
- •Doesn't Scale: N routers with M networks = O(N×M) configs
- •Error-Prone: Manual entry invites mistakes
- •Maintenance Burden: Every change requires manual updates
- •No Optimization: Can't respond to congestion
Dynamic Routing:
Routers run routing protocols that automatically:
- Discover neighbor routers
- Exchange reachability information
- Compute optimal paths
- Adapt to topology changes
- •Automatic Adaptation: Reroutes around failures
- •Scalability: Adding networks requires minimal config
- •Optimized Paths: Can select best routes based on metrics
- •Reduced Errors: Fewer manual configurations to get wrong
- •Self-Healing: Networks recover without intervention
- •Complexity: Protocols require understanding
- •Overhead: CPU, memory, bandwidth consumption
- •Security Surface: Routing protocols can be attacked
- •Convergence Time: Changes aren't instantaneous
- •Unpredictability: Paths may change unexpectedly
When to Use Each:
| Scenario | Recommended Approach |
|---|---|
| Small network, simple topology | Static routes often sufficient |
| Stub network (single exit point) | Static default route |
| Complex topology with redundancy | Dynamic routing essential |
| Internet backbone | Dynamic routing (BGP) mandatory |
| Enterprise core | Dynamic routing (OSPF/IS-IS) |
| Single-homed home network | Static default route |
| Multi-homed enterprise | Dynamic routing for failover |
Hybrid Approaches:
Most real networks use both:
- Static routes for specific, unchanging destinations
- Default static routes for stub networks
- Dynamic routing for the core network
- Redistributing static routes into dynamic protocols
Static routes don't automatically deactivate when links fail (unless configured with monitoring). A static route pointing to a down next-hop becomes a "black hole" that silently drops packets. Dynamic routing protocols detect failures and remove affected routes automatically.
Routing Algorithm Categories
Dynamic routing protocols use algorithms that fall into three major categories, each with distinct approaches to learning topology and computing paths.
1. Distance Vector Algorithms
Based on the Bellman-Ford algorithm, distance vector protocols share routing tables with neighbors:
- Information Shared: Each router tells neighbors "I can reach network X with cost Y"
- View of Network: Local only—knows distances but not complete topology
- Computation: Iterative—routes improve over time as information propagates
- Example Protocols: RIP ($RIPv1$, $RIPv2$), EIGRP (enhanced hybrid)
Distance Vector Operation:
Router A knows: Router B knows:
Network X: cost 2 Network X: cost 5
Network Y: cost 4 Network Y: cost 1
A tells B: "I can reach X with cost 2"
B calculates: Via A, cost to X = link_cost(B→A) + 2
If this is better than 5, B updates its table
2. Link State Algorithms
Based on Dijkstra's SPF (Shortest Path First) algorithm, link state protocols share link information:
- Information Shared: Each router floods "my links and their costs" to all routers
- View of Network: Complete—every router has full topology map
- Computation: Independent—each router computes shortest paths locally using Dijkstra
- Example Protocols: OSPF, IS-IS
Link State Operation:
Each router floods Link State Advertisements (LSAs):
Router A: "I have links to B (cost 1), C (cost 3)"
Router B: "I have links to A (cost 1), C (cost 2), D (cost 1)"
...
Every router builds complete graph.
Each runs Dijkstra to compute shortest paths to all nodes.
Result: All routers agree on shortest paths (consistent routing).
3. Path Vector Algorithms
Designed for inter-domain routing, path vector protocols share complete path information:
- Information Shared: "To reach X, the path is: A → B → C → X"
- View of Network: Path-level—knows the sequence of autonomous systems
- Computation: Policy-based—paths selected by administrator-defined rules
- Example Protocol: BGP (Border Gateway Protocol)
Path Vector Purpose:
Path vector is used for routing between organizations (Autonomous Systems). It enables:
- Loop prevention (reject paths that include yourself)
- Policy enforcement (prefer certain providers, avoid certain paths)
- Scalability (abstracts internal topology of each AS)
| Characteristic | Distance Vector | Link State | Path Vector |
|---|---|---|---|
| Information Exchanged | Distance to destinations | Link states (topology) | Complete AS paths |
| Topology Knowledge | None (distances only) | Complete | Path-level only |
| Algorithm | Bellman-Ford | Dijkstra SPF | Policy-based selection |
| Convergence | Slow (iterative) | Fast (flood-then-compute) | Moderate |
| Scalability | Limited | Good within domain | Excellent between domains |
| CPU/Memory | Low | High (stores topology) | Moderate |
| Loop Prevention | Split horizon, poison reverse | Inherent (SPF) | AS path checking |
| Typical Use | Small/legacy networks | Enterprise/ISP internal | Internet backbone |
Link state protocols are dominant for intra-domain routing (within organizations) because they converge faster and scale better. Path vector (BGP) is the only option for inter-domain routing because it supports the policy decisions required when different organizations interconnect. Distance vector protocols like RIP are legacy but still encountered in simple or educational contexts.
Routing Metrics
When multiple paths to a destination exist, routers must choose. Routing metrics provide a quantitative basis for this choice—they measure the "cost" or "quality" of a path.
Common Routing Metrics:
| Metric | Measures | Lower Is Better? | Used By |
|---|---|---|---|
| Hop Count | Number of routers traversed | Yes | RIP |
| Bandwidth | Link capacity (bps) | No (higher better) | OSPF (configurable), EIGRP |
| Delay | Time for packet transit | Yes | EIGRP |
| Load | Current utilization percentage | Yes | EIGRP (optional) |
| Reliability | Error rate / link stability | No (higher better) | EIGRP (optional) |
| MTU | Maximum transmission unit | No (higher better) | EIGRP (tiebreaker) |
| Administrative Cost | Manually assigned preference | Yes | OSPF, IS-IS |
| AS Path Length | Number of AS hops | Yes | BGP |
Hop Count:
The simplest metric—count how many routers the packet must traverse:
Path A: Source → R1 → R2 → Destination (2 hops)
Path B: Source → R3 → Destination (1 hop)
→ Path B preferred (fewer hops)
Limitation: Doesn't account for link speed. A path with 2 hops over Gigabit Ethernet is far faster than 1 hop over a 56 Kbps dialup link.
Bandwidth-Based Metrics:
OSPF (by default) uses a cost inversely proportional to bandwidth:
$$\text{OSPF Cost} = \frac{\text{Reference Bandwidth}}{\text{Interface Bandwidth}}$$
With a reference of 100 Mbps:
- 10 Mbps link → Cost = 10
- 100 Mbps link → Cost = 1
- 1 Gbps link → Cost = 0.1 → rounded to 1
Composite Metrics:
EIGRP computes a sophisticated metric combining multiple factors:
$$\text{EIGRP Metric} = 256 \times \left( K_1 \times \text{Bandwidth} + \frac{K_2 \times \text{Bandwidth}}{256 - \text{Load}} + K_3 \times \text{Delay} \right) \times \left( \frac{K_5}{\text{Reliability} + K_4} \right)$$
By default, only $K_1$ (Bandwidth) and $K_3$ (Delay) are used, simplifying to:
$$\text{Metric} = 256 \times \left( \frac{10^7}{\text{Bandwidth}_{min}} + \sum{\text{Delays}} \right)$$
where Bandwidth is in kbps and Delay is in tens of microseconds.
In practice, administrators often override automatic metrics to implement routing policy. Setting a higher OSPF cost on a link forces traffic to prefer other paths, even if the link is technically faster. This manual tuning is common for load balancing, preferring primary over backup links, and compliance requirements.
Intra-Domain vs. Inter-Domain Routing
The Internet's routing architecture divides the world into Autonomous Systems (ASs)—networks under a single administrative control. Routing operates differently within and between these domains.
Autonomous System (AS):
An AS is a collection of IP networks under a single organization's control with a unified routing policy:
- An ISP is typically one AS
- A large enterprise might be one or more ASs
- Each AS has a globally unique AS Number (ASN)
- ASNs are 16-bit (1-65535) or 32-bit (extended)
Two Routing Scopes:
Interior Gateway Protocols (IGPs) — Intra-Domain:
IGPs operate within a single AS:
- Goal: Find shortest/fastest paths to all networks in the AS
- Assumptions: All routers trust each other, common admin policies
- Metrics: Technical (bandwidth, delay, cost)
- Protocols: OSPF, IS-IS, EIGRP, RIP
- Characteristics: Fast convergence, detailed topology knowledge
Exterior Gateway Protocols (EGPs) — Inter-Domain:
EGPs operate between ASs:
- Goal: Exchange reachability information and enforce policy
- Assumptions: ASs don't fully trust each other, competing interests
- Selection: Policy-based (business relationships, contracts)
- Protocol: BGP (the only EGP in use today)
- Characteristics: Scalability, policy flexibility, deliberate stability
| Aspect | IGP (Intra-Domain) | EGP (Inter-Domain) |
|---|---|---|
| Scope | Single Autonomous System | Between Autonomous Systems |
| Trust Model | Full trust between routers | Limited trust, policy-based |
| Path Selection | Shortest/fastest path | Policy-preferred path |
| Metrics | Technical (bandwidth, delay) | AS path, policy attributes |
| Scale | Hundreds to thousands of routers | Millions of prefixes, ~80,000 ASs |
| Convergence | Seconds | Minutes (intentionally slow) |
| Examples | OSPF, IS-IS, EIGRP, RIP | BGP |
BGP (Border Gateway Protocol) is arguably the most critical protocol on the Internet. It's how every ISP learns about every other network on the planet. BGP misconfigurations can—and have—caused global Internet outages. BGP security (RPKI, BGPsec) is an active area of development because BGP was designed in a more trusting era.
Routing Convergence
When network topology changes—a link fails, a new route appears, a cost changes—routing protocols must update their tables. Convergence is the process of all routers reaching a consistent, up-to-date view of the network.
Convergence Timeline:
- Detection: Router notices the topology change (interface down, neighbor timeout, LSA received)
- Propagation: Information about the change spreads to other routers
- Computation: Each affected router recalculates routes
- Installation: New routes installed in forwarding tables
- Stability: All routers agree; network is converged
Convergence Time Matters:
During convergence:
- Routers may have inconsistent views
- Some routes may be black holes (pointing to failed links)
- Routing loops may temporarily form
- Packets may be dropped or delivered out of order
Faster convergence = shorter outage duration.
Factors Affecting Convergence Speed:
- •Detection Speed: How quickly is failure noticed? Dead timers, BFD (Bidirectional Forwarding Detection)
- •Propagation Speed: How fast does information spread? Flooding (link state) vs. periodic updates (distance vector)
- •Computation Speed: How fast can routes be recalculated? SPF scheduling, CPU power
- •Network Size: More routers/links = more updates and computation
- •Protocol Choice: Link state (OSPF) generally converges faster than distance vector (RIP)
- •Configuration: Timers, throttling, hierarchy all impact convergence
Convergence Problems:
Routing Loops During Convergence:
Before failure: A → B → C → Destination
Link B→C fails.
A still thinks: B is the path
B knows: C is unreachable, but maybe A knows another path?
B sends to A: "Try reaching destination!"
A sends back to B: "Sure, via you!"
→ Packet loops between A and B until TTL expires
Count-to-Infinity (Distance Vector):
In distance vector protocols, routers may slowly increment metrics until reaching "infinity":
A → B → C (B→C fails)
A thinks: Distance to C = 2 (via B)
B knows: C unreachable
B hears from A: "C is distance 2"
B thinks: Maybe I can reach C via A! Cost = 3
B tells A: "C is distance 3"
A thinks: Cost is now 4
... continues until metric reaches infinity (16 in RIP)
Mitigations:
- Split horizon: Don't advertise back to sender
- Poison reverse: Advertise unreachable back to sender
- Hold-down timers: Delay accepting new information after failure
- Triggered updates: Send immediate updates on change
Modern networks aim for sub-second convergence. Techniques include: BFD for millisecond failure detection, fast reroute (pre-computed backup paths), IP FRR (loop-free alternates), and careful timer tuning. For critical applications, even 50ms of packet loss can cause noticeable impact (VoIP, video, financial trading).
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.