【华为】OSPF邻接关系和LSA

网络拓扑

实验任务

  1. 按照要求完成IP地址配置;
  2. 按照要求完成OSPF多区域配置;
  3. 检查OSPF配置结果,检查OSPF邻居关系状态,检查OSPF路由表,检查OSPF LSDB.
  4. 手动修改接口的DR优先级,人工干预OSPF DR、BDR的选举结果。
  5. 在R5上将直连路由引入到OSPF中,在R1上察Type-5LSA。
  6. 单独观察 Type-1 LSA、Type-2 LSA、Type-3 LSA、Type-4 LSA
  7. R1上通过debug观察OSPF LSU、LSAck、LSR报文。

实验步骤

配置互联IP地址和L0 IP地址

以R1路由器配置为例,其他配置方法相同:

java 复制代码
interface GigabitEthernet0/0/0                                                                                                      
 ip address 10.0.123.1 255.255.255.0 

#
interface LoopBack0                                                                                                                 
 ip address 10.0.1.1 255.255.255.255 

#
sysname R1
#
router id 10.0.1.1 

配置OSPF多区域

以R1路由器配置为例,R1路由器G0/0/0接口属于Area 0,L0接口属于Area 2:

java 复制代码
ospf 1 router-id 10.0.1.1                                                                                                           
 area 0.0.0.0                                                                                                                       
  network 10.0.123.1 0.0.0.0                                                                                                        
 area 0.0.0.2                                                                                                                       
  network 10.0.1.1 0.0.0.0 

检查OSPF配置结果

以R1为例,查看OSPF邻居关系、路由表、LSDB

java 复制代码
<R1>display ospf peer brief                                                                                                         
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                  Peer Statistic Information                                                                                        
 ----------------------------------------------------------------------------                                                       
 Area Id          Interface                        Neighbor id      State                                                           
 0.0.0.0          GigabitEthernet0/0/0             10.0.2.2         Full                                                            
 0.0.0.0          GigabitEthernet0/0/0             10.0.3.3         Full                                                            
 0.0.0.0          GigabitEthernet0/0/0             10.0.4.4         Full                                                            
 ---------------------------------------------------------------------------- 

<R1>display ospf interface                                                                                                          
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                 Interfaces                                                                                                         
                                                                                                                                    
 Area: 0.0.0.0          (MPLS TE not enabled)                                                                                       
 IP Address      Type         State    Cost    Pri   DR              BDR                                                            
 10.0.123.1      Broadcast    DR       1       1     10.0.123.1      10.0.123.2                                                     
                                                                                                                                    
 Area: 0.0.0.2          (MPLS TE not enabled)                                                                                       
 IP Address      Type         State    Cost    Pri   DR              BDR                                                            
 10.0.1.1        P2P          P-2-P    0       1     0.0.0.0         0.0.0.0 

从OSPF接口状态可到在R1、R2、R3、R4广播网络中,R1的G0/0/0接口为DR(BDR为R2)。与R2、R3、R4建立邻接关系。

从R3上观察,R3与DR和BDR建立了邻接关系,与R3建立了邻居关系(2-Way)

java 复制代码
<R3>display ospf peer brief                                                                                                         
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.3.3                                                                                     
                  Peer Statistic Information                                                                                        
 ----------------------------------------------------------------------------                                                       
 Area Id          Interface                        Neighbor id      State                                                           
 0.0.0.0          GigabitEthernet0/0/0             10.0.1.1         Full                                                            
 0.0.0.0          GigabitEthernet0/0/0             10.0.2.2         Full                                                            
 0.0.0.0          GigabitEthernet0/0/0             10.0.4.4         2-Way                                                           
 ---------------------------------------------------------------------------- 

在R4上查看LSDB

java 复制代码
<R4>display ospf lsdb                                                                                                               
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.4.4                                                                                     
                 Link State Database                                                                                                
                                                                                                                                    
                         Area: 0.0.0.0                                                                                              
 Type      LinkState ID    AdvRouter          Age  Len   Sequence   Metric                                                          
 Router    10.0.3.3        10.0.3.3           375  48    80000007       0                                                           
 Router    10.0.4.4        10.0.4.4           375  48    80000005       0                                                           
 Router    10.0.2.2        10.0.2.2           377  48    80000008       0                                                           
 Router    10.0.1.1        10.0.1.1           377  36    8000000A       1                                                           
 Network   10.0.123.1      10.0.1.1           377  40    80000006       0                                                           
 Sum-Net   10.0.1.1        10.0.1.1           492  28    80000001       0                                                           
 Sum-Net   10.0.45.0       10.0.4.4           370  28    80000001       1                                                           
                                                                                                                                    
                         Area: 0.0.0.1                                                                                              
 Type      LinkState ID    AdvRouter          Age  Len   Sequence   Metric                                                          
 Router    10.0.5.5        10.0.5.5           308  36    80000004       1                                                           
 Router    10.0.4.4        10.0.4.4           308  36    80000004       1                                                           
 Network   10.0.45.2       10.0.5.5           308  32    80000002       0                                                           
 Sum-Net   10.0.3.3        10.0.4.4           370  28    80000001       1                                                           
 Sum-Net   10.0.2.2        10.0.4.4           370  28    80000001       1                                                           
 Sum-Net   10.0.1.1        10.0.4.4           370  28    80000001       1                                                           
 Sum-Net   10.0.4.4        10.0.4.4           370  28    80000001       0                                                           
 Sum-Net   10.0.123.0      10.0.4.4           370  28    80000001       1 

查看OSPF路由表

java 复制代码
<R4>display ospf routing                                                                                                            
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.4.4                                                                                     
                  Routing Tables                                                                                                    
                                                                                                                                    
 Routing for Network                                                                                                                
 Destination        Cost  Type       NextHop         AdvRouter       Area                                                           
 10.0.4.4/32        0     Stub       10.0.4.4        10.0.4.4        0.0.0.0                                                        
 10.0.45.0/30       1     Transit    10.0.45.1       10.0.4.4        0.0.0.1                                                        
 10.0.123.0/24      1     Transit    10.0.123.4      10.0.4.4        0.0.0.0                                                        
 10.0.1.1/32        1     Inter-area 10.0.123.1      10.0.1.1        0.0.0.0                                                        
 10.0.2.2/32        1     Stub       10.0.123.2      10.0.2.2        0.0.0.0                                                        
 10.0.3.3/32        1     Stub       10.0.123.3      10.0.3.3        0.0.0.0                                                        
                                                                                                                                    
 Total Nets: 6                                                                                                                      
 Intra Area: 5  Inter Area: 1  ASE: 0  NSSA: 0                           

修改DR优先级

干预广播网络中DR和BDR的选举。

  • 修改R4路由器G0/0/0接口DR优先级为255、修改R3路由器G0/0/0接口DR优先级为254;
  • 修改R2路由器G0/0/0接口DR优先级为0,不参与DR选举;
java 复制代码
# R4
interface GigabitEthernet0/0/0                                                                                                      
 ip address 10.0.123.4 255.255.255.0                                                                                                
 ospf dr-priority 255

# R3
interface GigabitEthernet0/0/0                                                                                                      
 ip address 10.0.123.3 255.255.255.0                                                                                                
 ospf dr-priority 254  

# R2
interface GigabitEthernet0/0/0                                                                                                      
 ip address 10.0.123.2 255.255.255.0                                                                                                
 ospf dr-priority 0   

由于OSPF DR为不可抢占(ENSP测试如果将DR的接口权限修改为0,其他路由器会重新选举DR),需要重启接口或OSPF进程重新选举。

java 复制代码
reset ospf 1 process

重启后查看DR和BDR,可以看到R1与R3和R4建立邻接关系,此时R4为DR、R3为BDR

java 复制代码
<R1>display ospf peer b                                                                                                             
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                  Peer Statistic Information                                                                                        
 ----------------------------------------------------------------------------                                                       
 Area Id          Interface                        Neighbor id      State                                                           
 0.0.0.0          GigabitEthernet0/0/0             10.0.2.2         2-Way                                                           
 0.0.0.0          GigabitEthernet0/0/0             10.0.3.3         Full                                                            
 0.0.0.0          GigabitEthernet0/0/0             10.0.4.4         Full                                                            
 ---------------------------------------------------------------------------

<R1>display ospf interface                                                                                                          
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                 Interfaces                                                                                                         
                                                                                                                                    
 Area: 0.0.0.0          (MPLS TE not enabled)                                                                                       
 IP Address      Type         State    Cost    Pri   DR              BDR                                                            
 10.0.123.1      Broadcast    DROther  1       1     10.0.123.4      10.0.123.3                                                     
                                                                                                                                    
 Area: 0.0.0.2          (MPLS TE not enabled)                                                                                       
 IP Address      Type         State    Cost    Pri   DR              BDR                                                            
 10.0.1.1        P2P          P-2-P    0       1     0.0.0.0         0.0.0.0    

引入直连路由

在R5上将L0接口路由引入OSPF,引入时进行了路由过滤只引入L0接口路由。

java 复制代码
acl number 2000                                                                                                                     
 rule 5 permit source 10.0.5.5 0 

ospf 1 router-id 10.0.5.5                                                                                                           
 filter-policy 2000 export                                                                                                          
 import-route direct 

在R1上查看外部路由信息

java 复制代码
<R1>display ospf routing                                                                                                            
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                  Routing Tables                                                                                                    
                                                                                                                                    
 Routing for Network                                                                                                                
 Destination        Cost  Type       NextHop         AdvRouter       Area                                                           
 10.0.1.1/32        0     Stub       10.0.1.1        10.0.1.1        0.0.0.2                                                        
 10.0.123.0/24      1     Transit    10.0.123.1      10.0.1.1        0.0.0.0                                                        
 10.0.2.2/32        1     Stub       10.0.123.2      10.0.2.2        0.0.0.0                                                        
 10.0.3.3/32        1     Stub       10.0.123.3      10.0.3.3        0.0.0.0                                                        
 10.0.4.4/32        1     Stub       10.0.123.4      10.0.4.4        0.0.0.0                                                        
 10.0.45.0/30       2     Inter-area 10.0.123.4      10.0.4.4        0.0.0.0                                                        
                                                                                                                                    
 Routing for ASEs                                                                                                                   
 Destination        Cost      Type       Tag         NextHop         AdvRouter                                                      
 10.0.5.5/32        1         Type2      1           10.0.123.4      10.0.5.5                                                       
                                                                                                                                    
 Total Nets: 7                                                                                                                      
 Intra Area: 5  Inter Area: 1  ASE: 1  NSSA: 0                                

查看Type-5 LSA

java 复制代码
<R1>display ospf lsdb ase                                                                                                           
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                 Link State Database                                                                                                
                                                                                                                                    
                                                                                                                                    
  Type      : External                                                                                                              
  Ls id     : 10.0.5.5                                                                                                              
  Adv rtr   : 10.0.5.5                                                                                                              
  Ls age    : 253                                                                                                                   
  Len       : 36                                                                                                                    
  Options   :  E                                                                                                                    
  seq#      : 80000001                                                                                                              
  chksum    : 0x7731                                                                                                                
  Net mask  : 255.255.255.255                                                                                                       
  TOS 0  Metric: 1                                                                                                                  
  E type    : 2                                                                                                                     
  Forwarding Address : 0.0.0.0                                                                                                      
  Tag       : 1                                                                                                                     
  Priority  : Medium                  

Type-5 LSA说明:

  • Ls id:外部路由的目的网络
  • Adv rtr:通告这条LSA的Router ID
  • Net mask:网络掩码

!CAUTION

在同一区域内路由器通过Type-5LSA得知这条外部路由可以通过R5到达,通过R5路由器在自己的Router LSA也描述了自己是ASBR。

但是不同区域路由器不知道R5这台路由器如何到达(Router LSA只在本区域内泛洪),怎么计算路由?

根据5类LSA,R3判断5类LSA是由R5产生,但是在R3的SPF树干中并不存在R5。

当区域内有ASBR时ABR会产生一条Type-4 LSA,描述ABR到ASBR信息。

根据R4生成的4类LSA,R3将到达外部网络的下一跳路由器设置为R4.

java 复制代码
<R3>display ospf lsdb asbr                                                                                                          
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.3.3                                                                                     
                         Area: 0.0.0.0                                                                                              
                 Link State Database                                                                                                
                                                                                                                                    
                                                                                                                                    
  Type      : Sum-Asbr                                                                                                              
  Ls id     : 10.0.5.5                                                                                                              
  Adv rtr   : 10.0.4.4                                                                                                              
  Ls age    : 1242                                                                                                                  
  Len       : 28                                                                                                                    
  Options   :  E                                                                                                                    
  seq#      : 80000001                                                                                                              
  chksum    : 0xec48                                                                                                                
  Tos 0  metric: 1      

<R1>display ospf routing                                                                                                            
                                                                                                                                    
         OSPF Process 1 with Router ID 10.0.1.1                                                                                     
                  Routing Tables                                                                                                    
                                                                                                                                    
 Routing for Network                                                                                                                
 Destination        Cost  Type       NextHop         AdvRouter       Area                                                           
 10.0.1.1/32        0     Stub       10.0.1.1        10.0.1.1        0.0.0.2                                                        
 10.0.123.0/24      1     Transit    10.0.123.1      10.0.1.1        0.0.0.0                                                        
 10.0.2.2/32        1     Stub       10.0.123.2      10.0.2.2        0.0.0.0                                                        
 10.0.3.3/32        1     Stub       10.0.123.3      10.0.3.3        0.0.0.0                                                        
 10.0.4.4/32        1     Stub       10.0.123.4      10.0.4.4        0.0.0.0                                                        
 10.0.45.0/30       2     Inter-area 10.0.123.4      10.0.4.4        0.0.0.0                                                        
                                                                                                                                    
 Routing for ASEs                                                                                                                   
 Destination        Cost      Type       Tag         NextHop         AdvRouter                                                      
 10.0.5.5/32        1         Type2      1           10.0.123.4      10.0.5.5                                                       
                                                                                                                                    
 Total Nets: 7                                                                                                                      
 Intra Area: 5  Inter Area: 1  ASE: 1  NSSA: 0                                              

观察LSR、LSU、LSAck报文

java 复制代码
<R1>terminal debugging                                                                                                              
Info: Current terminal debugging is on.                                                                                                                                                                                                               
<R1>terminal monitor                                                                                                                
Info: Current terminal monitor is on.

<R1>debugging ospf packet request   
<R1>debugging ospf packet update
<R1>debugging ospf packet ack

<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.1-08:00 R1 RM/6/RMDEBUG:                                                                                   
 FileID: 0xd0178024 Line: 2236 Level: 0x20                                                                                          
 OSPF 1: RECV Packet. Interface: GigabitEthernet0/0/0                                                                               
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.2-08:00 R1 RM/6/RMDEBUG:  Source Address: 10.0.123.4                                                       
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.3-08:00 R1 RM/6/RMDEBUG:  Destination Address: 224.0.0.5                                                   
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.4-08:00 R1 RM/6/RMDEBUG:  Ver# 2, Type: 4 (Link-State Update)                                              
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.5-08:00 R1 RM/6/RMDEBUG:  Length: 84, Router: 10.0.4.4                                                     
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.6-08:00 R1 RM/6/RMDEBUG:  Area: 0.0.0.0, Chksum: 2134                                                      
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.7-08:00 R1 RM/6/RMDEBUG:  AuType: 00                                                                       
<R1>                                                                                                                                
Jun  3 2026 09:44:44.352.8-08:00 R1 RM/6/RMDEBUG:  Key(ascii): * * * * * * * *      

拓展

5类的LSA就一定会有4类LSA吗?不一定、只有一个区域的情况下没有4类LSA。

4类的LSA就一定会有5类LSA吗?也不一定,执行了import命令即为ASBR,但是不一定会产生5类LSA。

相关推荐
李二。1 小时前
鸿蒙原生ArkTS-太空探索新闻AI
人工智能·华为·harmonyos
慧海灵舟2 小时前
鸿蒙南向开发教程 Day 7:互斥锁(Mutex)
华为·harmonyos
●VON2 小时前
鸿蒙Flutter实战:IndexedStack保持Tab页面状态
flutter·华为·harmonyos·鸿蒙
条tiao条2 小时前
鸿蒙 ArkTS 多线程完全指南:告别 UI 卡顿,从 TaskPool 到 Worker
ui·华为·harmonyos
周胡杰2 小时前
HarmonyOS 手表端翻腕触发交互实现:基于陀螺仪的两段式手势识别
华为·交互·harmonyos
枫叶丹42 小时前
【HarmonyOS 6.0】Map Kit 进阶:基于 MVT 矢量图层的动态地图数据叠加方案
开发语言·华为·harmonyos
2601_961194022 小时前
27考研刘晓燕资源
linux·sql·ubuntu·华为·pdf·.net
yuegu77713 小时前
HarmonyOS应用<节气通>开发第2篇:首页开发(上)——Tabs架构与骨架搭建
华为·harmonyos
程序猿追17 小时前
HarmonyOS——模拟器上写个扫雷的夜晚
华为·harmonyos