# Conditional Advertisement

**Topology**: russo-bgp-iol

<figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FvtWX6dyyu8lb25ST7ECM%2Fimage.png?alt=media&#x26;token=3ac204ed-a23e-410a-9990-316322ab4815" alt=""><figcaption></figcaption></figure>

Load **unix:lab1.init.cfg**

```
#R1-R6
configure replace unix:lab1.init.cfg
```



This is the Nick Russo BGP Multi-Homing topology using IOL nodes.





* Configure R4 and R5 to advertise an IPv4 and IPv6 default route to R6.
* R6 should prefer the default routes via R4.
* Configure R6 to only advertise its IPv4/IPv6 loopback addresses to R5 if the default route via R4 is gone.















































## Answer <a href="#id-1415b795-93cd-4451-acf0-e719861c1ede" id="id-1415b795-93cd-4451-acf0-e719861c1ede"></a>

```
#R4
router bgp 65000
 add ipv4
  neighbor 10.4.6.6 default-originate
 add ipv6
  neighbor FC00:10:4:6::6 default-originate

#R5
router bgp 65000
 add ipv4
  neighbor 10.5.6.6 default-originate
 add ipv6
  neighbor FC00:10:5:6::6 default-originate

#R6
ip prefix-list V4_DEFAULT permit 0.0.0.0/0
ipv6 prefix-list V6_DEFAULT permit ::/0
!
ip prefix-list V4_ADVERTISE permit 192.0.2.6/32
ipv6 prefix-list V6_ADVERTISE permit 2001:db8::6/128
!
ip community-list standard R4_DEFAULT permit 65006:4
!
route-map R4_IN
 set community 65006:4
!
route-map V4_DEFAULT_VIA_R4
 match ip addr prefix V4_DEFAULT
 match community R4_DEFAULT
!
route-map V6_DEFAULT_VIA_R4
 match ipv6 addr prefix V6_DEFAULT
 match community R4_DEFAULT
!
route-map V4_ADVERTISE
 match ip addr prefix V4_ADVERTISE 
!
route-map V6_ADVERTISE
 match ipv6 addr prefix V6_ADVERTISE 
!
router bgp 65006
 add ipv4
  neighbor 10.4.6.4 route-map R4_IN in
  neighbor 10.5.6.5 advertise-map V4_ADVERTISE non-exist-map V4_DEFAULT_VIA_R4
 add ipv6
  neighbor fc00:10:4:6::4 route-map R4_IN in
  neighbor fc00:10:5:6::5 advertise-map V6_ADVERTISE non-exist-map V6_DEFAULT_VIA_R4
```



## Explanation <a href="#id-53ef2934-0cb6-40b4-be30-f06631242bd4" id="id-53ef2934-0cb6-40b4-be30-f06631242bd4"></a>

This is quite a configuration intensive task. R6 must use prefix lists to identify the default routes and the local routes to advertise to R5. These must also belong to a route-map. Additionally, we need to match only R4’s default route. We cannot use a nexthop match for this. Instead, we assign a community to all routes received from R4, and match on this community. (Besides the prefix itself, you can only match on the AS\_PATH and community).



Pay attention to the syntax to achieve the desired functionality. The router will only advertise 192.0.2.6/32 if a 0.0.0.0/0 route with community 65006:4 does not exist in the BGP RIB.

```
ip prefix-list V4_DEFAULT permit 0.0.0.0/0
!
ip prefix-list V4_ADVERTISE permit 192.0.2.6/32
!
ip community-list standard R4_DEFAULT permit 65006:4
!
route-map V4_DEFAULT_VIA_R4
 match ip addr prefix V4_DEFAULT
 match community R4_DEFAULT
!
route-map V4_ADVERTISE
 match ip addr prefix V4_ADVERTISE 
!
router bgp 65006
 add ipv4
  neighbor 10.5.6.5 advertise-map V4_ADVERTISE non-exist-map V4_DEFAULT_VIA_R4
```



## Verification <a href="#id-0a5db529-ab21-4b62-a332-7a2055ba192f" id="id-0a5db529-ab21-4b62-a332-7a2055ba192f"></a>

When the defaults from R4 exist, R6 is withdrawing its local prefixes from R5.

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2Fs8WrHxRueBPJmJv8H93F%2Fimage.png?alt=media&#x26;token=0704a062-a3ce-4870-8e52-5ce30e0dff69" alt=""><figcaption></figcaption></figure></div>



Next, on R4 we remove the default origination for both address-families.

```
#R4
router bgp 65000
 add ipv4
  no neighbor 10.4.6.6 default-originate
 add ipv6
  no neighbor FC00:10:4:6::6 default-originate
!
do clear ip bgp * soft out
do clear bgp ipv6 uni * soft out
```



On R6 we debug IPv4 and IPv6 unicast updates. We see that the default routes have been withdrawn. In response, the BGP scanner on R6 changes the condition of the route-maps to Advertise. As a note, the bgp scan timer was lowered for IPv4 but not IPv6, which is why the IPv6 change takes so much longer. (If you are using this in production, you likely want to lower the scan timer as much as possible to reduce the outage interval).

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FxQn1sJQHqN82K94W3W7a%2Fimage.png?alt=media&#x26;token=f5a94ea1-34ec-462b-be93-b5e1c1072a27" alt=""><figcaption></figcaption></figure></div>



Once the defaults via R4 are lost, R6 advertises its local prefixes to R5 again. If these defaults are learned later, R6 withdraws these.



Besides the **non-exist-map**, there is also the option for an **exist-map**. With a **non-exist-map**, the prefix is only advertised if the route-map condition is not met. With the **exist-map**, the prefix is only advertised when the route-map condition is met.
