Open Shortest Path First (OSPF)
Open-Shortest-Path-First (OSPF) is the most widely used interior gateway protocol routing
protocol. Because it is a public or open source (non-proprietary) routing protocol while
EIGRP, is a Cisco proprietary protocol so other vendors can’t use it (edit: EIGRP has become
a public routing protocol since 2013). OSPF development has started since 1987 as the
replacement of RIP (Routing Information Protocol), the Distance Vector routing protocol. In
1989 first version of OSPF was released for experiment only. OSPFv2 came for IPv4 routing
in 1991 and OSPFv3 released in 1999 for IPv6 routing.
OSPF is a complex link-state routing protocol. Link-state routing protocols generate routing
updates only when a change occurs in the network topology. When a link changes state, the
device that detected the change creates a link-state advertisement (LSA) concerning that
link and sends to all neighboring devices using a special multicast address. Each routing
device takes a copy of the LSA, updates its link-state database (LSDB), and forwards the LSA
to all neighboring devices.
Here are the most important features of OSPF:
● A classless routing protocol
● Supports VLSM, CIDR, manual route summarization
● Equal cost load balancing
● Incremental update is supported
● Uses only one parameter as the metric – the interface cost.
● The administrative distance of OSPF routes is, by default, 110.
● Uses multicast addresses 224.0.0.5 (DR) and 224.0.0.6 (DR Other) for routing
updates.
Routers running OSPF have to establish neighbor relationships before exchanging routes.
Because OSPF is a link state routing protocol, neighbors don’t exchange routing tables.
Instead, they exchange information about network topology. Each OSPF router then runs SPF
or Dijkstra algorithm to calculate the best routes and adds those to the routing table.
Because each router knows the entire topology of a network, the chance for a routing loop
to occur is minimal.
Each OSPF router stores routing and topology information in three tables:
● Neighbor table – stores information about OSPF neighbors
● Topology table – stores the topology structure of a network
● Routing table – stores the best routes
OSPF areas
OSPF uses the concept of areas. An area is a logical grouping of contiguous networks and
routers. All routers in the same area have the same topology table, but they don’t know
about routers in the other areas. The main benefits of creating areas is that the size of the
topology and the routing table on a router is reduced, less time is required to run the SPF
algorithm and routing updates are also reduced.
Each area in the OSPF network has to connect to the backbone area (area 0). All router
inside an area must have the same area ID to become OSPF neighbors. A router that has
interfaces in more than one area (area 0 and area 1, for example) is called Area Border
Router (ABR). A router that connects an OSPF network to other routing domains (EIGRP
network, for example) is called Autonomous System Border Router (ASBR).
NOTE
In OSPF, manual route summarization is possible only on ABRs and ASBRs.
To better understand the concept of areas, consider the following example.
All routers are running OSPF. Routers R1 and R2 are inside the backbone area (area 0).
Router R3 is an ABR, because it has interfaces in two areas, namely area 0 and area 1.
Router R4 and R5 are inside area 1. Router R6 is an ASBR, because it connects OSPF
network to another routing domain (an EIGRP domain in this case). If the R1’s directly
connected subnet fails, router R1 sends the routing update only to R2 and R3, because all
routing updates all localized inside the area.
NOTE
The role of an ABR is to advertise address summaries to neighboring areas. The role of an
ASBR is to connect an OSPF routing domain to another external network (e.g. Internet,
EIGRP network…).
LSA, LSU and LSR
The LSAs (Link-State Advertisements) are used by OSPF routers to exchange topology
information. Each LSA contains routing and topology information to describe a part of an
OSPF network. When two neighbors decide to exchange routes, they send each other a list
of all LSAa in their respective topology database. Each router then checks its topology
database and sends a Link State Request (LSR) message requesting all LSAs not found in its
topology table. Other router responds with the Link State Update (LSU) that contains all LSAs
requested by the other neighbor.
The concept is explained in the following example:
After configuring OSPF on both routers, routers exchange LSAs to describe their respective
topology database. Router R1 sends an LSA header for its directly connected network
10.0.1.0/24. Router R2 check its topology database and determines that it doesn’t have
information about that network. Router R2 then sends Link State Request message
requesting further information about that network. Router R1 responds with Link State
Update which contains information about subnet 10.0.1.0/24 (next hop address, cost…).
OSPF neighbors
OSPF routers need to establish a neighbor relationship before exchanging routing updates.
OSPF neighbors are dynamically discovered by sending Hello packets out each OSPF-
enabled interface on a router. Hello packets are sent to the multicast IP address of
224.0.0.5.
The process is explained in the following figure:
Routers R1 and R2 are directly connected. After OSPF is enabled both routers send Hellos to
each other to establish a neighbor relationship. You can verify that the neighbor relationship
has indeed been established by typing the show ip ospf neighbors command.
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DR 00:00:30 192.168.0.2 FastEthernet0/0
In the example above, you can see that the router-id of R2 is 2.2.2.2. Each OSPF router is
assigned a router ID. A router ID is determined by using one of the following:
1. Using the router-id command under the OSPF process.
2. Using the highest IP address of the router’s loopback interfaces.
3. Using the highest IP address of the router’s physical interfaces.
The following fields in the Hello packets must be the same on both routers in order for
routers to become neighbors:
● Subnet
● Area id
● Hello and dead interval timers
● Authentication
● Area stub flag
● MTU
By default, OSPF sends hello packets every 10 second on an Ethernet network (Hello
interval). A dead timer is four times the value of the hello interval, so if a routers on an
Ethernet network doesn’t receive at least one Hello packet from an OSPF neighbor for 40
seconds, the routers declares that neighbor to be down.
OSPF neighbor states
Before establishing a neighbor relationship, OSPF routers need to go through several state
changes. These states are explained below.
1. Init state – a router has received a Hello message from the other OSPF router
2. 2-way state – the neighbor has received the Hello message and replied with a Hello
message of his own
3. Exstart state – beginning of the LSDB exchange between both routers. Routers are
starting to exchange link state information.
4. Exchange state – DBD (Database Descriptor) packets are exchanged. DBDs contain
LSAs headers. Routers will use this information to see what LSAs need to be exchanged.
5. Loading state – one neighbor sends LSRs (Link State Requests) for every network it
doesn’t know about. The other neighbor replies with the LSUs (Link State Updates) which
contain information about requested networks. After all the requested information have
been received, other neighbor goes through the same process
6. Full state – both routers have the synchronized database and are fully adjacent with
each other.
Adjacencies
Adjacency is the next step after the neighbor process. Adjacent routers are routers that go
beyond the simple Hello exchange and proceed into the database exchange process.
In order to minimize the amount of information exchange on a particular segment, OSPF
elects one router to be a designated router (DR), and one router to be a backup designated
router (BDR), on each multi-access segment.
The BDR is elected as a backup mechanism in case the DR goes down. The idea behind this
is that routers have a central point of contact for information exchange.
Rather than exchange updates with every other router on the segment, every router
exchanges information with the DR and BDR.
The DR and BDR relay the information to everybody creation else. In mathematical terms,
this cuts the information exchange from O(n*n) to O(n) where n is the number of routers on
a multi-access segment.
This router model illustrates the DR and BDR:
In this diagram, all routers share a common multi-access segment. Due to the exchange
of Hello packets, one router is elected DR and another is elected BDR.
Each router on the segment (which already became a neighbor) tries to establish an
adjacency with the DR and BDR.
DR Election
DR and BDR election is done via the Hello protocol. Hello packets are exchanged via IP
multicast packets (Appendix B) on each segment.
The router with the highest OSPF priority on a segment becomes the DR for that segment.
The same process is repeated for the BDR. In case of a tie, the router with the highest RID
prevails.
The default for the interface OSPF priority is one. Remember that the DR and BDR concepts
are per multiaccess segment. The OSPF priority value on an interface is done with the ip
ospf priority <value> interface command.
A priority value of zero indicates an interface which is not to be elected as DR or BDR. The
state of the interface with priority zero is DROTHER. This illustrates the DR election:
OSPF Cost
The cost (also called metric) of an interface in OSPF is an indication of the overhead required
to send packets across a certain interface.
The cost of an interface is inversely proportional to the bandwidth of that interface. A higher
bandwidth indicates a lower cost
There is more overhead (higher cost) and time delays involved through a 56k serial line than
through a 10M ethernet line.
The formula used to calculate the cost is:
● cost= 10000 0000/bandwidth in bps
For example, it costs 10 EXP8/10 EXP7 = 10 to cross a 10M Ethernet line and 10
EXP8/1544000 = 64 to cross a T1 line.
By default, the cost of an interface is calculated based on the bandwidth; you can force the
cost of an interface with the ip ospf cost <value> interface subconfiguration mode
command.