Skip to content

IntermediateLesson 3 of 9

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.

Try itWatch routers build a map and recover
10hello10hello10hello30helloR1R2R3R4What each router knows1-21-32-43-4R1R2R3R4knownnot yetgone

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.

CheckOSPF has finished flooding in a network. What do all the routers now have in common?

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.

Try itFind the cheapest path, then break it

Cut a link on the cheapest path, and watch the path move. Then change costs until two paths cost the same.

10101020101030100R110.0.1.0/24R210.0.2.0/24R310.0.3.0/24R410.0.4.0/24R510.0.5.0/24R610.0.6.0/24

R1, R2, R4, R6, a total cost of 30.

R1's routing table

PrefixNext hopCost
10.0.2.0/24R210
10.0.3.0/24R310
10.0.4.0/24R220
10.0.5.0/24R330
10.0.6.0/24R230
r1.ts, part of it
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.

CheckFrom one router, path 1 crosses two links with a cost of 50 each, and path 2 crosses four links with a cost of 10 each. Which path does OSPF use?

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:

ts
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 },
                },
            },
        },
    },
},
FieldWhat it does
router_idHow 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.
costThe 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: trueAnnounce the interface's network, but never form a neighbor on it. Use it on every VLAN of users, because no router is there.
bfd: trueNotice a dead link in under a second, instead of after many seconds without hellos.
redistributeIn routing.ospf: also announce routes from elsewhere, such as ["static"].
address_familiesIn routing.ospf: ["ipv4", "ipv6"] runs OSPF for IPv6 too.
CheckYour router runs OSPF on its cable to another router. You add a guests VLAN, where only phones and laptops are. How should it appear in the OSPF area?

OSPF runs directly on IP. It uses neither TCP nor UDP. If the router's input firewall drops by default, let OSPF in:

ts
{ 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.

Discussion

Stuck, or found a mistake? Ask here. You sign in with GitHub.

Released under the Business Source License 1.1.