Routers that talk: OSPF
With a A way for routers to tell each other which addresses they can reach, so nobody has to write every route by hand., routers tell each other what they can reach. So they find their own way, and a new one when a link fails. OSPF is a routing protocol that many networks run inside themselves.
Why static routes are not enough
Picture three offices, each with a router, joined in a triangle. With static routes, each router needs a route for each other office's networks. It also needs a second route, with a higher distance, for the long way round. Add a fourth office, and every router needs more routes. Add a VLAN, and every other router needs a route for it.
That is a lot of writing, and it is easy to forget one. Worse, a router usually stops using a static route only when the route's own link goes down. If the trouble is one hop further on, the router keeps sending into it.
How OSPF works
OSPF is a A kind of routing protocol in which every router learns every link in the network, then works out its own paths from that map. protocol. Every router learns the same map of links and what each link costs. Each one computes the cheapest path to every network, and computes again whenever the map changes.
Step 1 of 7
Neighbors say hello
Each router sends a hello message out of every interface that OSPF runs on. Two routers that hear each other become neighbors. They keep saying hello every few seconds.
Every router ends up with the same map, but not with the same routing table. R1 and R4 read the same map from different places, so each has its own paths.
Cost and the cheapest path
Each interface that OSPF runs on has a cost: a number for how much you would rather not send through it. The cost of a path is the sum of the costs of its links, and OSPF uses the path with the lowest total. That is not always the path with the fewest links, because two cheap links can beat one expensive link.
If you don't set a cost, the router works one out from the link's speed, so a faster link costs less. Each vendor does that its own way, and on fast links it may give every link the same cost. So set the costs yourself where the choice matters.
Cut a link on the cheapest path, and watch the path move. Then change costs until two paths cost the same.
R1, R2, R4, R6, a total cost of 30.
| Link | Cost | Cable |
|---|---|---|
| R1 to R2 (on the path) | ||
| R1 to R3 | ||
| R2 to R4 (on the path) | ||
| R3 to R5 | ||
| R4 to R6 (on the path) | ||
| R5 to R6 | ||
| R2 to R5 | ||
| R4 to R5 |
R1's routing table
| Prefix | Next hop | Cost |
|---|---|---|
| 10.0.2.0/24 | R2 | 10 |
| 10.0.3.0/24 | R3 | 10 |
| 10.0.4.0/24 | R2 | 20 |
| 10.0.5.0/24 | R3 | 30 |
| 10.0.6.0/24 | R2 | 30 |
routing: {
router_id: "10.255.255.1",
ospf: {
areas: {
"0.0.0.0": {
interfaces: {
"25g-1": { cost: 10, network: "point-to-point" }, // to R2
"25g-2": { cost: 10, network: "point-to-point" }, // to R3
office: { passive: true },
},
},
},
},
},
If you cut the link from R2 to R4, the path from R1 to R6 moves to R1, R3, R5, R6, at a cost of 40. R2 still has a link to R5, but that way costs 50. When two paths cost the same, OSPF can use both and share the traffic between them. That is called Equal-cost multipath: when several paths cost the same, the router shares traffic across all of them..
Each end of a link sets its own cost, for traffic that leaves through it. In the widget, both ends have the same cost. On real routers, set the same cost at both ends, unless you want traffic to take a different way back.
Areas
Every router in an area has the same map, and every change makes all of them compute again. In a large network, that map gets big. So OSPF lets you split the network into areas. The routers in an area have the full map of their own area only. A router in two areas passes on a summary of what each area can reach.
Area 0 is the The OSPF area that every other area must connect to, numbered 0. Traffic between two other areas crosses it.. Every other area connects to it, and traffic between two areas crosses it. Area numbers are written like IPv4 addresses, so area 0 is 0.0.0.0. A network of a few dozen routers usually needs only area 0.
OSPF in Circuit
OSPF is routing.ospf. Each area, under its ID, lists the interfaces that OSPF runs on:
interfaces: {
loopback: {
loopback: { addresses: ["10.255.255.1/32"] },
},
vlan_interface: {
office: { vlan: "office", addresses: ["10.0.1.1/24"] },
},
},
routing: {
router_id: "10.255.255.1",
ospf: {
areas: {
"0.0.0.0": {
interfaces: {
"25g-1": { cost: 10, network: "point-to-point", bfd: true },
"25g-2": { cost: 10, network: "point-to-point", bfd: true },
loopback: { passive: true },
office: { passive: true },
},
},
},
},
},| Field | What it does |
|---|---|
router_id | How the router is known to its neighbors. A loopback's address is a good choice: a loopback is on no cable, so it never goes down. |
cost | The cost of sending out of this interface. |
network: "point-to-point" | For a cable with one router at each end. It skips the election OSPF holds on a shared network, so neighbors come up sooner. |
passive: true | Announce the interface's network, but never form a neighbor on it. Use it on every VLAN of users, because no router is there. |
bfd: true | Notice a dead link in under a second, instead of after many seconds without hellos. |
redistribute | In routing.ospf: also announce routes from elsewhere, such as ["static"]. |
address_families | In routing.ospf: ["ipv4", "ipv6"] runs OSPF for IPv6 too. |
OSPF runs directly on IP. It uses neither TCP nor UDP. If the router's input firewall drops by default, let OSPF in:
{ description: "OSPF", if: { protocol: "ospf" }, then: "accept" },To see which routers become neighbors before you apply anything, open the OSPF layer of the graph in circuit studio.
Not every platform runs every part
VRP and Raisecom ROS run OSPF for IPv4 only, and Raisecom ROS runs it only on VLAN interfaces. Junos and FortiOS don't run it in a VRF. circuit validate reports anything a platform can't do. See Platforms.