Routing Protocols in Computer Networks: Distance Vector, Link State, RIP, OSPF, BGP with Worked Examples

Build routing from the control plane to Internet-wide policy. Compare how RIP, OSPF, and BGP carry updates, use ports and timers, react to failure, and create common GATE CS traps.

KnowledgeGate Team

Exam prep & CS education

Updated 31 Aug 20265 min read

Every packet leaving your laptop is handed from router to router. Routing protocols carry the control-plane information that lets those routers maintain usable paths without one central controller. This guide focuses on RIP, OSPF, and BGP behaviour, carriage, ports, timers, and protocol-level exam traps, with a worked RIP timer trace.

Routing protocols: where forwarding stops

Forwarding is local and per packet: a router looks up the destination prefix in an existing table and sends the packet through the selected interface. Routing is the control-plane process that creates and updates those entries. Longest-prefix matching belongs to forwarding; if prefixes and masks are not yet comfortable, begin with IP Addressing and Subnetting Explained.

The Internet is divided into autonomous systems, or ASes. RIP and OSPF carry routing information within an AS, while BGP carries reachability and policy between ASes. That protocol boundary, rather than a second set of algorithm derivations, is the organising idea for this post.

Distance vector routing: the control-plane minimum

A distance vector router receives cost estimates from neighbours and applies the Bellman-Ford minimum D_x(y) = min over neighbours v { c(x,v) + D_v(y) }. The point needed here is that a new advertisement can change both the selected cost and next hop; the router does not receive a complete topology map.

This post owns the protocol-carriage layer: how RIP, OSPF, and BGP transport routing information, detect stale peers, use timers, and react to change. Routing Algorithms: distance vector vs link state, with a worked Dijkstra owns the Bellman-Ford and Dijkstra mechanics, convergence tables, count-to-infinity defences, and complete worked traces.

RIP behaviour: why loop controls still matter

Count to infinity matters here only because it explains an observable RIP failure mode. During convergence, stale neighbour information can make a route metric rise; RIP caps the largest usable hop count at 15 and represents unreachable as 16. Split horizon and poisoned reverse reduce that feedback, while triggered updates and route timers determine how the protocol carries and retires the stale route. The sibling above owns the step-by-step arithmetic and multi-router edge cases.

At algorithm level, link state means that each router builds a topology database and runs Dijkstra to derive routes. The detailed five-node Dijkstra table belongs in the linked routing-algorithms article. For this protocol-focused guide, the important distinction is carriage: OSPF sends Hello packets to discover and maintain neighbours, floods link-state advertisements reliably within their scope, acknowledges them, and reruns SPF when topology state changes.

RIP, OSPF, and BGP in one table

Protocol

Family and scope

Route information or metric

Carriage

Key behaviour

RIP

Distance vector, intra-AS

Hop count, maximum 15; 16 is unreachable

UDP port 520

Periodic advertisements, suited to small networks

OSPF

Link state, intra-AS

Configurable cost

IP protocol 89, no TCP or UDP

Dijkstra, areas, authentication, equal-cost multipath

BGP

Path vector, inter-AS

AS path plus policy attributes such as local preference

TCP port 179

Policy-driven route selection between ASes

Routing protocol carriage: updates, ports, and timers

The transport facts are not decoration. They determine how peers form, how routing information is refreshed, and what a router can infer when messages stop arriving.

  • RIP: uses UDP port 520 and normally sends a full response every 30 seconds. If a learned route is not refreshed for 180 seconds, it becomes invalid with metric 16; the 120-second garbage-collection period then gives neighbours time to learn the withdrawal. A topology change can also trigger an update before the next periodic response.

  • OSPF: runs directly over IP protocol 89, not TCP or UDP. On broadcast and point-to-point networks, 10-second Hello and 40-second Dead intervals are common defaults, but they are configurable and must agree between neighbours. Hello packets maintain adjacency; Link State Update and acknowledgement packets carry topology changes reliably.

  • BGP: uses a persistent TCP connection on port 179. OPEN messages negotiate session parameters including the Hold Time, KEEPALIVE messages stop an idle session from expiring, and UPDATE messages carry incremental reachability advertisements, withdrawals, and path attributes. BGP does not periodically resend its whole table like RIP.

Worked carriage trace: suppose RIP refreshes a learned route at t = 0 and receives no later update. At t = 180 seconds the route becomes invalid and is advertised with metric 16; if it is still unrecovered, garbage collection removes it 120 seconds later, at t = 300 seconds. This trace tests protocol timers and withdrawal behaviour, not Bellman-Ford table arithmetic.

BGP advertises the AS path as a path attribute. A BGP speaker rejects a route whose AS path already contains its own AS number, so the inter-AS loop is visible in the advertisement itself. Other attributes, such as local preference, let policy override a numerically shorter-looking path.

Routing protocol traps that cost easy marks

  • Confusing routing with forwarding: a protocol update changes control-plane state; forwarding uses the resulting table for packets. An OSPF Hello does not forward user traffic.

  • Swapping carriage facts: RIP uses UDP 520, OSPF uses IP protocol 89, and BGP uses TCP 179. OSPF has no TCP or UDP port number.

  • Making the RIP off-by-one error: 15 is the largest usable hop count. A metric of 16 means unreachable, not a valid sixteen-hop route.

  • Treating all updates alike: RIP has periodic full responses, OSPF floods link-state changes, and BGP sends incremental UPDATE messages over a persistent session.

  • Memorising timer defaults as universal constants: OSPF Hello and Dead intervals vary by network type and configuration. The common 10/40 pair is a default context, and mismatched neighbours do not form a normal adjacency.

How GATE and interviews test routing protocols

Routing appears under Computer Networks in the GATE CS syllabus. Typical questions classify a protocol by scope, match it to UDP, TCP, or direct IP carriage, apply RIP timer and hop-count rules, interpret an OSPF adjacency failure, or reason about a BGP path attribute. Use the sibling article for Bellman-Ford and Dijkstra traces, and confirm the current concept list and paper pattern on the official GATE website and in the organising institute's information brochure rather than relying on an old summary.

Next, review the Basics of Unicast Routing Protocol, then attempt topic-wise tests under time pressure.

Short version and next step

  • Routing protocols build and revise control-plane state; forwarding uses the resulting table for each packet.

  • RIP is distance vector over UDP 520. It combines periodic and triggered updates, treats 16 as unreachable, and ages stale routes with timeout and garbage-collection timers.

  • OSPF is link state over IP protocol 89. Hello and Dead intervals maintain neighbours, while reliable LSA flooding keeps topology databases aligned.

  • BGP is path vector over TCP 179. It uses a persistent session, incremental UPDATE messages, negotiated liveness timers, AS paths, and policy attributes.

  • The routing-algorithms sibling owns Bellman-Ford, count-to-infinity, split horizon, poisoned reverse, Dijkstra, and the worked numerical traces.

For Computer Networks taught from the fundamentals upward, continue with the Zero to Hero complete CS course. To test routing numericals against the clock, use the topic-wise networking practice in the GATE Test Series.