10.BFD

BFD

BFD(Bidirectional Forwarding Detection):双向转发检查,是一种快速检测网络链路故障的协议,会定期发送控制报文来检测链路的可用性,一旦检测到链路故障,会立即通知相关设备进行故障切换,从而实现更快的故障检测和链路切换时间。

作用:可以做到毫秒级故障检查,通常结合三层协议(如静态路由、vrrp、ospf、BGP等)实现链路故障快速检查。

静态路由调用BFD

使用静态路由配置两条冗余备份的路由

image-20230927234331743

配置接口IP

[R1]inter gi 0/0/0
[R1-GigabitEthernet0/0/0]ip add 21.1.1.1 30
[R1-GigabitEthernet0/0/0]inter gi 0/0/1
[R1-GigabitEthernet0/0/1]ip add 22.1.1.1 30
[R1-GigabitEthernet0/0/1]inter loop 0
[R1-LoopBack0]ip add 1.1.1.1 32
[R1-LoopBack0]
[R2]inter gi 0/0/0
[R2-GigabitEthernet0/0/0]ip add 21.1.1.2 30
[R2-GigabitEthernet0/0/0]inter gi 0/0/1
[R2-GigabitEthernet0/0/1]ip add 22.1.1.2 30
[R2-GigabitEthernet0/0/1]inter loop 0
[R2-LoopBack0]ip add 2.2.2.2 32
[R2-LoopBack0]

配置静态路由

[R1]ip route-static 2.2.2.2 255.255.255.255 22.1.1.2 pre	
[R1]ip route-static 2.2.2.2 255.255.255.255 22.1.1.2 preference 70
[R2]ip route-static 1.1.1.1 32 22.1.1.1 pre 	
[R2]ip route-static 1.1.1.1 32 22.1.1.1 preference 70

由于不是接口直接相连,若其中一台的接口Down,另一台不会感知到,不会使静态路由失效,如果此时使用BFD进行检测,非直连接口down时,也会使静态路由失效,从而使用备份静态路由进行数据转发。

配置BFD会话的参数和属性

<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]bfd
[R1-bfd]q
[R1]bfd 1 bind peer-ip 21.1.1.2 source-ip 21.1.1.1 auto
[R1-bfd-session-1]commit
[R1-bfd-session-1]q
[R1]bfd 2 bind peer-ip 22.1.1.2 source-ip 22.1.1.1 auto
[R1-bfd-session-2]commit
[R1-bfd-session-2]q
[R1]

手动设置设备的辨识符

discriminator local 1

discriminator remote 1

[R2]bfd
[R2-bfd]q
[R2]bfd 1 bind peer-ip 21.1.1.1 source-ip 21.1.1.2 auto
[R2-bfd-session-1]commit
[R2-bfd-session-1]q
[R2]bfd 2 bind peer-ip 22.1.1.1 source-ip 22.1.1.2 auto
[R2-bfd-session-2]commit
[R2-bfd-session-2]q
[R2]

使BFD会话与静态路由关联起来

[R1]ip route-static 2.2.2.2 255.255.255.255 21.1.1.2 track bfd-session 1
Info: Succeeded in modifying route.
[R1]ip route-static 2.2.2.2 255.255.255.255 22.1.1.2 preference 70 track bfd-session 2
Info: Succeeded in modifying route.
[R1]

[R2]ip route-static 1.1.1.1 255.255.255.255 21.1.1.1 track bfd-session 1
Info: Succeeded in modifying route.	
[R2]ip route-static 1.1.1.1 255.255.255.255 22.1.1.1 preference 70 track bfd-session 2
Info: Succeeded in modifying route.
[R2]

当BFD会话1检测到链路故障时,该静态路由将被自动失效,从而实现快速的故障切换。

查看BFD状态

<R1>dis bfd se all
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  8192       21.1.1.2        Up        S_AUTO_PEER       -                  
8193  8193       22.1.1.2        Up        S_AUTO_PEER       -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 2/0
<R1>dis bfd se all verbose 
--------------------------------------------------------------------------------
Session MIndex : 258       (Multi Hop) State : Up        Name : 1              
--------------------------------------------------------------------------------
  Local Discriminator    : 8192             Remote Discriminator   : 8192      
  Session Detect Mode    : Asynchronous Mode Without Echo Function             
  BFD Bind Type          : Peer IP Address                                     
  Bind Session Type      : Static_Auto                                         
  Bind Peer IP Address   : 21.1.1.2                                            
  Bind Interface         : -                                                   
  Bind Source IP Address : 21.1.1.1                                            
  FSM Board Id           : 0                TOS-EXP                : 7         
  Min Tx Interval (ms)   : 1000             Min Rx Interval (ms)   : 1000      
  Actual Tx Interval (ms): 1000             Actual Rx Interval (ms): 1000      
  Local Detect Multi     : 3                Detect Interval (ms)   : 3000      
  Echo Passive           : Disable          Acl Number             : -         
  Destination Port       : 3784             TTL                    : 253       
  Proc Interface Status  : Disable          Process PST            : Disable   
  WTR Interval (ms)      : -                                                   
  Active Multi           : 3                                                   
  Last Local Diagnostic  : No Diagnostic                                       
  Bind Application       : AUTO 
  Session TX TmrID       : -                Session Detect TmrID   : -         
  Session Init TmrID     : -                Session WTR TmrID      : -         
  Session Echo Tx TmrID  : -                                                   
  PDT Index              : FSM-0 | RCV-0 | IF-0 | TOKEN-0                      
  Session Description    : -                                                   
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Session MIndex : 259       (Multi Hop) State : Up        Name : 2              
--------------------------------------------------------------------------------
  Local Discriminator    : 8193             Remote Discriminator   : 8193      
  Session Detect Mode    : Asynchronous Mode Without Echo Function             
  BFD Bind Type          : Peer IP Address                                     
  Bind Session Type      : Static_Auto                                         
  Bind Peer IP Address   : 22.1.1.2                                            
  Bind Interface         : -                                                   
  Bind Source IP Address : 22.1.1.1                                            
  FSM Board Id           : 0                TOS-EXP                : 7         
  Min Tx Interval (ms)   : 1000             Min Rx Interval (ms)   : 1000      
  Actual Tx Interval (ms): 1000             Actual Rx Interval (ms): 1000      
  Local Detect Multi     : 3                Detect Interval (ms)   : 3000      
  Echo Passive           : Disable          Acl Number             : -         
  Destination Port       : 3784             TTL                    : 253       
  Proc Interface Status  : Disable          Process PST            : Disable   
  WTR Interval (ms)      : -                                                   
  Active Multi           : 3                                                   
  Last Local Diagnostic  : No Diagnostic                                       
  Bind Application       : AUTO 
  Session TX TmrID       : -                Session Detect TmrID   : -         
  Session Init TmrID     : -                Session WTR TmrID      : -         
  Session Echo Tx TmrID  : -                                                   
  PDT Index              : FSM-1 | RCV-0 | IF-0 | TOKEN-0                      
  Session Description    : -                                                   
--------------------------------------------------------------------------------

     Total UP/DOWN Session Number : 2/0
<R1>


<R2>dis bfd se all
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  8192       21.1.1.1        Up        S_AUTO_PEER       -                  
8193  8193       22.1.1.1        Up        S_AUTO_PEER       -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 2/0
<R2>

查看路由

[R1]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        1.1.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack0
        2.2.2.2/32  Static  60   0          RD   21.1.1.2        GigabitEthernet
0/0/0
       21.1.1.0/30  Direct  0    0           D   21.1.1.1        GigabitEthernet
0/0/0
       21.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       21.1.1.3/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       22.1.1.0/30  Direct  0    0           D   22.1.1.1        GigabitEthernet
0/0/1
       22.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
       22.1.1.3/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
	
[R1]dis ip routing-table 2.2.2.2 255.255.255.255 verbose 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 2

Destination: 2.2.2.2/32
     Protocol: Static           Process ID: 0
   Preference: 60                     Cost: 0
      NextHop: 21.1.1.2          Neighbour: 0.0.0.0
        State: Active Adv Relied       Age: 00h04m05s
          Tag: 0                  Priority: medium
        Label: NULL                QoSInfo: 0x0
   IndirectID: 0x80000001       
 RelayNextHop: 0.0.0.0           Interface: GigabitEthernet0/0/0
     TunnelID: 0x0                   Flags: RD

Destination: 2.2.2.2/32
     Protocol: Static           Process ID: 0
   Preference: 70                     Cost: 0
      NextHop: 22.1.1.2          Neighbour: 0.0.0.0
        State: Inactive Adv Relied     Age: 00h04m05s
          Tag: 0                  Priority: medium
        Label: NULL                QoSInfo: 0x0
   IndirectID: 0x80000002       
 RelayNextHop: 0.0.0.0           Interface: GigabitEthernet0/0/1
     TunnelID: 0x0                   Flags: R
[R1]

OSPF 调用BFD加快收敛

撤销静态路由配置,配置OSPF

R1
ospf 1 router-id 1.1.1.1 
 area 0.0.0.0 
  network 1.1.1.1 0.0.0.0 
  network 21.1.1.0 0.0.0.7 
  network 22.1.1.0 0.0.0.7
  
R2
ospf 1 router-id 2.2.2.2 
 area 0.0.0.0 
  network 2.2.2.2 0.0.0.0 
  network 21.1.1.0 0.0.0.7 
  network 22.1.1.0 0.0.0.7

查看OSPF状态

[R2]display ospf interface

	 OSPF Process 1 with Router ID 2.2.2.2
		 Interfaces 

 Area: 0.0.0.0          (MPLS TE not enabled)
 IP Address      Type         State    Cost    Pri   DR              BDR 
 21.1.1.2        Broadcast    DR       1       1     21.1.1.2        21.1.1.1
 22.1.1.2        Broadcast    DR       1       1     22.1.1.2        22.1.1.1
 2.2.2.2         P2P          P-2-P    0       1     0.0.0.0         0.0.0.0
 
[R2]dis ospf peer brief 

	 OSPF Process 1 with Router ID 2.2.2.2
		  Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/0             1.1.1.1          Full        
 0.0.0.0          GigabitEthernet0/0/1             1.1.1.1          Full        
 ----------------------------------------------------------------------------
[R2]

不配置的情况下,OSPF收敛速度很慢

两台路由器R1和R2经过S1彼此互连,并将各自的接口运行于OSPF区域0,由于不是接口直接相连,若其中一台的接口Down,另一台不会立即感知,需要等待4倍的Hello时间来删除邻居,在这段时间内,对应路由不会失效,数据转发都会处于非正常状态。

手动down掉SW1的gi 0/0/2的接口,AR1的路由和OSPF邻居收敛速度很慢

image-20230928210523552

配置OSPF启用BFD

[R1]ospf 1
[R1-ospf-1]bfd all-interfaces enable
[R1-ospf-1]q
[R1]

[R2]ospf 1	
[R2-ospf-1]bfd all-interfaces enable 
[R2-ospf-1]q

dis bfd session all

image-20230928213541825

display ospf bfd session all

image-20230928213039687

down掉SW1的gi 0/0/1口,重新查看ospf的BFD状态

image-20230928213620506

image-20230928213202590

如果开启了debug功能,观察debug日志,会出现如下内容:

image-20230928213907790

BFD 与 VRRP 联动配置实验

配置接口IP和VRRP

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]inter gi 0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.10.2 29
[R1-GigabitEthernet0/0/0]vrrp vrid 1 virtual-ip 192.168.10.1
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]vrrp vrid 1 priority 105
[R1-GigabitEthernet0/0/0]dis vrrp br
Total:1     Master:1     Backup:0     Non-active:0      
VRID  State        Interface                Type     Virtual IP     
----------------------------------------------------------------
1     Master       GE0/0/0                  Normal   192.168.10.1   
[R1-GigabitEthernet0/0/0]
[Huawei]sy R2
[R2]inter gi 0/0/0
[R2-GigabitEthernet0/0/0]ip add 192.168.10.4 29
[R2-GigabitEthernet0/0/0]ip add 192.168.10.3 29
[R2-GigabitEthernet0/0/0]vrrp vrid 1 virtual-ip 192.168.10.1
[R2-GigabitEthernet0/0/0]
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys SW3
[SW3]inter vlanif 1
[SW3-Vlanif1]ip add 192.168.10.4 29
[SW3-Vlanif1]

配置BFD会话

[R1]bfd
[R1-bfd]q
[R1]bfd 1 bind peer-ip 192.168.10.4 source-ip 192.168.10.2 auto 
[R1-bfd-session-1]commit 
[R1-bfd-session-1]q
[R1]
[R2]bfd
[R2-bfd]q
[R2]bfd 2 bind peer-ip 192.168.10.4 source-ip 192.168.10.3 auto 
[R2-bfd-session-2]commit 
[R2-bfd-session-2]q
[R2]

SW3上配置BFD会话信息

[SW3]bfd 1 bind peer-ip 192.168.10.2 source-ip 192.168.10.4 auto 
[SW3-bfd-session-1]commit 
[SW3-bfd-session-1]q
[SW3]bfd 2 bind peer-ip 192.168.10.3 source-ip 192.168.10.4 auto 
[SW3-bfd-session-2]commit
[SW3-bfd-session-2]q
[SW3]

查看bfd会话状态

[R1]dis bfd session all
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  8192       192.168.10.4    Up        S_AUTO_PEER       -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0
[R1]dis bfd session all verbose 
--------------------------------------------------------------------------------
Session MIndex : 256       (Multi Hop) State : Up        Name : 1              
--------------------------------------------------------------------------------
  Local Discriminator    : 8192             Remote Discriminator   : 8192      
  Session Detect Mode    : Asynchronous Mode Without Echo Function             
  BFD Bind Type          : Peer IP Address                                     
  Bind Session Type      : Static_Auto                                         
  Bind Peer IP Address   : 192.168.10.4                                        
  Bind Interface         : -                                                   
  Bind Source IP Address : 192.168.10.2                                        
  FSM Board Id           : 0                TOS-EXP                : 7         
  Min Tx Interval (ms)   : 1000             Min Rx Interval (ms)   : 1000      
  Actual Tx Interval (ms): 1000             Actual Rx Interval (ms): 1000      
  Local Detect Multi     : 3                Detect Interval (ms)   : 3000      
  Echo Passive           : Disable          Acl Number             : -         
  Destination Port       : 3784             TTL                    : 253       
  Proc Interface Status  : Disable          Process PST            : Disable   
  WTR Interval (ms)      : -                                                   
  Active Multi           : 3                                                   
  Last Local Diagnostic  : No Diagnostic                                       
  Bind Application       : AUTO 
  Session TX TmrID       : -                Session Detect TmrID   : -         
  Session Init TmrID     : -                Session WTR TmrID      : -         
  Session Echo Tx TmrID  : -                                                   
  PDT Index              : FSM-0 | RCV-0 | IF-0 | TOKEN-0                      
  Session Description    : -                                                   
--------------------------------------------------------------------------------

     Total UP/DOWN Session Number : 1/0
[R1]

vrrp绑定BFD会话(配置跟踪BFD会话链路状态)

[R1]inter gi 0/0/0
[R1-GigabitEthernet0/0/0]vrrp vrid 1 track bfd-session session-name 1 reduced 10
[R1-GigabitEthernet0/0/0]q
[R1]
[R2]inter gi 0/0/0
[R2-GigabitEthernet0/0/0]vrrp vrid 1 track bfd-session session-name 2 reduced 10
[R2-GigabitEthernet0/0/0]q

检查联动配置

image-20231001175151165

测试配置是否成功

LSW1的gi 0/0/2接口down掉,R1上查看BFD会话状态,R2上查看VRRP状态

image-20231001175851144

image-20231001180135068

image-20231001175906702

posted @ 2023-09-05 23:47  姬雨晨  阅读(107)  评论(0编辑  收藏  举报