Dynamic Routing: RIP, OSPF and BGP Protocols
This is session 1 on dynamic routing (basics). In practical classes 11–12 you wrote every path by hand; now the routers “talk” to each other and build the map themselves. Today you will see the idea of three protocols in simulators: RIP — the “rumour” method that trusts what it hears from a neighbour (Bellman–Ford), OSPF — the method that knows the whole map and computes the cheapest path (Dijkstra), BGP — the “diplomacy” between autonomous systems. You will write both algorithms in Python yourself. Complex cases are in practical class 14.
Lesson goals and plan
By the end of the lesson you will…
- explain the difference between static and dynamic routing and the types of dynamic protocols (distance vector, link-state, path vector)
- carry out by hand the operating principle of RIP (hop metric, 30-second updates, 15-hop limit) and the Bellman–Ford update
- explain step by step the link-state idea of OSPF, the cost metric and Dijkstra’s algorithm
- explain the role of BGP between autonomous systems (AS) and the loop protection via AS_PATH
- calculate and show why RIP and OSPF choose different paths in the same network
- write the Bellman–Ford and Dijkstra algorithms in Python and pass the tests
Plan (according to the syllabus)
- Dynamic Routing: RIP, OSPF and BGP Protocols
Picture the two methods with a metro. RIP — the duty officer at each station hears only from neighbouring stations: “3 stations to Tashkent”. OSPF — every duty officer holds the whole metro map. BGP — the agreement between the metros of different cities. This is session 1; the continuation is in practical class 14.
Nobody. If every path had to be written by hand as in practical classes 11–12, the Internet would not work for a single day: whenever a cable broke, thousands of administrators around the world would have to rewrite tables. Instead, routers send each other messages through routing protocols — “these are the networks I know and this is how far they are” — and update their tables themselves. Today we listen in on this “conversation”.
Key terms
Theory reminder
In practical class 12 we saw two painful points of static routing: the number of entries grows quickly with the network, and the router does not notice a remote outage. Dynamic protocols solve both — in return the router spends part of its CPU, memory and link bandwidth.
| RIP (v2) | OSPF (v2) | BGP (v4) | |
|---|---|---|---|
| Type | Distance vector | Link-state | Path vector |
| Where used | Inside a small AS (IGP) | Inside large corporate and provider networks (IGP) | Between ASes — the “backbone” of the Internet (EGP) |
| Metric | Hop count (1–15; 16 = unreachable) | Cost = reference bandwidth / link bandwidth | Attributes and policy (LOCAL_PREF, AS_PATH length…) |
| Algorithm | Bellman–Ford | Dijkstra (SPF) | Path vector + policy rules |
| Updates | The whole table to the neighbours every 30 seconds | Hello packets (usually 10 s); on a change — only the changed LSA | TCP session (port 179); on a change — only the update |
| Transport | UDP 520, multicast 224.0.0.9 | IP protocol 89, multicast 224.0.0.5 / 224.0.0.6 | TCP 179 |
| AD (Cisco) | 120 | 110 | eBGP 20, iBGP 200 |
| Convergence | Slow (minutes) | Fast (seconds) | Depends on policy, relatively slow |
Dynamic Routing: RIP, OSPF and BGP Protocols
The course syllabus allots two sessions to this topic. Today (practical class 13) — the basics: the idea of the three protocols, RIP and Bellman–Ford, OSPF and Dijkstra, BGP and AS_PATH. Practical class 14 — the continuation: “counting to infinity” and split horizon, OSPF cost and area problems, reconvergence after a link failure, BGP policy between ASes and neighbour-relationship faults.
All the experiments take place on one “valley–republic backbone”: six city routers, links of different speeds. Pay special attention to the direct Andijan–Tashkent link: it is the shortest but the slowest (10 Mbit/s).
1. RIP: “my neighbour said…” — distance vector
A RIP router knows only its neighbours. Every 30 seconds it sends its table (“which network is how many hops”) to all neighbours. A router that receives T: 1 hop from a neighbour reasons: “so for me T is 1 + 1 = 2 hops, through this neighbour”, and updates its table if that is better than the current entry. This is the Bellman–Ford equation:
DX(y) = minv ∈ neighbours { c(X, v) + Dv(y) }
The best distance from X to y is the smallest, over all neighbours, of “the cost to the neighbour + the distance to y that the neighbour reported”. In RIP every link has cost c = 1 (hop).
Simulator: how a rumour spreads
At first every router knows only itself. Press the “Round” button — all routers simultaneously send their tables to their neighbours (in real RIP this corresponds to 30 seconds). Yellow — the entries that changed in this round. In how many rounds does the network converge? Through which neighbour does A’s path to T go?
:ik-chat: RIP: exchange of tables (Bellman–Ford, metric — hops)
Observation: in round 1 every router “hears” its neighbours, in round 2 — its neighbours’ neighbours, and so on. The message spreads one hop further each round, so the convergence time depends on the network “diameter”. In real RIP each round is ~30 seconds — several minutes in a large network! Another important thing: for A → T RIP chose the direct 10 Mbit/s link — because it counts only hops and does not know the speed.
Worked task 1. Carry out the Bellman–Ford update by hand
- Data
Router X’s neighbours: B (cost 1) and C (cost 4). B’s vector:
Y: 6, Z: 2. C’s vector:Y: 1, Z: 5. - For Y
Via B: 1 + 6 = 7; via C: 4 + 1 = 5 → DX(Y) = 5, via C.
- For Z
Via B: 1 + 2 = 3; via C: 4 + 5 = 9 → DX(Z) = 3, via B.
- The neighbours themselves
B: min(1, 4 + C’s distance to B) — if B is not in C’s vector, 1, via B. Send the result to the neighbours — they do the same calculation.
Cisco IOS: enabling RIPv2 (for information)R1(config)# router rip R1(config-router)# version 2 R1(config-router)# network 192.168.1.0 # on which interfaces RIP runs R1(config-router)# network 10.0.0.0 R1(config-router)# no auto-summary R1# show ip route rip # R 192.168.3.0/24 [120/2] via 10.0.12.2
In the table, [120/2] means [AD / metric]: AD = 120 (RIP), 2 hops. Compare with [1/0] for a static route.
2. OSPF: “I hold the whole map” — link-state
OSPF routers first find their neighbours with Hello packets, then each one spreads a message about its own links (LSA — Link State Advertisement). These messages spread through the area like a flood (flooding), and in the end every router’s LSDB (link-state database) is the same. After that each router runs the Dijkstra algorithm with itself as the root and builds the tree of cheapest paths (the SPF tree).
Cost — the price of a link
cost = reference bandwidth / interface bandwidth (integer part, at least 1). On Cisco the default reference is 100 Mbit/s: 10 Mbit/s → 10, 100 Mbit/s → 1, 1 Gbit/s → also 1 (!). That is why in modern networks the reference is made larger (auto-cost reference-bandwidth) — the topic of practical class 14. On our backbone it is 1000 Mbit/s.
Areas
A large OSPF network is divided into areas; the central area 0 (backbone) connects all the others. LSAs spread mainly inside an area — this reduces the size of the LSDB and the SPF calculation.
Simulator: Dijkstra step by step
Choose the root router and press “Step”. At each step the node with the smallest tentative distance becomes permanent (green), then the distances of its neighbours are updated (relaxation). The thick red lines are the tree of shortest paths. Compare the A → T path with the RIP result!
:ik-xarita: OSPF: Dijkstra (SPF) algorithm
Result: for A → T OSPF chooses the A → F → T path (cost 1 + 1 = 2), while RIP chooses the direct slow link (1 hop, but cost 100). The same network — two different “minds”. That is why RIP is hardly used in modern corporate networks.
Cisco IOS: enabling OSPF (for information)R1(config)# router ospf 1 R1(config-router)# router-id 1.1.1.1 R1(config-router)# network 192.168.1.0 0.0.0.255 area 0 # wildcard mask! R1(config-router)# network 10.0.12.0 0.0.0.3 area 0 R1# show ip ospf neighbor # neighbours and their state (FULL) R1# show ip route ospf # O 192.168.3.0/24 [110/2] via 10.0.12.2
3. BGP: the diplomacy of autonomous systems — path vector
The Internet is a network of networks made of tens of thousands of autonomous systems (AS): providers, content companies, universities. Inside each AS its own IGP runs (for example OSPF), and between ASes there is a single protocol — BGP. When BGP announces a route it attaches AS_PATH — the list of ASes it has passed through. Before passing a route to a neighbour, each AS writes its own number at the head of the list.
Loop protection
If an AS sees its own number in the AS_PATH of an announcement, it rejects it: this route has already passed through it. Loops in static routing (practical class 12) are prevented in BGP by this simple rule.
The best path is policy
BGP chooses not the “fastest” path but the one that fits business policy: first LOCAL_PREF (which provider is cheaper or more reliable), then the shortest AS_PATH and other attributes. These choices are studied in the simulator in practical class 14.
| Who announces → to whom | AS_PATH | Note |
|---|---|---|
| AS 500 → AS 300 | 500 | The origin AS announces its own prefix |
| AS 300 → AS 200 | 300 500 | Added its own number to the front |
| AS 200 → AS 100 | 200 300 500 | AS 100 sees this path as 3 ASes long |
| AS 100 → AS 300 (coming back) | 100 200 300 500 | AS 300 sees its own number → rejects it |
Independent tasks
Easy → hard: 6 tasks. The last two are the “heart” of the protocols: Bellman–Ford and Dijkstra. input() without a prompt.
Common mistakes
| Misconception | Correct answer |
|---|---|
| “RIP chooses the fastest path” | RIP chooses the path with the fewest hops; it does not know the speed |
| “OSPF cost is the link length (km)” | Cost is inversely related to bandwidth (reference / speed), and the administrator can also change it by hand |
| “Once a dynamic protocol is enabled, static routes are unnecessary” | In many networks both are used together: for example a static default route to the Internet and OSPF inside |
| “BGP always chooses the shortest AS_PATH” | Policy first (LOCAL_PREF and others); the AS_PATH length is a later criterion |
| “In Dijkstra the first neighbour encountered immediately becomes permanent” | The one that becomes permanent is the node with the smallest distance among all the tentative ones |
| “A plain mask is written in the OSPF network command” | A wildcard mask: /24 → 0.0.0.255, /30 → 0.0.0.3 |
Boss level
Boss level: RIP and OSPF — one network, two decisions
The program reads the network (links and costs) and a root router, and for each destination determines through which neighbour RIP (fewest hops) and OSPF (lowest cost) would send. Format: «D: RIP -> Q1 (H hop) | OSPF -> Q2 (cost C)», with « *» appended if the neighbours differ. On a tie — the alphabetically earlier neighbour. Destinations in alphabetical order. +70 XP
Hint: Run Dijkstra twice — once with every link weight 1, once with the real cost. If you put the triple (distance, first_neighbour, node) into the heap, ties are resolved alphabetically by themselves.
Reinforcement
Review questions
What is the difference between static and dynamic routing?
In static routing the administrator writes the paths by hand and they do not change; in dynamic routing the routers exchange information through a protocol, build the tables automatically and adapt to changes.
Explain the idea of distance vector, link-state and path vector protocols.
Distance vector — receive distance vectors from neighbours and compute with Bellman–Ford (RIP). Link-state — spread information about all links, and each router computes from the whole map with Dijkstra (OSPF). Path vector — the list of ASes passed through is carried with the route, and the choice is made by policy (BGP).
List the main features of RIP.
Metric — hops (max 15, 16 — unreachable), a full table update every 30 s, UDP 520, AD 120, Bellman–Ford, slow convergence, for small networks.
Write and explain the Bellman–Ford equation.
DX(y) = minv {c(X,v) + Dv(y)} — the best distance from X to y is the minimum, over all neighbours, of “the cost to the neighbour + the neighbour’s distance to y”.
How is cost calculated in OSPF?
cost = reference bandwidth / interface bandwidth (integer part, at least 1); on Cisco the reference is 100 Mbit/s by default.
State the steps of Dijkstra’s algorithm.
The root’s distance is 0, all the others ∞. At each step make the non-permanent node with the smallest distance permanent and update its neighbours’ distances (if it is cheaper through it) — until all nodes are permanent.
Why is BGP needed and what does AS_PATH do?
To exchange routes between autonomous systems. AS_PATH is the list of ASes the route has passed through: it protects against loops (an AS that sees its own number rejects the route) and is one of the criteria for choosing a path.
Why can RIP and OSPF choose different paths in the same network?
RIP counts only hops, while OSPF takes link speed into account: a path with few hops but a slow link is good for RIP and expensive for OSPF.
Independent work
The independent-study topic in the course syllabus: “Comparative analysis of the RIP, OSPF, EIGRP and BGP protocols.” (6 hours). The part related to this class:
- For the network of your variant, calculate by hand the paths from the root router to all routers by RIP (hops) and OSPF (cost), with a Dijkstra table, and check them with the lesson’s “Boss” program.
- Build a table comparing RIP, OSPF, EIGRP and BGP on at least 8 criteria (read more about EIGRP from other sources: hybrid/advanced distance vector, the DUAL algorithm, AD 90).
- In Packet Tracer, configure RIPv2 and OSPF in turn on your variant’s topology and compare the
show ip routeresults (screenshots).
| Criterion | Points |
|---|---|
| RIP and OSPF paths are calculated correctly, the Dijkstra table is complete | 2 |
| Comparison table (RIP, OSPF, EIGRP, BGP) — at least 8 criteria | 1 |
| Packet Tracer results and comments | 1 |
| Conclusion: which protocol suits this network and why | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.