Draft:OSPF Theory
This draft is ready for review. If you're the author, click below to notify a reviewer. A reviewer will check it for structure, sourcing, and accuracy. You may continue editing while you wait.Request reviewApprove draftReject draft
Author(s): Planterian
Last Updated: 5/28/2026
| Recommended Prerequisites (click to expand) |
|---|
|
Basic Devices in Computer Internetworking |
OSPF, or Open Shortest Path First, is an algorithm used by routers to find optimum routes between two points on a network. It functions by collecting the cost data of each router connection on the network, as well as the connections of each router. This data is then used in an algorithm known as the Dijkstra Shortest-Path First (SPF) algorithm. Using this algorithm, a router is able to compute the most efficient route for a given packet to reach a destination network. OSPFv2 is the most current version of OSPF for IPv4 networks. OSPFv3 is the version of OSPF used for IPv6 networks.
Basic Theory
The process of OSPF is comprised of several stages. The first stage is the discovery stage, in which all routers send Hello packets to all OSPF enabled ports, and wait for a response from other routers to discover their neighboring routers. This information is compiled for stage 2, at which point routers send out LSA (Link-State Advertisement) packets. These packets contain the state (up or down) and the cost (integer value used to compute efficiency) of the route between the two routers, as well as information about any LAN networks connected to the routers. These LSA packets are forwarded out of other connected ports on routers until all routers in the network have all LSAs in the network. In the next stage, routers build a LSDB (link-State Data Base) containing information from all the LSAs received, which gives the routers a map of the networks topology. The next stage is where the routers execute the SPF algorithm, computing the shortest path to all networks using the cost values and connection data. After this is completed, the data from the algorithm is placed into the routers IP routing table.
After this is done, routers can send LSU (Link-State Update) packets to inform other routers that a connection has been added, removed, or changed, at which point all routers redo the process of calculating optimum routes.
OSPF can be single area, wherein all routers are in the same logical “area” and can more easily connect, or it can be multi area, wherein separate logical areas are used to separate routers from each other. These areas are connected by border routers which exist in 2 or more areas at once, with different ports being in different logical areas. All areas must connect to one common area, usually area 0. Multi area OSPF is used for large networks, as routers in separate areas do not have to recalculate their routing tables when a router in a different area updates its links. As this is a resource intensive process, splitting the network into discrete areas allows administrators to reduce the amount of processing any one router has to do for OSPF.
There are several types of packets employed by the OSPF algorithm: The previously discussed Hello packets and LSA packets, as well as 3 other types. The first is the LSack packet, also known as the Link-State Acknowledgment packet, which is used by routers to acknowledge that they have received a packet from a received router. For example, a router sends a LSA packet and receives an LSack packet in return after the other router has received the LSA packet. The second type is the DBD (Data Base Description) packet, which is requested by routers from other routers periodically and contains a shortened copy of the requested routers OSPF routing database. This is done to check against the requesting routers own database to ensure they are identical, as this is necessary for proper routing. If there is a discrepancy detected, the router may send an LSR (Link-State Request) packet, which requests info on a specific link in the requested routers database. After an LSR is sent, the requested router can send an LSU (Link-State Update) packet with the requested link information.
A Router ID is a specific number attributed to a specific router that is used in the setup process. It identifies the router, while also assisting in deciding which router transmits its list first during setup. The router with the highest ID will be the first to send its info to other routers. If no ID is set up by an administrator, the ID will be automatically chosen. First, the router will check for any loop-back interfaces. If one exists, the IP of that interface will be used as the ID. If none exist, the highest configured IP on the router will be used.
OSPF States
There are 7 states within the OSPF algorithm that any port can be in. These are cycled through during the OSPF setup process.
The first state is the Down state. This state occurs when the router has yet to receive any Hello packets. In this state, the router tries sending Hello packets, and listens for any coming in. Once a Hello packet is received, it transitions to the next state.
The second state is the Init state. The Init state (or initialization state) occurs directly after a Hello packet is received. The Hello packet will contain the router ID of the sending router, and the receiving router quickly transitions into the next state.
The third state is the Two-Way state. In this state, bi-directional communication between the two routers is set up. In configurations where a DR and BDR are required, this is where they are elected. The routers then transition to the next state.
The fourth state is the ExStart state. In this state, the routers will decide who will be first in sending their LSA or DBD packets, and protocol information for sending of said packets such as sequence numbers is configured. The routers move to the next state.
The fifth state is the Exchange state. In this state, the routers exchange DBD or LSA packets. If more information is needed, transition to the 6th state. If everything seems correct, transition to the 7th state.
The sixth state is the Loading state. In this state, routers exchange LSR and LSU packets. This is done to fix discrepancies in DBD exchanges. After all discrepancies are fixed, transition to the next state.
The final seventh state is the Full state. At this point, the routers are fully configured and begin normal operation.
Designated and Backup Designated Routers
In large multi-access networks (networks where multiple routers are connected by multiple links), it can become an issue when every router sends out their own LSA. The number of LSA packets on the network can quickly balloon and cause traffic issues on the network. Due to this, large networks are configured to elect Designated Routers (DR) and Backup Designated Routers (BDR). These routers, elected for either having the best connection to the other routers or manually configured by an administrator, serve to mitigate the amount of LSAs on a network during setup. The process is as such: in a standard network, a router sends out its LSAs to all other routers it has access to, at which point all other routers send their LSAs to all other routers. In a DR enabled network, the first router only sends its LSA to the DR, and the DR will send the LSA to all other routers. Other routers will not respond to the LSA by flooding other routers with theirs. the BDR is elected as the second-best option, and used if the DR is offline or otherwise unavailable. All other routers on the network are configured at DROTHER (Designated Router Other). Note that routers will still use their routing table for the forwarding of standard packets, and DRs are only used for LSA packets.
The election process for a DR or BDR goes as follows: All routers have an interface priority value. The standard value is 1, with a max of 255. The router with the highest priority is elected as DR, and the second highest is elected as BDR. These numbers must be manually set by the system administrator. If all routers have a priority value of one, tie breaking methods must be used. A priority of 0 means that the router cannot be elected to DR or BDR. To do tie breaking, the routers use router ID. The router with the highest router ID is elected as DR, and so forth.
If a DR exits the network, the BDR becomes the DR and the third highest valued router is elected to BDR. If the previous DR then re-enters the network, it becomes a DROTHER even if its value is higher than the current DR. This persists until OSPF is recalculated or reset. The original DR cannot be elected to DR or BDR until the OSPF is recalculated or reset.
OSPF Cost
The cost value is used by OSPF protocol to find optimum routes for packet travel. There are two ways a cost value is determined. The first is an administrator setting the cost manually to a selected value through CLI. The second is preformed when no manual value is given. The cost value is calculated by taking the reference bandwidth, typically 10^8, and dividing it by the bandwidth of the route in bits per second (bps). If the interface bandwidth is greater than the reference bandwidth, the value is capped at 1. The reference bandwidth can be changed via CLI. The reference bandwidth should be the same on all routers to ensure the algorithm works as intended. The reference should be adjusted whenever there is a bandwidth greater than Fast Ethernet (such as Gigabit Ethernet)
Default routes
The default route in OSPF networks is used to connect OSPF networks to non-OSPF networks such as the IoT. This is done so that all devices on the OSPF network know how to reach the wider internet. To configure a default route, 2 things must occur. First, a default static route must be configured to the given interface per standard protocol, with mask 0.0.0.0. Then, the OSPF of the router must be configured to originate the default route to the network.