---
title: "OSPF working with routing tables"
subject: "Internet and Intranet"
chapter: 2
key: "semester_8/internet_and_intranet:ospf-working-routing-tables"
source: https://www.bctengineer.com/q/semester_8/internet_and_intranet/ospf-working-routing-tables
site: BCT Engineering
---

# OSPF working with routing tables

Internet and Intranet · Chapter 2: Internet Protocol Overview

- Asked in: 2069 Bhadra (old course), 15 marks
- Video: [What is OSPF and How Does It Work?](https://www.youtube.com/watch?v=Xb3CbIDMDRk) — CBT Nuggets
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/internet_and_intranet/ospf-working-routing-tables
- Whole chapter: https://www.bctengineer.com/md/semester_8/internet_and_intranet/chapter-2

## Question

Describe the working process of OSPF with example. Illustrate your answer with routing tables between source and destination machine. (Assume IP address, cost and network diagram by yourself).

## Short answer

OSPF is a link-state protocol using Hello packets for neighbour discovery, LSA flooding to build identical link-state databases, and Dijkstra SPF to compute shortest paths. In the example, R1 reaches PC2's LAN 192.168.3.0/24 via next hop 10.0.12.2 with cost 21.

## Answer

#### OSPF

**Open Shortest Path First (OSPF)** is a link-state interior gateway protocol (OSPFv2 in RFC 2328) that runs inside an autonomous system. Each router learns the whole topology and computes the shortest path to each network using **Dijkstra's SPF algorithm**. It is classless, supports VLSM, converges quickly, uses multicast 224.0.0.5/224.0.0.6, runs directly over IP (protocol 89) and uses **cost** as metric (cost = reference bandwidth / link bandwidth).

#### Working process

1. **Neighbour discovery:** routers send Hello packets on each interface (every 10 s). Neighbours with matching area, timers and authentication reach the 2-Way state. On multi-access LANs a Designated Router (DR) and Backup DR are elected.
2. **Database exchange:** neighbours exchange Database Descriptions (ExStart/Exchange), request missing records (Loading) and reach the **Full** state.
3. **LSA flooding:** each router describes its links and costs in Link State Advertisements, flooded to all routers in the area, so every router has an identical **Link State Database (LSDB)**.
4. **SPF calculation:** each router runs Dijkstra with itself as the root and builds a shortest path tree.
5. **Routing table:** best routes are installed. Equal-cost paths can be load-balanced.
6. **Maintenance:** Hellos continue; if a link changes, a new LSA is flooded and SPF is re-run.

#### Example (assumed)

```text
PC1--LAN1--[R1]---cost 10---[R2]--LAN2
 .1.10     |    10.0.12.0/30  |  192.168.2.0/24
           |                  |
     cost 30             cost 10
  10.0.13.0/30        10.0.23.0/30
           |                  |
           +------[R3]--------+
                    |
                  LAN3 --- PC2
              192.168.3.0/24 (.3.10)
```

Interfaces: R1: 192.168.1.1/24, 10.0.12.1, 10.0.13.1. R2: 10.0.12.2, 10.0.23.1, 192.168.2.1/24. R3: 10.0.23.2, 10.0.13.2, 192.168.3.1/24. LAN costs = 1.

**SPF from R1:** to R2 = 10; to R3 via R2 = 10 + 10 = 20 (direct link costs 30, so rejected); to LAN3 = 20 + 1 = 21 via R2.

**Routing table of R1**

| Destination | Type | Next hop | Cost |
|---|---|---|---|
| 192.168.1.0/24 | Connected | - | 1 |
| 10.0.12.0/30 | Connected | - | 10 |
| 10.0.13.0/30 | Connected | - | 30 |
| 192.168.2.0/24 | OSPF | 10.0.12.2 | 11 |
| 10.0.23.0/30 | OSPF | 10.0.12.2 | 20 |
| 192.168.3.0/24 | OSPF | 10.0.12.2 | 21 |

**Routing table of R2**

| Destination | Type | Next hop | Cost |
|---|---|---|---|
| 192.168.2.0/24 | Connected | - | 1 |
| 10.0.12.0/30 | Connected | - | 10 |
| 10.0.23.0/30 | Connected | - | 10 |
| 192.168.1.0/24 | OSPF | 10.0.12.1 | 11 |
| 192.168.3.0/24 | OSPF | 10.0.23.2 | 11 |
| 10.0.13.0/30 | OSPF | 10.0.12.1 or 10.0.23.2 (equal) | 40 |

**Routing table of R3**

| Destination | Type | Next hop | Cost |
|---|---|---|---|
| 192.168.3.0/24 | Connected | - | 1 |
| 10.0.23.0/30 | Connected | - | 10 |
| 10.0.13.0/30 | Connected | - | 30 |
| 192.168.2.0/24 | OSPF | 10.0.23.1 | 11 |
| 10.0.12.0/30 | OSPF | 10.0.23.1 | 20 |
| 192.168.1.0/24 | OSPF | 10.0.23.1 | 21 |

(R3 reaches LAN1 via R2: 10 + 10 + 1 = 21, better than direct 30 + 1 = 31.)

**Packet walk, PC1 (192.168.1.10) to PC2 (192.168.3.10):**
1. PC2 is outside PC1's subnet, so PC1 sends to its gateway 192.168.1.1 (R1).
2. R1 matches 192.168.3.0/24 (cost 21), forwards to next hop 10.0.12.2 (R2).
3. R2 matches 192.168.3.0/24 (cost 11), forwards to 10.0.23.2 (R3).
4. R3 has 192.168.3.0/24 connected and delivers directly to PC2 (ARP, then frame).
The reply follows R3 to R2 to R1 using the tables above.

**Configuration on R1 (Cisco style)**

```text
router ospf 1
 network 192.168.1.0 0.0.0.255 area 0
 network 10.0.12.0 0.0.0.3 area 0
 network 10.0.13.0 0.0.0.3 area 0
interface s0/0
 ip ospf cost 10
interface s0/1
 ip ospf cost 30
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What kind of protocol is OSPF and which algorithm does each router run?
   A. Distance-vector protocol using Bellman-Ford
   B. Link-state protocol using Dijkstra's SPF algorithm
   C. Path-vector protocol using BGP best path
   D. Static protocol with no algorithm
   Answer: B. OSPF is a link-state IGP; each router builds the LSDB and runs Dijkstra with itself as root. (Key point: OSPF type and algorithm)

2. What is the correct order of the OSPF process?
   A. SPF calculation, Hello, LSA flooding, database exchange
   B. Hello/neighbour discovery, database exchange, LSA flooding, SPF calculation, routing table
   C. LSA flooding, routing table, Hello, SPF
   D. Routing table, SPF, Hello, flooding
   Answer: B. Routers discover neighbours, exchange databases to reach Full state, flood LSAs, run SPF and install routes. (Key point: OSPF working order)

3. In the example, why does R1 reach R3 via R2 rather than the direct link?
   A. Via R2 costs 10 + 10 = 20, less than the direct cost of 30
   B. Direct links are never used by OSPF
   C. R2 has a higher router ID
   D. Via R2 has fewer hops, regardless of cost
   Answer: A. OSPF compares total cost, not hops: 20 beats 30. (Key point: Shortest path calculation)

4. What is R1's OSPF cost to 192.168.3.0/24, and what is the next hop?
   A. 31 via 10.0.13.2
   B. 21 via 10.0.12.2
   C. 11 via 10.0.12.2
   D. 30 via 10.0.13.2
   Answer: B. 10 (R1-R2) + 10 (R2-R3) + 1 (LAN3) = 21, via R2 at 10.0.12.2. (Key point: Cost to LAN3)

5. How is OSPF cost defined?
   A. Number of hops
   B. Reference bandwidth divided by link bandwidth
   C. Round trip delay in ms
   D. Number of LSAs received
   Answer: B. Cost = reference bandwidth / link bandwidth, so faster links have lower cost. (Key point: OSPF cost metric)

## Related in Internet and Intranet

- [VLSM preventing IP address loss](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avlsm-prevents-ip-loss) — Internet and Intranet, chapter 2
- [TCP/IP applications; IPv4 vs IPv6 routing](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Atcpip-application-ipv4-ipv6-routing) — Internet and Intranet, chapter 2
- [IANA, ICANN functions and IP address role](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Aiana-icann-ip-role) — Internet and Intranet, chapter 1

## Related in other subjects

- [Routing criteria; RIP, OSPF, BGP, IGRP, EIGRP](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Arouting-criteria-protocols) — Computer Networks and Security, chapter 4
- [Why IP address when MAC exists](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Amac-vs-ip-address) — Computer Networks and Security, chapter 4
- [Coffee vending machine use case diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Acoffee-vending-machine-use-case) — Object Oriented Analysis and Design, chapter 2
- [Bottle recycling machine state diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Abottle-recycling-state-diagram) — Object Oriented Analysis and Design, chapter 2
