BGP LOCAL_PREF

この記事は約27分で読めます。

LOCAL_PREFはWEIGHTに次いで優先度の高いパスパトリビュートである。LOCAL_PREFはiBGPピアに対してアドバタイズし、AS内部の全BGPスピーカで共有する。外部ASへの上りの通信経路が複数存在する場合に、どの通信経路を優先して使用するか制御したい場合に使用する。

検証ネットワーク構成

R1~R6はC891FJ-K9 15.8(3)M6、R7はWS-C3560-8PC-S 15.0(2)SE9を使用。

上図において、R7からR1への通信経路は、WEIGHT、LOCAL_PREF、MEDを設定していない限り必ずAS200を通る。理由は以下の通り。

通信経路①:R7⇒R6⇒R4(R6はルートリフレクタでR4の生成したiBGPルートをR7に反射する前提)

結論的に、R7⇒R6⇒R4の通信経路はベストパスではない。

R7⇒R6⇒R4の経路はNEXT_HOP(10.0.30.1)までのメトリックが3になる。対してR7⇒R4(R5)の経路はNEXT_HOPまでのメトリックは2であるため、R7⇒R4の経路が優先されるからだ。

と思っていたが、正常時のR7のshow ip bgpを見てみると、R6経由のNEXT_HOPへのメトリックは2と表示される。Cisco891でもCatalyst 3560でも結果は変わらなかった。Cisco IOSではshow ip bgpのNEXT_HOPのメトリック計算にはshow ip routeのメトリック値がそのまま使用されると思われる。

R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 21
Paths: (3 available, best #2, table default)
  Advertised to update-groups:
     11         16
  200 100
    10.0.30.1 (metric 2) from 10.0.90.1 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 4.4.4.4, Cluster list: 6.6.6.6
  200 100, (Received from a RR-client)
    10.0.30.1 (metric 2) from 10.0.70.1 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, internal, best
  300 100, (Received from a RR-client)
    10.0.40.1 (metric 2) from 10.0.60.1 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal

試しにR7でFa0/1、Fa0/2をshutdownし、物理的な通信経路をR7⇒R6⇒R4に限定したうえで、R7でshow ip bgpを実行してみたところ、想定通りの結果(NEXT_HOPへのメトリックが3)が得られた。

R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 36
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  200 100
    10.0.30.1 (metric 3) from 10.0.90.1 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Originator: 4.4.4.4, Cluster list: 6.6.6.6

上記結果より、show ip bgpのNEXT_HOPへのメトリック計算にはshow ip routeの値がそのまま反映されると考えて間違いなさそうだ。通常運用時はR7⇒R6⇒R4のNEXT_HOPへのメトリックは2であるため、メトリック計算だけでは以下通信経路勝負しても決着が付かない。

通信経路②:R7⇒R4(赤線)、R7⇒R5(青線)

R7⇒R4の経路はNEXT_HOP(10.0.30.1)までのメトリックが2である。R7⇒R5の経路もNEXT_HOP(10.0.40.1)までのメトリックが2であり、互角である。上述の通り、R7⇒R6⇒R4もメトリックが2である。

この場合、R7から見たiBGPピアのルータIDが最も小さい経路がベストパスに選ばれる。R4(4.4.4.4)が最も小さいルータIDとなるため、R7⇒R4の通信経路がベストパスとなる。

尚、ルートリフレクタ経由で学習した経路情報には「Originator」属性が付与される。ルータIDの比較時は本属性がルータIDの代わりに使用される。以下の例では1番目の経路情報はOriginator: 4.4.4.4がルータIDとして使用されるため、2番目の経路情報とルータIDが同じとなり、決着がつかない。ルータIDでも決着がつかない場合は「より小さいネイバーアドレスから受信した」経路情報が優先される。

  200 100
    10.0.30.1 (metric 2) from 10.0.90.1 (6.6.6.6) ⇒ネイバーアドレスは10.0.90.1(敗北)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 4.4.4.4, Cluster list: 6.6.6.6 ⇒ルータIDは4.4.4.4として扱われる。
  200 100, (Received from a RR-client)
    10.0.30.1 (metric 2) from 10.0.70.1 (4.4.4.4) ⇒ネイバーアドレスは10.0.70.1(勝利)
      Origin IGP, metric 0, localpref 100, valid, internal, best

上記はCCOのベストパス選択アルゴリズムの11~13に書かれている。

Select BGP Best Path Algorithm
This document describes the function of the Border Gateway Protocol (BGP) best path algorithm.

11. Prefer the route that comes from the BGP router with the lowest router ID. The router ID is the highest IP address on the router, with preference given to loopback addresses. Also, you can use the bgp router-id command in order to manually set the router ID.

Note: If a path contains route reflector (RR) attributes, the originator ID is substituted for the router ID in the path selection process.

12. If the originator or router ID is the same for multiple paths, prefer the path with the minimum cluster list length. This is only present in BGP RR environments. It allows clients to peer with RRs or clients in other clusters. In this scenario, the client must be aware of the RR-specific BGP attribute.

13. Prefer the path that comes from the lowest neighbor address. This address is the IP address that is used in the BGP neighbor configuration. The address corresponds to the remote peer that is used in the TCP connection with the local router.

https://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/13753-25.html

設定変更前のBGPテーブル

下図の通り、R7からR1への通信経路をR4経由ではなく、R5経由に変更する。

設定変更前のR7のBGPテーブルは以下の通り。

R7#show ip bgp
BGP table version is 52, local router ID is 7.7.7.7
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.1/32       10.0.30.1                0    100      0 200 100 i
* i                 10.0.30.1                0    100      0 200 100 i
* i                 10.0.40.1                0    100      0 300 100 i
*>i2.2.2.2/32       10.0.30.1                0    100      0 200 i
* i                 10.0.30.1                0    100      0 200 i
* i3.3.3.3/32       10.0.40.1                0    100      0 300 i
*>i                 10.0.40.1                0    100      0 300 i
r>i4.4.4.4/32       10.0.70.1                0    100      0 i
r i                 10.0.50.1                0    100      0 i
r i5.5.5.5/32       10.0.80.1                0    100      0 i
r>i                 10.0.60.1                0    100      0 i
r>i6.6.6.6/32       10.0.90.1                0    100      0 i
*> 7.7.7.7/32       0.0.0.0                  0         32768 i
R7#
R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 52
Paths: (3 available, best #1, table default)
  Advertised to update-groups:
     16         17
  200 100, (Received from a RR-client)
    10.0.30.1 (metric 2) from 10.0.70.1 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, internal, best
  200 100
    10.0.30.1 (metric 2) from 10.0.90.1 (6.6.6.6)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 4.4.4.4, Cluster list: 6.6.6.6
  300 100, (Received from a RR-client)
    10.0.40.1 (metric 2) from 10.0.60.1 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal

R7は1.1.1.1/32の経路情報をiBGPで学習しており、NEXT_HOPが10.0.30.1でルータIDが4.4.4.4(R4)から受信した経路をベストパスに選んでいることがわかる。

LOCAL_PREFの設定

LOCAL_PREFの設定変更方法は2通りある。

①iBGPピアに対して全経路情報のLOCAL_PREF値を変える方法(bgp default local-preference <値>)

②iBGPピアに対して特定の経路情報のLOCAL_PREF値のみを変える方法(route-map)

今回は1.1.1.1/32の通信経路のみをR5経由に変更するという要件のため、route-mapを使用する。

LOCAL_PREFはiBGPピアに対してアドバタイズし、AS内部の全BGPスピーカで共有する情報のため、route-mapはout方向で設定する。設定はAS境界ルータ(R5)で設定する。

##### 作業前のR5のBGP設定 #####
R5#show run | sect bgp
router bgp 400
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 network 5.5.5.5 mask 255.255.255.255
 neighbor 10.0.40.1 remote-as 300
 neighbor 10.0.60.2 remote-as 400
 neighbor 10.0.80.2 remote-as 400

##### prefix-listで1.1.1.1/32を定義 #####
R5(config)#ip prefix-list AS400->AS300 seq 10 permit 1.1.1.1/32

##### route-mapで1.1.1.1/32に対してLOCAL_PREF値1000を設定 #####
R5(config)#route-map AS400->AS300 permit 10
R5(config-route-map)#match ip address prefix-list AS400->AS300
R5(config-route-map)#set local-preference ?
  <0-4294967295>  Preference value
R5(config-route-map)#set local-preference 1000

##### route-mapの空打ち(1.1.1.1/32 LOCAL_PREF 1000以外のルートもアドバタイズするようにする) #####
R5(config)#route-map AS400->AS300 permit 20

##### R7に対してroute-mapをout方向に設定 #####
R5(config)#router bgp 400
R5(config-router)#neighbor 10.0.60.2 route-map AS400->AS300 out

##### 作業後のR5のBGP設定 #####
R5#show run | sect bgp
router bgp 400
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 network 5.5.5.5 mask 255.255.255.255
 neighbor 10.0.40.1 remote-as 300
 neighbor 10.0.60.2 remote-as 400
 neighbor 10.0.60.2 route-map AS400->AS300 out
 neighbor 10.0.80.2 remote-as 400

設定変更後はR5においてclear ip bgp 10.0.60.2 soft outは必要ない。即時でR7のBGPテーブルに設定変更内容が反映された。

設定変更後のBGPテーブル

設定変更後のR7のBGPテーブルは以下の通り。

R7#show ip bgp
BGP table version is 53, local router ID is 7.7.7.7
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, x best-external, f RT-Filter
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.1/32       10.0.40.1                0   1000      0 300 100 i
*>i2.2.2.2/32       10.0.30.1                0    100      0 200 i
* i                 10.0.30.1                0    100      0 200 i
* i3.3.3.3/32       10.0.40.1                0    100      0 300 i
*>i                 10.0.40.1                0    100      0 300 i
r>i4.4.4.4/32       10.0.70.1                0    100      0 i
r i                 10.0.50.1                0    100      0 i
r i5.5.5.5/32       10.0.80.1                0    100      0 i
r>i                 10.0.60.1                0    100      0 i
r>i6.6.6.6/32       10.0.90.1                0    100      0 i
*> 7.7.7.7/32       0.0.0.0                  0         32768 i
R7#
R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 53
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     16         17
  300 100, (Received from a RR-client)
    10.0.40.1 (metric 2) from 10.0.60.1 (5.5.5.5)
      Origin IGP, metric 0, localpref 1000, valid, internal, best

5.5.5.5(R5)から受信した経路情報1.1.1.1/32のLOCAL_PREFが100(デフォルト値)から1000に変更されており、ベストパスに選定されていることが確認できる。

尚、LOCAL_PREF値はAS内部で共有される情報のため、AS400内の他のBGPスピーカにも情報が伝搬されている。以下にR4,R5,R6のBGPテーブルの情報も掲載する。

##### R4 BGPテーブル #####
R4#show run | sect bgp
router bgp 400
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 network 4.4.4.4 mask 255.255.255.255
 neighbor 10.0.30.1 remote-as 200
 neighbor 10.0.50.2 remote-as 400
 neighbor 10.0.70.2 remote-as 400
R4#
R4#show ip bgp
BGP table version is 68, local router ID is 4.4.4.4
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,
              t secondary path,
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.1/32       10.0.40.1                0   1000      0 300 100 i
 *>i                   10.0.40.1                0   1000      0 300 100 i
 *                     10.0.30.1                              0 200 100 i
 *>   2.2.2.2/32       10.0.30.1                0             0 200 i
 * i  3.3.3.3/32       10.0.40.1                0    100      0 300 i
 *>i                   10.0.40.1                0    100      0 300 i
 *                     10.0.30.1                              0 200 100 300 i
 *>   4.4.4.4/32       0.0.0.0                  0         32768 i
 r i  5.5.5.5/32       10.0.60.1                0    100      0 i
 r>i                   10.0.80.1                0    100      0 i
 r i  6.6.6.6/32       10.0.90.1                0    100      0 i
 r>i                   10.0.50.2                0    100      0 i
 r>i  7.7.7.7/32       10.0.70.2                0    100      0 i
 r i                   10.0.90.2                0    100      0 i
R4#
R4#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 68
Paths: (3 available, best #2, table default)
  Advertised to update-groups:
     13
  Refresh Epoch 1
  300 100
    10.0.40.1 (metric 3) from 10.0.50.2 (6.6.6.6)
      Origin IGP, metric 0, localpref 1000, valid, internal
      Originator: 5.5.5.5, Cluster list: 6.6.6.6, 7.7.7.7
   ⇒Cluster listが2番目の経路情報よりも長いため、ベストパスにならない。
      rx pathid: 0, tx pathid: 0
  Refresh Epoch 1
  300 100
    10.0.40.1 (metric 3) from 10.0.70.2 (7.7.7.7)
      Origin IGP, metric 0, localpref 1000, valid, internal, best
      Originator: 5.5.5.5, Cluster list: 7.7.7.7
      rx pathid: 0, tx pathid: 0x0
  Refresh Epoch 2
  200 100
    10.0.30.1 from 10.0.30.1 (2.2.2.2)
      Origin IGP, localpref 100, valid, external
      rx pathid: 0, tx pathid: 0

##### R5 BGPテーブル #####
R5#show run | sect bgp
router bgp 400
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 network 5.5.5.5 mask 255.255.255.255
 neighbor 10.0.40.1 remote-as 300
 neighbor 10.0.60.2 remote-as 400
 neighbor 10.0.60.2 route-map AS400->AS300 out
 neighbor 10.0.80.2 remote-as 400
R5#
R5#show ip bgp
BGP table version is 40, local router ID is 5.5.5.5
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,
              t secondary path,
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.1/32       10.0.40.1                              0 300 100 i
 *>i  2.2.2.2/32       10.0.30.1                0    100      0 200 i
 * i                   10.0.30.1                0    100      0 200 i
 *                     10.0.40.1                              0 300 100 200 i
 *>   3.3.3.3/32       10.0.40.1                0             0 300 i
 r>i  4.4.4.4/32       10.0.70.1                0    100      0 i
 r i                   10.0.50.1                0    100      0 i
 *>   5.5.5.5/32       0.0.0.0                  0         32768 i
 r i  6.6.6.6/32       10.0.90.1                0    100      0 i
 r>i                   10.0.80.2                0    100      0 i
 r>i  7.7.7.7/32       10.0.60.2                0    100      0 i
 r i                   10.0.90.2                0    100      0 i
R5#
R5#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 16
Paths: (1 available, best #1, table default)
  Advertised to update-groups:
     11         15
  Refresh Epoch 1
  300 100
    10.0.40.1 from 10.0.40.1 (3.3.3.3)
      Origin IGP, localpref 100, valid, external, best
      rx pathid: 0, tx pathid: 0x0

##### R6 BGPテーブル #####
R6#show run | sect bgp
router bgp 400
 bgp router-id 6.6.6.6
 bgp log-neighbor-changes
 network 6.6.6.6 mask 255.255.255.255
 neighbor 10.0.50.1 remote-as 400
 neighbor 10.0.50.1 route-reflector-client
 neighbor 10.0.80.1 remote-as 400
 neighbor 10.0.80.1 route-reflector-client
 neighbor 10.0.90.2 remote-as 400
R6#
R6#show ip bgp
BGP table version is 19, 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,
              t secondary path,
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.1/32       10.0.40.1                0   1000      0 300 100 i
 * i                   10.0.40.1                0    100      0 300 100 i
 * i  2.2.2.2/32       10.0.30.1                0    100      0 200 i
 *>i                   10.0.30.1                0    100      0 200 i
 * i  3.3.3.3/32       10.0.40.1                0    100      0 300 i
 *>i                   10.0.40.1                0    100      0 300 i
 r i  4.4.4.4/32       10.0.70.1                0    100      0 i
 r>i                   10.0.50.1                0    100      0 i
 r i  5.5.5.5/32       10.0.60.1                0    100      0 i
 r>i                   10.0.80.1                0    100      0 i
 *>   6.6.6.6/32       0.0.0.0                  0         32768 i
 r>i  7.7.7.7/32       10.0.90.2                0    100      0 i
R6#
R6#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 19
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     5
  Refresh Epoch 1
  300 100
    10.0.40.1 (metric 2) from 10.0.90.2 (7.7.7.7)
      Origin IGP, metric 0, localpref 1000, valid, internal, best
      Originator: 5.5.5.5, Cluster list: 7.7.7.7
      rx pathid: 0, tx pathid: 0x0
  Refresh Epoch 3
  300 100, (Received from a RR-client)
    10.0.40.1 (metric 2) from 10.0.80.1 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0

以上

コメント

タイトルとURLをコピーしました