OSPF routers periodically send Hello packets on every OSPF-enabled interface, and negotiate the specific parameters, including the area ID, authentication method, Hello packet interval, and dead interval, in the Hello packets with other routers that receive Hello packets. If the negotiation succeeds, the receiving router adds the router ID of the originating router to the neighbor list of the returned Hello packet. The two routers then establish bidirectional communication and an OSPF neighbor relationship. If a router does not receive a Hello packet from its neighbor within the dead interval, the router terminates the neighbor relationship with this neighbor.
After establishing an OSPF neighbor relationship, two neighbors need to exchange DD packets and LSAs to establish an adjacency.
Not all neighbors establish adjacencies. Whether neighbors establish adjacencies depends on the network type and DR/BDR establishment. On P2P and P2MP links, all devices need to exchange LSAs and establish only adjacencies. On broadcast and NBMA links, DR others do not need to exchange LSAs and establish only neighbor relationships. LSAs need to be exchanged between the DR and BDR, and between the DR, BDR, and DR others, so they establish adjacencies with each other. In Figure 1, two DR others each have established three neighbor relationships and two adjacencies.
A neighbor relationship indicates that two neighbors reach the 2-Way state, whereas an adjacency indicates that two neighbors reach the Exstart state or higher.
The process of establishing an OSPF adjacency varies depending on the network type.
Broadcast Network
On a broadcast network, the DR and BDR establish an adjacency with each router on the same network segment, but DR others establish only neighbor relationships with each other. Figure 2 shows the process of establishing an OSPF adjacency.
Neighbor relationship establishment
RouterA uses the multicast address 224.0.0.5 to send a Hello packet through the OSPF interface connected to a broadcast network. The packet carries the DR field of 1.1.1.1 (ID of RouterA) and the Neighbors Seen field of 0, indicating that a neighbor RouterB has not been discovered and RouterA regards itself as the DR.
After RouterB receives the packet, it returns a Hello packet to RouterA. The returned packet carries the DR field of 2.2.2.2 (ID of Router B) and the Neighbors Seen field of 1.1.1.1 (RouterA's router ID). RouterA has been discovered but its router ID is less than that of RouterB, and therefore RouterB regards itself as the DR. Then RouterB's neighbor state changes to Init.
After RouterA receives the response, RouterA's neighbor state changes to 2-Way. Then, RouterA and RouterB start to send their LSDB information to each other, which does not occur between DR others on a broadcast network.
Master/Slave negotiation and DD packet exchange
To improve transmission efficiency, RouterA and RouterB determine which LSAs in each other's LSDB need to be updated before sending LSR packets. If one party detects that an LSA of the other party is already in its own LSDB, it does not send an LSR packet for updating the LSA to its own LSDB. To achieve the preceding purpose, RouterA and RouterB first send DD packets, which carry summaries of LSAs in their own LSDBs. Each summary identifies an LSA. To ensure reliable packet transmission, the master/slave roles must be determined through DD packet exchange. The party serving as the master uses the Seq field to define a sequence number. The master increases the sequence number by 1 each time it sends a new DD packet. When the other party serving as the slave sends a DD packet, it sets the Seq field of the packet to the sequence number carried in the last DD packet received from the master.
After RouterB receives the DD packet, RouterB's state changes to Exstart and RouterB returns a DD packet to RouterA. The returned packet does not carry LSA summaries. Because RouterB has a larger router ID than RouterA, RouterB declares itself the master and sets the Seq field to Y.
After RouterA receives the DD packet, it agrees that RouterB is the master and RouterA's state changes to Exchange. Then, RouterA sends a DD packet to RouterB to transmit LSA summaries. The packet carries the Seq field of Y and the MS field of 0 indicating that RouterA declares itself the slave.
After RouterB receives the packet, RouterB's state changes to Exchange and RouterB sends a new DD packet containing its own LSA summaries to RouterA. The value of the Seq field carried in the new DD packet is changed to Y+1. RouterA uses the same sequence number as RouterB to acknowledge that it has received DD packets from RouterB. RouterB uses the sequence number from RouterA plus 1 to acknowledge that it has received DD packets from RouterA. When RouterB sends the last DD packet, it sets the M field in the packet to 0.
LSDB synchronization (LSA request, LSA transmission, and LSA response)
After RouterA receives the last DD packet, it finds that many LSAs in RouterB's LSDB do not exist in its own LSDB. Therefore, RouterA's neighbor state changes to Loading. After RouterB receives the last DD packet from RouterA, RouterB's neighbor state directly changes to Full because RouterB's LSDB already contains all LSAs of RouterA.
RouterA sends an LSR packet for updating LSAs from RouterB to its own LSDB. RouterB sends an LSU to After RouterA. After receiving the packet from RouterB, RouterA sends an LSAck packet to RouterB for acknowledgement.
The preceding procedure ends when the LSAs in RouterA's LSDB are the same as those in RouterB's LSDB. RouterA's neighbor state then changes to Full. After RouterA and RouterB exchange DD packets and update all LSAs, an adjacency is established between them.
NBMA Network
On an NBMA network, all routers establish adjacencies only with the DR and BDR. Figure 3 shows the process of establishing an OSPF adjacency.
Neighbor relationship establishment
After RouterB sends a Hello packet to a Down interface of RouterA, RouterB's neighbor state changes to Attempt. The packet carries the DR field of 2.2.2.2 (ID of RouterB) and the Neighbors Seen field of 0. A neighbor RouterA has not been discovered, and RouterB regards itself as the DR.
After RouterA receives the packet, RouterA's state changes to Init and RouterA returns a Hello packet. The returned packet carries the DR and Neighbors Seen fields of 2.2.2.2. RouterB has been discovered but its router ID is greater than that of RouterA, and therefore RouterA agrees that RouterB is the DR. Then, RouterA and RouterB start to exchange DD packets and LSDB information with each other, which does not occur between DR others on a broadcast network.
The processes of negotiating master/slave roles and exchanging DD packets on an NBMA network are the same as those on a broadcast network.
The process of synchronizing LSDBs (LSA request, LSA transmission, and LSA response) on an NBMA network is the same as that on a broadcast network.
P2P Network and P2MP Network
The process for establishing an adjacency on a P2P/P2MP network is similar to that on a broadcast network except that no DR or BDR needs to be elected on a P2P/P2MP network. DD packets are transmitted in multicast mode on P2P networks and in unicast mode on P2MP networks.