10.1.15.12-06212024

Compound Variable

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. For example, you can define a compound variable,

$routing = $hasBGP?$as:($hasOSPF?$rid:($hasISIS?$level:”N/A”)) , to present the following semantics:

 Graphical user interface, text, application

Description automatically generated

  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”.

Refer to Compound Variable Properties on how to define a compound variable,

Compound Variable Properties

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

The following table lists the properties of a compound variable.

PropertyDescription
Variable NameThe name of a compound variable.
Type

The type of 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
Information

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 used for string-type variables.

OperatorDescriptionExample
+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”
MatchPattern()

Support the match of regular expressions.

Format: $var.MatchPattern(input, pattern)

  • input - source string to match.
  • pattern - regular expression or sub string.
  • MatchPattern(“abc”, “a”) - match strings that contain "a".
  • MatchPattern("abc","^ab") - match strings starting with "ab".
String + NumberMerge a string-type variable and a number-type variable.$str2 = $str1 + $number1
StartsWithMatch a string starting with specified sub string.$a.StartsWith("abc")
EndsWithMatch a string ending with specified sub string.$a.EndsWith("def")
ContainsMatch a string that contains specific characters.$a.Contains("ab")
IsEmptyJudge 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.

OperatorDescriptionExample
+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.

OperatorDescriptionExample
&&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 NameDescriptionExample
NB_GetDeviceObtain a device name by using an IP address.NB_GetDevice($ip)
NB_GetMgmtIPObtain 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)
  • GetTableRowCoun