【BGP】ベストパス選定(PART2 動作確認)

BGP のベストパスが実際にどう選ばれるのかを、Cisco ルータで確認します。属性に差をつけた 2 つの経路を用意し、上位の比較項目から 1 つずつ差をなくしていくことで、どの項目でベストパスが決まるかを順番に見ていきます。

次の記事を読んでいない方は、先に読むのがおすすめです。

>> 参考:【BGP】ベストパス選定(PART1 アルゴリズム)

この記事でわかること
  1. Weight の大きい経路が選ばれる
  2. Local Preference の大きい経路が選ばれる
  3. 自分で生成した経路が選ばれる
  4. AS_PATH の短い経路が選ばれる
  5. Origin の小さい経路が選ばれる
  6. MED の小さい経路が選ばれる
  7. すべて同じときは、先に受信した経路が選ばれる

検証構成

次の構成で検証します。AS 23 の R2 と R3 から同じ経路(23.23.23.23/32)を広告し、R6 が R2 と R3 のどちらをベストパスに選ぶかを見ていきます。

AS 23 AS 6 R2 Lo23 23.23.23.23/32 .2 192.168.26.0/24 R3 Lo23 23.23.23.23/32 .3 192.168.36.0/24 R6 .6
図1 検証構成(R6 側のアドレスはすべて .6)

初期設定

R2 と R3 は、Loopback23 の 23.23.23.23/32 を BGP で広告します。

R2

R2(config)# interface loopback23 
R2(config-if)#  ip address 23.23.23.23 255.255.255.255 
R2(config)# router bgp 23 
R2(config-router)# network 23.23.23.23 mask 255.255.255.255 
R2(config-router)# neighbor 192.168.26.6 remote-as 6 
R2(config-router)#  bgp router-id 22.22.22.22 

R3

R3(config)# interface loopback23 
R3(config-if)# ip address 23.23.23.23 255.255.255.255 
R3(config)# router bgp 23 
R3(config-router)# network 23.23.23.23 mask 255.255.255.255 
R3(config-router)# neighbor 192.168.36.6 remote-as 6 
R3(config-router)#  bgp router-id 3.3.3.3 

R6 では、R2、R3 から受信する経路の属性を、ネイバーごとのルートマップ(in)で変えています。また、R6 自身でも 23.23.23.23/32 を生成するため、スタティックルートと network コマンドを設定しています。

R6

R6(config)# ip route 23.23.23.23 255.255.255.255 192.168.26.2 100 
!
R6(config)# route-map R3-Attribute permit 10 
R6(config-route-map)# set metric 100 
R6(config-route-map)# set weight 65535 
R6(config-route-map)# set as-path prepend 23 23 23 23 

R6(config)# route-map R2-Attribute permit 10 
R6(config-route-map)# set local-preference 900 
R6(config-route-map)# set weight 32768 
R6(config-route-map)# set origin incomplete 
!
R6(config)# router bgp 6 
R6(config-router)# network 23.23.23.23 mask 255.255.255.255 
R6(config-router)# neighbor 192.168.26.2 remote-as 23 
R6(config-router)# neighbor 192.168.26.2 route-map R2-Attribute in 
R6(config-router)# neighbor 192.168.36.3 remote-as 23 
R6(config-router)# neighbor 192.168.36.3 route-map R3-Attribute in 
!
設定意味
ip route ... 100R6 の network コマンドで経路を生成するための、ルーティングテーブル上の経路。アドミニストレーティブディスタンスを 100 にしている
R3-AttributeR3 からの経路を MED 100、Weight 65535 にし、AS_PATH に 23 を 4 つ付け足す
R2-AttributeR2 からの経路を Local Preference 900、Weight 32768、Origin incomplete にする

この設定で、R6 が受け取る 23.23.23.23/32 の属性は次のとおりです。これに加えて、R6 自身が network コマンドで生成した経路があります。

順番比較項目R2 からの経路R3 からの経路
1Weight(大きい方)3276865535
2Local Preference(大きい方)900100
3自分で生成した経路どちらも違う(R6 自身が network で生成した経路が別にある)
4AS_PATH(短い方)2323 23 23 23 23
5Origin(IGP < EGP < Incomplete)incompleteIGP
6MED(小さい方)0100

ここから、上の比較項目から順に差をなくし、ベストパスの変化を確認していきます。BGP テーブル(show ip bgp)では、ベストパスに > が付きます。

比較項目を 1 つずつ確認する

Weight の比較

BGP のベストパス選択では、Weight が最初に比べられます。R3 からの経路の Weight は 65535、R2 からの経路は 32768 なので、R3 の経路がベストパスになります。

R6

R6# show ip bgp
BGP table version is 2, 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
 *   23.23.23.23/32   192.168.26.2             0    900  32768 23 ?
 *>                   192.168.36.3           100         65535 23 23 23 23 23 i

R6# show ip bgp 23.23.23.23 
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     29        
  Refresh Epoch 1
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin incomplete, metric 0, localpref 900, weight 32768, valid, external
  Refresh Epoch 2
  23 23 23 23 23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 65535, valid, external, best
AS 23 AS 6 R2 Weight 32768 R3 Weight 65535 ベストパス R6
図2 Weight の比較
補足

Weight は Cisco 独自の属性で、設定したルータの中だけで使われ、他のルータには伝わりません。値の範囲は 0〜65535 で、他のルータから学習した経路は既定で 0、自分で生成した経路は既定で 32768 です。

Local Preference の比較

R3 からの経路の Weight を 32768 に変えます。

R6

R6(config)# route-map R3-Attribute permit 10
R6(config-route-map)# set weight 32768

R6# clear ip bgp *

Weight が同じになったので、次に Local Preference を比べます。Local Preference は R2 が 900、R3 が 100(既定値)で、R2 の方が大きいので、R2 の経路がベストパスになります。

R6

R6# show ip bgp
BGP table version is 2, 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
 *   23.23.23.23/32   192.168.36.3           100         32768 23 23 23 23 23 i
 *>                   192.168.26.2             0    900  32768 23 ?


R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     30        
  Refresh Epoch 2
  23 23 23 23 23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 32768, valid, external
  Refresh Epoch 1
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin incomplete, metric 0, localpref 900, weight 32768, valid, external, best
AS 23 AS 6 R2 Local Preference 900 ベストパス R3 Local Preference 100 R6
図3 Local Preference の比較

自分で生成した経路

R2 からの経路の Local Preference を既定の 100 に戻します。

R6

R6(config)# route-map R2-Attribute permit 10 
R6(config-route-map)# no set local-preference 900 

R6# clear ip bgp * 

Local Preference が同じになったので、次は自分で生成した経路かどうかを比べます。R6 には、あらかじめ network コマンドで 23.23.23.23/32 を生成する設定をしています。自分で生成した経路(Path が Local)がベストパスになります。

R6

R6# show ip bgp 
BGP table version is 2, 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
 *   23.23.23.23/32   192.168.36.3           100         32768 23 23 23 23 23 i
 *                    192.168.26.2             0         32768 23 ?
 *>                   192.168.26.2             0         32768 i

R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (3 available, best #3, table default)
  Advertised to update-groups:
     31        
  Refresh Epoch 1
  23 23 23 23 23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 32768, valid, external
  Refresh Epoch 2
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin incomplete, metric 0, localpref 100, weight 32768, valid, external
  Refresh Epoch 1
  Local
    192.168.26.2 from 0.0.0.0 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best
AS 23 AS 6 R2 自分で生成した経路か いいえ R3 自分で生成した経路か いいえ R6 R6 が network で生成した経路 ベストパス(Local)
図4 自分で生成した経路
表示意味
LocalR6 自身が生成した経路(AS_PATH は空)
from 0.0.0.0 (6.6.6.6)ネイバーから受信した経路ではない
sourced, localnetwork コマンドなどで、このルータが生成した経路

AS_PATH の比較

R6 で、自分で経路を生成する設定(network コマンド)を削除します。

R6

R6(config)# router bgp 6
R6(config-router)# no network 23.23.23.23 mask 255.255.255.255

R6#clear ip bgp *

自分で生成した経路がなくなったので、次に AS_PATH の長さを比べます。AS_PATH は R2 の経路の方が短いので、R2 の経路がベストパスになります。

R6

R6# show ip bgp
BGP table version is 2, 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
 *   23.23.23.23/32   192.168.36.3           100         32768 23 23 23 23 23 i
 *>                   192.168.26.2             0         32768 23 ?


R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     32        
  Refresh Epoch 1
  23 23 23 23 23 
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 32768, valid, external
  Refresh Epoch 1
  23 
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin incomplete, metric 0, localpref 100, weight 32768, valid, external, best 
AS 23 AS 6 R2 AS_PATH の長さ 23(1) ベストパス R3 AS_PATH の長さ 23 ×5(5) R6
図5 AS_PATH の比較

Origin の比較

R3 からの経路に AS_PATH を付け足す設定を削除します。

R6

R6(config)# route-map R3-Attribute permit 10
R6(config-route-map)# no set as-path prepend 23 23 23 23

R6# clear ip bgp *

AS_PATH の長さが同じになったので、次は Origin を比べます。Origin は小さい方が優先で、IGP < EGP < Incomplete の順です。R3 の経路は IGP、R2 の経路は incomplete なので、R3 の経路がベストパスになります。

R6

R6# show ip bgp
BGP table version is 2, 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
 *>  23.23.23.23/32   192.168.36.3           100         32768 23 i
 *                    192.168.26.2             0         32768 23 ?



R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     33        
  Refresh Epoch 2
  23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 32768, valid, external, best
  Refresh Epoch 1
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin incomplete, metric 0, localpref 100, weight 32768, valid, external
AS 23 AS 6 R2 Origin incomplete R3 Origin IGP ベストパス R6
図6 Origin の比較

MED の比較

R2 からの経路の Origin を変える設定を削除します。

R6

R6(config)# route-map R2-Attribute permit 10 
R6(config-route-map)# no set origin incomplete 

R6# clear ip bgp * 

Origin がどちらも IGP になったので、次は MED を比べます。MED は小さい方が優先なので、MED 0 の R2 の経路がベストパスになります。R2 と R3 は同じ AS 23 なので、MED を比べる条件(隣接 AS が同じ)も満たしています。

R6

R6# show ip bgp       
BGP table version is 2, 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
 *>  23.23.23.23/32   192.168.26.2             0         32768 23 i
 *                    192.168.36.3           100         32768 23 I


R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     34        
  Refresh Epoch 2
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin IGP, metric 0, localpref 100, weight 32768, valid, external, best
  Refresh Epoch 1
  23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 100, localpref 100, weight 32768, valid, external
AS 23 AS 6 R2 MED 0 ベストパス R3 MED 100 R6
図7 MED の比較

タイブレーク

R3 からの経路の MED を変える設定を削除します。

R6

R6(config)# route-map R3-Attribute permit 10
R6(config-route-map)# no set metric 100

R6# clear ip bgp *

MED がどちらも 0 になりました。どちらも eBGP の経路で、ネクストホップは直接接続しているので、ここまでで差がつきません。タイブレークとして、先に受信した経路がベストパスになります。この検証では R3 の経路が選ばれました。

R6

R6# show ip bgp            
BGP table version is 2, 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
 *   23.23.23.23/32   192.168.26.2             0         32768 23 i
 *>                   192.168.36.3             0         32768 23 i
R6#


R6# show ip bgp 23.23.23.23
BGP routing table entry for 23.23.23.23/32, version 2
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     35        
  Refresh Epoch 1
  23
    192.168.26.2 from 192.168.26.2 (22.22.22.22)
      Origin IGP, metric 0, localpref 100, weight 32768, valid, external
  Refresh Epoch 2
  23
    192.168.36.3 from 192.168.36.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, weight 32768, valid, external, best
AS 23 AS 6 R2 MED まで同じ 後に受信 R3 MED まで同じ 先に受信 ベストパス R6
図8 タイブレーク
補足

この記事では、属性を変えるたびに clear ip bgp *(ハードリセット)で反映しています。運用中のネットワークでは、受信する経路の属性を変えたときは clear ip bgp * in のようなソフトリセットで反映できます。詳しくは ルートリフレッシュ機能の記事 を参考にしてください。

まとめ

STEPベストパスが決まった比較項目ベストパス
1Weight(65535 > 32768)R3
2Local Preference(900 > 100)R2
3自分で生成した経路R6 自身(Local)
4AS_PATH(1 < 5)R2
5Origin(IGP < incomplete)R3
6MED(0 < 100)R2
7先に受信した経路R3

上位の比較項目で差がつけば、それより下の項目は使われません。どの項目でベストパスが決まったかは、属性を 1 つずつそろえていくと確かめられます。

コメント