Cost-Community (iBGP)

Topology: ine-spv4

Load bgp.cost-community.ibgp.init.cfg

#IOS-XE
config replace flash:bgp.cost-community.ibgp.init.cfg
 
#IOS-XR
configure
load bootflash:bgp.cost-community.ibgp.init.cfg
commit replace
y

Using IGP cost-community, influence R1 and R2 to prefer the route to XR2’s loopbacks via R4.

Answer

#R4
route-map IBGP_OUT
 set extcommunity cost igp 24 100
!
router bgp 100
 template peer-policy IBGP
  route-map IBGP_OUT out
  send-community extended

Explanation

The cost-community is an extcommunity, which has two POIs (points of insertion). The cost community can be inserted as “pre-bestpath” in which it is evaluated before any other BGP bestpath step, including weight. Cost-community can also have a “IGP” POI, in which it is evaluated after the IGP nexthop metric for the route. This allows cost-community to essentially be a tie-breaker, as it is evaluated before the lowest RID step in the bestpath selection process.

In this lab, before we make any changes, R1 is preferring to reach XR2’s prefixes using R3 due to the lowest RID. The IGP metric to both next hops is identical.

Next, we configure R4 to set the cost-community with IGP POI outbound to iBGP peers. It also must send extcommunities to its iBGP peers. It is important to note that cost-community is not transitive. It cannot be sent to an eBGP peer. The only exception to this is when you translate AIGP into cost-community. In that one case, you can send the cost-community to an eBGP peer.

#R4
route-map IBGP_OUT
 set extcommunity cost igp 24 100
!
router bgp 100
 template peer-policy IBGP
  route-map IBGP_OUT out
  send-community extended

When setting cost-community you have two POI options: IGP or pre-bestpath. When none is specified, igp is assumed.

R4(config-route-map)#set extcommunity cost ?
  <0-255>       Community ID
  igp           Compare following IGP cost comparison
  pre-bestpath  Compare before all other steps in bestpath calculation

Next, you configure a community ID. The lowest community ID is preferred among routes with the same POI but different community IDs. For example, if we configure R3 to use community ID 23 but a higher value, R1 will still pick R3 as bestpath, due to the lower community ID. (The cost is only compared when the community ID is the same).

#R3
route-map IBGP_OUT
 set extcommunity cost igp 23 50000
!
router bgp 100
 template peer-policy IBGP
  route-map IBGP_OUT out
  send-community extended

If we instead change the community ID to be the same value, only then are the final cost values compared, and R4 wins again.

#R3
route-map IBGP_OUT
 no set extcommunity cost igp 23 50000
 set extcommunity cost igp 24 50000

It is important to note that when one path has a cost-community value, any other paths that don’t have a cost-community value will implicitly have the default value of (2^32)/2. This is the midpoint of the max possible value. A handy way to obtain this value is to solicit context-sensitive help on the route-map on IOS-XE.

To prove this, we can remove the cost-community from R3 and set R4 to a value above this number. R1 should now prefer R3 instead of R4, even though R3 is not sending any cost-community at all.

#R3
router bgp 100
 template peer-policy IBGP
  no route-map IBGP_OUT out

#R4
route-map IBGP_OUT permit 10
 set extcommunity cost igp 24 2147483648

Also note that the default POI when none is specifed on IOS-XE is IGP.

#R4
route-map IBGP_OUT permit 10
 set extcommunity cost 24 100

We can also use the “bgp bestpath cost-community ignore” command if desired. Using this on R1 will make R1 skip this step and proceed on to the lowest RID.

#R1
router bgp 100
 bgp bestpath cost-community ignore

Last updated