Dynamic routing protocols differ in how routers share information and compute the best paths. Three protocols dominate practice.

Distance-Vector Routing and RIP

In distance-vector routing, each router knows only the distance (cost) to each destination and the direction (next hop). Periodically, each router sends its whole table to its neighbours. A router updates its routes using the Bellman-Ford equation: D(x, y) = min over neighbours v of [c(x, v) + D(v, y)]. RIP (Routing Information Protocol) uses hop count as its metric, with a maximum of 15 hops (16 means unreachable), and sends updates every 30 seconds over UDP port 520. RIPv2 adds subnet masks (classless routing) and authentication. RIP is simple, but converges slowly and suffers the count-to-infinity problem, in which routers keep raising each other's distance to a lost network. It is reduced by split horizon (do not advertise a route back to the neighbour it was learned from), route poisoning (advertise a lost route with metric 16) and hold-down timers.

Definition: Link-state routing. A routing method in which every router floods information about its own links to all routers, so that each builds a complete map of the network and computes shortest paths with Dijkstra's algorithm.

In link-state routing, each router sends link-state advertisements (LSAs) describing its directly connected links and their costs to all routers in the area (flooding). Every router builds the same link-state database, a complete map of the topology, and runs Dijkstra's shortest path first (SPF) algorithm to compute the best path to every destination. OSPF (Open Shortest Path First) is the main link-state IGP. Its metric is cost, based on bandwidth (reference bandwidth / link bandwidth). Routers find neighbours with Hello packets, and send updates only when something changes, giving fast convergence with no count-to-infinity. Large networks are divided into areas connected to a backbone area 0, which limits flooding. OSPF supports CIDR, VLSM and authentication.

Path-Vector Routing and BGP

BGP (Border Gateway Protocol), version 4, is the exterior gateway protocol of the internet, the protocol that connects autonomous systems, such as ISPs and large organisations, each identified by an AS number. It is a path-vector protocol: each route carries the full AS path, the list of ASes it passes through, which prevents loops (a router rejects a path containing its own AS). BGP runs over TCP port 179, and chooses routes by policies and attributes (such as local preference, AS-path length and MED), not just shortest distance, since business agreements between providers matter. eBGP runs between ASes and iBGP within one.

Table 3.2: RIP, OSPF and BGP

Feature RIP OSPF BGP
Type Distance vector Link state Path vector
Scope Interior (IGP) Interior (IGP) Exterior (EGP)
Metric Hop count, max 15 Cost (bandwidth) Policies, AS path
Algorithm Bellman-Ford Dijkstra Path selection
Convergence Slow Fast Slow, stable
Transport UDP 520 IP protocol 89 TCP 179

Example 3.2: Dijkstra's algorithm

Problem: Five routers have links A–B 2, A–C 5, B–C 1, B–D 4, C–D 1, C–E 6 and D–E 2. Find the shortest cost from A to every router, and the path to E.

Solution:

  1. Start: A = 0. Neighbours: B = 2, C = 5.
  2. Fix B (2). Through B: C = 2 + 1 = 3 (better than 5), D = 2 + 4 = 6.
  3. Fix C (3). Through C: D = 3 + 1 = 4 (better than 6), E = 3 + 6 = 9.
  4. Fix D (4). Through D: E = 4 + 2 = 6 (better than 9). Fix E (6).

Result: B 2, C 3, D 4, E 6; the path to E is A → B → C → D → E.

import heapq
links = {("A", "B"): 2, ("A", "C"): 5, ("B", "C"): 1, ("B", "D"): 4,
         ("C", "D"): 1, ("C", "E"): 6, ("D", "E"): 2}
g = {}
for (u, v), w in links.items():
    g.setdefault(u, []).append((v, w))
    g.setdefault(v, []).append((u, w))
dist, prev, pq = {"A": 0}, {}, [(0, "A")]
while pq:
    d, u = heapq.heappop(pq)
    for v, w in g[u]:
        if d + w < dist.get(v, 99):
            dist[v], prev[v] = d + w, u
            heapq.heappush(pq, (d + w, v))
path, n = ["E"], "E"
while n != "A":
    n = prev[n]
    path.insert(0, n)
print("costs from A:", dict(sorted(dist.items())))
print("path to E:", " -> ".join(path))

Output

costs from A: {'A': 0, 'B': 2, 'C': 3, 'D': 4, 'E': 6}
path to E: A -> B -> C -> D -> E

Common mistakes

  • Thinking RIP chooses the fastest path. It counts hops, so a slow two-hop path beats a fast three-hop path.
  • Calling BGP an interior protocol. It connects autonomous systems.
  • Forgetting that OSPF areas must all connect to backbone area 0.

Key takeaways

  • RIP: distance vector, hop count up to 15, updates every 30 s, Bellman-Ford.
  • OSPF: link state, cost by bandwidth, Dijkstra, areas, fast convergence.
  • BGP: path vector between ASes, policy based, TCP port 179.
  • Split horizon and route poisoning reduce count-to-infinity.

Practice questions

  1. What is the maximum hop count in RIP?
  2. Which algorithm does OSPF use?
  3. How does BGP prevent loops?

Answers to the practice questions

  1. 15; 16 means unreachable.
  2. Dijkstra's shortest path first algorithm.
  3. Each route carries its AS path, and a router rejects paths containing its own AS number.

Sources

  • Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit III