OSPF
OSPF
A routing protocol inside one organisation: routers share a map and compute shortest paths.
OSPF is a routing protocol for inside one organisation in which every router holds the same map. Routers greet neighbours with Hellos, become Full neighbours, and flood LSAs describing their links and costs. Each router runs Dijkstra on that link-state database, and the lowest total cost wins. When a link or router fails, the map changes and every router recomputes within seconds.
How OSPF works, step by step
OSPF (version 2, RFC 2328) is a link-state protocol: instead of passing routes along, routers share a map of the network and each computes its own routes from it. It runs directly on IP, protocol number 89, with no TCP or UDP, and its packets on a link carry TTL 1.
- Hello. Every OSPF interface sends a Hello to
224.0.0.5(all OSPF routers) every hello interval, 10 seconds by default on Ethernet. A Hello carries the sender's router ID, its area, mask, timers, priority and the list of neighbours it has heard. Two routers become neighbours only if area, subnet, hello and dead intervals, authentication and MTU agree. - 2-Way. When a router finds its own ID in a neighbour's Hello, both know they hear each other. On a link with several routers they elect a designated router (DR) and a backup (BDR); everyone exchanges maps with those two only.
- ExStart, Exchange, Loading. The pair agree who leads, swap Database Description packets listing what each holds, request what they lack (Link State Request), and send it (Link State Update, acknowledged by LSAck).
- Full. Both now hold the same link-state database: every router's Router LSA ("I am on these links, at these costs"), plus a Network LSA for each multi-access link, written by its DR.
- SPF. Each router runs Dijkstra's shortest-path algorithm with itself at the root. The path with the lowest total cost wins. An interface's cost is a reference speed divided by its bandwidth. Cisco's reference is 100 Mb/s, so every link of 100 Mb/s or faster costs 1 until it is raised; FRR's is 100 Gb/s.
- Change. If no Hello arrives for the dead interval (40 seconds by default), the neighbour is dropped. The router floods a new LSA with a higher sequence number, and every router reruns SPF.
Large networks are split into areas around a backbone, area 0, so a change in one area does not make every router recompute.
What it looks like on a Linux machine
In the OSPF routing lab six routers run FRR, an open-source routing suite, with fast timers: a Hello every second, dead after 4. A capture shows the Hellos:
$ tcpdump -lnni baggageTunnel -v ip proto 89
10.0.11.2 > 224.0.0.5: OSPFv2, Hello, length 48
Router-ID 1.1.1.1, Backbone Area, Authentication Type: none (0)
Hello Timer 1s, Dead Timer 4s, Mask 255.255.255.0, Priority 1
FRR's shell, vtysh, shows the neighbours and the routes:
$ vtysh -c 'show ip ospf neighbor'
Neighbor ID Pri State Up Time Dead Time Address Interface
3.3.3.3 1 2-Way/DROther 13.172s 3.840s 10.0.13.3 apron:10.0.13.2
4.4.4.4 1 Full/Backup 10.661s 3.117s 10.0.13.4 apron:10.0.13.2
6.6.6.6 1 Full/DR 5.680s 3.345s 10.0.13.5 apron:10.0.13.2
1.1.1.1 1 Full/Backup 5.679s 3.396s 10.0.11.2 baggageTunnel:10.0.11.3
$ vtysh -c 'show ip route ospf'
O>* 10.0.1.0/24 [110/20] via 10.0.11.2, baggageTunnel, weight 1, 00:00:06
[110/20] is the administrative distance, 110 for OSPF, then the cost: 10 for the tunnel and 10 for the network
behind the next router. FRR installs the route in the kernel, where ip route shows it with proto ospf. Tell OSPF
the tunnel's real speed with bandwidth 10 and the route moves to the fiber; cut the fiber without taking a card
down and after 4 seconds it moves back on its own.
What goes wrong, and how you see it
No neighbour at all. Hellos are sent but never answered: check that area, subnet mask, hello and dead timers and authentication match on both ends, and that the interface is not passive. A firewall dropping protocol 89 has the same effect.
Stuck in ExStart or Exchange. The classic cause is an MTU mismatch: one side's Database Description packets are too big for the other, and the pair never reach Full.
Stuck in 2-Way. On a multi-access link two routers that are neither DR nor BDR stay 2-Way on purpose. It is only a problem if one of them should have been the DR. OSPF network types decide which links hold an election at all, and the OSPF routing lab covers both.
Full, and still no path. With point-to-point on one end of a link and broadcast on the other, both ends read
Full and the path still goes, because neither router's record points at what the other wrote. Compare the network
type on both ends.
A path you did not expect. Costs belong to the outgoing interface, so each direction can take a different path:
asymmetric routing, which confuses traceroutes and stateful firewalls. Compare show ip route on both ends.
Slow failover. With default timers a silent failure takes up to 40 seconds to notice. BFD detects it in under a second.
Questions people ask
What is the difference between OSPF and BGP? OSPF finds the fastest path inside one organisation, from a shared map. BGP connects organisations and chooses routes by policy and AS path, not link speed.
What is OSPF's administrative distance? 110: preferred to RIP's 120, less trusted than a static route (1) or eBGP (20).
What is the router ID? A 32-bit number written like an address that names the router in OSPF. It is set by hand or taken from an interface address; two routers with the same ID break the database.
Read next
- Routing table The list a device uses to decide where each packet goes next.
- Multicast One packet to a group of listeners, like all OSPF routers on a link (224.0.0.5).
- BGP The protocol between autonomous systems: how the networks of the internet find each other.
- Administrative distance How much a router trusts a source of routes, when several offer the same network.
- RIP A distance-vector routing protocol: each router tells its neighbours how many hops away every network is.
- Designated router The OSPF router a shared segment elects to sync with everyone, so routers need not all sync with each other.
- OSPF areas and LSA types OSPF splits a big network into areas around area 0, with border routers summing one area up for another.
- Asymmetric routing Traffic there and back taking different paths, because each router picks its own way out.
- EIGRP Cisco's advanced distance-vector protocol: neighbours share distances, with a backup path worked out in advance.
- Router ID The 32-bit name an OSPF (or BGP) router goes by, written like an IPv4 address and unique in the domain.
- OSPF network type How OSPF treats a link: broadcast with a DR election, or point-to-point between two routers with none.
- MPLS Forwarding by a short label put in front of the IP header, instead of by the destination address.
- LDP Hands out MPLS labels: each router picks a label for every route it has and tells its neighbours.
- Control plane and data plane Deciding where traffic should go (control plane) against moving each packet by those decisions (data plane).