一個拓撲全搞定 - - 之 BGP13條路徑選擇算法 - 案例分析

1.1.BGP協議最佳路徑選擇算法

BGP是一個路徑矢量路由協議,也就是說,它的工作就是在自主系統間交換路由信息,以便發現訪問互聯網某處數據的最有效路徑。每個 BGP路由器通過鄰居聲名與周邊的一個或多個路由器連接。一旦建立了鄰居關係,這些BGP路由器之間就會相互交換路由信息。據我最近一次統計,整個互聯網上有大約12.5萬個路由信息,因此要配備一個強大的路由器才能將所有BGP路由信息接收下來。

1.1.1.BGP 最佳路徑選擇算法概述

由於整個互聯網的BGP路由表有超過60萬個路由,同時一個BGP路由器可能從多個來源收到多份的路由表,因此肯定會有一種方法可以比較不同的 BGP路由表,並從中選擇最佳的路由方案。這種方法就是BGP 最佳路徑選擇算法。

可能你會注意到,Cisco BGP路由器會將應用權重(weight)作爲路由表的第一標準,而其它品牌的路由器則不是這樣。Cisco的官方BGP最佳路徑選擇算法文檔中詳細列明瞭所參考的各項標準。接下來我會列出每種標準並給出解釋和範例。

默認情況下,BGP最佳路徑都是基於最短自治系統(AS)的原理得出的。不過很多時候,諸如weightlocalpreference以及MED這樣的標準都是網絡管理員自行設定的。

接下來我們就按照BGP選擇最佳路徑的參考順序將這幾項標準介紹一下:

n #1 Weight 權重是Cisco爲本地路由器設定的自定義參數,並不隨路由器更新而變化。如果指向某一IP地址的路徑有多條(這很常見),那麼BGP會尋找權重最高的路徑。設定權重的參考因素很多,包括鄰居命令, as-path 訪問列表,或者路由鏡像等。

n #2 Local Preference本地出口優先級參數會告知 AS 哪條路徑具有本地優先,數值越高優先級越高。默認爲100。比如:

n bgp defaultlocal-preference 150

n #3 Network orAggregate 這個參數會選擇本地發起的網絡或聚合作爲路徑。將特定的路徑加入路由中,會讓路由更有效率,同時也節省了網絡空間。更多有關聚合的信息,可以參考Cisco的文章“UnderstandingRoute Aggregation in BGP.

n #4 Shortest AS_PATH BGP 只有在weight, local preferencelocally originated相當接近的時候才使用這個參數。

n #5 Lowest origintype 這個參數處理InteriorGateway Protocol (IGP) 協議的優先級低於 Exterior GatewayProtocol (EGP)協議。

n #6 Lowestmulti-exit discriminator (MED) 較低的 MED 值要優於較高的MED值。

n #7 eBGP over iBGP 類似於#5,BGP AS Path 更傾向 eBGP 而不是 iBGP

n #8 Lowest IGPmetric 這個參數傾向於採用最低IGP作爲BGP下一跳。

n #9 Multiple paths 這個參數決定是否要在路由表中裝入多個路徑。可以參考 BGP Multipath 獲取更多信息。

n #10 External paths 當所有路徑都爲外部路徑時,選擇首先接收到的路徑(較老的路徑)

n #11 Lowest routerID 選擇來自具有最低路由器IDBGP路由器的路徑。

n #12 Minimum clusterlist 如果多個路徑的originator或路由器 ID相同,選擇cluster列表長度最短的路徑。

n #13 Lowest neighboraddress 這是指最低鄰居地址傳來的路徑。

1.1.2.案例分析

1.1.2.1.  拓撲圖

wKiom1mMNN2ib6H9AAFXF1UxMHE942.png




上圖爲BGP協議最佳路徑選擇算法的驗證拓撲。

1.1.2.2.  驗證方法:

l 跟蹤1.1.1.0/24驗證第7

l 跟蹤3.3.3.0/24驗證第10,11,13

l 路由過濾跟蹤3.3.3.0/24驗證第6(影響鄰居最佳路由選擇)

l 跟蹤33.33.33.0/24驗證第5,並在此基礎上驗證第3

l 跟蹤33.33.33.0/24驗證第4

l 跟蹤1.1.1.0/24驗證第1,2

若要完成此實驗需滿足兩個重要條件:1.已經同步或者同步已經關閉,2.下一跳可達。

1.1.3.驗證第十三條,最低的鄰居IP地址:

R1R6間建立兩個鄰接關係,然後在R1上觀察網絡3.3.3.0/24使用那一條路徑作爲下一跳。

實驗輸出

R1#show ip bgp

BGP table version is 2, local router ID is 1.1.1.1

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

              r RIB-failure, S Stale, m multipath,  b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

     Network          Next Hop            Metric LocPrf Weight Path

 *>  3.3.3.3/24       16.16.16.6                             0 65236 i

 *                    61.61.61.6                             0 65236 i

1.1.4.驗證第十一條,比較較小的鄰居的RouterID

R3上觀察1.1.1.0/24的路由,優選從R2過來的那條路徑

實驗輸出

R3#show ip bgp

BGP table version is 2, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 * i  1.1.1.0/24       36.36.36.6               0    100       0 65101 i

 *>i                  23.23.23.2               0    100       0 65101 i

1.1.5.驗證第十條,EBGP優選the oldestone

通過在R2上輸入命令cle ip bgp * ,重置R1R2的鄰接關係,然後在R1的路由表中觀察到關於網絡3.3.3.0/24的下一跳的變化情況

實施策略前輸出

R1#show ip route bgp

Codes: L - local, C - connected, S - static, R -  RIP, M - mobile, B - BGP

       D -  EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 -  OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 -  OSPF external type 1, E2 - OSPF external type 2

       i -  IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

       ia -  IS-IS inter area, * - candidate default, U - per-user static route

       o -  ODR, P - periodic downloaded static route, H - NHRP, l - LISP

       a -  application route

       + -  replicated route, % - next hop override

 

Gateway of last resort is not set

 

       3.0.0.0/24 is subnetted, 1 subnets

B         3.3.3.0 [20/0] via 12.12.12.2, 00:00:46

實施策略後輸出

R1#show ip route bgp

Codes: L - local, C - connected, S - static, R -  RIP, M - mobile, B - BGP

       D -  EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 -  OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 -  OSPF external type 1, E2 - OSPF external type 2

       i -  IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

       ia -  IS-IS inter area, * - candidate default, U - per-user static route

       o -  ODR, P - periodic downloaded static route, H - NHRP, l - LISP

       a -  application route

       + -  replicated route, % - next hop override

 

Gateway of last resort is not set

 

       3.0.0.0/24 is subnetted, 1 subnets

B        3.3.3.0 [20/0] via 16.16.16.6, 00:00:05

1.1.6.驗證第九條,maximum-paths負載分擔

R1開啓命令maximum-paths 2,應該在R1的路由表中看到關於網絡3.3.3.0/24有兩個下一跳,實現了負載分擔。

配置如下

router bgp 1

  bgp  router-id 1.1.1.1

   maximum-paths 2

實驗輸出

R1#show ip route bgp

Codes: L - local, C - connected, S - static, R -  RIP, M - mobile, B - BGP

       D -  EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 -  OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 -  OSPF external type 1, E2 - OSPF external type 2

       i -  IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2

       ia -  IS-IS inter area, * - candidate default, U - per-user static route

       o -  ODR, P - periodic downloaded static route, H - NHRP, l - LISP

       a -  application route

       + -  replicated route, % - next hop override

 

Gateway of last resort is not set

 

       3.0.0.0/24 is subnetted, 1 subnets

B         3.3.3.0 [20/0] via 16.16.16.6, 00:00:05

                  [20/0] via 12.12.12.2, 00:00:05

1.1.7.驗證第八條,lowestIGP metric

R3觀察1.1.1.0/24的路由,通過在R2上修改R2,R3間鏈路的帶寬,從而影響EIGRPmetric

配置如下

int s0/1

bandwidth 100

實驗輸出

R3#show ip bgp 1.1.1.0 255.255.255.0

BGP routing table entry for 1.1.1.0/24, version 5

Paths: (2 available, no best path)

  Not  advertised to any peer

  Refresh  Epoch 2

  65101

    12.12.12.1  (inaccessible) from 23.23.23.2 (2.2.2.2)

      Origin  IGP, metric 0, localpref 100, valid, internal

      rx  pathid: 0, tx pathid: 0

  Refresh  Epoch 2

  65101

     16.16.16.1 (inaccessible) from 36.36.36.6 (6.6.6.6) best

      Origin  IGP, metric 0, localpref 100, valid, internal

      rx  pathid: 0, tx pathid: 0

1.1.8.驗證第七條,EBGP VsIBGP

R2R6間建立IBGP鄰接關係,然後在R6上觀察網絡1.1.1.0/24的兩個來源:

R1來的是EBGP,從R2來的是IBGP

實驗輸出

R6#show ip bgp

BGP table version is 3, local router ID is 6.6.6.6

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 * i  1.1.1.0/24       12.12.12.1               0    100       0 65101 i

 *>                   16.16.16.1               0             0 65101 i

1.1.9.驗證第六條,MED

R2R6上分別修改關於網絡3.3.3.0/24med值,然後在R1上觀察。

試驗配置

R2

router bgp 236

bgp router-id 2.2.2.2

neighbor 12.12.12.1 route-map Net3 out

!

route-map Net3 permit 10

 match ip  address 3

 set metric  20

route-map Net3 permit 20

!

access-list 3 permit 3.3.3.0 0.0.0.255

R6

router bgp 236

bgp router-id 6.6.6.6

neighbor 16.16.16.1 route-map Net3 out

!

route-map Net3 permit 10

 match ip  address 3

 set metric  60

route-map Net3 permit 20

!

access-list 3 permit 3.3.3.0 0.0.0.255

實驗輸出

R1#show ip bgp

BGP table version is 6, local router ID is 1.1.1.1

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *>  3.3.3.0/24       12.12.12.2              20             0 65236 i

 *                    16.16.16.6              60             0 65236 i

1.1.10.        驗證第五條,locally originated

R3上觀察26.26.26.0/24的網絡

網絡26.26.26.0/24R6被重分發直連進入BGP表;在R2上被network進入BGP

試驗配置

R6

router bgp 236

 bgp  router-id 6.6.6.6

 redistribute connected route-map S02

!

route-map S02 permit 10

 match  interface Serial0/2

R2

router bgp 236

bgp router-id 2.2.2.2

network 26.26.26.0 mask 255.255.255.0

實驗輸出

R3#show ip bgp

BGP table version is 15, local router ID is  3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *>i  26.26.26.0/24    23.23.23.2               0    100       0 i

 * i                  36.36.36.6               0    100       0 ?

1.1.11.        驗證第四條,Prefer shortest AS path.

R3觀察1.1.1.0/24的路由,R3應該可以收到分別從R2R6的兩條路由。

R2上加route-map,利用as-pathprepend修改從R1過來的路由1.1.1.0/24AS-path的長度

實驗配置

R2

router bgp 236

  neighbor  12.12.12.1 route-map Net1 in

!

route-map Net1 permit 10

 match ip  address 1

 set as-path  prepend 1

 set as-path  prepend last-as 2

!

route-map Net1 permit 20

!

access-list 1 permit 1.1.1.0 0.0.0.255

實驗輸出

R3#show ip bgp

BGP table version is 7, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *> i  1.1.1.0/24       23.23.23.2               0    100       0 1 65101 65101 65101 i

1.1.12.        驗證第三條,是否起源於local router

在路由器R3觀察網絡1.1.1.0/24的兩個來源:一個從IBGP學到,一個是本地network進來的

R3上面多加一個環回接口1.1.1.3/24,或者在R2R1運行EIGRPR3通過EIGRPR2學到R1EIGRP中宣告的1.1.1./0的路由。

實驗輸出

R3#show ip bgp

BGP table version is 6, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *>  1.1.1.0/24       0.0.0.0                  0         32768 i

1.1.13.        驗證第二條,本地優先級

配置之前後showip bgp(tracerout 1.1.1.1)觀察1.1.1.0/24路由

通過在R2上修改1.1.1.0/24的路由的本地優先級,從而影響R3的路由選擇,將R3到網絡1.1.1.0/24的下一跳由原來的36.36.36.6 修改爲23.23.23.2

實驗配置

R2

router bgp 236

bgp router-id 6.6.6.6

neighbor 23.23.23.3 route-map Net1 out

access-list 1 permit 1.1.1.0 0.0.0.255

!

route-map Net1 permit 10

 match ip  address 1

 set  local-preference 200

!

route-map Net1 permit 20

實驗輸出

R3#show ip bgp

BGP table version is 7, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *>i  1.1.1.0/24       23.23.23.2               0    200       0 1 65101 65101 65101 i

1.1.14.        驗證第一條,weight

配置前後觀察R31.1.1.0/24的路由

實驗配置

R3

router bgp 236

   neighbor  36.36.36.6 route-map Net1 in

route-map Net1 permit 10

 match ip  address 1

 set weight  5

!

route-map Net1 permit 20

!

access-list 1 permit 1.1.1.0 0.0.0.255

實驗輸出

R3#show ip bgp

BGP table version is 7, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, *  valid, > best, i - internal,

               r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

               x best-external, a additional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? - incomplete

RPKI validation codes: V valid, I invalid, N Not  found

 

      Network          Next Hop            Metric LocPrf Weight Path

 *>i  1.1.1.0/24       23.23.23.2               0    200       5 1 65101 65101 65101 i

 

wKioL1mMNHjT5QmYAAFXF1UxMHE989.png-wh_50

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