BGP Best Path SelectionにてよくLocal PreferenceやMED、AS-PATH等での経路制御はよく見るけど、優先順位3番目のLocally originatedを理由としたbest path selectionを見たことないなと思い簡易に挙動を確認してみた
構成
確認方法
3台のRouterで挙動を確認していく
R1にてconnectedの192.168.12.0/24経路をebgpで広報し、R2にて
- networkコマンドによる192.168.12.0/24を広報
- redistributed connectedによる192.168.12.0/24を広報
の2パターンで設定を実行した際のR2におけるshow ip bgp 192.168.12.0/24 best-path-reason (IOS-XE), show bgp 192.168.12.0/24 bestpath-compare(IOS-XR)及びR3におけるshow ip bgpを確認する
IOS-XR(25.2.1)とIOS-XE(17.11.01a)の2パターンで挙動確認
Config
IOS-XE
R1
interface Loopback0
ip address 1.1.1.1 255.255.255.255
!
interface GigabitEthernet2
ip address 192.168.12.1 255.255.255.0
!
router bgp 100
bgp router-id 1.1.1.1
bgp log-neighbor-changes
network 192.168.12.0
neighbor 192.168.12.2 remote-as 200
!
R2
interface Loopback0
ip address 2.2.2.2 255.255.255.255
!
interface GigabitEthernet2
ip address 192.168.12.2 255.255.255.0
!
interface GigabitEthernet3
ip address 192.168.23.2 255.255.255.0
!
router bgp 200
bgp router-id 2.2.2.2
bgp log-neighbor-changes
neighbor 192.168.12.1 remote-as 100
neighbor 192.168.23.3 remote-as 300
!
R3
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
interface GigabitEthernet3
ip address 192.168.23.3 255.255.255.0
!
router bgp 300
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 192.168.23.2 remote-as 200
!
IOS-XR
R1
interface Loopback0
ipv4 address 1.1.1.1 255.255.255.255
!
interface GigabitEthernet0/0/0/1
ipv4 address 192.168.12.1 255.255.255.0
!
route-policy PASS
pass
end-policy
!
router bgp 100
bgp router-id 1.1.1.1
address-family ipv4 unicast
network 192.168.12.0/24
!
neighbor 192.168.12.2
remote-as 200
address-family ipv4 unicast
route-policy PASS in
route-policy PASS out
!
!
!
R2
interface Loopback0
ipv4 address 2.2.2.2 255.255.255.255
!
interface GigabitEthernet0/0/0/0
ipv4 address 192.168.12.2 255.255.255.0
!
interface GigabitEthernet0/0/0/1
ipv4 address 192.168.23.2 255.255.255.0
!
route-policy PASS
pass
end-policy
!
router bgp 200
bgp router-id 2.2.2.2
address-family ipv4 unicast
!
neighbor 192.168.12.1
remote-as 100
address-family ipv4 unicast
route-policy PASS in
route-policy PASS out
!
!
neighbor 192.168.23.3
remote-as 300
address-family ipv4 unicast
route-policy PASS in
route-policy PASS out
!
!
!
R3
interface Loopback0
ipv4 address 3.3.3.3 255.255.255.255
!
interface GigabitEthernet0/0/0/0
ipv4 address 192.168.23.3 255.255.255.0
!
router bgp 300
bgp router-id 3.3.3.3
address-family ipv4 unicast
!
neighbor 192.168.23.2
remote-as 200
address-family ipv4 unicast
route-policy PASS in
route-policy PASS out
!
!
!
挙動確認
IOS-XE
まずはIOS-XEでの挙動確認から
上記configを投入しただけの状態でR2のshow ip bgpを確認すると受信した経路はRIB-Failureとなっている
r02#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
r> 192.168.12.0 192.168.12.1 0 0 100 i
理由はR2自身がconnectedで持っている経路が広報されているため、connectedの方がAD値が低くそちらの経路が優先されるためRIB-Failureとなる。reasonを確認してみると「Higher admin distance」と表示される
r02#show ip bgp rib-failure
Network Next Hop RIB-failure RIB-NH Matches
192.168.12.0 192.168.12.1 Higher admin distance n/a
ただbest pathとしては選択されているため、R3にはそのまま経路広報されており、R3上では正しく広報されたprefixを確認することができる。as-path的にもR1が生成した経路となっている
r03#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0 192.168.23.2 0 200 100 i
この状態でR2上にnetwork設定を実施する
router bgp 200
network 192.168.12.0
設定後はshow ip bgpの結果は以下となる
r02#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0 0.0.0.0 0 32768 i
* 192.168.12.1 0 0 100 i
ローカルで生成された経路としてNext Hopが0.0.0.0の経路が追加で表示されbest pathとして選択されている。ローカル生成された経路は自動的にweight値に32768が付与される
ローカルで生成する方法としてはredistributedやaggregate-addressなどがあるが、今回はredistribute connectedでも同様の結果になることを確認した
r02#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 2.2.2.2/32 0.0.0.0 0 32768 ?
*> 192.168.12.0 0.0.0.0 0 32768 ?
* 192.168.12.1 0 0 100 i
*> 192.168.23.0 0.0.0.0 0 32768 ?
OriginはnetworkがIGP、redistributedはincompleteとなる
ちなみに今回の環境でnetworkとredistributedの両方を設定した場合にはnetwork(originがIGP)の経路のみが表示される形となった
R3でのshow ip bgpを確認するとas-pathが200のみとなっているので、R1で広報された経路でなく、R2で生成された経路が優先されそちらの経路が広報されている
r03#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0 192.168.23.2 0 0 200 i
ただこの状態でのbest path selectionは単純に優先度1位のweight値による比較となっているのでlocally orinatedによる比較ではない状況
show ip bgp bet-path-reasonの一番下に「Best Path Evaluation: Lower weight」と表示されている
r02#show ip bgp 192.168.12.0 best-path-reason
BGP routing table entry for 192.168.12.0/24, version 3
Paths: (2 available, best #1, table default)
Advertised to update-groups:
1
Refresh Epoch 1
Local
0.0.0.0 from 0.0.0.0 (2.2.2.2)
Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best
rx pathid: 0, tx pathid: 0x0
Updated on Aug 15 2025 07:51:07 UTC
Best Path Evaluation: Overall best path
Refresh Epoch 1
100
192.168.12.1 from 192.168.12.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Updated on Aug 15 2025 07:48:57 UTC
Best Path Evaluation: Lower weight
weightによる比較を回避するため下記configを投入してweight値を同じにする
route-map WEIGHT permit 10
set weight 32768
!
router bgp 200
neighbor 192.168.12.1 route-map WEIGHT in
!
結果として同じweight値の状態でもローカル生成の経路がbestpathとして選択されている状態となる
r02#show ip bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0 0.0.0.0 0 32768 i
* 192.168.12.1 0 32768 100 i
best-path-reasonを確認すると先ほどと理由が変わり「Best Path Evaluation: Not sourced」となっている
これでIOS-XEにおけるLocally originatedによるbest path selectionの挙動を確認することができた
r02#show ip bgp 192.168.12.0 best-path-reason
BGP routing table entry for 192.168.12.0/24, version 11
Paths: (2 available, best #1, table default)
Advertised to update-groups:
1
Refresh Epoch 1
Local
0.0.0.0 from 0.0.0.0 (2.2.2.2)
Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best
rx pathid: 0, tx pathid: 0x0
Updated on Aug 15 2025 07:58:08 UTC
Best Path Evaluation: Overall best path
Refresh Epoch 2
100
192.168.12.1 from 192.168.12.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, weight 32768, valid, external
rx pathid: 0, tx pathid: 0
Updated on Aug 15 2025 07:57:29 UTC
Best Path Evaluation: Not sourced
IOS-XR
続いて同じような確認方法でIOS-XRについても確認していく
結果としては基本的にIOS-XEと同じ挙動をしたが1点細かな点での差分としては上記のconfigを投入した段階でIOS-XEはRIB-FailureとなっていたがIOS-XRは特にそのようには見えてなく結果としては正しく処理されているように見える
ただもちろんだがRIB上にはconnectedの経路が存在するのでbgpとしての経路は表示されない
RP/0/RP0/CPU0:xr02#show bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 192.168.12.1 0 0 100 i
R1で確認。networkコマンドによりローカル生成されていることを確認
RP/0/RP0/CPU0:xr01#show bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 0.0.0.0 0 32768 i
R3で確認。R1で生成された経路がR2を経由してR3で受信できていることを確認
RP/0/RP0/CPU0:xr03#show bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 192.168.23.2 0 200 100 i
Locally originatedの挙動を確認するためR2で下記configを投入
router bgp 200
address-family ipv4 unicast
network 192.168.12.0/24
IOS-XEと同じような結果となる
RP/0/RP0/CPU0:xr02#show bgp | b Network
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 0.0.0.0 0 32768 i
* 192.168.12.1 0 0 100 i
redistributedに関しても同様に確認し、こちらも同様の結果を得る
router bgp 200
address-family ipv4 unicast
redistribute connected
RP/0/RP0/CPU0:xr02#show bgp | b Network
Fri Aug 15 07:31:16.539 UTC
Network Next Hop Metric LocPrf Weight Path
*> 2.2.2.2/32 0.0.0.0 0 32768 ?
*> 192.168.12.0/24 0.0.0.0 0 32768 ?
* 192.168.12.1 0 0 100 i
*> 192.168.23.0/24 0.0.0.0 0 32768 ?
R3上でもas-path的にR1で生成された経路でなくR2で生成された経路(R2でbest pathとして選択された経路)を受信している
RP/0/RP0/CPU0:xr03#show bgp | b Network
Fri Aug 15 07:28:24.948 UTC
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 192.168.23.2 0 0 200 i
この状態だとweightによる比較のためこちらもroute-mapによるweight値調整を行う
RP/0/RP0/CPU0:xr02#show bgp 192.168.12.0/24 bestpath-compare | b Path
Fri Aug 15 07:27:48.792 UTC
Paths: (2 available, best #1)
Advertised IPv4 Unicast paths to update-groups (with more than one peer):
0.2
Path #1: Received by speaker 0
Flags: 0x2000000041040123+0x00, import: 0x020
Advertised IPv4 Unicast paths to update-groups (with more than one peer):
0.2
Local
0.0.0.0 from 0.0.0.0 (2.2.2.2), if-handle 0x00000010
Origin IGP, metric 0, localpref 100, weight 32768, valid, local, best, group-best
Received Path ID 0, Local Path ID 1, version 10
best of local AS, Overall best
Path #2: Received by speaker 0
Flags: 0x3000000001020001+0x00, import: 0x020
Not advertised to any peer
100
192.168.12.1 from 192.168.12.1 (1.1.1.1), if-handle 0x00000000
Origin IGP, metric 0, localpref 100, valid, external, group-best
Received Path ID 0, Local Path ID 0, version 0
Origin-AS validity: (disabled)
best of AS 100
Lower weight than best path (path #1)
下記configをR2に投入
route-policy WEIGHT
set weight 32768
end-policy
!
router bgp 200
!
neighbor 192.168.12.1
address-family ipv4 unicast
route-policy WEIGHT in
route-policy PASS out
!
!
weight値が同じになりreasonを確認すると Not a local path as opposed to best path (path #1)とあることからIOS-XRでもLocally originatedによるbest path selectionの挙動を確認することができた
RP/0/RP0/CPU0:xr02#show bgp | b Network
Fri Aug 15 07:35:06.553 UTC
Network Next Hop Metric LocPrf Weight Path
*> 192.168.12.0/24 0.0.0.0 0 32768 i
* 192.168.12.1 0 32768 100 i
RP/0/RP0/CPU0:xr02#show bgp 192.168.12.0/24 bestpath-compare | b Path
Fri Aug 15 07:36:12.478 UTC
Paths: (2 available, best #1)
Advertised IPv4 Unicast paths to update-groups (with more than one peer):
0.2
Path #1: Received by speaker 0
Flags: 0x2000000041040123+0x00, import: 0x020
Advertised IPv4 Unicast paths to update-groups (with more than one peer):
0.2
Local
0.0.0.0 from 0.0.0.0 (2.2.2.2), if-handle 0x00000010
Origin IGP, metric 0, localpref 100, weight 32768, valid, local, best, group-best
Received Path ID 0, Local Path ID 1, version 20
best of local AS, Overall best
Path #2: Received by speaker 0
Flags: 0x3000000001020001+0x00, import: 0x020
Not advertised to any peer
100
192.168.12.1 from 192.168.12.1 (1.1.1.1), if-handle 0x00000000
Origin IGP, metric 0, localpref 100, weight 32768, valid, external, group-best
Received Path ID 0, Local Path ID 0, version 0
Origin-AS validity: (disabled)
best of AS 100
Not a local path as opposed to best path (path #1)
今回の確認でローカルで生成されたルートの扱いがなんとなくわかったような気がする。ユースケースについてはまだあまり分かってない