Saturday 16 June 2012

BGP Attributes: Local Preference

BGP Attributes: Local Preference
 

·         Unlike weight attribute, which is relevant only to the local router, local preference is an attribute that is exchanged among routers in the same AS.
·         Higher value is preferred.
·         The default local preference is 100.
·         Local Preference is used to affect the traffic that is leaving your AS.

     R4----------------R2---------------R1--------------R3

·         R2: Ser1/0 – 100.1.24.2 ßà R4: Ser1/0 – 100.1.24.4
·         R2: Ser1/1 – 10.1.12.2 ßà R1: Ser1/1 – 10.1.12.1
·         R1: Ser1/0 – 100.1.13.1 ßà R3: Ser1/0 – 100.1.13.3

·         AS 100: R1 & R2
·         AS 300: R3
·         AS 400: R4

·         iBGP between R1 & R2
·         eBGP between R2 and R4
·         eBGP between R1 and R3
·         Created a loopback 34.34.34.34/32 on R3 and R4 and advertised into BGP.
·         R1’s and R2’s loopbacks are also advertised into BGP.
·         Let’s see how to use Local Preference in this scenario

BGP Configs:

R3(config-router)#do show run | begin router bgp 300
router bgp 300
 no synchronization
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 network 34.34.34.34 mask 255.255.255.255
 neighbor 100.1.13.1 remote-as 100
 no auto-summary
!

R4(config-router)#do show run | begin router bgp 400
router bgp 400
 no synchronization
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 network 34.34.34.34 mask 255.255.255.255
 neighbor 100.1.24.2 remote-as 100
 no auto-summary
!
R1(config-router)#do show run | begin router bgp 100
router bgp 100
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 network 1.1.1.1 mask 255.255.255.255
 neighbor 2.2.2.2 remote-as 100
 neighbor 2.2.2.2 update-source Loopback0
 neighbor 2.2.2.2 next-hop-self
 neighbor 100.1.13.3 remote-as 300
 no auto-summary
!

R2(config-router)#do show run | begin router bgp 100
router bgp 100
 no synchronization
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 network 2.2.2.2 mask 255.255.255.255
 neighbor 1.1.1.1 remote-as 100
 neighbor 1.1.1.1 update-source Loopback0
 neighbor 1.1.1.1 next-hop-self
 neighbor 100.1.24.4 remote-as 400
 no auto-summary
!

R3#show ip bgp sum
BGP router identifier 3.3.3.3, local AS number 300
BGP table version is 4, main routing table version 4
3 network entries using 351 bytes of memory
3 path entries using 156 bytes of memory
4/3 BGP path/bestpath attribute entries using 496 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1027 total bytes of memory
BGP activity 3/0 prefixes, 3/0 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
100.1.13.1      4   100     944     943        4    0    0 15:39:22        2
R3#

R4#show ip bgp sum
BGP router identifier 4.4.4.4, local AS number 400
BGP table version is 6, main routing table version 6
3 network entries using 351 bytes of memory
3 path entries using 156 bytes of memory
4/3 BGP path/bestpath attribute entries using 496 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1027 total bytes of memory
BGP activity 3/0 prefixes, 4/1 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
100.1.24.2      4   100     946     943        6    0    0 15:39:32        2
R4#

R1#show ip bgp sum
BGP router identifier 1.1.1.1, local AS number 100
BGP table version is 5, main routing table version 5
3 network entries using 351 bytes of memory
4 path entries using 208 bytes of memory
5/3 BGP path/bestpath attribute entries using 620 bytes of memory
2 BGP AS-PATH entries using 48 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1227 total bytes of memory
BGP activity 3/0 prefixes, 4/0 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2.2.2.2         4   100     945     945        5    0    0 15:40:07        2
100.1.13.3      4   300     943     944        5    0    0 15:39:42        1
R1#

R2#show ip bgp sum
BGP router identifier 2.2.2.2, local AS number 100
BGP table version is 6, main routing table version 6
3 network entries using 351 bytes of memory
4 path entries using 208 bytes of memory
5/3 BGP path/bestpath attribute entries using 620 bytes of memory
2 BGP AS-PATH entries using 48 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 1227 total bytes of memory
BGP activity 3/0 prefixes, 4/0 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
1.1.1.1         4   100     945     945        6    0    0 15:40:08        2
100.1.24.4      4   400     943     946        6    0    0 15:39:31        1
R2#

BGP Table:

R3#show ip bgp
BGP table version is 4, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       100.1.13.1               0             0 100 i
*> 2.2.2.2/32       100.1.13.1                             0 100 i
*> 34.34.34.34/32   0.0.0.0                  0         32768 i
R3#

R4#show ip bgp
BGP table version is 6, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       100.1.24.2                             0 100 i
*> 2.2.2.2/32       100.1.24.2               0             0 100 i
*> 34.34.34.34/32   0.0.0.0                  0         32768 i
R4#

R1#show ip bgp
BGP table version is 5, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                  0         32768 i
r>i2.2.2.2/32       2.2.2.2                  0    100      0 i
* i34.34.34.34/32   2.2.2.2                  0    100      0 400 i
*>                  100.1.13.3               0             0 300 i
R1#

R1#show ip bgp 34.34.34.34
BGP routing table entry for 34.34.34.34/32, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2
  400
    2.2.2.2 (metric 65) from 2.2.2.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal
  300
    100.1.13.3 from 100.1.13.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best
R1#

Observation:

·         R1 is learning 34.34.34.34 from two neighbors.
·         One from eBGP neighbor R3 and another one from an iBGP neighbor R2
·         R1 has chosen the best path to reach 34.34.34.34 through R3
·         This expected because eBGP has AD of 20 and iBGP has an AD of 200

·         R2’s loopback 2.2.2.2/32 has “r” symbol in the front (rib-failure).
·         This means R1 is learning about 2.2.2.2/32 from some other means which has a better (lower) AD
·         R2 has already learnt this route via OSPF which has an AD of 110, so R1 will show this as rib-failure in BGP Table.

R1#show ip route ospf
     2.0.0.0/32 is subnetted, 1 subnets
O       2.2.2.2 [110/65] via 10.1.12.2, 16:01:27, Serial1/1
R1#

R2#show ip bgp
BGP table version is 6, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
r>i1.1.1.1/32       1.1.1.1                  0    100      0 i
*> 2.2.2.2/32       0.0.0.0                  0         32768 i
*> 34.34.34.34/32   100.1.24.4               0             0 400 i
* i                 1.1.1.1                  0    100      0 300 i
R2#

R2#show ip bgp 34.34.34.34
BGP routing table entry for 34.34.34.34/32, version 3
Paths: (2 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  400
    100.1.24.4 from 100.1.24.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, external, best
  300
    1.1.1.1 (metric 65) from 1.1.1.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal
R2#

Observation:

·         R2 is learning 34.34.34.34 from two neighbors.
·         One from eBGP neighbor R4 and another one from an iBGP neighbor R1
·         R2 has chosen the best path to reach 34.34.34.34 through R4
·         This expected because eBGP has AD of 20 and iBGP has an AD of 200

·         R1’s loopback 1.1.1.1/32 has “r” symbol in the front (rib-failure).
·         This means R2 is learning about 1.1.1.1/32 from some other means which has a better (lower) AD
·         R1 has already learnt this route via OSPF which has an AD of 110, so R1 will show this as rib-failure in BGP Table.

R2#show ip route ospf
     1.0.0.0/32 is subnetted, 1 subnets
O       1.1.1.1 [110/65] via 10.1.12.1, 16:03:30, Serial1/1
R2#

·         Now, back to our learning on Local Preference Attribute.
·         What if R1 ahs to go through R2 to reach the prefix 34.34.34.34 ???
·         We can use Local Preference attribute to do this.


Configuring Local Preference: Configuring Globally

R2(config-router)#router bgp 100
R2(config-router)#bgp default local-preference 1999

R2(config-router)#do show ip bgp
BGP table version is 5, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
r>i1.1.1.1/32       1.1.1.1                  0    100      0 i
*> 2.2.2.2/32       0.0.0.0                  0         32768 i
*> 34.34.34.34/32   100.1.24.4               0             0 400 i
R2(config-router)#
R2(config-router)#do show ip bgp 34.34.34.34
BGP routing table entry for 34.34.34.34/32, version 3
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  400
    100.1.24.4 from 100.1.24.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 1999, valid, external, best
R2(config-router)#

R1(config-router)#do show ip bgp
BGP table version is 12, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                  0         32768 i
r>i2.2.2.2/32       2.2.2.2                  0   1999      0 i
*>i34.34.34.34/32   2.2.2.2                  0   1999      0 400 i
*                   100.1.13.3               0             0 300 i
R1(config-router)#

R1(config-router)#do trace 34.34.34.34 source 1.1.1.1

Type escape sequence to abort.
Tracing the route to 34.34.34.34

  1 10.1.12.2 16 msec 60 msec 32 msec
  2 100.1.24.4 32 msec *  64 msec
R1(config-router)#

Observations:

·         My configuration is working and now R1 is taking the path through R2 to reach the prefix 34.34.34.34/32
·         Also, since it is local to an AS, the value has been propagated to R1 also.

·         Since I have configured Local Preference globally on R2, The value has been applied to all the routes from R2

Configuring Local Preference: Configuring per neighbor

R2(config-router)#no  bgp default local-preference 1999

R2(config-router)#route-map LOCAL
R2(config-route-map)#set local
R2(config-route-map)#set local-preference 2999
R2(config-route-map)#router bgp 100
R2(config-router)#neighbor 100.1.24.4 route-map LOCAL in
R2(config-router)#

** If we want to be prefix specific, we can match the prefix using access-list, prefix-list etc and call that address in a route-map


R2(config-router)#do show ip bgp
BGP table version is 5, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
r>i1.1.1.1/32       1.1.1.1                  0    100      0 i
*> 2.2.2.2/32       0.0.0.0                  0         32768 i
*> 34.34.34.34/32   100.1.24.4               0   2999      0 400 i
R2(config-router)#

R1(config-router)#do show ip bgp
BGP table version is 18, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                  0         32768 i
r>i2.2.2.2/32       2.2.2.2                  0    100      0 i
*>i34.34.34.34/32   2.2.2.2                  0   2999      0 400 i
*                   100.1.13.3               0             0 300 i
R1(config-router)#

R1(config-router)#do trace 34.34.34.34 source 1.1.1.1

Type escape sequence to abort.
Tracing the route to 34.34.34.34

  1 10.1.12.2 28 msec 64 msec 28 msec
  2 100.1.24.4 60 msec *  64 msec
R1(config-router)#

Observations:

·         My configuration is working and now R1 is taking the path through R2 to reach the prefix 34.34.34.34/32
·         Also, since it is local to an AS, the value has been propagated to R1 also.

·         Since I have configured Local Preference for the neighbor R4, The value has been applied for the prefix learnt from R4, which is 34.34.34.34/32

No comments:

Post a Comment