Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 79 ยท Routing

RIP and OSPF Protocol Behavior Walkthrough

See how RIPv2 and OSPF actually behave on a network: message formats, timers, neighbor states, DR and BDR election, areas, costs and convergence, with runnable simulations.

The previous lessons taught the algorithms of routing: Dijkstra for link-state and Bellman-Ford for distance-vector. A real router does not run an algorithm in isolation. It runs a protocol: it finds neighbors, exchanges messages in a defined format, keeps timers, detects failures and reacts to them. Two protocols dominate the inside of organizations. RIP is the simple distance-vector protocol, and OSPF is the link-state protocol that most enterprise and campus networks use.

This lesson follows what these two protocols do on the wire and inside the router. You will see the messages, the timers, the states a neighbor relationship goes through, how a designated router is chosen on a shared segment, how areas keep large networks manageable, and why the metric of OSPF needs care. Two small simulations let you try the election and the cost calculation yourself.

RIP in practice

RIP version 2 is simple enough to describe completely.

Transport. RIP runs over UDP port 520. RIPv2 messages go to the multicast address 224.0.0.9, so only routers that run RIP process them. (RIPv1 used broadcast. RIPng for IPv6 uses UDP port 521 and the address ff02::9.)

Message format. A RIP message has a 4-byte header (command, version) followed by up to 25 route entries of 20 bytes each. Each entry holds an address family, a route tag, the destination network, its subnet mask, an optional next hop and the metric from 1 to 16. The maximum message size is 4 + 25 x 20 = 504 bytes, which is why a router with a large table sends many messages. There are two commands: a request (ask a neighbor for its table, typically sent at start-up) and a response (the table itself).

Timers. A router sends its full table every 30 seconds. If a route has not been refreshed for 180 seconds (the timeout, six missed updates), the router marks it invalid: it advertises it with metric 16 and stops using it. After a further 120 seconds (garbage collection) the route is removed. Triggered updates send a change immediately, without waiting for the 30-second timer, and a small random jitter on the timer avoids all routers sending at the same instant.

Behavior after a failure. Because every router learns routes second-hand and trusts its neighbors, bad news travels slowly, as shown in the count-to-infinity example. Split horizon with poison reverse, triggered updates and the small infinity (16) limit the damage, but a RIP network can take minutes to converge after a failure, and it is limited to a diameter of 15 hops. RIPv2 supports authentication and carries masks, so it handles CIDR and VLSM. Its metric is the hop count alone, which ignores speed.

OSPF in practice

Open Shortest Path First is a link-state protocol. Every router builds a map of the whole area and computes shortest paths with Dijkstra, as in the earlier lesson. In practice, that requires some machinery.

Transport. OSPF does not use TCP or UDP. It runs directly over IP, protocol number 89. Routers talk to each other with multicast addresses: 224.0.0.5 (all OSPF routers) and 224.0.0.6 (the designated routers).

Five message types. Hello finds neighbors and checks that they are alive. Database Description summarizes what a router's database contains. Link State Request asks for specific pieces. Link State Update carries the pieces (the LSAs). Link State Acknowledgment confirms them. Each LSA describes a part of the topology, for example a router and its links, or a network segment, and carries a sequence number and an age, so that routers always keep the newest copy.

Hello and dead timers. On a broadcast network, routers send Hellos every 10 seconds, and declare a neighbor dead after 40 seconds (four missed Hellos) of silence. These values must match between neighbors, or they refuse to become adjacent. Faster detection is possible with shorter timers or with an additional protocol (BFD) that detects link failure in milliseconds.

The neighbor life cycle

Two routers do not simply become friends. They go through a series of states, and a router only exchanges routing information fully with an adjacent neighbor in the last state.

flowchart LR
    D["Down"] --> I["Init: I heard a Hello"]
    I --> T["2-Way: neighbor heard my Hello too"]
    T --> E["ExStart: choose master and slave"]
    E --> X["Exchange: swap database summaries"]
    X --> L["Loading: request missing LSAs"]
    L --> F["Full: databases identical"]

Neighbor states from silence to a fully synchronized database. On a broadcast segment, routers that are not the DR or BDR stay at 2-Way with each other.

When the two databases are identical (Full), each router runs Dijkstra over the same data and gets consistent routes. Whenever a link changes, the router that notices floods a new LSA to the whole area, every router updates its database and recomputes, usually within a second or less. That is why OSPF converges much faster than RIP.

Designated routers

On a shared segment with n routers (for example a switch), a full mesh of adjacencies would need n(n-1)/2 of them, and every change would be flooded many times. OSPF instead elects a designated router (DR) and a backup designated router (BDR). Every other router forms an adjacency only with the DR and the BDR, sends its updates to 224.0.0.6, and the DR floods them to everybody else on the segment.

The election is decided by the priority configured on each interface (default 1, and 0 means "never eligible"), and ties are broken by the highest router ID, a 32-bit number written like an address. It is not preemptive: a new router with a higher priority does not take over a working DR. Only when the DR fails does the BDR become DR and a new BDR get elected. This avoids needless disturbance in the network.

Python DR and BDR election and the adjacency count

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

R3 and R2 win the first election because they have the highest router IDs among equal priorities, and R4 is never eligible, because its priority is 0. R5 arrives with priority 200 and changes nothing: the election is not preemptive. Only after R3 fails does R2 become the DR, and R5, who is the best of the rest, becomes the BDR. The second table shows the savings: 20 routers on one segment need 190 adjacencies in a full mesh but only 37 with a DR and a BDR.

Areas: keeping big networks small

In a very large network, a link-state database with thousands of routers is expensive: every change triggers a flood and an SPF run everywhere. OSPF divides the network into areas. Routers inside one area share a full topology database. Between areas, routers exchange only summaries of networks, not topology.

flowchart TB
    subgraph A0["Area 0: the backbone"]
        direction LR
        ABR1["ABR 1"] --- ABR2["ABR 2"]
    end
    subgraph A1["Area 1"]
        R1["Internal routers"]
    end
    subgraph A2["Area 2"]
        R2["Internal routers"]
    end
    ABR1 --- R1
    ABR2 --- R2

All areas must connect to the backbone, area 0. Area border routers (ABRs) sit in two areas and summarize one into the other.

  • Area 0, the backbone, connects all other areas. Traffic between two areas always passes through it.
  • An area border router (ABR) has interfaces in several areas and holds a database for each of them. It advertises the networks of one area into another as summary LSAs (type 3), ideally as a single aggregated prefix, which hides the instability of one area from the others.
  • An autonomous system boundary router (ASBR) connects OSPF to another routing domain (static routes, BGP, RIP) and injects those routes as external LSAs (type 5).
  • Stub and not-so-stubby areas reject external routes and use a default route instead, which keeps the databases of small branch areas tiny.

The main LSA types are: type 1 (router: a router's own links), type 2 (network: the DR describes a shared segment), type 3 (summary from an ABR), type 4 (where to find an ASBR) and type 5 (external routes).

The cost metric and why it needs tuning

OSPF's metric is a cost assigned to each interface. The usual formula is

TEXT
cost = reference bandwidth / interface bandwidth        (at least 1)

and a path costs the sum of the costs of its outgoing links. With the traditional reference bandwidth of 100 Mbit/s, a Fast Ethernet link costs 1, a 10 Mbit/s link costs 10. The problem is that every link faster than 100 Mbit/s also costs 1, so OSPF cannot tell a gigabit link from a 10-gigabit link. The usual fix is to raise the reference bandwidth (for example to 100 Gbit/s or 1 Tbit/s) consistently on all routers.

The next program compares RIP and OSPF in two scenarios and shows RIP's timers in action.

Python Hop count versus bandwidth-based cost

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In scenario 1, RIP picks the one-hop route over the slow 10 Mbit/s link, because a hop is a hop. OSPF sends traffic over the three fast links instead (cost 3 against 10). In scenario 2 the default reference bandwidth makes a 100 Mbit/s direct link look as good as a 10 Gbit/s link, so OSPF chooses the slow direct path (cost 1 against 2). Raising the reference bandwidth to 100 Gbit/s separates all the speeds, and the 10 Gbit/s path wins. The last block lists the RIP timers: a route is useful for 180 seconds without an update, is advertised as unreachable until second 300, and is then deleted.

OSPF terms, packet types and network types

A few terms recur in OSPF documents. The router ID is a 32-bit identifier written like an IPv4 address that names each router (usually the highest loopback address). An LSA (link-state advertisement) describes one router's links, the LSDB (link-state database) is the collection of all LSAs in an area, and the cost of a link is derived from its bandwidth.

OSPF has five packet types, all carried directly in IP (protocol number 89):

Type Name Purpose
1 Hello Discover neighbors, check they agree on parameters (area, timers), and act as a keepalive
2 Database Description (DBD) Summarize the headers of the LSAs a router holds, used when two neighbors first synchronize
3 Link-State Request (LSR) Ask a neighbor for the full LSAs that this router is missing
4 Link-State Update (LSU) Carry the full LSAs, both during synchronization and when something changes
5 Link-State Acknowledgment (LSAck) Confirm receipt of an LSU, because OSPF builds its own reliability on top of IP

The sequence when two routers meet is Hello, then DBD exchange, then LSR and LSU for the missing pieces, then LSAck, ending in the Full state shown in the neighbor life cycle above.

OSPF behaves differently depending on the network type of an interface:

  • Broadcast multi-access (Ethernet): Hellos are multicast to 224.0.0.5, and a designated router and backup are elected.
  • Point-to-point (a serial or tunnel link between two routers): no election, neighbors form straight away.
  • Point-to-multipoint: a non-broadcast network treated as a collection of point-to-point links, with no election.
  • NBMA (non-broadcast multi-access, such as old Frame Relay clouds): several routers share a network that cannot broadcast, so neighbors must be configured by hand and a DR is elected.

Timers can be adjusted: the Hello interval (10 s on broadcast links) and the dead interval (4 times as long). Shorter timers detect failure faster at the cost of more traffic and more risk of flapping. Routers must agree on these values to become neighbors. Advantages of OSPF are fast convergence, no hop limit, support for VLSM, authentication and areas for scaling. Its drawbacks are a more complex design and configuration and higher CPU and memory use than RIP.

SPF throttling

A flapping link could make every router recompute its shortest-path tree many times a second. SPF throttling limits this: after the first change the router waits a short initial delay to collect more changes, and if changes keep coming it increases the delay (the hold time) up to a maximum before running SPF again. Quiet networks therefore converge fast, and unstable ones do not overload their routers. IS-IS has the same feature.

Comparing the two

RIPv2 OSPF
Type Distance-vector Link-state
Transport UDP 520 IP protocol 89
Metric Hop count (max 15) Cost from bandwidth
Updates Whole table every 30 s Hello every 10 s, LSAs only on change
Convergence Minutes after a failure Seconds or less
Scale Small networks Large networks, divided into areas
Configuration Minimal Router IDs, areas, costs, authentication
Typical use Labs, tiny networks Campus, enterprise and data-center networks

IS-IS is a second link-state protocol with the same ideas. It is common inside large carrier networks. BGP connects the independent networks of the Internet to each other, and is often used together with OSPF or IS-IS inside each one.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How often does a RIP router send its full table, and when is a route declared invalid?

    RIP updates every 30 seconds and marks a route invalid after 180 seconds (six missed updates). It is removed after a further 120 seconds.
  2. 2. What makes two OSPF routers on a switch become neighbors with correct Hello behavior?

    Neighbors go from Down to Init and 2-Way by hearing each other's Hellos. Mismatched timers or other parameters prevent adjacency. Router IDs must be different. TCP 179 is BGP.
  3. 3. A router with priority 250 joins a segment that already has a working DR. What happens?

    OSPF avoids disturbing a stable DR. The new router only matters in the next election, after the DR or BDR fails.
  4. 4. With the default reference bandwidth of 100 Mbit/s, what is the cost of a 10 Gbit/s link?

    100 / 10000 rounds down to 0, and the minimum cost is 1. So 100 Mbit/s, 1 Gbit/s and 10 Gbit/s links all cost 1.
  5. 5. What is the role of an area border router (ABR)?

    ABRs hold one database per attached area and pass summaries (type 3 LSAs) between them, which keeps topology changes local to each area.

Summary

  • RIPv2 runs over UDP 520 with multicast to 224.0.0.9, sends up to 25 entries per message, updates every 30 seconds and uses timeout 180 s and garbage collection 120 s. Its metric is the hop count with a maximum of 15.
  • OSPF runs directly over IP (protocol 89), finds neighbors with Hellos (every 10 s, dead after 40 s on broadcast networks) and passes through the states Down, Init, 2-Way, ExStart, Exchange, Loading and Full.
  • On a shared segment, OSPF elects a DR and a BDR by priority and then router ID. The election is not preemptive, and priority 0 means ineligible. This reduces the number of adjacencies from n(n-1)/2 to about 2n.
  • Areas keep link-state databases small: area 0 is the backbone, ABRs summarize between areas, ASBRs inject external routes.
  • OSPF cost is the reference bandwidth divided by the link bandwidth. Raise the reference bandwidth consistently, or fast links look identical.

Next, see how routing works between organizations in BGP and Inter-Domain Routing.