Last active
September 11, 2015 17:50
-
-
Save jeffbrl/bf4d12037fa76e62fd4c to your computer and use it in GitHub Desktop.
Slax script to display RRO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version 1.0; | |
ns junos = "http://xml.juniper.net/junos/*/junos"; | |
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; | |
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; | |
import "../import/junos.xsl"; | |
match / | |
{ | |
<op-script-results> { | |
var $rpc = { | |
<get-mpls-lsp-information> { | |
<detail>; | |
} | |
} | |
var $out = jcs:invoke($rpc); | |
for-each ($out/rsvp-session-data/rsvp-session/mpls-lsp) { | |
<output> "LSP name: " _ name; | |
call display_rro($raw_rro=mpls-lsp-path/received-rro); | |
} | |
} | |
} | |
template display_rro($raw_rro) | |
{ | |
/* <output> "RRO: " _ $raw_rro; */ | |
/* this is lazy IPv4 regex; slax does seem to able to parse | |
* more accurate ones (e.g., ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ ) | |
*/ | |
var $ipv4_regex = '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'; | |
var $label_regex = 'Label=([0-9]+)'; | |
/* remove everything up to and including first colon */ | |
var $modified_rro = jcs:regex(':(.*)', $raw_rro); | |
var $substrings = jcs:split('\)', $modified_rro[1]); | |
var $my_output = { | |
for-each($substrings) { | |
var $ipv4_literal = jcs:regex($ipv4_regex, .); | |
var $label = jcs:regex($label_regex, .); | |
if($ipv4_literal && $label) { | |
expr $ipv4_literal[1] _ " [" _ $label[1] _ "] "; | |
} | |
else if($ipv4_literal) { | |
expr $ipv4_literal _ " "; | |
} | |
} | |
} | |
<output>$my_output _ '\n'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment