BGP Conditional Advertisement

BGP Conditional Advertisement

BGP, by default, advertises all the best paths in its BGP table to external peers. Sometimes, it might be required that BGP advertises some paths conditionally, meaning, advertise paths only if some other routes are available.

Conditional advertisement has two forms- advertisement of some prefix(es) when some other prefix(es) do not exist and advertisement of some prefix(es) when some other prefix(es) exist. The prefixes to be advertised are defined by advertise-map. The condition is defined by a route-map called non-exist-map for conditions that do not exist or by a route-map called exist-map for conditions that do exist.

The first form of conditional advertisement is configured as follows-

neighbor <neighbor-ip-address> advertise-map <map1> non-exist-map <map2>

The map2 route-map tracks the prefix(es) in the local router. If a match is made, the status of the non-exist-map is Withdraw; when no match is made, the status is Advertise.

The map1 route-map defines the prefix(es) that are to be advertised when the status of non-exist-map is Advertise. When the status of the non-exist-map is Withdraw, the prefix(es) in advertise-map are not advertised.

The second form of conditional advertisement is configured as follows-

neighbor <neighbor-ip-address> advertise-map <map1> exist-map <map2>

Again, the map2 route-map tracks the prefix(es) in the local router. If a match is made, the status of the exist-map is Advertise; when no match is made, the status of the exist-map is Withdraw. The function is map1 route-map is same as above.

Configuration:

AS 100 is multihomed to AS 200 (backup) and AS 300 (primary). R1 router gets its internal block of 172.16.1.0/24 from AS 300. R3 router advertises 172.16.2.0/24 to R1 router.

R1 router advertises 172.16.1.0/24 to R2 router only if the link between R1 - R3 fails. The non-exist-map tracks 172.16.2.0/24 prefix received from AS 300 (R3 router). And the advertise-map will advertise/withdraw local prefix 172.16.1.0/24 based on the status. R1's configuration is as follows-

BGP configuration on R1

router bgp 100
 network 172.16.1.0 mask 255.255.255.0
 neighbor 10.12.1.2 remote-as 200
 neighbor 10.12.1.2 advertise-map TO_AS200 non-exist-map FROM_AS300
 neighbor 10.13.1.2 remote-as 300
!
ip prefix-list 10 seq 5 permit 172.16.2.0/24
ip prefix-list 20 seq 5 permit 172.16.1.0/24
!
ip as-path access-list 10 permit ^300
!
route-map FROM_AS300 permit 10
 match ip address prefix-list 10
 match as-path 10
!
route-map TO_AS200 permit 10
 match ip address prefix-list 20
!

BGP configuration on R2 and R3

R2 router:
router bgp 200
 neighbor 10.12.1.1 remote-as 100
!
R3 router:
router bgp 300
 neighbor 10.13.1.1 remote-as 100
 network 172.16.2.0 mask 255.255.255.0
!

Verification:

Under normal circumstances i.e. when the link between R1 - R3 is working, R1 does not advertise 172.16.1.0/24 to R2 router.

R1-R3 link is operational

R1# show ip bgp neighbor 10.12.1.2 | include Condition-map
  Condition-map FROM_AS300, Advertise-map TO_AS200, status: Withdraw
R1# show ip bgp 172.16.2.0
BGP routing table entry for 172.16.2.0/24, version 4
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2
  300
    10.13.1.2 from 10.13.1.2 (172.16.2.1)
      Origin IGP, metric 0, localpref 100, valid, external, best
R2# show ip bgp 172.16.1.0
% Network not in table

When the link between R1 - R3 goes down, the tracking of 172.16.2.0/24 by R1 router fails. The status of the non-exist-map changes to Advertise from Withdraw. R1 now advertises 172.16.1.0/24 to R2 router.

R1-R3 link goes down

R1#
*Mar  1 00:08:13.867: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to down
*Mar  1 00:08:13.879: %BGP-5-ADJCHANGE: neighbor 10.13.1.2 Down Interface flap
*Mar  1 00:08:26.607: BPG(0): Condition FROM_AS300 changes to Advertise
*Mar  1 00:08:26.607: BPG(0): Condition FROM_AS300 changes to Advertise
*Mar  1 00:08:26.607: BGP(0): net 172.16.1.0/24 matches ADV MAP TO_AS200: bump version to 7
*Mar  1 00:08:26.987: BGP(0): nettable_walker 172.16.1.0/24 route sourced locally
*Mar  1 00:08:44.007: BGP(0): 10.12.1.2 172.16.1.0/24 matches advertise map TO_AS200, state: Advertise
*Mar  1 00:08:44.007: BGP(0): 10.12.1.2 send UPDATE (format) 172.16.1.0/24, next 10.12.1.1, metric 0, path Local
R1# show ip bgp neighbor 10.12.1.2 | include Condition-map
  Condition-map FROM_AS300, Advertise-map TO_AS200, status: Advertise
R1# show ip bgp 172.16.2.0
% Network not in table
R1# show ip bgp neighbor 10.12.1.2 advertised-routes
BGP table version is 7, local router ID is 172.16.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
*> 172.16.1.0/24    0.0.0.0                  0         32768 i
Total number of prefixes 1
R2# show ip bgp 172.16.1.0
BGP routing table entry for 172.16.1.0/24, version 6
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
  Not advertised to any peer
  100
    10.12.1.1 from 10.12.1.1 (172.16.1.1)
      Origin IGP, metric 0, localpref 100, valid, external, best

When the link between R1 - R3 is restored, R1 withdraws 172.16.1.0/24 from R2 router by advertising it as Unreachable. The status changes to Withdraw again as 172.16.2.0/24 is reachable by R1 router.

R1-R3 link is restored

*Mar  1 00:33:56.027: %BGP-5-ADJCHANGE: neighbor 10.13.1.2 Up
*Mar  1 00:33:56.031: BGP(0): Revise route installing 1 of 1 routes for 172.16.2.0/24 -> 10.13.1.2(main) to main IP table
*Mar  1 00:33:56.035: BGP(0): 10.13.1.2 send UPDATE (format) 172.16.1.0/24, next 10.13.1.1, metric 0, path Local
*Mar  1 00:33:56.039: BGP(0): 10.12.1.2 send UPDATE (format) 172.16.2.0/24, next 10.12.1.1, metric 0, path 300
*Mar  1 00:34:26.907: BPG(0): Condition FROM_AS300 changes to Withdraw
*Mar  1 00:34:26.907: BPG(0): Condition FROM_AS300 changes to Withdraw
*Mar  1 00:34:26.911: BGP(0): net 172.16.1.0/24 matches ADV MAP TO_AS200: bump version to 13
*Mar  1 00:34:27.147: BGP(0): nettable_walker 172.16.1.0/24 route sourced locally
*Mar  1 00:34:27.147: BGP(0): 10.12.1.2 172.16.1.0/24 matches advertise map TO_AS200, state: Withdraw
*Mar  1 00:34:27.147: BGP(0): 10.12.1.2 send unreachable 172.16.1.0/24
*Mar  1 00:34:27.151: BGP(0): 10.12.1.2 send UPDATE 172.16.1.0/24 -- unreachable
*Mar  1 00:34:27.151: BGP(0): 10.13.1.2 skip UPDATE 172.16.1.0/24 (chgflags: 0x0), next 0.0.0.0, path
R1# show ip bgp nei 10.12.1.2 | i Condition-map
  Condition-map FROM_AS300, Advertise-map TO_AS200, status: Withdraw
R2# show ip bgp 172.16.1.0
% Network not in table