OSPF experiment and configuration - super detailed

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

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.

Link status
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 typeMessage function
Hello messageIt 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:

  1. 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.

Routing calculation
OSPF uses SPF (Shortest Path First) algorithm to calculate the route, which can achieve the purpose of rapid route convergence.


Topological graph

Experimental steps:

Configure ip and gateway for PC



Configuration content of each route


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]int e0/0/0                     #Access interface
[R1-Ethernet0/0/0]ip add 24 #Set ip
[R1-Ethernet0/0/0]int e0/0/1
[R1-Ethernet0/0/1]ip add 24
[R1]ospf router-id        #Set the marker router ID
[R1-ospf-1]area 0                 #Access area
[R1-ospf-1-area-]network  #Announce ip


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 24
[R2-Ethernet0/0/0]int e0/0/1
[R2-Ethernet0/0/1]ip add 24
[R2-Ethernet0/0/1]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 24
[R2]ospf router-id
[R2-ospf-1]area 0
[R2-ospf-1-area-]area 2


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 24
[R3-Ethernet0/0/0]int e0/0/1
[R3-Ethernet0/0/1]ip add 24
[R3]ospf router-id
[R3-ospf-1]area 0
[R3-ospf-1-area-]area 1


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 24
[R4-Ethernet0/0/0]int e0/0/1
[R4-Ethernet0/0/1]ip add 24
[R4]ospf router-id
[R4-ospf-1]area 1


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 24
[R5-Ethernet0/0/1]int e0/0/0
[R5-Ethernet0/0/0]ip add 24
[R5]ospf router-id
[R5-ospf-1]area 2

Keywords: network Network Protocol p2p

Added by chuckjones on Thu, 23 Dec 2021 05:41:34 +0200