Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Variable Expressions Overview

Junos OS enables you to create expressions—groups of arithmetic operators, string operators, and operands—for use as variables within dynamic profiles. You configure variable expressions at the [dynamic-profiles profile-name variables] hierarchy level. At run time, the variable expressions are calculated and used as variable values to configure dynamic subscriber interfaces.

When configuring expressions in dynamic profiles, you must adhere to the following rules:

  • You can configure expressions only within a variable stanza of a dynamic profile.
  • Dynamic profiles that contain expressions must be used only for service activation.
  • You can assign expressions only to user-defined variables. You cannot assign expressions to internal variables or predefined variables.
  • Expression values are given precedence over default values.
  • Entire expressions must be contained within quotation marks (“ ”).
  • Strings within the expressions must be quoted within single quotation marks (’ ’) and the single quotation marks can contain only strings.
  • White space is treated as a delimiter for all operands and operators. Strings containing spaces that you create within expressions are treated as single strings and include any leading or trailing white space. For example:
    dynamic-profiles {service profile {variables {scheduler-name;video-filter equals “ ‘ Filter 1 ’ ” # Everything within the single quotation marks is considered a string, including the leading and trailing white space}}}
  • The expression must be either all arithmetic operators or all string operators; mixing arithmetic operators and string operators is not allowed unless properly converted to the correct type.
  • Expressions can refer to other system predefined variables or other user-defined variables. However, no circular referencing between variables is allowed. For example, the following reference is incorrect:
    dynamic-profiles {Service_Profile_1 {variables {scheduler-name;transmit-rate2 equals “ ( $transmit-rate1 * 2)/3” # refers to transmit-rate1transmit-rate1 equals “ ( $transmit-rate2 * 2)/3” # refers to transmit-rate2}}}
  • Any mandatory variable that does not contain a “default” value or an “equals” expression must contain a value as a part of service activation. For example, a RADIUS service VSA like “service-video( value1, value2)” that contains two or fewer mandatory variables in the dynamic service profile definition “service-video” succeeds. The service activation fails if at least one mandatory variable does not have any value associated with it, either through default or equals attribute evaluation.

Table 1 lists supported operators and functions you can use to create expressions.

Note: Precedence 5 is the highest level.

Table 1: Operators and Functions

Operation

Operator

Associativity

Precedence

Action

Arithmetic Addition

+

Left

1

Adds the elements to the right and left of the operator together.

Arithmetic Subtraction

-

Left

1

Subtracts the element to the right of the operator from the element to the left of the operator.

Arithmetic Multiplication

*

Left

2

Multiplies the element to the left of the operator by the element to the right of the operator.

Arithmetic Division

/

Left

2

Divides the element to the left of the operator by the element to the right of the operator.

Arithmetic Modulo

%

Left

2

Divides the element to the left of the operator by the element to the right of the operator and returns the integer remainder. If the element to the left of the operator is less than the element to the right of the operator, the result is the element to the left of the operator.

Concatenation

##

Left

3

Creates a new string by joining the string values to the left of the operator and the values to the right of the operator together.

Maximum

max(param1,param2)

Left

4

Takes the maximum of the two values passed as parameters.

Minimum

min(param1,param2)

Left

4

Takes the minimum of the two values passed as parameters.

Round

round(param1)

-

4

Rounds the value to the nearest integer.

Truncate

trunc(param1)

-

4

Truncates a non-integer value to the value left of the decimal point.

Convert to String

toStr(param1)

-

4

Converts the variable inside the parentheses to a null terminated string.

Convert to Integer

toInt(param1)

-

4

Converts the parameter to an integer. A single string or variable is allowed as a parameter.

Random

rand()

-

4

Generates a random numerical value.

Parentheses

( )

-

5

Groups operands and operators to achieve results different from simple precedence; effectively has the highest precedence.

Expressions are evaluated after variables are populated with values. The evaluation is conducted immediately before profile instantiation and includes value checking. If the computed values are not acceptable, or rules governing expression syntax are broken, the expression evaluation fails, profile instantiation does not occur, and messages are logged to describe the errors.

Table 2 lists the possible expression error scenarios and the action taken by the router software.

Table 2: Expression Errors and Actions

Error

Occurance

Action

Variable Value

Parsing error

Commit check phase

Commit fails

not applicable

Circular variable dependency error

Commit check phase

Commit fails

not applicable

Variables inside the expressions are not defined

Commit check phase

Commit fails

not applicable

Divide by zero

Profile Instantiation

Profile instantiation fails

Zero (0)

Adding string to a number

Profile Instantiation

Profile instantiation fails

Zero (0)

Overflow error

Profile Instantiation

Profile instantiation fails

Undefined

Underflow error

Profile Instantiation

Profile instantiation fails

Undefined

You can also configure the user-defined variables with a default value. The default value provides a standalone configuration for the associated statement or a backup for the statement configuration if the RADIUS server is inaccessible or the VSA attribute does not contain a value.

Published: 2013-02-11