This article demonstrates how to configure a generated route and inject that default route in OSPF from R2 to R3 based on the presence of 172.16.0.0/32 in the BGP routing table in R2. Also, if in case we lose that route we want to flush the default route from our OSPF domain.
Topology:
In the following policy, we match the BGP route and based on that we inject a default generate route:
set policy-options policy-statement BGP_IMPORT term 1 from protocol bgp set policy-options policy-statement BGP_IMPORT term 1 from route-filter 172.16.0.0/32 exact set policy-options policy-statement BGP_IMPORT term 1 then accept set policy-options policy-statement BGP_IMPORT term 2 then reject set routing-options generate defaults preference 130 set routing-options generate route 0.0.0.0/0 policy BGP_IMPORT
In following policy we match the default aggregated route that was generated and export into OSPF:
set policy-options policy-statement OSPF_EXPORT term 1 from protocol aggregate set policy-options policy-statement OSPF_EXPORT term 1 from route-filter 0.0.0.0/0 exact set policy-options policy-statement OSPF_EXPORT term 1 then accept set protocols ospf export OSPF_EXPORT
inet.0: 38 destinations, 38 routes (38 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.0.0/32 192.168.12.1 1 I * 172.16.0.1/32 192.168.12.1 1 I * 172.16.0.2/32 192.168.12.1 1 I * 172.16.0.3/32 192.168.12.1 1 I * 172.16.0.4/32 192.168.12.1 1 I
inet.0: 38 destinations, 38 routes (38 active, 0 holddown, 0 hidden) 0.0.0.0/0 (1 entry, 1 announced) *Aggregate Preference: 130 Next hop type: Router, Next hop index: 614 Address: 0xc8d6770 Next-hop reference count: 16 Next hop: 192.168.12.1 via ge-0/0/0.0, selected <-- The default next hop for generate route will be associated with the next hop of primary contributing route Session Id: 0x140 State: <Active Int Ext> Local AS: 2 Age: 3:03 Validation State: unverified Task: Aggregate Announcement bits (2): 0-KRT 2-OSPF AS path: I Flags: Generate Depth: 0 Active Contributing Routes (1): 172.16.0.0/32 proto BGP <-- This is primary contributing route which has a next hop of 192.168.12.1 in bgp table
inet.0: 36 destinations, 36 routes (36 active, 0 holddown, 0 hidden) 0.0.0.0/0 (1 entry, 1 announced) *OSPF Preference: 150 Next hop type: Router, Next hop index: 618 Address: 0xc8d5f90 Next-hop reference count: 18 Next hop: 192.168.23.1 via ge-0/0/4.0, selected Session Id: 0x140 State: <Active Int Ext> Age: 7:33 Metric: 0 Validation State: unverified Tag: 0 Task: OSPF Announcement bits (1): 0-KRT AS path: I
inet.0: 37 destinations, 37 routes (36 active, 0 holddown, 1 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.0.1/32 192.168.12.1 1 I * 172.16.0.2/32 192.168.12.1 1 I * 172.16.0.3/32 192.168.12.1 1 I * 172.16.0.4/32 192.168.12.1 1 I
inet.0: 37 destinations, 37 routes (36 active, 0 holddown, 1 hidden)