BFD技術的全面解析

BFD出現的技術背景

BFD技術的全面解析
RTA和RTD建立了OSPF鄰接關係,Hello包發送週期爲10秒;當交換機SWB與SWC鏈路物理中斷,路由器RTA和RTD無法感知,需要等待OSPF協議鄰居失效計時器超時後纔會中斷鄰接關係
BFD技術的全面解析
SWA和SWB啓用了VRRP協議,實現了主備網關的作用,SWB爲主用網關。
當出口路由器RTB與外網Router的鏈路中斷,SWB雖然可以通過動態路由協議感知,但是無法聯動連接下游的網關接口,且繼續爲主網關。
用戶的數據流還是發送到SWB,SWB再通過三層路由轉發給SWA,最後由RTA出口。雖然結果不至於造成業務中斷,但是會產生次優路徑。

BFD的實現原理

一種全網統一、檢測迅速、監控網絡中鏈路或者IP路由的雙向轉發連通狀況,併爲上層應用提供服務的技
BFD技術的全面解析
BFD會話建立後會週期性地快速發送BFD報文,如果在檢測時間內沒有收到對端BFD報文則認爲該雙向轉發路徑發生了故障,通知被服務的相關層應用進行相應的處理。
本身並沒有鄰居發現機制,而是靠被服務的上層應用通知其鄰居信息以建立會話。
不管是物理接口狀態、二層鏈路狀態、網絡層地址可達性、還是傳輸層連接狀態、應用層協議運行狀態,都可以被BFD感知到

BFD會話的檢測機制

BFD技術的全面解析
BFD建立會話存在標識符的概念,類似於OSPF建立鄰居需要一個路由器的Router ID。
標識符分爲本地標識符和遠端標識符,本地標識符用於表示本端設備,遠端標識符用於表示對端設備。
靜態建立BFD會話是指通過命令行手工配置BFD會話參數,包括配置本地標識符和遠端標識符等,然後手工下發BFD會話建立請求。
動態建立BFD會話是指由應用程序觸發創建BFD會話,當應用程序動態觸發創建BFD會話時,系統分配屬於動態會話標識符區域的值作爲BFD會話的本地標識符。然後向對端發送Remote Discriminator的值爲0的BFD控制報文,進行會話協商。當BFD會話的一端收到Remote Discriminator的值爲0的BFD控制報文時,判斷該報文是否與本地BFD會話匹配,如果匹配,則學習接收到的BFD報文中Local Discriminator的值,獲取遠端標識符。

BFD的檢測機制是兩個系統建立BFD會話,並沿它們之間的路徑週期性發送BFD控制報文,如果一方在既定的時間內沒有收到BFD控制報文,則認爲路徑上發生了故障,BFD控制報文是UDP報文,端口號3784。
BFD提供異步檢測模式。在這種模式下,系統之間相互週期性地發送BFD控制報文,如果某個系統連續3個報文都沒有接收到,就認爲此BFD會話的狀態是Down

BFD的狀態機

BFD技術的全面解析
RTA和RTB各自啓動BFD狀態機,初始狀態爲Down,發送狀態爲Down的BFD報文。對於靜態配置BFD會話,報文中的Remote Discriminator的值是用戶指定的;對於動態創建BFD會話,Remote Discriminator的值是0。
RTB收到狀態爲Down的BFD報文後,狀態切換至Init,併發送狀態爲Init的BFD報文。
RTB本地BFD狀態爲Init後,不再處理接收到的狀態爲Down的報文。
RTB收到狀態爲Init的BFD報文後,本地狀態切換至Up。
RTA的BFD狀態變化同RTB。
鄰居會話建立成功後,RTA和RTB週期性的向對方發送狀態爲Up的控制報文。

BFD的配置

OSPF協議聯動BFD協議

BFD技術的全面解析
某公司通過兩臺二層交換機作爲中繼將兩個相距較遠的部門連接。RTA、RTD上運行OSPF,建立OSPF鄰居關係,保證網絡層相互可達。
已知RTA、RTB都支持BFD功能,要求使用OSPF與BFD聯動技術,採用BFD控制報文方式實現當RTA或RTB與二層交換機之間以及二層交換機之間的鏈路出現故障(如鏈路down)時,BFD能夠快速感知並通告OSPF協議。
BFD技術的全面解析

RA的配置文件

#
 sysname RA
#
bfd
#
interface GigabitEthernet0/0/1
 ip address 10.0.12.1 255.255.255.0 
#
ospf 1 
 bfd all-interfaces enable
 area 0.0.0.0 
  network 10.0.12.0 0.0.0.255 
#

RD的配置文件

#
 sysname RD
#
interface GigabitEthernet0/0/1
 ip address 10.0.12.2 255.255.255.0 
#
Bfd
#
ospf 1 
 bfd all-interfaces enable
 area 0.0.0.0 
  network 10.0.12.0 0.0.0.255 
#

檢查RTA的OSPF鄰居關係

[RA]display ospf peer brief 

     OSPF Process 1 with Router ID 10.0.12.1
          Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/1             10.0.12.2        Full        
 ----------------------------------------------------------------------------   

檢查RTA的BFD狀態

[RA]display bfd session all 
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  8192       10.0.12.2       Up        D_IP_IF     GigabitEthernet0/0/1     
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0
[RA]

把SWB和SWC之間的鏈路shutdown一下

[SW1-GigabitEthernet0/0/2]shutdown

在RA上面進行查看

彈出的一些日誌信息

Sep 28 2019 17:04:18-08:00 RA %%01BFD/4/STACHG_TODWN(l)[8]:BFD session changed t
o Down. (SlotNumber=0, Discriminator=2097152, Diagnostic=DetectDown, Application
s=OSPF, ProcessPST=False, BindInterfaceName=GigabitEthernet0/0/1, InterfacePhysi
calState=Up, InterfaceProtocolState=Up) 

Sep 28 2019 17:04:18-08:00 RA %%01OSPF/3/NBR_CHG_DOWN(l)[9]:Neighbor event:neigh
bor state changed to Down. (ProcessId=256, NeighborAddress=2.12.0.10, NeighborEv
ent=KillNbr, NeighborPreviousState=Full, NeighborCurrentState=Down) 

Sep 28 2019 17:04:18-08:00 RA %%01OSPF/3/NBR_DOWN_REASON(l)[10]:Neighbor state l
eaves full or changed to Down. (ProcessId=256, NeighborRouterId=2.12.0.10, Neigh
borAreaId=0, NeighborInterface=GigabitEthernet0/0/1,NeighborDownImmediate reason
=Neighbor Down Due to Kill Neighbor, NeighborDownPrimeReason=BFD Session Down, N
eighborChangeTime=2019-09-28 17:04:18-08:00) 

查看BFD的會話信息

[RA]display bfd session all
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  0          10.0.12.2       Down      D_IP_IF     GigabitEthernet0/0/1     
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 0/1

查看OSPF的鄰居狀態信息

[RA]display ospf peer brief 

     OSPF Process 1 with Router ID 10.0.12.1
          Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 ----------------------------------------------------------------------------

總結:

中間的鏈路故障,BFD通過監測模塊進行檢測,然後交給track模塊,由追蹤模塊交給應用模塊,也就是OSPF進程進行處理

VRRP聯動BFD協議

BFD技術的全面解析
VRRP的配置參考上面

#
Bfd         //全局啓動BFD協議
#
bfd 1 bind peer-ip 10.0.24.2 source-ip 10.0.45.5 auto       //因爲當中沒有任何動態路由協議 所以需要手動指定鄰居的IP地址和自己的IP地址   後面的auto就是讓其動態產生本地標識符
commit                  //有一些交換機裏面需要commit一下bfd的配置

進行查看BFD的會話

<RA>display bfd session all 
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8195  8194       10.0.12.2       Up        D_IP_IF     GigabitEthernet0/0/1     
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0
<RA>

BFD技術的全面解析

RA的配置文件

#
 sysname RA
#
interface GigabitEthernet0/0/0
 ip address 13.1.1.1 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 10.0.0.1 255.255.255.0 
 vrrp vrid 1 virtual-ip 10.0.0.10
 vrrp vrid 1 priority 120
 vrrp vrid 1 preempt-mode timer delay 20
 vrrp vrid 1 track interface GigabitEthernet0/0/0 reduced 30
 vrrp vrid 1 track bfd-session session-name 1 reduced 30
#
bfd 1 bind peer-ip 13.1.1.3 source-ip 13.1.1.1 auto
 commit
#
ip route-static 3.3.3.3 255.255.255.255 13.1.1.3
#

RB的配置文件

#
 sysname RB
#
interface GigabitEthernet0/0/0
 ip address 23.1.1.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 10.0.0.2 255.255.255.0 
 vrrp vrid 1 virtual-ip 10.0.0.10
#
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
#

RC的配置文件

#
 sysname RC
#
interface GigabitEthernet0/0/0
 ip address 13.1.1.3 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 23.1.1.3 255.255.255.0 
#
interface LoopBack0
 ip address 3.3.3.3 255.255.255.255 
#
bfd 1 bind peer-ip 13.1.1.1 source-ip 13.1.1.3 auto
 commit
#
ip route-static 10.0.0.0 255.255.255.0 13.1.1.1
ip route-static 10.0.0.0 255.255.255.0 23.1.1.2
#

檢查bfd的狀態

[RA]display bfd session all 
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  8192       13.1.1.3        Up        S_AUTO_PEER       -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 1/0

檢查VRRP的狀態

[RA]display vrrp
  GigabitEthernet0/0/1 | Virtual Router 1
    State : Master
    Virtual IP : 10.0.0.10
    Master IP : 10.0.0.1
    PriorityRun : 120
    PriorityConfig : 120
    MasterPriority : 120
    Preempt : YES   Delay Time : 20 s
    TimerRun : 1 s
    TimerConfig : 1 s
    Auth type : NONE
    Virtual MAC : 0000-5e00-0101
    Check TTL : YES
    Config type : normal-vrrp
    Backup-forward : disabled
    Track IF : GigabitEthernet0/0/0   Priority reduced : 30
    IF state : UP
    Track BFD : 1  Priority reduced : 30
    BFD-session state : UP
    Create time : 2019-09-28 17:15:24 UTC-08:00
    Last change time : 2019-09-28 17:26:50 UTC-08:00

在PC上面路由追蹤一下

PC>tracert 3.3.3.3

traceroute to 3.3.3.3, 8 hops max
(ICMP), press Ctrl+C to stop
 1  10.0.0.1   63 ms  46 ms  47 ms
 2  3.3.3.3   63 ms  62 ms  47 ms

在交換機上面關閉一下接口

[SW3-GigabitEthernet0/0/1]shutdown

在RA上查看如下信息

[RA]
Sep 28 2019 17:34:22-08:00 RA %%01BFD/4/STACHG_TODWN(l)[16]:BFD session changed 
to Down. (SlotNumber=0, Discriminator=2097152, Diagnostic=DetectDown, Applicatio
ns=VRRP | AUTO, ProcessPST=False, BindInterfaceName=None, InterfacePhysicalState
=None, InterfaceProtocolState=None) 
[RA]
Sep 28 2019 17:34:22-08:00 RA VRRP/2/VRRPMASTERDOWN:OID 16777216.50331648.100663
296.16777216.67108864.16777216.3674669056.83886080.419430400.2130706432.33554432
.503316480.16777216 The state of VRRP changed from master to other state. (VrrpI
fIndex=67108864, VrId=16777216, IfIndex=67108864, IPAddress=1.1.1.13, NodeName=R
A, IfName=GigabitEthernet0/0/1, CurrentState=Backup, ChangeReason=priority calcu
lation) 
[RA]
Sep 28 2019 17:34:22-08:00 RA %%01VRRP/4/STATEWARNINGEXTEND(l)[17]:Virtual Route
r state MASTER changed to BACKUP, because of priority calculation. (Interface=Gi
gabitEthernet0/0/1, VrId=16777216, InetType=IPv4) 
[RA]

查看BFD的狀態

[RA]display bfd session all 
--------------------------------------------------------------------------------
Local Remote     PeerIpAddr      State     Type        InterfaceName            
--------------------------------------------------------------------------------

8192  0          13.1.1.3        Down      S_AUTO_PEER       -                  
--------------------------------------------------------------------------------
     Total UP/DOWN Session Number : 0/1

查看VRRP的狀態

[RA]display vrrp
  GigabitEthernet0/0/1 | Virtual Router 1
    State : Backup
    Virtual IP : 10.0.0.10
    Master IP : 10.0.0.2
    PriorityRun : 90
    PriorityConfig : 120
    MasterPriority : 100
    Preempt : YES   Delay Time : 20 s
    TimerRun : 1 s
    TimerConfig : 1 s
    Auth type : NONE
    Virtual MAC : 0000-5e00-0101
    Check TTL : YES
    Config type : normal-vrrp
    Backup-forward : disabled
    Track IF : GigabitEthernet0/0/0   Priority reduced : 30
    IF state : UP
    Track BFD : 1  Priority reduced : 30
    BFD-session state : DOWN
    Create time : 2019-09-28 17:15:24 UTC-08:00
    Last change time : 2019-09-28 17:34:22 UTC-08:00

在PC上面路由追蹤一下

PC>tracert 3.3.3.3

traceroute to 3.3.3.3, 8 hops max
(ICMP), press Ctrl+C to stop
 1  10.0.0.2   47 ms  47 ms  47 ms
 2  3.3.3.3   46 ms  47 ms  47 ms

PC>

單臂回聲

BFD技術的全面解析
單臂回聲功能:
是指通過BFD報文的環回操作檢測轉發鏈路的連通性。
兩臺直接相連的設備中RTA和RTB,其中一臺設備RTA支持BFD功能,另一臺設備RTB不支持BFD功能,只支持基本的網絡層轉發。爲了能夠快速的檢測這兩臺設備之間的故障,可以在支持BFD功能的設備RTA上創建單臂回聲功能的BFD會話。RTA主動發起回聲請求功能,不支持BFD功能的設備RTB接收到該報文後直接將其環回,從而實現轉發鏈路的連通性檢測功能。
實現的技術原理就是支持BFD功能的路由器RTA在出接口發送目的地址和源地址都是自己的BFD探測報文,不支持BFD功能的路由器RTB收到探測報文就直接回發給路由器RTA。
BFD技術的全面解析

SWA的配置文件

<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan 13
[SwitchA-vlan13] quit
[SwitchA] interface gigabitethernet 0/0/1
[SwitchA-GigabitEthernet0/0/1] port link-type hybrid
[SwitchA-GigabitEthernet0/0/1] port hybrid pvid vlan 13
[SwitchA-GigabitEthernet0/0/1] port hybrid untagged vlan 13 
[SwitchA-GigabitEthernet0/0/1] quit
[SwitchA] interface vlanif13
[SwitchA-Vlanif13] ip address 10.1.1.5 24
[SwitchA-Vlanif13] quit
[SwitchA] bfd
[SwitchA-bfd] quit
[SwitchA] bfd atob bind peer-ip 10.1.1.6 interface vlanif13 source-ip 10.1.1.5 one-arm-echo
[SwitchA-bfd-session-atob] discriminator local 1
[SwitchA-bfd-session-atob] min-echo-rx-interval 100
[SwitchA-bfd-session-atob] commit
[SwitchA-bfd-session-atob] quit

SWB的配置文件

<HUAWEI> system-view
[HUAWEI] sysname SwitchB
[SwitchB] vlan 13
[SwitchB-vlan13] quit
[SwitchB] interface gigabitethernet 0/0/1
[SwitchB-GigabitEthernet0/0/1] port link-type hybrid
[SwitchB-GigabitEthernet0/0/1] port hybrid pvid vlan 13
[SwitchB-GigabitEthernet0/0/1] port hybrid untagged vlan 13 
[SwitchB-GigabitEthernet0/0/1] quit
[SwitchB] interface vlanif13
[SwitchB-Vlanif13] ip address 10.1.1.6 24
[SwitchB-Vlanif13] quit

檢查

[SwitchA] display bfd session all verbose
--------------------------------------------------------------------------------
Session MIndex : 256       (One Hop) State : Up        Name : atob
--------------------------------------------------------------------------------
  Local Discriminator    : 1                Remote Discriminator   : -
  Session Detect Mode    : Asynchronous One-arm-echo Mode
  BFD Bind Type          : Interface(Vlanif13)
  Bind Session Type      : Static
  Bind Peer IP Address   : 10.1.1.6
  NextHop Ip Address     : 10.1.1.6
  Bind Interface         : Vlanif13
  Bind Source IP Address : 10.1.1.5
  FSM Board Id           : 0                TOS-EXP                : 7
  Echo Rx Interval (ms)  : 100
  Actual Tx Interval (ms): 100              Actual Rx Interval (ms): 100
  Local Detect Multi     : 3                Detect Interval (ms)   : 300
  Echo Passive           : Disable          Acl Number             : -
  Destination Port       : 3784             TTL                    : 255
  Proc Interface Status  : Disable          Process PST            : Disable
  WTR Interval (ms)      : -                
  Active Multi           : 3                DSCP                   : - 
  Last Local Diagnostic  : No Diagnostic
  Bind Application       : No Application Bind
  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   

BFD默認參數及調整方法

BFD技術的全面解析

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章