OSPF basics and simple experiments

definition:     

  OSPF (Open Shortest Path First ) is an Interior Gateway Protocol (IGP) for routing decisions within a single autonomous system (AS). It is an implementation of the link state routing protocol , which belongs to the interior gateway protocol (IGP), so it operates inside the autonomous system. The famous Dijkstra's algorithm is used to calculate the shortest path tree . OSPF supports load balancing and route selection based on service types, and also supports multiple routing forms, such as specific host routing and subnet routing.

working principle:

        OSPF simply means that two adjacent routers become neighbors by sending messages, and the neighbors send link state information to each other to form an adjacency, and then each calculates the route according to the shortest path algorithm, puts it in the OSPF routing table, and OSPF routes Compared with other routes, the best ones are added to the global routing table. The whole process uses five messages, three stages, and four tables.

five messages

  • Hello packet: establishes and maintains a neighbor relationship.
  • DBD message: Send link state header information.
  • LSR message: Send the required link state header information from the DBD to neighbors and request complete information.
  • LSU message: Send the complete information corresponding to the header information requested by the LSR to the neighbor.
  • LSACK: Acknowledge the message after receiving the LSU message.

three phases

  • Neighbor discovery: A neighbor relationship is established by sending Hello packets.
  • Route notification: Neighbors send link state information to form adjacencies.
  • Routing calculation: Calculate the routing table according to the shortest path algorithm.

four tables

  • Neighbor Table: Main records form neighbor relationship routers.
  • Link state database: records link state information.
  • OSPF routing table: derived from the link state database.
  • Global Routing Table: Compare OSPF routes with others.

work process:

(1) Know your own link

Each router knows about its own links, the networks it is directly connected to.

(2) Looking for neighbors

Different from RIP, OSPF does not immediately broadcast routing information to the network after running, but first searches for peripheral routers in the network that can exchange link state information with itself. Routers that can exchange link state information are neighbors.

(3) Create a link state packet

Once a router has established a neighbor relationship, it can create link-state packets.

(4) Link state information transmission

The router floods the LSA describing the link state to the neighbors, and finally forms a link state database containing the complete link state information of the network.

(5) Calculation route

Each router in the routing area can use the SPF algorithm to calculate routes independently.

experiment:

 PC1:

PC2:

PC3:

 Router R1:

<Huawei>system-view   //进入系统试图
[Huawei]sysname R1    //更改名字
[R1]undo info-center enable   //关闭信息中心功能
[R1]int g0/0/0   //进入接口
[R1-GigabitEthernet0/0/0]ip add 192.168.1.2 30   //配置IP地址
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 192.168.2.1 30
[R1-GigabitEthernet0/0/1]display ip interface brief   //查看端口IP简要状态信息
[R1-GigabitEthernet0/0/1]quit
[R1]
[R1]ospf router-id 1.1.1.1
[R1-ospf-1]area 0   //设置area区域为0
[R1-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.3
[R1-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.3
[R1-ospf-1-area-0.0.0.0]quit
[R1-ospf-1]quit 
[R1]quit 
<R1>save 

Router R2:

<Huawei>system-view
[Huawei]sysname R2
[R2]undo info-center enable 
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 192.168.2.2 30
[R2-GigabitEthernet0/0/1]int g0/0/2
[R2-GigabitEthernet0/0/2]ip add 192.168.3.1 30
[R2-GigabitEthernet0/0/2]int g0/0/3
[R2-GigabitEthernet0/0/3]ip add 192.168.6.1 30
[R2-GigabitEthernet0/0/3]display ip interface brief 
[R2-GigabitEthernet0/0/3]quit
[R2]
[R2]ospf router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.3
[R2-ospf-1-area-0.0.0.0]network 192.168.3.0 0.0.0.3
[R2-ospf-1-area-0.0.0.0]area 2
[R2-ospf-1-area-0.0.0.2]network 192.168.6.0 0.0.0.3
[R2-ospf-1-area-0.0.0.2]quit
[R2-ospf-1]quit
[R2]quit
<R2>save

 Router R3:

<Huawei>system-view
[Huawei]sysname R3
[R3]undo info-center enable 
[R3]int g0/0/2
[R3-GigabitEthernet0/0/2]ip add 192.168.3.2 30
[R3-GigabitEthernet0/0/2]int g0/0/1
[R3-GigabitEthernet0/0/1]ip add 192.168.4.1 30
[R3-GigabitEthernet0/0/1]display ip interface brief  
[R3-GigabitEthernet0/0/1]quit
[R3]
[R3]ospf router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 192.168.3.0 0.0.0.3
[R3-ospf-1-area-0.0.0.0]area 1
[R3-ospf-1-area-0.0.0.1]network 192.168.4.0 0.0.0.3
[R3-ospf-1-area-0.0.0.1]quit
[R3-ospf-1]quit
[R3]quit
<R3>save

 Router R4:

<Huawei>system-view
[Huawei]sysname R4
[R4]undo info-center enable 
[R4]int g0/0/1
[R4-GigabitEthernet0/0/1]ip add 192.168.4.2 30
[R4-GigabitEthernet0/0/1]int g0/0/0
[R4-GigabitEthernet0/0/0]ip add 192.168.5.2 30
[R4-GigabitEthernet0/0/0]display ip interface brief   
[R4-GigabitEthernet0/0/0]quit
[R4]
[R4]ospf router-id 4.4.4.4
[R4-ospf-1]area 1
[R4-ospf-1-area-0.0.0.1]network 192.168.4.0 0.0.0.3
[R4-ospf-1-area-0.0.0.1]network 192.168.5.0 0.0.0.3
[R4-ospf-1-area-0.0.0.1]quit
[R4-ospf-1]quit
[R4]quit
<R4>save

 Router R5:

<Huawei>system-view
[Huawei]sysname R5
[R5]undo info-center enable 
[R5]int g0/0/3
[R5-GigabitEthernet0/0/3]ip add 192.168.6.2 30
[R5-GigabitEthernet0/0/3]int g0/0/0
[R5-GigabitEthernet0/0/0]ip add 192.168.7.2 30
[R5-GigabitEthernet0/0/0]display ip interface brief    
[R5-GigabitEthernet0/0/0]quit
[R5]
[R5]ospf router-id 5.5.5.5
[R5-ospf-1]area 2
[R5-ospf-1-area-0.0.0.2]network 192.168.6.0 0.0.0.3
[R5-ospf-1-area-0.0.0.2]network 192.168.7.0 0.0.0.3
[R5-ospf-1-area-0.0.0.2]quit
[R5-ospf-1]quit
[R5]quit
<R5>save

Go to ping to see the final result:

PC1 goes to ping PC2 and PC3

PC3 to ping PC2

 

Guess you like

Origin blog.csdn.net/zhao__b/article/details/122093057