How to configure bgp conditional advertisement on Juniper MX triggered by lost of route.

By | 15.06.2019

Consider an unusual case of bgp conditional advertisement triggered by lost of route.
Our task is:
Announce certain networks to backup uplink only if the default route from the main uplink is lost.
Both uplinks announce the default route – 0/0.

To implement this, we need to check the availability of the route from the main uplink. To do so, we need to put it in a separate table with the RIB group:

Adding RIB group with import policy:

set routing-options rib-groups inet.0_to_check-conditional export-rib inet.0
set routing-options rib-groups inet.0_to_check-conditional import-rib [inet.0  check-conditional.inet.0]
set routing-options rib-groups inet.0_to_check-conditional import-policy default-route-only-accept

import policy:

set policy-options policy-statement default-route-only-accept term accept from route-filter 0.0.0.0/0 exact
set policy-options policy-statement default-route-only-accept term accept then accept
set policy-options policy-statement default-route-only-accept term deny then reject

Apply RIB group to main upstream peer :

set protocols bgp group UPSTREAM type external
set protocols bgp group UPSTREAM local-as 64399
set protocols bgp group UPSTREAM family inet unicast rib-group  inet.0_to_check-conditional 
set protocols bgp group UPSTREAM neighbor 10.10.10.1 description upstream-main
set protocols bgp group UPSTREAM neighbor 10.10.10.1 peer-as 64500

After commit, we should have a route from the main uplink in the table check-conditional.inet.0

>show route table check-conditional.inet.0  
 check-conditional.inet.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
 = Active Route, - = Last Active, * = Both 
 0.0.0.0/0          *[BGP/170] 00:01:26, localpref 150
                       AS path: 64500 I, validation-state: unverified
                     > to  10.10.10.1 via ae10.10

Now we can set up conditional check in export policy to a backup upstream.
The check is based on the condition mechanism builtin in Junos.
Here is how it works:
The announcement of our networks is controlled by an upstream-backup-out policy.
In the check term, the route is checked in the check-conditional.inet.0 table. If the route is present, the match occurs and action – reject is executed.

If no route is matched in the check-conditional.inet.0 table, there will be no match in the check term, and the routes will be processed in the announce term.
Thus, if the route disappears from the main uplink, our networks will be announced to backup upstream.

Create conditional policy :

set policy-options condition conditional_advertise if-route-exists 0.0.0.0/0
set policy-options condition conditional_advertise if-route-exists table check-conditional.inet.0

Adding export policy for backup upstream:

set policy-options policy-statement upstream-backup-out term check from prefix-list MY-NETWORKS
set policy-options policy-statement upstream-backup-out term check from condition conditional_advertise
set policy-options policy-statement upstream-backup-out term check then reject
set policy-options policy-statement upstream-backup-out term announce from prefix-list MY-NETWORKS 
set policy-options policy-statement upstream-backup-out term  announce  then accept
set policy-options policy-statement upstream-backup-out term discard-all then reject

Apply export policy for backup upstream :

set protocols bgp group UPSTREAM-BACKUP neighbor 10.20.20.1 export upstream-backup-out

Leave a Reply

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