Let's say you have an ospf network and you are connecting to a RIP router. You want to advertise your network to the RIP router, but do not want to advertise all your routes in order to keep the amount of prefixes low in the RIP routing table. You can create an aggregate route, but you want to only advertise this route on the condition that a host route is available in OSPF.
First the setup. We've got a network subnet of 192.168/16. We then want to connect to the RIP router.
user@router# set protocols rip group RIPv4 neighbor ge-0/0/3
[edit]
user@router# run show route
inet.0: 46 destinations, 46 routes (46 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
0.0.0.0/0 *[OSPF/150] 00:25:00, metric 0, tag 0
to 192.168.0.21 via ge-2/0/0.0
to 192.168.4.1 via ge-2/0/14.0
> to 192.168.4.2 via ge-2/0/14.0
192.168.0.0/30 *[OSPF/10] 5d 03:20:59, metric 100
> to 192.168.4.1 via ge-2/0/14.0
192.168.0.20/30 *[Direct/0] 5d 03:52:03
> via ge-2/0/0.0
192.168.0.22/32 *[Local/0] 1w0d 01:17:46
Local via ge-2/0/0.0
192.168.0.48/28 *[Direct/0] 6d 02:17:09
> via vlan.100
192.168.10.0/24 *[RIP/100] 00:00:36, metric 2, tag 0
> to 192.168.0.30 via ge-0/0/3.0
192.168.11.0/24 *[RIP/100] 00:00:36, metric 2, tag 0
> to 192.168.0.30 via ge-0/0/3.0
192.168.12.0/24 *[RIP/100] 00:00:36, metric 2, tag 0
> to 192.168.0.30 via ge-0/0/3.0
192.168.20.0/23 *[OSPF/150] 5d 20:50:14, metric 16777215, tag 0
Discard
192.168.20.0/24 *[OSPF/150] 5d 20:51:07, metric 2, tag 0
> to 192.168.0.59 via vlan.100
192.168.100.254/32 *[OSPF/150] 5d 20:51:07, metric 2, tag 0
> to 192.168.0.59 via vlan.100
Notice that we're going to only advertise if the 192.168.100.254 host route appears in the routing table.
So now we'll use the "generate" route instead of an aggregate route, but also add a policy.
[edit]
user@router# set routing-options generate route 192.168/16 policy CHECK-HOST
[edit]
user@router# set policy-options policy-statement CHECK-HOST term t1 from route-filter 192.168.100.254/32 exact
[edit]
user@router# set policy-options policy-statement CHECK-HOST term t1 then accept
[edit]
user@router# set policy-options policy-statement CHECK-HOST term t2 then reject
[edit]
user@router# commit
commit complete
Now let's check if the policy works.
[edit]
user@router# run show route 192.168/16 exact
inet.0: 47 destinations, 47 routes (47 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.0/16 *[Aggregate/130] 00:00:15
> to 192.168.0.59 via vlan.100
[edit]
user@router# run show route 192.168/16 exact detail
inet.0: 47 destinations, 47 routes (47 active, 0 holddown, 0 hidden)
192.168.0.0/16 (1 entry, 1 announced)
*Aggregate Preference: 130
Next hop type: Router, Next hop index: 542
Address: 0x157da7c
Next-hop reference count: 12
Next hop: 192.168.0.59 via vlan.100, selected
State: <Active Int Ext>
Age: 17
Task: Aggregate
Announcement bits (1): 0-KRT
AS path: I
Flags: Generate Depth: 0 Active
Contributing Routes (1):
192.168.100.254/32 proto OSPF
As you can see the contributing route is available, so we can now advertise this aggregate to the RIP router.
[edit]
user@router# set policy-options policy-statement AGG->RIP term t1 from protocol aggregate
[edit]
user@router# set policy-options policy-statement AGG->RIP term t1 from route-filter 192.168/16 exact
[edit]
user@router# set policy-options policy-statement AGG->RIP term t1 then accept
[edit]
user@router# set policy-options policy-statement AGG->RIP term LAST then reject
[edit]
user@router# commit
commit complete
[edit]
user@router# set protocols rip group RIPv4 export AGG->RIP
[edit]
user@router# commit
commit complete
Let's check to see if we're advertising the route.
[edit]
user@router# run show route advertising-protocol rip 192.168.0.29
inet.0: 47 destinations, 47 routes (47 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.0/16 *[Aggregate/130] 00:02:08
> to 192.168.0.59 via vlan.100
Now if we stop receiving the host OSPF route.
user@router# run show route 192.168.100.254
user@router# run show route hidden detail
inet.0: 24 destinations, 24 routes (23 active, 1 holddown, 1 hidden)
192.168.0.0/16 (1 entry, 1 announced)
Aggregate
Next hop type: Reject
Address: 0x1147eec
Next-hop reference count: 1
State: <Hidden Int Ext>
Age: 26:46
Task: Aggregate
Announcement bits (1): 4-RIPv2
AS path: I
Flags: Generate Depth: 0 Inactive