Sub topic 16
OSPF: areas, costs, and designated routers
OSPF (Open Shortest Path First) is the most widely deployed link-state protocol in enterprise networks. This chapter covers the three features that shape a real OSPF design: areas, interface costs, and designated routers.
This chapter assumes you know the following:
- IP addressing and subnetting.
- How a routing table and longest-prefix match work.
- The link-state model from earlier chapters: hello packets, flooding of advertisements, the link-state database, and Dijkstra's algorithm.
Where OSPF fits
OSPF version 2 (OSPFv2, RFC 2328) routes IPv4. OSPFv3 (RFC 5340) routes IPv6 and follows the same design. OSPF runs directly over IP, as protocol number 89. It does not use TCP or UDP. It sends hellos to the multicast addresses 224.0.0.5 (all OSPF routers) and 224.0.0.6 (all designated routers). Because it does not use TCP, OSPF provides its own reliability. Each link-state advertisement (LSA) is acknowledged, and unacknowledged LSAs are retransmitted.
The protocol follows the link-state recipe:
- Routers find neighbors with hello packets.
- Neighbors that qualify become adjacent and synchronize their databases.
- Each router floods LSAs describing its links.
- Every router in an area ends up with an identical link-state database.
- Each router runs Dijkstra's algorithm on that database and installs the resulting routes.
The features below address the problems this recipe has at scale.
Why areas exist
In a flat link-state network, every router holds every LSA and reruns Dijkstra whenever any link changes. In a large network this causes three problems:
- The database grows, which uses more memory.
- Dijkstra runs more often and takes longer.
- A flapping link anywhere makes every router recompute.
OSPF limits these problems by dividing the network into areas. An area is a set of routers and links that share one link-state database. A router sees full topology detail only for the areas it belongs to.
Area 0, the backbone, is required. Every other area must connect to area 0, and traffic between two non-backbone areas passes through it. This gives a two-level hierarchy.
Routers have different roles depending on where they sit:
| Role | Where it sits | What it does |
|---|---|---|
| Internal router | All interfaces in one area | Keeps one database |
| Backbone router | At least one interface in area 0 | Takes part in the backbone |
| Area border router (ABR) | Interfaces in two or more areas | Keeps one database per area and summarizes routes between them |
| AS boundary router (ASBR) | Connects to another routing domain | Injects external routes into OSPF |
What crosses an area boundary
An ABR does not forward LSAs between areas. It runs a separate Dijkstra for each area. It then advertises the resulting prefixes and their costs into the neighboring area as summary LSAs (Type 3). This is distance-vector behavior between areas: a router in area 1 knows that a prefix in area 2 is reachable through ABR1 at some total cost, but it does not know the topology behind that prefix.
This has two effects:
- A link failure inside area 2 triggers Dijkstra only inside area 2. Other areas see at most a change in a summary route.
- An ABR can aggregate several prefixes into one summary, so other areas hold fewer routes and see fewer changes.
The cost is that the backbone rule constrains design. Paths between areas always pass through area 0, even when a more direct path exists through another area.
Common LSA types
| Type | Name | Originated by | Flooded in |
|---|---|---|---|
| 1 | Router LSA | Every router | Its own area |
| 2 | Network LSA | Designated router | Its own area |
| 3 | Summary LSA | ABR | The area it advertises into |
| 4 | ASBR summary LSA | ABR | Areas other than the ASBR's |
| 5 | External LSA | ASBR | Whole domain, except stub areas |
Stub areas reduce the load further. A stub area blocks Type 5 LSAs, and its ABR injects a default route instead. Internal routers then need only the area's own topology plus that default.
Costs
OSPF's metric is cost, a number assigned to each outgoing interface. The cost of a path is the sum of the outgoing interface costs along it. Dijkstra selects the path with the lowest total.
Cisco IOS computes the default cost this way:
cost = reference bandwidth / interface bandwidthThe default reference bandwidth is 100 Mbit/s, and the cost is never less than 1. This produces a well-known problem:
| Interface | Bandwidth | Default cost (reference 100 Mbit/s) |
|---|---|---|
| Ethernet | 10 Mbit/s | 10 |
| Fast Ethernet | 100 Mbit/s | 1 |
| Gigabit Ethernet | 1 Gbit/s | 1 |
| 10 Gigabit Ethernet | 10 Gbit/s | 1 |
Fast Ethernet, Gigabit, and 10 Gigabit links all get cost 1, so OSPF cannot tell them apart. It treats a path of three gigabit hops as equal to one 100 Mbit/s hop. Raise the reference bandwidth on every router in the domain so that fast links get distinct costs. You can also set a cost directly on an interface.
router ospf 1
auto-cost reference-bandwidth 100000
!
interface GigabitEthernet0/1
ip ospf cost 10The first command sets the reference to 100,000 Mbit/s. A 1 Gbit/s link then costs 100 and a 10 Gbit/s link costs 10.
If two paths have the same total cost, OSPF installs both and load-balances across them. This is called equal-cost multipath (ECMP).
Designated routers
On a point-to-point link, two routers form one adjacency. On a broadcast network such as an Ethernet segment, a full mesh of adjacencies would be wasteful. With n routers on the segment, a full mesh needs n(n−1)/2 adjacencies. Ten routers need 45, and each would exchange its own LSA updates.
OSPF solves this by electing two special routers on each broadcast segment:
- The designated router (DR) forms an adjacency with every other router on the segment. It floods updates for the segment and originates the Type 2 network LSA that describes the segment.
- The backup designated router (BDR) also forms adjacencies with every other router and takes over if the DR fails.
All other routers are called DROTHERs. A DROTHER forms full adjacencies only with the DR and BDR. Two DROTHERs stay in the 2-Way state with each other, which means they see each other's hellos but do not exchange databases. A DROTHER sends updates to 224.0.0.6, which only the DR and BDR receive. The DR then floods them to 224.0.0.5.
How the election works
Each router's hello carries its priority and the current DR and BDR. The rules are:
- The router with the highest priority wins. The default priority is 1.
- If priorities tie, the highest router ID wins.
- A priority of 0 makes a router ineligible.
The election is not preemptive. A router that joins later with a higher priority does not displace the existing DR. The DR changes only when it fails or when the OSPF process restarts. After a DR failure, the BDR becomes DR and a new BDR is elected.
Router ID is a 32-bit value written like an IPv4 address. You can set it explicitly, as in the example below. Otherwise the router picks one automatically, usually from the highest loopback address.
Where a segment has only two routers, you can skip the election. Setting ip ospf network point-to-point on both interfaces makes OSPF treat the link as point-to-point, which speeds up adjacency and avoids DR-related delay.
A minimal configuration
This configuration enables OSPF on interfaces in 10.0.0.0/24 and places them in area 0:
router ospf 1
router-id 1.1.1.1
network 10.0.0.0 0.0.0.255 area 0The 1 in router ospf 1 is a process ID, which has only local meaning. The network command uses a wildcard mask, where 0 bits must match. It selects interfaces whose addresses fall in 10.0.0.0/24, enables OSPF on them, and assigns them to area 0.
To verify the result, these commands are useful:
show ip ospf neighborlists neighbors, their state, and their DR or BDR role.show ip ospf databaseshows the LSAs by type.show ip route ospfshows the routes OSPF installed.
Common errors
Adjacencies fail to form for a short list of reasons. Check these first:
- Area ID mismatch. Both ends of a link must put it in the same area.
- Hello or dead interval mismatch. The defaults are 10 and 40 seconds on broadcast links. These values must match.
- Subnet or mask mismatch. Neighbors on a broadcast link must share a subnet.
- Authentication mismatch. Keys and types must agree.
- Duplicate router IDs. Two routers with the same ID cause unstable databases.
- Stuck in 2-Way. On a broadcast segment this is normal between two DROTHERs. It is a fault only if the router should be adjacent to a DR or BDR.
- Disconnected area. An area with no path to area 0 cannot exchange routes with the rest of the network. A virtual link can repair this, but redesigning the topology is usually better.
Exercise
A segment has four routers with OSPF priorities 1, 1, 5, and 0. The router with priority 5 starts last, after the others have already elected a DR. Which router is the DR, and what happens to the priority 5 router?
Show answer
The DR is whichever of the two priority-1 routers has the higher router ID, because the election is not preemptive and the first election ran without the priority-5 router. The priority-5 router does not take over. It joins as a DROTHER, or becomes BDR if the BDR slot is still open and it wins that election. The priority-0 router can never be DR or BDR. It stays a DROTHER.
Exercise
Every router in an OSPF domain uses the default reference bandwidth of 100 Mbit/s. A path crosses two 10 Gbit/s links. A second path crosses one 100 Mbit/s link. What are the two total costs, and what does OSPF do with them?
Show answer
Each 10 Gbit/s link has cost 1, so the first path costs 2. The 100 Mbit/s link costs 1, so the second path costs 1. OSPF prefers the 100 Mbit/s path, which is the wrong choice. Raising the reference bandwidth to 100000 Mbit/s changes the costs to 10 and 1 per 10 Gbit/s hop. The first path then costs 2 and the 100 Mbit/s link costs 1000, so OSPF correctly prefers the fast path.