Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Configuring Policy Templates


The policy templates are used to define the policy rules that are inserted or removed from network devices. Templates are combined with parameters from the service activation context to generate Junos XML management protocol and Telnet commands that add and remove service policies.

The policy templates section has this basic structure:

Table 1 describes the policy template elements in the configuration file.

Table 1: Policy Template Elements for Configuration File



<target interface-class=


Defines a single policy template, which is selected by matching the interface-class attribute with the value found in the dpiInterfaceClasses parameter. If the interface-class attribute is not provided or its value is "", the target applies to all interfaces.

For example: <target interface-class="MXEnterprise">


Defines what the script service should do when activating or modifying a session. This element is triggered when the dpiAdminState parameter changes from "disabled" to "enabled".


Defines what the script service should do when deactivating a session. This element is triggered when the dpiAdminState parameter changes from "enabled" to "disabled".


Contains a sequence of Junos XML management protocol commands to manage policies on routers running Junos OS.

This element can contain <if> and <for-each-rule> elements, delimited variables, literal text, and XML elements, which are not interpreted.

<telnet host="hostname">

Contains a sequence of prompt and command pairs to match on the Telnet device, similar to an expect script. The host attribute is a variable that can include a regular expression to extract a part of the value from the variable. See the <variable> element.

For example: <telnet host="deviceIP">

This element can contain <if>, <for-each-rule>, <prompt>, and <command> elements. The <prompt> and <command> elements must alternate, and the sequence must start with the <prompt> element. This element can also contain delimited variables and literal text.

<variable-delimiters start="delimiter" end="delimiter">

Specifies the delimiters for variables in the configuration file. The default delimiters enclose the variable within three square brackets ([[[ variable ]]]).

If you want to specify a different delimiter, you must specify the <variable-delimiters> element immediately after the opening tag for the <junoscript> or <telnet> element. The delimiters apply to the contents of the <junoscript> or <telnet> element. Any other occurrences of the <variable-delimiters> element within that element are ignored.

For example: <variable-delimiters start="(*" end="*)">

<if test=


Defines conditional expressions used to generate configuration commands.

The test attribute is a variable expression without delimiters. The test is true if the variable has a value and if the optional regular expression matches the variable.

For example, the forwarding-class statement would be added to the body only if the map expression contained the fcl key to satisfy the test condition:

<if test="fcl">

forwarding-class [[[ fcl ]]];



Creates the specified body in the policy template for instantiating each map expression found in the dpiRules parameter. For example, if you have two map expressions in the dpiRules parameter, the policy template would generate the body of the <for-each-rule> element once for each map expression.

The <for-each-rule> element has a ruleNumber variable to sequentially track the processing of each map expression.

You can use the test attribute to provide a condition for the rule; using this attribute would be the same as adding an <if> element.


When using special XML characters as part of the policy templates, they must be coded in XML. For example, the left angle bracket (<) must be coded as &lt;.

The following example uses some elements to show a policy template that activates application-aware access list (AACL) services and service sets on an MX Series router by loading the configuration in text format using Junos XML management protocol.

If the example uses the following dpiRules substitution:

The two map expressions in the dpiRules parameter might generate the following target configuration (with two terms) from the policy template example:

Related Documentation