1. Basic concepts and terms
1. Link status
The OSPF router collects the connection status information of each router on the network area where it is located, that is, the link status information (Link-State), and generates a link status database (Link-State Database). The router has mastered the link status information of all routers in this area, which is equivalent to understanding the topological status of the entire network. The OSPF router uses the "Shortest Path First, SPF" to independently calculate the route to any destination.
2. Area
The OSPF protocol introduces the concept of "hierarchical routing" to divide the network into a set of independent parts connected by a "backbone" connection. These independent parts are called "areas" and the "backbone" part is called "backbone area". Each region is like a separate network, and the OSPF router of that region only saves the link status of the region. The link state database of each router can maintain a reasonable size, and the time and number of packets for routing calculation will not be too large.
3. OSPF network type
According to the physical network connected to the router, OSPF divides the network into four types: Broadcast multiAccess, None Broadcast MultiAccess, NBMA, Point-to-Point, and Point-to-MultiPoint.
Broadcast multi-access networks such as Ethernet, Token Ring, FDDI. NBMA-type networks such as: Frame Relay, X.25, SMDS. Point-to-Point networks such as: PPP, HDLC.
4. Assign Router (DR) and Backup Assign Router (BDR)
There may be multiple routers on a multi-access network. In order to avoid the heavy overhead caused by establishing a completely adjacent relationship between routers, OSPF requires that a DR be elected in the region. Each router establishes a completely adjacent relationship with it. DR is responsible for collecting all link status information and publishing it to other routers. While electing DR, a BDR is also elected. When DR fails, BDR assumes the responsibility of DR.
Point-to-point networks do not require DR because there are only two nodes that are completely adjacent to each other. The OSPF protocol consists of the Hello protocol, the exchange protocol, and the proliferation protocol. This article only introduces the Hello protocol, and the other two protocols can be referred to the specific description in RFC2328.
When the router opens OSPF routing on a port, a Hello message will be sent from this port, and it will periodically send Hello messages at certain intervals in the future. The OSPF router uses Hello messages to initialize a new neighbor relationship and confirm the communication status between neighbors of neighbors.
For broadcast and non-broadcast multi-access networks, the router uses the Hello protocol to elect a DR. In a broadcast network, Hello packets are broadcast periodically using the multicast address 224.0.0.5, and the router neighbors are automatically discovered through this process. In the NBMA network, DR is responsible for sending Hello messages to other routers one by one.
2. Protocol operation
Step 1: Establish the adjacency relationship of the router
The so-called "adjacency" refers to a relationship established between the selected adjacent routers by the OSPF router for the purpose of exchanging routing information.
The router first sends Hello packets with its own ID information (Loopback port or largest IP address). If the adjacent router receives this Hello message, it will add the ID information in the message to its own Hello message.
If a port of the router receives a Hello message with its own ID information sent from another router, it determines whether an adjacency relationship can be established based on the network type of the port.
In a point-to-point network, the router will directly establish an adjacency relationship with the peer router, and the router will directly enter the third step of operation: discovering other routers. If it is a MultiAccess network, the router will enter the election step.
Step 2: Election DR/BDR
Different types of networks elect DR and BDR in different ways.
The MultiAccess network supports multiple routers. In this case, OSPF needs to establish a central node as link state and LSA update. The election is determined using the ID and Priority field values in the Hello message. The priority field value size is from 0 to 255, and the router with the highest priority value becomes DR. If the priority weight is the same, the router with the highest ID value is elected as DR, and the router with the second highest priority weight is elected as BDR. Both priority weight and ID value can be set directly.
Step 3: Discover the router
In this step, the router and the router first use the ID information of the Hello message to confirm the master-slave relationship, and then the master-slave routers exchange part of the link status information with each other. Each router analyzes and compares the information. If there is new content in the received information, the router will ask the other party to send complete link status information. After this state is completed, a fully adjacency relationship is established between the routers, and the adjacency router has its own independent and complete link state database.
In the MultiAccess network, DR and BDR exchange information, and exchange link status information with other routers in the subnet at the same time.
Information between adjacent routers in Point-to-Point or Point-to-MultiPoint network.
Step 4: Select the appropriate router
When a router has a complete independent link state database, it will use the SPF algorithm to calculate and create routing tables. The OSPF router independently calculates the path to each destination network based on the content of the link state database and stores the path into the routing table.
OSPF uses metrics (Cost) to calculate the destination path, and the shortest path is the smallest path. When configuring an OSPF router, you can set the link Cost size according to actual conditions, such as link bandwidth, delay or economic expenses. The smaller the Cost, the greater the possibility that the link will be selected as a route.
Step 5: Maintain routing information
When the link state changes, OSPF informs other routers on the network through the Flooding process. The OSPF router receives a link status update message containing new information, updates its own link status database, and then recalculates the routing table using the SPF algorithm. During the recalculation process, the router continues to use the old routing table until the SPF completes the new routing table calculation. New link status information will be sent to other routers. It is worth noting that even if the link status does not change, the OSPF routing information will be automatically updated, with the default time being 30 minutes.