7.1 Routing Policy Framework & Term Evaluation
Key Takeaways
Routing policies in Junos OS control route flow at two distinct junctions: importing routes from dynamic protocols into the Routing Information Base (inet.0) and exporting active routes from inet.0 into dynamic routing protocols.
Default routing policies vary strictly by protocol: BGP imports all valid routes and exports all active BGP routes, whereas OSPF/IS-IS flood their native link-state information; export policy controls redistribution and import policy affects supported local RIB installation.
A Junos policy statement comprises ordered terms evaluated sequentially from top to bottom; each term contains optional 'from' match criteria (evaluated with logical AND across conditions) and 'then' actions.
Terminating actions ('accept' and 'reject') halt policy evaluation immediately, while flow-control actions ('next term' and 'next policy') allow subsequent terms or chained policy statements to be evaluated.
If an evaluated route reaches the end of a policy chain without matching any explicit term with a terminating action, Junos executes the implicit protocol default action of the protocol where the policy is applied.
Routing Policy Framework & Term Evaluation
In Junos OS, routing policy provides a centralized, deterministic framework for controlling the exchange of routing information between protocol processes and the Routing Information Base (RIB, known as inet.0 for IPv4 unicast). While dynamic routing protocols calculate reachability based on standard algorithm metrics, enterprise network architects deploy routing policies to enforce administrative boundaries, redistribute routes across protocol boundaries, manipulate route path attributes, and prevent routing loops. Mastering policy construction, term execution order, and implicit protocol defaults is a core competency for the JNCIS-ENT examination.
1. Architectural Role of Routing Policies in Junos OS
Junos OS strictly decouples the control plane (running on the Routing Engine) from the forwarding plane (running on the Packet Forwarding Engine). Within the Routing Engine (RE), the routing protocol daemon (rpd) manages all routing protocols and maintains the routing table (inet.0). Routing policies operate directly within rpd at two distinct junctions: Import and Export.
+---------------------------------------------------------------------------------------------------+
| JUNOS ROUTING POLICY INTERACTION ARCHITECTURE |
+---------------------------------------------------------------------------------------------------+
| |
| +-------------------+ +------------------+ +-------------------+ |
| | Incoming Protocol | ====> | Routing Table | ====> | Outgoing Protocol | |
| | Updates (BGP/OSPF)| | (inet.0) | | Advertisements | |
| +-------------------+ +------------------+ +-------------------+ |
| | | | |
| v v v |
| [ IMPORT POLICY ] Active Route [ EXPORT POLICY ] |
| Controls which routes Selection Algorithm Controls which active |
| enter inet.0 (Preference/Metric) routes leave inet.0 |
| |
+---------------------------------------------------------------------------------------------------+
Import Policies vs. Export Policies
- Import Policy: Evaluates routes received from routing protocol peers or neighbors before those routes are accepted into the Routing Information Base (
inet.0). An import policy can filter unwanted routes, alter route preferences, or tag prefixes before they participate in the route selection process. - Export Policy: Evaluates routes currently residing in
inet.0before advertising them to neighboring routers via dynamic routing protocols. An export policy controls redistribution (e.g., introducing static or direct routes into OSPF or BGP) and manipulates protocol-specific attributes (such as BGP AS-path, communities, or OSPF external metrics).
The Golden Active-Route Rule: Normal export uses active eligible routes. Hidden routes are unusable. Special features such as BGP
advertise-inactiveor add-path change normal advertisement behavior; they are explicit exceptions rather than evidence that every inactive route is exportable.
2. Junos Default Routing Policies by Protocol
When no user-defined routing policy is applied, Junos OS enforces built-in default routing policies. These defaults vary significantly across protocols to preserve protocol integrity and prevent accidental transit routing.
| Protocol | Default Import Behavior | Default Export Behavior | Technical Rationale |
|---|---|---|---|
| BGP | Accept all valid BGP routes into inet.0. | Export all active BGP routes to peers; Reject all non-BGP routes. | Facilitates global reachability exchange by default while blocking unintentional redistribution of IGP or static routes into the BGP autonomous system. |
| OSPF | Accept all valid LSAs into the Link-State Database (LSDB). | Reject all non-OSPF routes by default. (Native OSPF routes flood automatically). | OSPF requires identical LSDB synchronization across all routers within an area; RIB import policy does not filter the area’s LSA flooding. Redistribution requires an explicit policy. |
| IS-IS | Accept all valid LSPs into the Level 1 and Level 2 LSDBs. | Reject all non-IS-IS routes by default. (Native IS-IS routes flood automatically). | IS-IS import policy can restrict local RIB installation without changing LSP flooding or another router’s LSDB. Redistribution of external routes requires an explicit export policy. |
| RIP | Accept all valid RIP updates from configured neighbors. | Reject all routes by default. | Prevents distance-vector routing loops and unbounded count-to-infinity propagation unless an administrator explicitly defines an export policy. |
The Link-State Protocol Filtering Trap on the JNCIS-ENT Exam
A frequent misconception among enterprise engineers involves attempting to filter intra-area OSPF routes using an import policy. In Junos OS, you cannot filter OSPF intra-area (Area 0 or non-backbone) routes using an import policy. Because OSPF uses Dijkstra's Shortest Path First (SPF) algorithm, every router within an area must maintain an identical link-state database. If individual routers suppressed specific LSAs locally via import policies, the SPF tree would partition, causing catastrophic routing loops or black holes. Policy filtering in OSPF can only occur at Area Border Routers (ABRs) via summarization and type 3 LSA filtering, or at Autonomous System Boundary Routers (ASBRs) via export policies redistributing external routes (Type 5/7 LSAs).
3. Structure of a Junos Policy Statement
Junos routing policies are defined centrally under the [edit policy-options] hierarchy and applied within the respective protocol or routing-options stanza. A policy statement consists of one or more named terms that house match conditions (from) and actions (then).
[edit policy-options]
policy-statement <policy-name> {
term <term-name> {
from {
<match-conditions>;
}
then {
<actions>;
<action-modifiers>;
}
}
}
Evaluation Logic Inside a Term
- Multiple Match Conditions (
from): When multiple distinct match conditions are defined within a single term (e.g., matching both a protocol and a prefix list), Junos evaluates them using a logical AND. The route must satisfy all specified match criteria to trigger the term's action. - Multiple Arguments within a Single Match Condition: If a single match condition contains multiple arguments (e.g.,
from protocol [ ospf static direct ]), Junos evaluates them using a logical OR. If the route matches any listed argument, that specific condition is satisfied. - Omitting the
fromStatement: If a term contains nofromstatement, it automatically matches all routes. Any route evaluated by this term immediately executes the specifiedthenaction. - Omitting a terminating action: Attribute changes do not themselves accept or reject a route. Evaluation proceeds through later terms/policies until a terminating action or the protocol default resolves the result.
4. Term Evaluation Mechanics: Terminating vs. Flow-Control Actions
Junos OS evaluates policy terms in strict sequential order from top to bottom. The first term in the stanza is evaluated first; if a route does not match, the second term is evaluated, continuing down the list.
Terminating Actions
Terminating actions immediately conclude evaluation for the route. Once a terminating action executes, Junos halts all further processing—no subsequent terms or policies in the chain are evaluated for that route:
accept: Accepts the route (installs it intoinet.0if an import policy, or advertises it if an export policy) and immediately terminates policy evaluation.reject: Silently drops or blocks the route (prevents installation intoinet.0or prevents protocol advertisement) and immediately terminates policy evaluation.
Flow-Control Actions
Flow-control actions override the default termination behavior, enabling complex multi-stage evaluation pipelines:
next term: Applies configured route attribute modifiers and moves to evaluate the next term within the same policy statement. This is commonly used to apply an action modifier (like setting an administrative tag or community) before testing the route against subsequent criteria.next policy: Skips all remaining terms in the current policy statement and moves directly to evaluate the first term of the next policy statement in a chained policy list.
Action Modifiers (Non-Terminating Properties)
Action modifiers alter the attributes of a route without terminating evaluation (unless coupled with an explicit terminating action):
metric <value>: Sets the internal multi-exit discriminator (MED) or protocol cost.preference <value>: Overrides the default Junos route preference (administrative distance).community (add | set | delete) <name>: Manipulates BGP community attributes.as-path-prepend <asn-sequence>: Prepends autonomous system numbers to influence inbound BGP traffic.tag <value>: Applies an internal 32-bit administrative tag used for downstream filtering.
[edit policy-options policy-statement tag-and-accept]
set term term-1 from protocol static
set term term-1 then tag 200
set term term-1 then next term
set term term-2 from tag 200
set term term-2 then metric 50
set term term-2 then accept
5. Policy Chains and The Implicit Protocol Default Action
In enterprise configurations, multiple policy statements can be applied in a chained list to an interface, protocol, or peer group:
[edit protocols bgp group ebgp-peers]
user@router# set export [ scrub-routes set-communities advertise-prefixes ]
When a route is evaluated against a chained policy list:
- The route enters
scrub-routesand evaluates its terms sequentially. - If a term executes
acceptorreject, evaluation terminates completely. - If the route does not match any term, or if a term executes
next policy, evaluation moves to the first term ofset-communities. - If the route traverses all terms in all chained policies without matching an explicit terminating action, it encounters the implicit default protocol action.
The Implicit Default Fallthrough Trap: The implicit default action at the end of a policy chain is not a universal accept or reject. It is strictly determined by the protocol to which the policy is applied! If you apply a custom export policy to BGP that only matches and rejects RFC 1918 subnets, all other active BGP routes fall through to the end of the policy and are advertised by BGP's default export policy (which exports active BGP routes). Conversely, in OSPF export, any route falling through the policy is rejected by OSPF's default export policy.
Official references checked 2026-10-18: Protocol defaults and import scope.
An enterprise network engineer wants to redistribute directly connected interface subnets into OSPF on a Junos router. Which configuration strategy correctly accomplishes this redistribution?
Configure an explicit export policy under [edit protocols ospf export] matching protocol direct and accepting the routes, because OSPF's default export policy rejects all non-OSPF routes.
Apply an import policy under [edit protocols ospf import] matching protocol direct, because Junos imports connected interfaces directly into the Link-State Database.
Enable dynamic route learning under [edit protocols ospf area 0.0.0.0], which automatically redistributes all active direct routes with a default metric of 20 without requiring a policy.
Apply a policy statement under [edit routing-options forwarding-table] using the export action, because redistribution between protocols is processed exclusively in the Packet Forwarding Engine.
In a Junos OS policy statement, what is the functional difference between the flow-control action 'next term' and the action 'next policy'?
'next term' restarts evaluation at the beginning of the current term, whereas 'next policy' commits the configuration and signals the routing protocol daemon.
'next term' applies any attribute modifiers and moves to the subsequent term in the same policy, whereas 'next policy' skips remaining terms in the active policy and evaluates the next policy statement in the chain.
'next term' accepts the route and proceeds to the next term, whereas 'next policy' rejects the route and exits the policy chain.
'next term' is valid only in BGP import policies, whereas 'next policy' is restricted to OSPF and IS-IS export policies.
An administrator creates a custom policy statement named 'export-static' with a single term matching protocol static and executing then accept. This policy is applied as the sole export policy to an EBGP peering group under [edit protocols bgp group external-peers export export-static]. What happens to active BGP routes learned from other BGP peers when evaluated against this peering group?
All active BGP routes are immediately discarded because configuring any custom export policy disables all protocol default behaviors.
Active BGP routes are converted to static routes with preference 5 before being advertised to the EBGP peer.
Active BGP routes are advertised to the EBGP peer because routes that do not match the custom term fall through to the implicit BGP default export action, which advertises active BGP routes.
Active BGP routes are held in a dampened state until an explicit BGP match term is added to the policy statement.
Sections you finish are checked off in the contents.