>_nexthopreachable

JNCIP-ENT: Enterprise Routing Policy Construction

Ali Bahadır Coşkun16 min read

This lab continues from BGP route reflection and communities. The three previous labs introduced one policy tool at a time. First a route filter in the first BGP lab, then local preference and prepend in the second, and communities in the third. This lab combines them into a single policy set on both border routers of AS 65100, and examines how terms within a policy route to each other.

Overview

PrefixWhat it isAS path at R1 and R3
203.0.113.0/24Customer LAN behind R1originated in AS 65100
198.51.100.0/24Customer LAN attached to R465200
192.0.2.0/24Customer LAN attached to R5, transited by R465200 65300

We will perform the following tasks:

  • Add the AS 65300 customer LAN, and extend R4's export chain so the prefix reaches AS 65100.
  • Advertise 10.0.0.0/24 as an aggregate in place of the individual loopbacks, and suppress the specifics with a prefix-list filter.
  • Reject external prefixes longer than /24, and classify the remainder by origin AS with AS-path regex, communities and local preference.
  • Build a policy that advertises nothing then correct it.
  • Validate the finished policy with test policy.

Topology

Adding the AS 65300 customer LAN

R5

junos
set interfaces ge-0/0/1 unit 0 family inet address 192.0.2.1/24set policy-options policy-statement ADV-LAN term lan from protocol directset policy-options policy-statement ADV-LAN term lan from route-filter 192.0.2.0/24 exactset policy-options policy-statement ADV-LAN term lan then acceptset policy-options policy-statement ADV-LAN term reject then rejectset protocols bgp group ext-as65200 export ADV-LAN

We commit, wait for the session to R4 to return to Established, and check what R5 offers:

junos
show route advertising-protocol bgp 172.16.45.1 192.0.2.0/24 detail

R5 advertises 192.0.2.0/24 and nothing else, because ADV-LAN ends in a reject term.

R4

R4 receives the prefix but does not pass it to AS 65100. Its ADV-CUSTOMER policy from the earlier labs matches its own direct 198.51.100.0/24 and rejects everything else.

We add a second policy in front of it:

junos
set policy-options policy-statement ADV-R5-TRANSIT term r5-lan from protocol bgpset policy-options policy-statement ADV-R5-TRANSIT term r5-lan from route-filter 192.0.2.0/24 exactset policy-options policy-statement ADV-R5-TRANSIT term r5-lan then acceptdelete protocols bgp group ext-as65100 exportset protocols bgp group ext-as65100 export [ ADV-R5-TRANSIT ADV-CUSTOMER ]

ADV-R5-TRANSIT has no final reject. It accepts the one prefix it matches and allows everything else to fall through to ADV-CUSTOMER, which still decides on 198.51.100.0/24. A reject term at the end of the first policy would prevent ADV-CUSTOMER from being reached, and R4 would stop advertising its own LAN.

On R4:

junos
show route 192.0.2.0/24 detailshow route advertising-protocol bgp 172.16.14.1 192.0.2.0/24 detailshow route advertising-protocol bgp 172.16.34.1 192.0.2.0/24 detail

Verifying the three route classes

On R1 and R3:

junos
show route 198.51.100.0/24 detailshow route 192.0.2.0/24 detail

Both borders have 198.51.100.0/24 with AS path 65200 and 192.0.2.0/24 with AS path 65200 65300.

Advertising the approved prefix set

Both borders currently run ADV-INTERNAL, which advertises 10.0.0.0/24 orlonger, so R4 receives three separate loopback /32s. The requirement is that R4 receive one summary and the customer prefix, and nothing else.

Route-filter match types

There are six match types. For a filter anchored at 10.0.0.0/24:

  • exact matches 10.0.0.0/24 only.
  • orlonger matches the /24 and everything longer inside it.
  • longer matches everything longer inside it, but not the /24 itself.
  • upto /26 matches the /24, /25 and /26 levels.
  • prefix-length-range /25-/32 matches only prefixes in that mask range inside the /24.
  • through matches the two named endpoints and the prefixes between them on the tree.

R1 and R3

Both borders take the same configuration.

junos
set routing-options aggregate route 10.0.0.0/24set policy-options prefix-list ENT-PUBLIC 10.0.0.0/24set policy-options prefix-list ENT-PUBLIC 203.0.113.0/24set policy-options policy-statement ADV-CLEAN term approved from prefix-list ENT-PUBLICset policy-options policy-statement ADV-CLEAN term approved then acceptset policy-options policy-statement ADV-CLEAN term suppress from prefix-list-filter ENT-PUBLIC longerset policy-options policy-statement ADV-CLEAN term suppress then rejectset policy-options policy-statement ADV-CLEAN term reject then rejectdelete protocols bgp group ext-as65200 exportset protocols bgp group ext-as65200 export ADV-CLEAN

The approved term accepts the two list entries. The suppress term rejects anything longer than them, which removes the loopback /32s. The final term rejects everything else, so the policy is deny by default rather than relying on BGP's export default.

On R1:

junos
show route 10.0.0.0/24 exact detailshow route advertising-protocol bgp 172.16.14.2 detailshow route advertising-protocol bgp 172.16.14.2 10.0.0.1/32 detail

The aggregate is active and lists its contributors. The advertising list contains 10.0.0.0/24 and 203.0.113.0/24. The command for the individual loopback returns nothing.

On R4:

junos
show route 10.0.0.0/24 detailshow route 10.0.0.1/32show route 203.0.113.0/24 detail

R4 has the /24 and the customer prefix, and the individual loopbacks are absent. This also removes the specific routes used for the loopback traceroutes in the earlier labs; the /24 now covers them at R4, resolved through whichever border R4 selects.

The aggregate on R1 and the route R4 installs are two different objects. R1's copy is generated locally and its next-hop is Reject; the advertisement carries the normal BGP next-hop, so R4's copy forwards.

Filtering and classifying inbound routes

Next we will reject anything longer than /24, then tag the remainder with a community and a local preference based on the origin AS.

AS-path regular expressions

An AS-path expression is matched against the complete AS path. Each token is an AS number, and the last number is the origin AS. .* 65300 therefore matches 65200 65300 but not 65200, and .* 65200 matches the single-AS path in this topology.

The usual operators are available: ^, $, ., *, +, ?, {n}, (), | and [ ]. When several separate expressions should act as one OR condition, an as-path-group is used instead of one long expression.

R1 and R3

Same configuration on both borders.

junos
set policy-options as-path ORIG-65200 ".* 65200"set policy-options as-path ORIG-65300 ".* 65300"set policy-options community NEAR members 65100:200set policy-options community FAR members 65100:300set policy-options policy-statement INBOUND term drop-specifics from route-filter 0.0.0.0/0 prefix-length-range /25-/32set policy-options policy-statement INBOUND term drop-specifics then rejectset policy-options policy-statement INBOUND term mark-near from as-path ORIG-65200set policy-options policy-statement INBOUND term mark-near then community add NEARset policy-options policy-statement INBOUND term mark-near then local-preference 110set policy-options policy-statement INBOUND term mark-near then acceptset policy-options policy-statement INBOUND term mark-far from as-path ORIG-65300set policy-options policy-statement INBOUND term mark-far then community add FARset policy-options policy-statement INBOUND term mark-far then local-preference 90set policy-options policy-statement INBOUND term mark-far then acceptset policy-options policy-statement INBOUND term default then acceptset protocols bgp group ext-as65200 import INBOUND

drop-specifics matches nothing because both external prefixes are /24s.

The marking terms combine several actions. Multiple from conditions in one term are together, and multiple then actions. The accept at the end of each term terminates evaluation, which is why mark-far never sees a route that mark-near has already matched.

On R1 and R3:

junos
show route 198.51.100.0/24 detailshow route 192.0.2.0/24 detailshow route aspath-regex ".* 65300"show route community-name NEARshow route community-name FAR

198.51.100.0/24 carries 65100:200 and local preference 110. 192.0.2.0/24 carries 65100:300 and local preference 90. The live regex test returns 192.0.2.0/24 only.

Both prefixes arrive at both borders independently, and both borders apply the same value for a given class, so this policy does not move the AS exit. It ranks the two route classes relative to each other, which takes effect when a second path to the same prefix appears. Selecting R1 over R3 for a given prefix requires unequal attributes on the competing paths for that prefix, as in the second lab.

NEAR and FAR are a two-class example of a scheme every transit network runs. Each session is classified on ingress by what the neighbor is, customer, settlement-free peer, or paid transit, and the community is set once at that point. A separate policy reads only the community and sets local preference, in that order of preference, so a customer route is used even when a transit provider offers a shorter AS path. The ordering is a commercial decision rather than a topological one: the customer route earns revenue and the transit route costs money.

Keeping the two policies separate is what makes this maintainable. The ingress classification belongs on the border facing the neighbor, and the preference values are identical on every router and rarely change. Production schemes usually add a second set of communities for geography or exit region, and a third set that customers are allowed to send to request treatment, such as a documented community that asks the provider to lower local preference on one prefix for outbound load sharing.

Composing a policy chain

The next requirement is to tag the advertised routes with 65100:10 without weakening the approved-prefix filter.

Junos evaluates a chain left to right, and the terms inside each policy top to bottom. accept and reject are terminating actions and stop evaluation immediately. A modifying action, such as adding a community or setting local preference, is not terminating; the route carries the change and continues to the next term, then to the next policy in the chain. If nothing terminates by the end of the chain, the protocol default decides.

A chain with no terminating action

The first version is configured on R1 under commit confirmed, which rolls the change back automatically if it is not confirmed within five minutes. This is the normal way to make a policy or interface change on a remote router when the session used to manage it depends on the routing the change affects. A policy that drops the advertisement carrying the management path, or an interface change that breaks the path to the router, would otherwise leave the device unreachable and require console or out-of-band access. The timer restores the previous configuration without anyone logging in.

junos
set policy-options community OUTBOUND members 65100:10set policy-options policy-statement TAG-OUT term approved from prefix-list ENT-PUBLICset policy-options policy-statement TAG-OUT term approved then community add OUTBOUNDset policy-options policy-statement REJECT-ALL term all then rejectdelete protocols bgp group ext-as65200 exportset protocols bgp group ext-as65200 export [ TAG-OUT REJECT-ALL ]
junos
commit confirmed 5

Then:

junos
show route advertising-protocol bgp 172.16.14.2 10.0.0.0/24 detailshow route advertising-protocol bgp 172.16.14.2 203.0.113.0/24 detail

Both return nothing, so R1 advertises neither approved prefix. TAG-OUT matched them and added the community, but adding a community does not terminate evaluation, so both routes continued into REJECT-ALL and were rejected there.

Two empty results on their own only prove the commands returned nothing, so we confirm it from the receiving side. On R4:

junos
show route receive-protocol bgp 172.16.14.1

R4 receives no prefixes at all from R1. It keeps 10.0.0.0/24 only because R3 still advertises it.

Adding a terminating action

junos
set policy-options policy-statement TAG-OUT term approved then acceptcommit

A normal commit also confirms the pending commit confirmed, so this corrects the policy and cancels the rollback.

junos
show route advertising-protocol bgp 172.16.14.2 10.0.0.0/24 detailshow route advertising-protocol bgp 172.16.14.2 203.0.113.0/24 detail

Both prefixes are now advertised with community 65100:10. No prefix outside ENT-PUBLIC can be advertised, because TAG-OUT accepts only what the prefix list matches and everything else still falls through to REJECT-ALL.

Moving the decision into ADV-CLEAN

The configuration above works, but it places the accept decision in the marking policy. Two policies then control what is advertised, and a change to the prefix list affects both the tagging and the filtering. Keeping the marking policy non-terminating and letting one policy make the final decision is easier to maintain.

This is how policy is composed on a router with many sessions. Rather than one long policy per neighbor, the configuration holds a small number of building blocks, each doing one job, and each session gets a chain of the blocks it needs. A per-neighbor block that sets or strips something specific is followed by the shared filter that every session runs, so the sanity checks cannot be forgotten on a new session and cannot drift between sessions. R4's ADV-R5-TRANSIT chain earlier in the lab is the same arrangement seen from the other side: a per-customer policy that accepts one customer's prefixes, placed ahead of the common policy that handles everything else.

On R1:

junos
delete policy-options policy-statement TAG-OUT term approved then acceptdelete protocols bgp group ext-as65200 exportset protocols bgp group ext-as65200 export [ TAG-OUT ADV-CLEAN ]

On R3:

junos
set policy-options community OUTBOUND members 65100:10set policy-options policy-statement TAG-OUT term approved from prefix-list ENT-PUBLICset policy-options policy-statement TAG-OUT term approved then community add OUTBOUNDdelete protocols bgp group ext-as65200 exportset protocols bgp group ext-as65200 export [ TAG-OUT ADV-CLEAN ]

This uses the same non-terminating behavior deliberately. TAG-OUT adds the community and falls through, and ADV-CLEAN accepts the approved prefixes, rejects the specifics and rejects everything else.

On R1 and R3:

junos
show route advertising-protocol bgp 172.16.14.2 10.0.0.0/24 detailshow route advertising-protocol bgp 172.16.14.2 203.0.113.0/24 detailshow route advertising-protocol bgp 172.16.14.2 10.0.0.1/32 detail

The aggregate and the customer prefix carry 65100:10, and the loopback /32s are still not advertised.

Protocol defaults

If a route reaches the end of a chain without a terminating action, the protocol default applies. It is not the same for every protocol:

  • BGP import accepts routes received from the peer. BGP export advertises active BGP routes, subject to the normal advertisement rules.
  • OSPF import accepts the SPF results. OSPF export rejects, so redistribution into OSPF requires an explicit export policy.
  • IS-IS import accepts the SPF results and cannot be overridden by import policy. Its export default accepts direct routes on IS-IS interfaces and rejects the rest.

then default-action accept and then default-action reject replace the protocol default for a route that reaches that action without policy having terminated.

test policy

test policy evaluates a policy against the active routes without attaching it to a protocol.

junos
test policy ADV-CLEAN 10.0.0.0/24test policy ADV-CLEAN 10.0.0.1/32test policy ADV-CLEAN 192.0.2.0/24

10.0.0.0/24 is accepted, 10.0.0.1/32 is rejected by the suppress term, and 192.0.2.0/24 is rejected by the final term.

test policy has two limitations. It uses an accept-all default for a route that reaches the end of the policy without terminating, which does not match BGP export, so a policy that relies on the protocol default tests as permissive regardless of what the protocol would do. This is the reason for the explicit final reject in ADV-CLEAN: it makes the deny-by-default behavior visible to the test. The second limitation is that not every match condition is supported, so show | compare and the advertising-protocol checks are still required.

The operational use is checking a policy before it can affect a session. A new export filter can be tested against the current table on the live router while the session still runs the old policy, and the output attached to the change record. The same output is useful after an incident, to establish whether a prefix was filtered by policy or was never in the table. Where this is automated, the test policy output and a show | compare of the candidate configuration are collected in the pre-change checks, and the advertising-protocol output before and after the commit is compared to confirm that only the intended prefixes changed.

Key points:

  • A prefix list is a reusable list of exact prefixes. from prefix-list matches them exactly; from prefix-list-filter <name> <match-type> applies route-filter behavior to the whole list, so one list can drive both an accept and a suppress term.
  • The six route-filter match types are exact, orlonger, longer, upto, prefix-length-range and through. Within one term Junos evaluates only the longest matching entry, and an action on a route-filter entry overrides the term action.
  • An AS-path expression is matched against the complete path, and the last AS in the path is the origin AS. An as-path-group is used when several expressions should act as one OR condition.
  • Chains are evaluated left to right. A policy with no final reject falls through to the next policy. A policy with a final reject ends evaluation for anything it does not accept.
  • An aggregate requires contributing routes to become active and uses a reject next-hop by default, so it cannot forward traffic addressed inside the summary that has no more specific route.
  • The same local preference applied at every border classifies routes, it does not select an exit. Moving the exit requires unequal attributes on the competing paths to the same prefix.