What is OSPF?
Open Shortest Path First (OSPF) is an internal gateway protocol based on link state developed by IETF.
At present, OSPF Version 2 (RFC2328) is used for IPv4 protocol and OSPF Version 3 (RFC2740) is used for IPv6 protocol.
OSPF basic concepts
Router ID must exist if OSPF protocol is to be run. Router ID is a 32-bit unsigned integer, which is the unique identification of a router in the autonomous system.
There are two ways to set the Router ID:
Manually configure through the command line. In the actual network deployment, it is recommended to manually configure the Router ID of OSPF, because this is related to the stability of the protocol.
Automatically selected by protocol.
If the Router ID is not configured manually, the device will automatically select one from the IP address of the current interface as the Router ID. The selection order is:
Priority is given to selecting the largest IP address from Loopback addresses as the Router ID.
If the Loopback interface is not configured, select the largest IP address in the interface address as the Router ID.
After the router runs OSPF and determines the Router ID, If the interface corresponding to the Router ID goes Down or disappears (for example, undo interface loopback loopback number is executed) or a larger IP address appears, OSPF will still maintain the original Router ID. the Router ID will not be re selected until the system Router ID or OSPF Router ID is reconfigured and the OSPF process is restarted.
OSPF is a link state protocol. You can think of a link as an interface to a router. Link state is a description of the interface and the relationship between the interface and adjacent routers. For example, the information of the interface includes the IP address, mask, type of connected network, connected neighbors, etc. The collection of all these link states forms a link state database.
OSPF uses cost "overhead" as the routing metric.
Each interface that activates OSPF has a cost value. OSPF interface cost=100M / interface bandwidth, where 100m is OSPF reference bandwidth.
The cost of an OSPF route is the sum of the cost values of all local incoming interfaces from the origin of the route.
|Message type||Message function|
|Hello message||It is sent periodically to discover and maintain OSPF neighbor relationships.|
|DD message (Database Description packet)||Describes the summary information of the local LSDB (Link State Database), which is used for database synchronization between two devices.|
|LSR message (Link State Request packet)|| |
Used to request the required LSA from the other party.
The equipment will send LSR message to OSPF neighbors only after they successfully exchange DD message.
|LSU message (Link State Update packet)||It is used to send the LSA required by the other party.|
|LSAck message (link state acknowledgement packet)||Used to confirm the received LSA.|
How does OSPF work?
The calculation process of OSPF protocol routing can be briefly described as follows:
- The process of establishing adjacency relationship is as follows:
1. The local device sends Hello message outward through the interface to establish neighbor relationship with the opposite device.
2. The devices at both ends negotiate the master / slave relationship and exchange DD messages.
3. The devices at both ends complete the synchronization of the link database LSDB by updating the LSA.
At this point, the adjacency relationship is established successfully.
OSPF uses SPF (Shortest Path First) algorithm to calculate the route, which can achieve the purpose of rapid route convergence.
Configure ip and gateway for PC
Configuration content of each route
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R1 #Change route name [R1]un in en #Turn off message prompt Info: Information center is disabled. [R1] [R1]int e0/0/0 #Access interface [R1-Ethernet0/0/0]ip add 192.168.1.2 24 #Set ip [R1-Ethernet0/0/0]int e0/0/1 [R1-Ethernet0/0/1]ip add 192.168.2.1 24 [R1-Ethernet0/0/1]q [R1]ospf router-id 184.108.40.206 #Set the marker router ID [R1-ospf-1]area 0 #Access area [R1-ospf-1-area-0.0.0.0]network 192.168.1.2 0.0.0.0 #Announce ip [R1-ospf-1-area-0.0.0.0]network 192.168.2.1 0.0.0.0
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R2 [R2]un in en Info: Information center is disabled. [R2]int e0/0/0 [R2-Ethernet0/0/0]ip add 192.168.2.2 24 [R2-Ethernet0/0/0]int e0/0/1 [R2-Ethernet0/0/1]ip add 192.168.3.1 24 [R2-Ethernet0/0/1]int g0/0/0 [R2-GigabitEthernet0/0/0]ip add 192.168.6.1 24 [R2-GigabitEthernet0/0/0]q [R2]ospf router-id 220.127.116.11 [R2-ospf-1]area 0 [R2-ospf-1-area-0.0.0.0]network 192.168.2.2 0.0.0.0 [R2-ospf-1-area-0.0.0.0]network 192.168.3.1 0.0.0.0 [R2-ospf-1-area-0.0.0.0]area 2 [R2-ospf-1-area-0.0.0.2]network 192.168.6.1 0.0.0.0
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R3 [R3]un in en Info: Information center is disabled. [R3]int e0/0/0 [R3-Ethernet0/0/0]ip add 192.168.3.2 24 [R3-Ethernet0/0/0]int e0/0/1 [R3-Ethernet0/0/1]ip add 192.168.4.1 24 [R3-Ethernet0/0/1]q [R3]ospf router-id 18.104.22.168 [R3-ospf-1]area 0 [R3-ospf-1-area-0.0.0.0]network 192.168.3.2 0.0.0.0 [R3-ospf-1-area-0.0.0.0]area 1 [R3-ospf-1-area-0.0.0.1]network 192.168.4.1 0.0.0.0
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R4 [R4]un in en Info: Information center is disabled. [R4]int e0/0/0 [R4-Ethernet0/0/0]ip add 192.168.4.2 24 [R4-Ethernet0/0/0]int e0/0/1 [R4-Ethernet0/0/1]ip add 192.168.5.1 24 [R4-Ethernet0/0/1]q [R4]ospf router-id 22.214.171.124 [R4-ospf-1]area 1 [R4-ospf-1-area-0.0.0.1]network 192.168.4.2 0.0.0.0 [R4-ospf-1-area-0.0.0.1]network 192.168.5.1 0.0.0.0
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R5 [R5]un in en Info: Information center is disabled. [R5]int e0/0/1 [R5-Ethernet0/0/1]ip add 192.168.7.1 24 [R5-Ethernet0/0/1]int e0/0/0 [R5-Ethernet0/0/0]ip add 192.168.6.2 24 [R5-Ethernet0/0/0]q [R5]ospf router-id 126.96.36.199 [R5-ospf-1]area 2 [R5-ospf-1-area-0.0.0.2]network 192.168.6.2 0.0.0.0 [R5-ospf-1-area-0.0.0.2]network 192.168.7.1 0.0.0.0