Actions in Routing Policy Terms
Each term in a routing policy can include a then
statement, which defines
the actions to take if a route matches all the conditions in the from
and to
statements in the term:
then { actions; }
You can include this statement at the following hierarchy levels:
[edit policy-options policy-statement policy-name term term-name]
[edit logical-systems logical-system-name policy-options policy-statement policy-name term term-name]
If a term does not have from
and to
statements, all routes are
considered to match, and the actions apply to them all. For information about the from
and to
statements, see Routing Policy Match Conditions.
You can specify one or more actions in the then
statement. There are three
types of actions:
Flow control actions, which affect whether to accept or reject the route and whether to evaluate the next term or routing policy.
Actions that manipulate route characteristics.
Trace action, which logs route matches.
Note:When you specify an action that manipulates the route characteristics, the changes occur in a copy of the source route. The source route itself does not change. The effect of the action is visible only after the route is imported into or exported from the routing table. To view the source route before the routing policy has been applied, use the
show route receive-protocol
command. To view a route after an export policy has been applied, use theshow route advertised-protocol
command.During policy evaluation, the characteristics in the copy of the source route always change immediately after the action is evaluated. However, the route is not copied to the routing table or a routing protocol until the policy evaluation is complete.
The then
statement is optional. If you omit it, one of the following occurs:
The next term in the routing policy, if one is present, is evaluated.
If there are no more terms in the routing policy, the next routing policy, if one is present, is evaluated.
If there are no more terms or routing policies, the accept or reject action specified by the default policy is taken. For more information, see Default Routing Policies.
The following sections discuss these actions:
Configuring Flow Control Actions
Table 1 lists the flow control actions. You can specify one of these actions along with the trace action or one or more of the actions that manipulate route characteristics (see Configuring Actions That Manipulate Route Characteristics).
Flow Control Action |
Description |
---|---|
|
Accept the route and propagate it. After a route is accepted, no other terms in the routing policy and no other routing policies are evaluated. |
|
Accept and override any action intrinsic to the protocol. This is a nonterminating policy action. |
|
Reject the route and do not propagate it. After a route is rejected, no other terms in the routing policy and no other routing policies are evaluated. |
|
Reject and override any action intrinsic to the protocol. This is a nonterminating policy action. |
|
Skip to and evaluate the next term in the same routing policy. Any accept or reject
action specified in the
Note:
On Junos OS Evolved, |
|
Skip to and evaluate the next routing policy. Any accept or reject action specified
in the
|
|
Segment routing-traffic engineered (SR-TE) template to apply for PCE-initiated LSPs. |
Configuring Actions That Manipulate Route Characteristics
You can specify one or more of the actions listed in Table 2 to manipulate route characteristics.
Action |
Description |
---|---|
|
(BGP only) Enable sending up to 20 BGP paths to a destination for
a subset of |
|
(BGP only) Affix one or more AS numbers at the beginning of the AS path. If specifying more than one AS number, enclose the numbers in quotation marks (“ ”). The AS numbers are added after the local AS number has been added to the path. This action adds AS numbers to AS sequences only, not to AS sets. If the existing AS path begins with a confederation sequence or set, the affixed AS numbers are placed within a confederation sequence. Otherwise, the affixed AS numbers are placed within a nonconfederation sequence. For more information, see Understanding Prepending AS Numbers to BGP AS Paths. In Junos OS Release 9.1 and later, you can specify 4-byte AS numbers as defined in RFC 4893, BGP Support for Four-octet AS Number Space, as well as the 2-byte AS numbers that are supported in earlier releases of the Junos OS. |
|
(BGP only) Extract the last AS number in the existing AS path and
affix that AS number to the beginning of the AS path
The AS number is added before the local AS number has been added to the path. This action adds AS numbers to AS sequences only, not to AS sets. If the existing AS path begins with a confederation sequence or set, the affixed AS numbers are placed within a confederation sequence. Otherwise, the affixed AS numbers are placed within a non-confederation sequence. This option is typically used in non-IBGP export policies. Note:
Starting in Junos OS Release 17.3, it is possible to commit a
null configuration for the count value, and if so, Junos
will convert the null to a 1 count rather than a 0 count, or
disallowing the commit. The effect of having your
|
|
(Assisted replication [AR] with optimized intersubnet multicast
[OISM] only) Enable an AR leaf device in an EVPN network running
OISM to deterministically steer multicast flows to specific AR
replicator devices. Optionally include the
|
|
(BGP only) Set the output priority queue used for this route. There are 17 prioritized output queues: an expedited queue that is the highest priority, and 16 numbered queues where 1 is the lowest priority and 16 is the highest. |
|
(Class of service [CoS] only) Apply the specified class-of-service parameters to routes installed into the routing table. For more information, see the Junos OS Class of Service User Guide for Routing Devices. |
|
Set the preference value to the specified value. The
If you set the preference with the |
|
Change the color preference value by the specified amount. If an addition operation results in a value that is greater than 4,294,967,295 (232 – 1), the value is set to 232 – 1. If a subtraction operation results in a value less than 0, the value is set to 0. If an attribute value is not already set at the time of the addition or subtraction operation, the attribute value defaults to a value of 0 regardless of the amount specified. If you perform an addition to an attribute with a value of 0, the number you add becomes the resulting attribute value. |
|
(BGP only) Add the specified communities to the set of communities in the route. For more information, see Understanding BGP Communities, Extended Communities, and Large Communities as Routing Policy Match Conditions. |
|
(BGP only) Delete the specified communities from the set of communities in the route. For more information, see Understanding BGP Communities, Extended Communities, and Large Communities as Routing Policy Match Conditions. |
|
(BGP only) Replace any communities that were in the route in with the specified communities. For more information, see Understanding BGP Communities, Extended Communities, and Large Communities as Routing Policy Match Conditions. |
|
Set CoS-based next-hop map in forwarding table. |
|
(BGP only) Apply the specified route-damping parameters to the route. These parameters override the default damping parameters. This action is useful only in an import policy, because the damping parameters affect the state of routes in the routing table. To apply damping parameters, you must enable BGP flap damping as described in the Junos OS Routing Protocols Library for Routing Devices, and you must create a named list of parameters as described in Using Routing Policies to Damp BGP Route Flapping. |
|
Maintain packet counts for a route passing through your network, based on the destination address in the packet. You can do the following:
|
|
Set the external metric type for routes exported by OSPF. You
must specify the keyword |
|
Create the forwarding class that includes packets based on both the destination address and the source address in the packet. You can do the following:
|
|
Choose which next hops, among a set of equal LSP next hops, are
installed in the forwarding table. Use the export policy for the
forwarding table to specify the LSP next hop to be used for the
desired routes. Specify the |
|
For PTX Series routers only, override the default BGP routing policy. For more information, see Example: Overriding the Default BGP Routing Policy on PTX Series Packet Transport Routers. |
|
(BGP only) For MX Series routers with modular port concentrators (MPCs) and for QFX10000 switches only, specify consistent load balancing for one or more IP addresses. This feature preserves the affinity of a flow to a path in an equal-cost multipath (ECMP) group when one or more next-hop paths fail. Only flows for paths that are inactive are redirected. Flows mapped to servers that remain active are maintained. |
|
(MX Series Routers - AFT-based) Enable symmetric consistent hashing to support consistent hashing with static routes and achieve symmetric load-balancing with correlated source IP and destination IP load-balancing hash-key in forward and reverse direction. This action is used in a scenario where consistent hash is to be applied on anycast IPs used for load-balancing the traffic learnt via static route towards ECMP server group in upstream and downstream direction. Because the expectation is that all flows from a customer should reach the same ECMP server, only the source-IP is used for creating the load-balancing hash in one direction and destination-IP is used for creating the load-balancing hash in the reverse direction. |
|
Calculate load balancing hash based solely on destination IP address. This allows a service provider to direct traffic toward a specific content server in per-subscriber aware environments. |
|
(For export to the forwarding table only) Install all next-hop addresses in the forwarding table and have the forwarding table perform per-packet load balancing. This policy action allows you to optimize VPLS traffic flows across multiple paths. For more information, see Configuring Per-Packet Load Balancing. |
|
For PTX Series routers only, override the default per-packet load balancing routing policy for BGP. For more information, see Example: Overriding the Default BGP Routing Policy on PTX Series Packet Transport Routers. |
|
Calculate load balancing hash based solely on source IP address. This allows a service provider to direct traffic toward a specific content server in per-subscriber aware environments. |
|
(BGP only) Set the BGP local preference (LOCAL_PREF) attribute. The preference value can be a number in the range from 0 through 4,294,967,295 (232 – 1). |
|
Change the local preference value by the specified amount. If an addition operation results in a value that is greater than 4,294,967,295 (232 – 1), the value is set to 232 – 1. If a subtraction operation results in a value less than 0, the value is set to 0. If an attribute value is not already set at the time of the addition or subtraction operation, the attribute value defaults to a value of 0 regardless of the amount specified. If you perform an addition to an attribute with a value of 0, the number you add becomes the resulting attribute value. For BGP, if the attribute value is not known, it is initialized to 100 before the routing policy is applied. |
|
Sets the
If no term matches, then no multicast data packets are sent. |
|
Set the metric. You can specify up to four metric values,
starting with (BGP only) |
|
Change the metric value by the specified amount. If an addition operation results in a value that is greater than 4,294,967,295 (232 – 1), the value is set to 232 – 1. If a subtraction operation results in a value less than 0, the value is set to 0. If an attribute value is not already set at the time of the addition or subtraction operation, the attribute value defaults to a value of 0 regardless of the amount specified. If you perform an addition to an attribute with a value of 0, the number you add becomes the resulting attribute value. |
|
Calculate a metric based on the current values of
This policy action overrides the current value of the metric attribute with the result of the expression ((x * metric) + a) + ((y * metric2) + b) where |
|
(BGP only) Change the metric (MED) value by the specified negative or positive offset. This action is useful only in an external BGP (EBGP) export policy. |
|
Set the next-hop address. When the advertising protocol is BGP, you can set the next hop only when any third-party next hop can be advertised; that is, when you are using IBGP or EBGP confederations. If you specify If you specify If you specify If you specify If you use the term 1 { from { protocol bgp; rib vrf-customer2.inet.0; community customer; } then { next-hop next-table vrf-customer1.inet.0; } } term 2 { from { protocol bgp; rib vrf-customer1.inet.0; community customer; } then { next-hop next-table vrf-customer2.inet.0; } } If you specify |
|
(BGP only) Set the BGP origin attribute to one of the following values:
|
|
Set the ingress root node for a multipoint LDP (M-LDP)-based point-to-multipoint label-switched path (LSP). For more information, see Example: Configuring Multipoint LDP In-Band Signaling for Point-to-Multipoint LSPs. |
|
Set the preference value. You can specify a primary preference
value ( To specify even finer-grained preference values, see the
If you set the preference with the |
|
Change the preference value by the specified amount. If an addition operation results in a value that is greater than 4,294,967,295 (232 – 1), the value is set to 232 – 1. If a subtraction operation results in a value less than 0, the value is set to 0. If an attribute value is not already set at the time of the addition or subtraction operation, the attribute value defaults to a value of 0 regardless of the amount specified. If you perform an addition to an attribute with a value of 0, the number you add becomes the resulting attribute value. |
|
(OSPF import only) Specify a priority for prefixes included in an
OSPF import policy. Prefixes learned through OSPF are installed
in the routing table based on the priority assigned to the
prefixes. Prefixes assigned a priority of Note:
An OSPF import policy can only be used to set priority or to
filter OSPF external routes. If an OSPF import policy is
applied that results in a |
|
Maintain packet counts for a route passing through your network, based on the source address. You can do the following:
Note:
When configuring policy action statements, you can configure only one source class for each matching route. In other words, more than one source class cannot be applied to the same route. |
|
Specify one or more IPv4 or IPv6 source addresses for the source-specific multicast (SSM) policy |
|
Specify one or more IPv4 or IPv6 source addresses for the source-specific multicast (SSM) policy. |
|
Set the tag value. You can specify two tag strings:
|
|
Change the tag value by the specified amount. If an addition operation results in a value that is greater than 4,294,967,295 (232 – 1), the value is set to 232 – 1. If a subtraction operation results in a value less than 0, the value is set to 0. If an attribute value is not already set at the time of the addition or subtraction operation, the attribute value defaults to a value of 0 regardless of the amount specified. If you perform an addition to an attribute with a value of 0, the number you add becomes the resulting attribute value. |
|
When BGP origin validation is configured, set the validation state of a route prefix to valid, invalid, or unknown. The route validation database contains route origin authorization (ROA) records that map route prefixes to expected originating autonomous systems (ASs). This prevents the accidental advertisement of invalid routes. |
Configuring the Default Action in Routing Policies
The default-action
statement overrides any action intrinsic to the protocol.
This action is also nonterminating, so that various policy terms can be evaluated before the
policy is terminated. You can specify a default action, either accept
or reject
, as follows:
[edit] policy-options { policy-statement policy-name { term term-name { from { family family-name; match-conditions; policy subroutine-policy-name; prefix-list name; route-filter destination-prefix match-type <actions>; source-address-filter source-prefix match-type <actions>; } to { match-conditions; policy subroutine-policy-name; } then { actions; default-action (accept | reject); } } } }
The resulting action is set either by the protocol or by the last policy term that is matched.
Example: Configuring the Default Action in a Routing Policy
Configure a routing policy that matches routes based on three policy terms. If the route
matches the first term, a certain community tag is attached. If the route matches two separate
terms, then both community tags are attached. If the route does not match any terms, it is
rejected (protocol’s default action). Note that the terms hub
and spoke
are mutually exclusive.
[edit] policy-options { policy-statement test { term set-default { then default-action reject; } term hub { from interface ge-2/1/0.5; then { community add test-01-hub; default-action accept; } } term spoke { from interface [ ge-2/1/0.1 ge-2/1/0.2 ]; then { community add test-01-spoke; default-action accept; } } term management { from protocol direct; then { community add management; default-action accept; } } } }
Configuring a Final Action in Routing Policies
In addition to specifying an action using the then
statement in a named term,
you can also specify an action using the then
statement in an unnamed term, as
follows:
[edit] policy-options { policy-statement policy-name { term term-name { from { family family-name; match-conditions; policy subroutine-policy-name; prefix-list name; route-filter destination-prefix match-type <actions>; source-address-filter source-prefix match-type <actions>; } to { match-conditions; policy subroutine-policy-name; } then { actions; } } then action; } }
Logging Matches to a Routing Policy Term
If you specify the trace action, the match is logged to a trace file. To set up a trace
file, you must specify the following elements in the global traceoptions
statement:
Trace filename
policy
option in theflag
statement
The following example uses the trace filename of policy-log
:
[edit] routing-options { traceoptions { file “policy-log"; flag policy; } }
This action does not affect the flow control during routing policy evaluation.
If a term that specifies a trace action also specifies a flow control action, the name
of the term is logged in the trace file. If a term specifies a trace action only, the word
<default
> is logged.
Configuring Separate Actions for Routes in Route Lists
If you specify route lists in the from
statement, for each route in the list,
you can specify an action to take on that individual route directly, without including a then
statement. For more information, see Understanding
Route Filters for Use in Routing Policy Match Conditions.