RIP, OSPF and BGP overview
The three routing protocols of the Internet and where each fits: autonomous systems and the split between intra-domain and inter-domain routing, RIP (distance vector, hop count, UDP), OSPF (link state, cost, areas, designated router, carried directly in IP) and BGP (path vector, TCP, policy), with the facts GATE asks and the differences that the metrics make.
Why it exists
The Internet is a network of networks run by different organisations, and one routing algorithm cannot serve all of them. Inside one organisation (an autonomous system, AS) the goal is the best path, and everyone cooperates: an intra-domain or interior gateway protocol (IGP) such as RIP or OSPF. Between organisations the goal is also policy (who may carry whose traffic, at what price), so a different protocol, BGP, runs between ASes. GATE asks which protocol uses which algorithm, which transport carries it, what metric it uses, and a few numbers.
Prerequisites
You need the two algorithms behind them: distance vector routing (Bellman-Ford, with the count to infinity and its fixes) and link state routing (flooding and Dijkstra).
Precise definitions
Autonomous system. A set of networks and routers under one administration with one routing policy, identified by an AS number. Routing inside an AS uses an interior protocol (RIP, OSPF, IS-IS); routing between ASes uses the exterior protocol BGP.
RIP (Routing Information Protocol). A distance vector protocol.
- Metric: hop count; every link costs 1; 16 means infinity (unreachable), so a RIP network can be at most 15 hops across, which also limits the count to infinity.
- Each router sends its whole table to its neighbours about every 30 seconds in UDP datagrams to port 520 (so RIP is an application of UDP). A message has a 4-byte header and up to 25 routes of 20 bytes each: 504 bytes of data.
- A route not heard for 180 seconds is marked unreachable and removed after a further 120 seconds.
- Uses split horizon (with poisoned reverse) and triggered updates against the count to infinity (see the distance vector page). Slow convergence; simple; suited to small networks.
OSPF (Open Shortest Path First). A link state protocol.
- Each router describes its own links and costs in a link state advertisement (LSA), which is flooded to all routers of its area; every router then holds the same map and runs Dijkstra's algorithm on it to build its routing table.
- Metric: a cost per interface, set by the administrator, often derived from the bandwidth: many routers use , at least 1 (10 Mbps: 10; 100 Mbps and faster: 1). A path costs the sum of the costs of its links.
- Messages are carried directly in IP datagrams (protocol number 89): not TCP, not UDP. Neighbours exchange Hello packets (every 10 s on a broadcast network; a neighbour silent for 40 s is dead).
- Hierarchy: a large AS is divided into areas, all joined by the backbone area 0, to limit the flooding. Routers between areas summarise.
- On a broadcast LAN the routers elect a designated router (DR) and a backup (BDR): highest priority wins, ties go to the highest router ID, priority 0 is never elected. Every other router forms an adjacency only with the DR and the BDR, so n routers have adjacencies instead of .
- Faster convergence than RIP, no count to infinity (every router knows the whole map), supports CIDR and several equal-cost paths; more memory and computation.
BGP (Border Gateway Protocol). The inter-domain protocol, a path vector protocol.
- Neighbouring routers (peers) keep a TCP connection on port 179 and send updates over it: BGP is reliable by using TCP.
- A route to a prefix carries the AS path: the list of ASes it has crossed. A router adds its own AS number when it passes a route on and rejects any route whose AS path already contains its own number: that prevents loops (the way the count to infinity is avoided).
- Policy first. A router does not simply take the shortest path. Typically an AS prefers a route through a customer (who pays) to one through a peer (free) to one through a provider (costs money), and then the shortest AS path; and it advertises routes learned from a peer or provider only to customers, so that it does not carry traffic for free. The attributes (local preference, AS path length, and others) decide.
- eBGP runs between ASes, iBGP between routers inside one AS. BGP routes CIDR prefixes and can aggregate them. It converges slowly and values stability.
| RIP | OSPF | BGP | |
|---|---|---|---|
| scope | inside an AS | inside an AS (areas) | between ASes |
| algorithm | distance vector | link state (Dijkstra) | path vector |
| metric | hop count (max 15) | cost (e.g. from bandwidth) | AS path and policy |
| carried by | UDP port 520 | IP protocol 89 | TCP port 179 |
| updates | whole table, every 30 s | link states flooded on change | incremental updates |
| loops | split horizon, hop limit | none (global map) | AS path check |
How it works
RIP's message size. A table of routes needs messages of at most 504 bytes.
How many RIP messages does a router send to advertise its routing table?: start
Computed by a script, not typed| table size | messages | size of the last message(s) in bytes | total RIP data (bytes) |
|---|---|---|---|
| 10 routes | |||
| 25 routes | |||
| 26 routes | |||
| 100 routes | |||
| 1000 routes |
Step 0
RIP is distance vector routing: each router sends its whole table to its neighbours. The size rules are those of RIP version 2 (RFC 2453, quoted from memory); the arithmetic is computed.
OSPF's cost. The 100 Mbps reference makes every fast interface cost 1.
OSPF interface cost from the bandwidth (reference bandwidth 100 Mbps): start
Computed by a script, not typed| link | 100 Mbps / bandwidth | cost |
|---|---|---|
| 10 Mbps Ethernet | ||
| 100 Mbps Fast Ethernet | ||
| 1 Gbps Ethernet | ||
| 10 Gbps Ethernet | ||
| T1 line, 1.544 Mbps |
Step 0
OSPF does not fix the cost; it is configurable. The formula with a 100 Mbps reference is the common default of many routers (not part of the standard), so use it only when a question says so.
The metric matters. One network, two metrics: RIP counts hops, OSPF adds up costs. To R4 the two-hop path through two slow 10 Mbps links wins for RIP; the three-hop path over fast links wins for OSPF.
The same network, two metrics: RIP chooses by hop count, OSPF by cost: start
Computed by a script, not typed| destination | RIP: path | hops | OSPF: path | cost |
|---|---|---|---|---|
| R1 to R2 | ||||
| R1 to R3 | ||||
| R1 to R4 | ||||
| R1 to R5 |
Step 0
Links: R1-R2 and R2-R4 at 10 Mbps, R1-R3 at 1 Gbps, R3-R5 and R5-R4 at 100 Mbps. Shortest paths by Dijkstra with weight 1 per link (RIP) and with the OSPF cost (OSPF).
Electing the designated router.
OSPF on a broadcast LAN: electing the designated router: start
Computed by a script, not typed| router | role |
|---|---|
| R1: priority 1, router ID 1.1.1.1 | |
| R2: priority 1, router ID 2.2.2.2 | |
| R3: priority 100, router ID 0.0.0.3 | |
| R4: priority 0, router ID 9.9.9.9 |
Step 0
Rule: the highest priority wins, ties go to the highest router ID; priority 0 is never elected. Every other router forms an adjacency only with the DR and the BDR, so n routers on a LAN have 2n - 3 adjacencies instead of n(n - 1)/2 (4 routers: 5 against 6; 10 routers: 17 against 45).
BGP as a path vector. Round by round the best AS path to the prefix of AS 5 spreads outward; every AS puts its own number in front, and a path that already contains the number of the receiver would be refused.
BGP as a path vector: the AS path to the prefix of AS 5, round by round: start
Computed by a script, not typed| round | AS 1 | AS 2 | AS 3 | AS 4 | AS 5 | AS 6 |
|---|---|---|---|---|---|---|
| round 0 | ||||||
| round 1 | ||||||
| round 2 | ||||||
| round 3 |
Step 0
AS links: 1-2, 1-3, 2-4, 3-4, 3-6, 4-5, 5-6. The table shows the best AS path (its own number first, origin last) each AS holds. Shortest-path selection only: real BGP applies policy first (next table).
Policy beats length. AS 3 prefers the longer route through its customer to the shorter one through its peer.
BGP policy: a longer route can win: start
Computed by a script, not typed| AS | shortest AS path | customer > peer > provider, then shortest |
|---|---|---|
| AS 1 | ||
| AS 3 | ||
| AS 4 |
Step 0
Links: AS 3 is the provider of AS 4, AS 4 the provider of AS 5, AS 1 the provider of AS 3, and AS 3 and AS 5 are peers. A route learned from a peer or a provider is passed on only to customers. Simulated (scripts/cn_t2.py, bgp).
Worked examples
EX 1Which protocol, which transport?
EasyRIP: distance vector, hop count, UDP port 520, interior. OSPF: link state, cost, carried in IP (protocol 89) with no transport protocol, interior, with areas. BGP: path vector, TCP port 179, exterior (between ASes), policy-based. A question asking "which of these uses TCP" wants BGP; "which is carried directly by IP" wants OSPF; "which uses UDP" wants RIP. Which uses the Bellman-Ford algorithm? RIP (distributed). Dijkstra? OSPF. A statement that OSPF "implements Bellman-Ford" or "is an inter-domain protocol" is false.
EX 2OSPF cost against hop count, in C
MediumThe five-router network of the table: R1-R2 and R2-R4 at 10 Mbps, R1-R3 at 1 Gbps, R3-R5 and R5-R4 at 100 Mbps. The program finds the shortest path from R1 to R4 with weight 1 per link (RIP) and with the OSPF cost.
#include <stdio.h>
#define N 5
#define INF 1000000
static const long bw[N][N] = { /* bit/s, 0 = no link; routers R1..R5 are 0..4 */
{0, 10000000, 1000000000, 0, 0},
{10000000, 0, 0, 10000000, 0},
{1000000000, 0, 0, 0, 100000000},
{0, 10000000, 0, 0, 100000000},
{0, 0, 100000000, 100000000, 0}};
static long cost_of(long b) { long c = 100000000L / b; return c < 1 ? 1 : c; } /* reference bandwidth 100 Mbps, at least 1 */
static void shortest(int hops) {
long dist[N], prev[N];
int done[N] = {0};
for (int i = 0; i < N; i++) { dist[i] = INF; prev[i] = -1; }
dist[0] = 0;
for (int round = 0; round < N; round++) {
int u = -1;
for (int i = 0; i < N; i++)
if (!done[i] && (u < 0 || dist[i] < dist[u])) u = i;
done[u] = 1;
for (int v = 0; v < N; v++) {
if (!bw[u][v]) continue;
long w = hops ? 1 : cost_of(bw[u][v]);
if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; prev[v] = u; }
}
}
int path[N], len = 0;
for (int x = 3; x >= 0; x = (int)prev[x]) path[len++] = x;
printf("%s: R1 to R4 costs %ld via", hops ? "RIP (hops)" : "OSPF (cost)", dist[3]);
for (int i = len - 1; i >= 0; i--) printf(" R%d", path[i] + 1);
printf("\n");
}
int main(void) {
printf("OSPF costs: 10 Mbps %ld, 100 Mbps %ld, 1 Gbps %ld, T1 (1.544 Mbps) %ld\n", cost_of(10000000), cost_of(100000000), cost_of(1000000000), cost_of(1544000));
shortest(1);
shortest(0);
return 0;
}OSPF costs: 10 Mbps 10, 100 Mbps 1, 1 Gbps 1, T1 (1.544 Mbps) 64
RIP (hops): R1 to R4 costs 2 via R1 R2 R4
OSPF (cost): R1 to R4 costs 3 via R1 R3 R5 R4Reading it. The OSPF cost of a 10 Mbps link is , of a 100 Mbps or faster link 1 (the minimum), of a T1 line . RIP sees R1-R2-R4 as two hops, the best. OSPF sees that path cost and the path R1-R3-R5-R4, with three hops, costs , and chooses it. So the same network can give different routes under different metrics; and with the 100 Mbps reference OSPF cannot distinguish 100 Mbps from 10 Gbps links.
EX 3How many RIP messages?
MediumA router has a table of 60 routes. Each RIP message has a 4-byte header and at most 25 entries of 20 bytes.
#include <stdio.h>
int main(void) {
int routes[4] = {10, 25, 26, 60};
for (int i = 0; i < 4; i++) {
int n = routes[i], messages = (n + 24) / 25, bytes = 4 * messages + 20 * n;
printf("%3d routes: %d message%s, %d bytes of RIP data in all; the last message has %d bytes\n", n, messages, messages > 1 ? "s" : "", bytes, 4 + 20 * (n - 25 * (messages - 1)));
}
return 0;
} 10 routes: 1 message, 204 bytes of RIP data in all; the last message has 204 bytes
25 routes: 1 message, 504 bytes of RIP data in all; the last message has 504 bytes
26 routes: 2 messages, 528 bytes of RIP data in all; the last message has 24 bytes
60 routes: 3 messages, 1212 bytes of RIP data in all; the last message has 204 bytesReading it. A full message has bytes. 60 routes fill two messages and put 10 routes in a third of bytes: . Every router repeats this to every neighbour every 30 seconds, which is the price of distance vector routing: the whole table, over and over.
EX 4A BGP route and the loop check
MediumAS 1 receives from its neighbour the route to a prefix with AS path 2 4 5 (the prefix belongs to AS 5). AS 1 passes it on to its own neighbours with the path 1 2 4 5. If a route with the path 3 1 7 arrives at AS 1, AS 1 rejects it because its own number, 1, is in the path: accepting it would create a loop. This is the way BGP avoids the count to infinity of distance vector routing: it keeps the whole path, not just a distance. In the animation the path spreads one AS per round and no AS appears twice.
Policy changes the choice: AS 3 has a peer route 3 5 and a customer route 3 4 5. By shortest AS path it takes 3 5. With the customer-peer-provider policy it takes the longer 3 4 5, because the customer route earns money. A question that asks for the BGP path under a stated policy expects the policy to decide first and the length second.
EX 5Which statement is true?
GATE levelOSPF packets are carried in TCP segments. False: directly in IP, protocol 89. RIP packets are carried in UDP datagrams. True. BGP uses TCP. True. RIP is a link state protocol. False: distance vector. OSPF supports hierarchical routing with areas. True. In RIP a distance of 16 means unreachable. True. OSPF runs Dijkstra on a map built from flooded link state advertisements. True. OSPF may use the bandwidth to compute the link cost. True. BGP is an intra-domain protocol. False. Which protocol limits the diameter of the network to 15 hops? RIP. On a LAN with 5 routers, how many OSPF adjacencies form with a DR and a BDR? , against in a full mesh. A question that says "interior gateway protocol" means RIP, OSPF or IS-IS; "exterior gateway protocol" means BGP.
Cheat box
Cheat box
- Intra-AS: RIP (distance vector, hop count, max 15, UDP 520, 30 s, 25 routes per message) and OSPF (link state, cost, IP protocol 89, areas, DR / BDR, Dijkstra). Inter-AS: BGP (path vector, TCP 179, AS path, policy).
- RIP: 16 infinity; split horizon; slow. OSPF: floods LSAs, fast, no count to infinity.
- OSPF cost reference bandwidth / bandwidth (common default: , at least 1).
- DR election: highest priority, then highest router ID; priority 0 never. Adjacencies .
- BGP rejects a route with its own AS in the path; policy (customer peer provider) before path length.
- Bellman-Ford RIP; Dijkstra OSPF.
Traps and GATE patterns
Connections
Across subjects
No cross-subject links yet.
RIP is distance vector routing made into a protocol (and an application of UDP); OSPF is link state routing; BGP rides on TCP and routes the aggregated prefixes of CIDR. The count to infinity that limits RIP to 15 hops is why BGP carries paths instead of distances.
PYQs
7 previous year questions from your book. I re-solved each one myself (0 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the routing protocols given in List-I and the names given in List-II: List-I List-II (i) Distance vector routing (a) Bellman-Ford (ii) Link state routing (b) Dijkstra For matching of items in List-I with those in List-II, which ONE of the following options is CORRECT?
- (a)(i) - (a) and (ii) - (b)
- (b)(i) - (a) and (ii) - (a)
- (c)(i) - (b) and (ii) - (a)
- (d)(i) - (b) and (ii) - (b) COMPUTER NETWORK
A machine receives an IPv4 datagram. The protocol field of the IPv4 header has the protocol number of a protocol X. Which ONE of the following is NOT a possible candidate for X?
- (a)Internet Control Message Protocol (ICMP)
- (b)Internet Group Management Protocol (IGMP)
- (c)Open Shortest Path First (OSPF)
- (d)Routing Information Protocol (RIP)
Which of the following statements is/are INCORRECT about the OSPF (Open Shortest Path First) routing protocol used in the Internet?
- (a)OSPF implements Bellman-Ford algorithm to find shortest paths.
- (b)OSPF uses Dijkstra's shortest path algorithm to implement least-cost path routing.
- (c)OSPF is used as an inter-domain routing protocol.
- (d)OSPF implements hierarchical routing.
Consider the following statements about the functionality of an IP-based router. I. A router does not modify the IP packets during forwarding. II. It is not necessary for a router to implement any routing protocol. III. A router should reassemble IP fragments if the MTU of the outgoing link is larger than the size of the incoming IP packet. Which of the above statements is/are TRUE?
- (a)I only
- (b)I and II only
- (c)II and III only
- (d)II only
Consider the following statements about the routing protocols, Routing Information Protocol (RIP) and Open Shortest Path First (OSPF) in an IPv4 network. I. RIP uses distance vector routing II. RIP packets are sent using UDP III. OSPF packets are sent using TCP IV. OSPF operation is based on link-state routing protocol Which of the statements above are CORRECT?
- (a)I and IV only
- (b)I, II and III only
- (c)I, II and IV only
- (d)II, III and IV only
Which one of the following is TRUE about the interior gateway routing protocols - Routing Information Protocol (RIP) and Open Shortest Path First (OSPF)?
- (a)RIP uses distance vector routing and OSPF uses link state routing.
- (b)OSPF uses distance vector routing and RIP uses link state routing.
- (c)Both RIP and OSPF use link state routing.
- (d)Both RIP and OSPF use distance vector routing.
Packets of the same session may be routed through different paths in:
- (a)TCP, but not UDP
- (b)TCP and UDP
- (c)UDP, but not TCP
- (d)Neither TCP nor UDP
Self-check
Question 1
Which of RIP, OSPF, BGP are carried over UDP, over IP directly and over TCP, in that order?
Show answerHide
RIP (UDP, port 520), OSPF (IP protocol 89), BGP (TCP, port 179).
Question 2
A RIP table has 80 routes. How many messages are needed to advertise it?
Show answerHide
messages (25 + 25 + 25 + 5 routes).
Question 3
The cost of a 100 Mbps link in OSPF with a 100 Mbps reference bandwidth? Of a 1 Gbps link?
Show answerHide
Both 1: and , raised to the minimum 1.
Question 4
Why does BGP not suffer from the count to infinity?
Show answerHide
Each route carries the full AS path and a router rejects a route that contains its own AS number, so a loop cannot form.
Question 5
Routers R1 (priority 5, ID 1.1.1.1), R2 (priority 5, ID 3.3.3.3), R3 (priority 0, ID 9.9.9.9). Who is the DR?
Show answerHide
R2: the highest priority is shared by R1 and R2, the higher router ID (3.3.3.3) wins; R3 has priority 0 and cannot be elected (R1 becomes the BDR).
Revision card
One-screen revision
- RIP: distance vector, hops, 16 = infinity, UDP 520, 30 s. OSPF: link state, cost, IP 89, areas, DR / BDR, Dijkstra. BGP: path vector, TCP 179, AS path, policy.
- Interior: RIP, OSPF. Exterior: BGP.
- OSPF cost reference / bandwidth, at least 1. Adjacencies with DR and BDR: .
- BGP: reject a path containing your own AS; policy before length.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 5, Sections 5.3 (intra-AS routing in the Internet: OSPF) and 5.4 (routing among the ISPs: BGP); RIP in the same chapter's earlier editions
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.6.6 (Internet routing protocols: OSPF, BGP)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 20 (Unicast routing protocols: RIP, OSPF, BGP)
Verification
The arithmetic and the simulations are computed (scripts/cn_t2.py, scripts/gen-cn6-traces.py) and recomputed independently by scripts/enum-checks/cn_t2_check.py: the number of RIP messages and their sizes for 0 to 2000 routes, the OSPF cost, Dijkstra against Floyd-Warshall on 300 random graphs, the designated router election against a sort, the number of adjacencies with a designated router (2n - 3 against n(n - 1)/2), the BGP path vector on 300 random graphs (the AS path length equals the breadth-first distance plus one, no repeated AS) and the policy variant on 400 random provider hierarchies (every chosen path valley-free); tests/cn-t2-traces.test.ts recomputes the printed tables. The C programs are compiled and run by npm run verify:c, and the check compares the first with Dijkstra. The protocol constants are QUOTED from the RFCs from memory and need verification against them: RIP (infinity 16, at most 25 routes per message, UDP port 520, updates every 30 s, route timeout 180 s, garbage collection 120 s), OSPF (IP protocol 89, hello 10 s and dead interval 40 s on broadcast networks, areas with backbone area 0, the multicast addresses 224.0.0.5 and 224.0.0.6) and BGP (TCP port 179, the AS_PATH attribute). The OSPF cost formula with a 100 Mbps reference bandwidth is the default of many routers, not part of the standard. The BGP policy example is the usual customer-peer-provider model, a simplification of real routing policy. Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)