 Let us know what you think.

Do you have time for a two-minute survey?

Guide That Contains This Content
[+] Expand All
[-] Collapse All

# Special Built-In Functions

Use function called wildcardtocidr

Sample

The result could be:

converting 62.179.128.0 wild mask 0.0.1.255 => 62.179.128.0/23

Convert ISIS system ID to IPv4

toipv4 (node.isis_system_id)
Sample:
toipv4(1921.6800.0001) will return 192.168.0.1

Match string value

Use function called getmatch

Sample:

set \$(interface.name) “Bundle-Ether1”
set \$(number) getmatch(interface.name, “[0-9.]+”)
print “\$(number)”

The result of the print out is “1”

Get physical interface from sub interface

Use function called getphysical
Sample:

set \$(logical) “ge-0/0/1.12”
set \$(physical) getphysical(logical)
print “\$(physical)

The result of the print out is “ge-0/0/1”.

Arithmetic Function

Arithmetic functions supported are add, subtract, multiply, and divide

Sample:

set \$(a) "5"
set \$(b) "2"

The result of the print out is “7”

set \$(substract_result) subtract(a,b)
print "\$(substract_result)"

The result of the print out is “3”

set \$(multiply_result) multiply(a,b)
print "\$(multiply_result)"

The result of the print out is “10”

set \$(divide_result) divide(a,b)
print "\$(divide_result)"

The result of the print out is “2.5”

String Extraction Function

String extraction functions returns the character of properties of a string. The first character in a string starts at index 1. String functions includes len, right, left, mid, and find.

• len(string) # returns the length of the string
• right(string, num_char) # returns the number of characters from the right
• left(string, num_char), # returns the number of characters from the left
• mid(string, start_index, num_char) # returns the number of characters from the specified start index
• find(txt_to_find, string, [start_index]) # find the index of the character in the string, the start_index is optional

Sample:

set \$(host_name) "us-pe-01"
set \$(country) mid(host_name,1,2)
print "country is \$(country)"
set \$(role) mid(host_name,4,5)
print "role is \$(role)"
set \$(intf) "port-1/8/5:10G"
set \$(colon) ":"
set \$(res) right(intf, len(intf)- find(colon,intf,1))
print "test case 1: \$(intf) => \$(res)"

The result of the print out is "port-1/8/5:10G => 10G"

set \$(intf2) "GigabitEthernet0/7/0/36.1778"
set \$(res2) left(intf2, find(".",intf2,1)-1)
print "test case 2: \$(intf2) => \$(res2)"

The result of the print out is "GigabitEthernet0/7/0/36.1778 => GigabitEthernet0/7/0/36"

set \$(s) "1234567890"
set \$(len) len(s)
print "test case 3 (a): length = \$(len)"

The result of the print out is “test case 3 (a): length = 10"

Array Extraction Function

To extract an array from a string, the string syntax must have the array elements enclosed by bracket [,] and delimited by comma or white space. Then use the toarray function on the string to extract the array elements.

Sample:

set \$(string) "protocol [ bgp direct static ]"
set \$(array) toarray(string)
print "test case 3: \$(array)" # prints [bgp, direct, static]

Data Structure Objects

Data structure objects allows the user to create an object that can have multiple attributes assigned to it.

Sample:

@define rule object_test
create \$(interface_obj)
set \$(interface_obj.name) "ge-0/0/0"
set \$(interface_obj.isis) "yes"
set \$(interface_obj.disable) "no"
print "interface \$(interface_obj)"
create \$(interface_obj)
set \$(interface_obj.name) "ge-0/0/1"
set \$(interface_obj.isis) "no"
set \$(interface_obj.disable) "no" 