BGP Cost Community

Posted by
Facebooktwitterredditpinterestlinkedintumblr

This post explores the use of BGP cost community to prefer one path over the other in a multipath environment as shown in the figure. BGP cost community is a nontransitive extended community attribute that is passed to iBGP peers only. This feature allows us to customize the BGP best path selection process at the point of insertion (meaning from BGP table to routing table) for a local AS or confederation by assigning cost values to specific route.

BGP Cost Community

By default, BGP cost community is not use as part of BGP best path selection process. Consider the example below (presented under Before tab), BGP selected the path via 12.1.1.2 this is because it has the lowest BGP router ID of 2.2.2.2. By implementing BGP cost community, we can change its preferred path via 13.1.1.2 (presented under After tab).

R1#sh ip bgp 40.1.1.1
BGP routing table entry for 40.1.1.0/24, version 4
Paths: (2 available, best #2, table default)
  Not advertised to any peer
  Refresh Epoch 1
  65513
    13.1.1.2 from 13.1.1.2 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal
  Refresh Epoch 1
  65513
    12.1.1.2 from 12.1.1.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal, best

R1#sh ip bgp 40.1.1.1
BGP routing table entry for 40.1.1.0/24, version 6
Paths: (2 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 3
  65513
    13.1.1.2 from 13.1.1.2 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Extended Community: Cost:igp:1:50
  Refresh Epoch 3
  65513
    12.1.1.2 from 12.1.1.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, internal
      Extended Community: Cost:igp:1:100

The BGP cost community is configured using a route-map with a set clause – set extcommunity cost community-id cost-value.

cost-value is the the value assign to different routes. This value is from 0 to 4294967295. The lower the cost the better. If no cost is configured, Cisco automatically assigns a value of 2147483647 (half of 4294967295).

When a route has two paths that have been configured with the same cost, the best path selection process prefers the path with the lowest community ID. community-id is a range from 0 to 255.

BGP cost community is configured in R2 and R3 towards R1. Take note that send-community must be configured as well otherwise R1 won’t get the BGP cost community attribute.

ip prefix-list COSTCOMMUNITY seq 1 permit 40.1.1.0/24
!
route-map COSTCOMMUNITY permit 1
 match ip address prefix-list COSTCOMMUNITY
 set extcommunity cost igp 1 100
!
 router bgp 65512
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 12.1.1.1 remote-as 65512
 neighbor 24.1.1.1 remote-as 65513
 !
 address-family ipv4
  neighbor 12.1.1.1 activate
  neighbor 12.1.1.1 send-community extended
  neighbor 12.1.1.1 next-hop-self
  neighbor 12.1.1.1 route-map COSTCOMMUNITY out
  neighbor 24.1.1.1 activate
 exit-address-family

ip prefix-list COSTCOMMUNITY seq 1 permit 40.1.1.0/24
!
route-map COSTCOMMUNITY permit 10
 match ip address prefix-list COSTCOMMUNITY
 set extcommunity cost igp 1 50
!
router bgp 65512
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 13.1.1.1 remote-as 65512
 neighbor 34.1.1.1 remote-as 65513
 !
 address-family ipv4
  neighbor 13.1.1.1 activate
  neighbor 13.1.1.1 send-community both
  neighbor 13.1.1.1 next-hop-self
  neighbor 13.1.1.1 route-map COSTCOMMUNITY out
  neighbor 34.1.1.1 activate
 exit-address-family

2 comments

  1. Very nice blog, still in this way , give us some more cisco mpls vpn information if you have.
    Many thanks,

Leave a Reply

Your email address will not be published. Required fields are marked *

*