Skip to content
Chethan Yadav_
Computer Networks

CN/Lesson 4 of 8/5 min read

Routing

Routers and routing tables, static vs dynamic routing, distance vector and link state algorithms, count-to-infinity, RIP, OSPF, autonomous systems and BGP.


On this page

Routing

Routing is the process of choosing paths for packets across networks. A router is a layer 3 device that connects networks and forwards packets based on destination IP addresses.

  • Routing (control plane): build the table by running algorithms and exchanging information with other routers.
  • Forwarding (data plane): for each packet, look up the table and send it out the right interface, in hardware at line rate.

Routing Table

Each entry: destination prefix, next hop, outgoing interface, metric.

Destination      Next hop       Interface   Metric
10.0.0.0/8       192.168.1.2    eth1        20
10.1.0.0/16      192.168.1.3    eth2        10
0.0.0.0/0        203.0.113.1    eth0        1     (default route)

The router picks the longest prefix match. A packet to 10.1.5.5 matches both /8 and /16; the /16 wins.

Default Gateway

The default gateway is the router a host sends packets to when the destination is not on its local subnet. The default route 0.0.0.0/0 matches everything and is used when nothing more specific matches.

Static Routing

Routes configured manually by an administrator.

  • Simple, predictable, no protocol overhead, secure.
  • Does not adapt to failures; does not scale.

Dynamic Routing

Routers exchange information using routing protocols and recompute routes when the topology changes.

Classification:

  • Interior Gateway Protocols (IGP): inside one organization: RIP, OSPF, IS-IS, EIGRP.
  • Exterior Gateway Protocols (EGP): between organizations: BGP.

Distance Vector Routing

Each router keeps a vector of the best known distance to every destination and shares it only with neighbors, periodically. Based on the Bellman-Ford equation:

D_x(y) = min over neighbors v of { cost(x, v) + D_v(y) }

"Routing by rumor": a router knows only what neighbors tell it, not the full topology.

  • Simple, low memory.
  • Slow convergence, and the count-to-infinity problem.

Count-to-Infinity

Topology A - B - C, costs 1. If link B-C fails, B may learn from A that A can reach C at cost 2 (A's route actually goes through B). B sets its cost to 3, A updates to 4, and so on, slowly counting up to "infinity".

Split Horizon

Fixes for count-to-infinity:

  • Split horizon: do not advertise a route back to the neighbor you learned it from.
  • Poison reverse: advertise it back with infinite cost.
  • Route poisoning: advertise a failed route with infinite metric.
  • Hold-down timers: ignore updates for a failed route for a while.
  • Define a small "infinity" (16 in RIP).

Each router:

  1. Discovers neighbors and link costs (hello packets).
  2. Floods a Link State Advertisement (LSA) describing its links to all routers.
  3. Builds a complete map of the network (the link state database).
  4. Runs Dijkstra's shortest path algorithm to compute routes to every destination.
  • Fast convergence, no count-to-infinity, each router sees the whole topology.
  • More memory and CPU; flooding overhead.
Distance vectorLink state
Knows only neighbors' vectorsKnows the full topology
Bellman-FordDijkstra
Periodic full table to neighborsEvent-driven LSAs flooded to all
Slow convergence, count-to-infinityFast convergence
RIPOSPF, IS-IS

RIP

Routing Information Protocol: distance vector, metric = hop count, max 15 hops (16 = unreachable), updates every 30 seconds over UDP port 520. RIPv2 adds subnet masks (classless) and authentication. Only for small networks.

OSPF

Open Shortest Path First: link state, metric = cost (based on bandwidth), runs directly over IP (protocol 89).

  • Divides large networks into areas connected to a backbone area 0, limiting flooding.
  • Elects a Designated Router (DR) on multi-access networks to reduce adjacencies.
  • Supports equal-cost multipath, authentication, CIDR.

The most common enterprise IGP.

Autonomous System

An Autonomous System (AS) is a set of networks under one administrative control with a single routing policy, identified by an AS number (ASN). Examples: an ISP, Google, a university. The internet is a network of about 75,000+ ASes.

  • Intra-AS routing: IGP (OSPF).
  • Inter-AS routing: BGP.

BGP

Border Gateway Protocol is the routing protocol of the internet. It is a path vector protocol: advertisements carry the full list of ASes on the path (AS_PATH), which prevents loops (reject a route containing your own ASN).

  • Runs over TCP port 179 between configured peers.
  • eBGP between different ASes; iBGP inside one AS.
  • Route selection is policy based, not just shortest path: local preference, AS path length, origin, MED, business relationships (customers, peers, providers).

Security: BGP trusts what peers announce. BGP hijacking (announcing someone else's prefix, or a more specific one) has redirected traffic for YouTube, crypto services and more. Mitigations: RPKI route origin validation, prefix filtering.

Quick revision

  • Longest prefix match picks the route; 0.0.0.0/0 is the default route.
  • Distance vector = Bellman-Ford, neighbors only, count-to-infinity (fix with split horizon).
  • Link state = Dijkstra on a full map; OSPF.
  • RIP max 15 hops; OSPF uses areas; BGP is path vector over TCP 179 between ASes.