BGP のベストパスが実際にどう選ばれるのかを、Cisco ルータで確認します。属性に差をつけた 2 つの経路を用意し、上位の比較項目から 1 つずつ差をなくしていくことで、どの項目でベストパスが決まるかを順番に見ていきます。
次の記事を読んでいない方は、先に読むのがおすすめです。
>> 参考:【BGP】ベストパス選定(PART1 アルゴリズム)
- Weight の大きい経路が選ばれる
- Local Preference の大きい経路が選ばれる
- 自分で生成した経路が選ばれる
- AS_PATH の短い経路が選ばれる
- Origin の小さい経路が選ばれる
- MED の小さい経路が選ばれる
- すべて同じときは、先に受信した経路が選ばれる
検証構成
次の構成で検証します。AS 23 の R2 と R3 から同じ経路(23.23.23.23/32)を広告し、R6 が R2 と R3 のどちらをベストパスに選ぶかを見ていきます。
初期設定
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 ... 100 | R6 の network コマンドで経路を生成するための、ルーティングテーブル上の経路。アドミニストレーティブディスタンスを 100 にしている |
R3-Attribute | R3 からの経路を MED 100、Weight 65535 にし、AS_PATH に 23 を 4 つ付け足す |
R2-Attribute | R2 からの経路を Local Preference 900、Weight 32768、Origin incomplete にする |
この設定で、R6 が受け取る 23.23.23.23/32 の属性は次のとおりです。これに加えて、R6 自身が network コマンドで生成した経路があります。
| 順番 | 比較項目 | R2 からの経路 | R3 からの経路 |
|---|---|---|---|
| 1 | Weight(大きい方) | 32768 | 65535 |
| 2 | Local Preference(大きい方) | 900 | 100 |
| 3 | 自分で生成した経路 | どちらも違う(R6 自身が network で生成した経路が別にある) | |
| 4 | AS_PATH(短い方) | 23 | 23 23 23 23 23 |
| 5 | Origin(IGP < EGP < Incomplete) | incomplete | IGP |
| 6 | MED(小さい方) | 0 | 100 |
ここから、上の比較項目から順に差をなくし、ベストパスの変化を確認していきます。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
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
自分で生成した経路
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
| 表示 | 意味 |
|---|---|
| Local | R6 自身が生成した経路(AS_PATH は空) |
| from 0.0.0.0 (6.6.6.6) | ネイバーから受信した経路ではない |
| sourced, local | network コマンドなどで、このルータが生成した経路 |
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
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
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
タイブレーク
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
この記事では、属性を変えるたびに clear ip bgp *(ハードリセット)で反映しています。運用中のネットワークでは、受信する経路の属性を変えたときは clear ip bgp * in のようなソフトリセットで反映できます。詳しくは ルートリフレッシュ機能の記事 を参考にしてください。
まとめ
| STEP | ベストパスが決まった比較項目 | ベストパス |
|---|---|---|
| 1 | Weight(65535 > 32768) | R3 |
| 2 | Local Preference(900 > 100) | R2 |
| 3 | 自分で生成した経路 | R6 自身(Local) |
| 4 | AS_PATH(1 < 5) | R2 |
| 5 | Origin(IGP < incomplete) | R3 |
| 6 | MED(0 < 100) | R2 |
| 7 | 先に受信した経路 | R3 |
上位の比較項目で差がつけば、それより下の項目は使われません。どの項目でベストパスが決まったかは、属性を 1 つずつそろえていくと確かめられます。
コメント