Beyond existing built-in variables and parser variables, the system supports compound variables in a data view template definition to organize multiple variables to represent complex network semantics.

Example: $routing = $hasBGP?$as:($hasOSPF?$rid:($hasISIS?$level:”N/A”))

The semantic of this compound variable means:

1.If $hasBGP is true, return the value of $as; if not, return the value of ($hasOSPF?$rid:($hasISIS?$level:”N/A”)).

2.If $hasOSPF is true, return the value of $rid; if not, return the value of $hasISIS?$level:”N/A”).

3.If $hasISIS is true, return the value of $level; if not, return ”N/A”.

For more detailed explanation about how to define a compound variable, refer to Compound Variable Properties.

Compound Variable Properties

Compound variables can be separately defined at both device level and interface level, composed of built-in variables or parser variables, operators and functions.

The following table lists the properties of a compound variable.

Property

Description

Variable Name

The name of a compound variable.

Type

The type of a compound variable:

String - String Operators can be used to define a string-type compound variable.

Number - Number Operators can be used to define a number-type compound variable.

Bool - Bool Operators can be used to define a bool-type compound variable.

Definition

Define a compound variable with built-in functions or formulas, including Global Functions.

Examples:

String Type: $routing = $bgp_config + $ospf_config

Number Type: $error = $input_error + $output_error

Bool Type: $device_busy = $cpu > 90 and $mem > 80

General Notes for Compound Variable Definition:

1) Device-level compound variables can be composed of device variables and input variables; interface-level compound variables can be composed of device variables, interface variables and input variables.

2) Line breaks are not allowed.

3) Nested compound variables are not allowed.

String Operators

The following table lists the built-in operators that can be used for string-type variables.

Operator

Description

Example

+

Merge two string-type variables.

$routing = $bgp_config + $ospf_config

==

Equals specified string.

$a==$b?1:0

!==

Not equals specified string.

$a!==$b?1:0

Substring

Only keep a sub string out of source string.

Format: $var.Substring(startIndex, length)

startIndex - the digit of source string from where the index starts.

length (optional) - the length of string to keep. If left blank, all the remaining string will be kept.

If $a = abcdef, then:

$a.Substring(1,2) returns “bc”

$a.Substring(1) returns “bcdef”

IsMatch()

Support the match of regular expressions.

Format: $var.IsMatch(input, pattern)

input - source string to match.

pattern - regular expression or sub string.

IsMatch(“abc”, “a”) - match strings that contain "a".

IsMatch("abc","^ab") - match strings starting with "ab".

String + Number

Merge a string-type variable and a number-type variable.

$str2 = $str1 + $number1

StartsWith

Match a string starting with specified sub string.

$a.StartsWith("abc")

EndsWith

Match a string ending with specified sub string.

$a.EndsWith("def")

Contains

Match a string that contains specific characters.

$a.Contains("ab")

IsEmpty

Judge whether the value of a string or a variable is null.

IsEmpty($var1) - Recommended to use.

IsEmpty($var1)?true:false
Note: "true" and "false" must be all lower cases.

Number Operators

The following table lists the built-in operators that can be used for number-type variables.

Operator

Description

Example

+

Add two number-type variables.

$error = $input_error + $output_error

-

Subtract two number-type variables.

$error = $input_error - $output_error

*

Multiply two number-type variables.

$a*$b

/

Divide two number-type variables.

$a/$b

>

Judge whether the value of a number-type variable is greater than that of another one.

$cpu > 90

>=

Judge whether the value of a number-type variable is equal to or greater than that of another one.

$a>=$b

<

Judge whether the value of a number-type variable is less than that of another one.

$a<$b

<=

Judge whether the value of a number-type variable is equal to or less than that of another one.

$a<=$b

==

Judge whether the values of two number-type variables equal.

$a==$b

!=

Judge whether the values of two number-type variables don't equal.

$a!=$b

Bool Operators

The following table lists the built-in operators that can be used for bool-type variables.

Operator

Description

Example

&&

Combine two variables, indicating both var1 and var2.

$cpu > 90 && $mem > 80

||

Alternate two variables, indicating either var1 or var2.

$cpu > 90 || $mem > 80

Get the opposite result of a variable.

!$cpu > 90

?:

The ternary operator.

$cpu > 90?1:0

It means if $cpu > 90, return 1; if not, return 0.

()

Prioritize a formula.

($a-$b)*$c

Global Functions

The following table lists the global functions that can be used to define a compound variable.

Function Name

Description

Example

NB_GetDevice

Obtain a device name by using an IP address.

NB_GetDevice($ip)

NB_GetMgmtIP

Obtain a management IP address by using a hostname.

NB_GetMgmtIP($hostName)

GetTableRowCount

Obtain the number of rows for a table-type variable.

Format: GetTableRowCount($Table, $vrf, $PeIP)

Notes:

1) "$" is not required when referencing a function.

2) Both $vrf and $PeIP are optional, and can be left blank.

GetTableRowCount($intfTable)

GetTableRowCount($RouteTable)

GetTableRowCount($RouteTable, $vrf)

GetTableRowCount($BGPNbrTable, $vrf, $PeIP)