OSPF Data Structures
Before routers start exchanging routing updates, they must form a neighbor adjacency, which is a relationship between two OSPF routers. Building OSPF network adjacency is necessary to ensure that two routers communicate and have the same view of the network. Once established, the OSPF neighbors are put into each neighbor’s database tables, and the exit interfaces are mapped to them.
Once an adjacency has been established, routers exchange information about the links' state. This information is in the form of link-state advertisements (LSAs), which describe the Layer 3 device and the networks connected to it (state of a specific link).
All this exchanged information is then stored in a special table called the link-state database (LSDB). Each router builds its copy of the LSDB, which is a database of all the LSAs received from other routers and contains information about the state of the links in the network, including the cost of reaching each link. As a result, all routers within an area are synchronized and have the same topology database.
Using the information in the LSDB, each OSPF-enabled router calculates the shortest path (best path) to each destination network using the shortest path first (SPF) or Dijkstra algorithm. This provides the best route to each learned network from OSPF neighbors and is installed in the routing table.
As shown in the image above, R1 learns about the 192.168.1.0/24 network from its OSPF neighbors R2 and R3 and, after performing the SPF calculation, selects the best route through R2 and installs it in the routing table.
When routers exchange LSAs, five types of OSPF packets are involved in the process, each with a different purpose:
- Hello: For discovering and maintaining the OSPF neighbor relationship.
- Database Description (DBD): Contains a summary of the LSDB.
- Link State Request (LSR): For requesting information about a missing route that an OSPF neighbor has.
- Link State Update (LSU): Update information sent to an OSPF neighbor after receiving an LSR packet.
- Link State Acknowledgement (LSAck): Acknowledgement for the received DBD, LSR, and LSU packets.