# OSPF Fundamentals

OSPF is the interior routing protocol most enterprises actually run. It builds a shared map of the network and computes shortest paths from it, which makes it fast to converge and easy to reason about — once you understand areas and cost.

## The idea

Every router floods information about its own links to every other router in the same area. Each router assembles an identical link-state database and runs Dijkstra's algorithm on it. Because everyone has the same map, everyone computes consistent paths.

| Property | Value |
|---|---|
| Type | Link-state, interior gateway protocol (IGP) |
| IP protocol number | 89 (not TCP or UDP) |
| Multicast | 224.0.0.5 (all routers), 224.0.0.6 (DR/BDR) |
| Hello interval | 10 s on broadcast, 30 s on NBMA |
| Dead interval | 4 × hello = 40 s |
| Metric | Cost, by default 100 Mbps ÷ interface bandwidth |
| Admin distance | 110 (Cisco) |

## Areas and the backbone

OSPF splits a large network into **areas** so that topology changes stay local.

- **Area 0** is the backbone; every other area must connect to it.
- **ABR** (area border router) sits between area 0 and another area, and summarises between them.
- **ASBR** connects to a different routing domain and injects external routes.
- **LSA types** you will meet: 1 (router), 2 (network/DR), 3 (summary from ABR), 4 (ASBR summary), 5 (external), 7 (NSSA external).

```mermaid
graph TD
    A[Area 0 backbone] --- B[ABR]
    B --- C[Area 10]
    B --- D[Area 20]
    A --- E[ASBR]
    E --- F[External domain]
```

Single-area OSPF works for small networks and is a reasonable starting point. Multi-area exists to bound flooding and give you summarisation points.

## Cost, and the trap in the default

Cost = reference bandwidth ÷ interface bandwidth. The reference defaults to 100 Mbps, so:

| Interface | Default cost |
|---|---|
| 10 Mbps | 10 |
| 100 Mbps | 1 |
| 1 Gbps | 1 |
| 10 Gbps | 1 |
| 40 Gbps | 1 |

Every link at 100 Mbps or faster gets cost 1, so OSPF cannot tell a 1 Gbps link from a 40 Gbps one. The fix is to raise the reference bandwidth on every router, consistently:

```bash
# Cisco
router ospf 1
 auto-cost reference-bandwidth 100000     # 100 Gbps in Mbps

# FRR / Linux
ip ospf cost 10                            # or set cost per interface
```

Changing it on one router only is worse than not changing it: two routers now disagree about the map.

## Neighbours, DR and BDR

On a broadcast segment OSPF elects a **Designated Router** and **Backup DR** to reduce adjacencies from n(n−1)/2 to 2n−1. Election is by interface priority (default 1), then router ID — highest wins. Priority 0 means "never".

Neighbours must agree on: area ID, hello/dead timers, subnet and mask, authentication, MTU (for DBD exchange), and stub flags. Any mismatch means the adjacency sticks in `INIT`, `EXSTART` or `EXCHANGE`, and routes never appear.

```bash
show ip ospf neighbor
show ip ospf interface brief
show ip route ospf
show ip ospf database
```

## Where it goes wrong

- **MTU mismatch.** The adjacency forms and then breaks at database exchange, flapping every few minutes — a tunnel with a smaller MTU on one end is the classic cause.
- **Reference bandwidth changed on one router.** Asymmetric costs, traffic taking the slow path, and no error anywhere.
- **Missing area 0.** Two areas connected directly without the backbone create a virtual-link dependency that nobody documents.
- **Summarisation blackholes.** A summary that is wider than the addresses actually present silently discards traffic for the gap.
- **Timers mismatched after a vendor migration.** Hello 10/dead 40 on one side, 30/120 on the other: neighbours never come up, and the log says nothing useful.
- **Redistribution loops.** Mutual redistribution between OSPF and BGP (or static) without filters re-injects routes endlessly.
- **Authentication off "temporarily".** Anyone on the segment can inject LSAs; the temporary change outlives the reason.

## Teaching hook

**The shared map analogy.** OSPF is not gossip about destinations (that is distance-vector); it is every router contributing its own street to one common map, then each router calculating its own best route from that map.

Exercise: draw six routers, assign costs, and have learners compute the shortest path by hand before running it. The moment the hand calculation matches `show ip route`, the protocol stops being magic.

## Related Notes

- [[Routing/Routing-Fundamentals.md]] — distance-vector vs link-state
- [[Routing/BGP-And-Internet-Routing.md]] — the protocol OSPF hands off to at the edge
- [[Foundations/Network-Design-And-Topologies.md]] — where areas come from
- [[Routing/Route-Selection-And-Metrics.md]] — what wins when protocols disagree
