Finding LSPs to Multiple Destinations
This example checks for label-switched paths (LSPs) to multiple destinations.
<?xml version="1.0" standalone="yes"?><xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:junos="http://xml.juniper.net/junos/*/junos"xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0" version="1.0"><xsl:variable name="arguments"><argument><name>address</name><description>LSP endpoint</description></argument></xsl:variable><xsl:param name="address"/><xsl:template match="/"><op-script-output><xsl:choose><xsl:when test="$address = ''"><xnm:error><message>missing mandatory argument 'address'</message></xnm:error></xsl:when><xsl:otherwise><xsl:variable name="get-configuration"><get-configuration database="committed"><configuration><protocols><mpls/></protocols></configuration></get-configuration></xsl:variable><xsl:variable name="config" select="jcs:invoke($get-configuration)"/><xsl:variable name="mpls" select="$config/protocols/mpls"/><xsl:variable name="get-route-information"><get-route-information><terse/><destination><xsl:value-of select="$address"/></destination></get-route-information></xsl:variable><xsl:variable name="rpc-out" select="jcs:invoke($get-route-information)"/><xsl:choose><xsl:when test="$rpc-out//xnm:error"><xsl:copy-of select="$rpc-out//xnm:error"/></xsl:when><xsl:otherwise><xsl:for-each select="$rpc-out/route-table/rt/rt-destination"><xsl:choose><xsl:when test="contains(.,'/32')"><xsl:variable name="dest" select="substring-before(.,'/')"/><xsl:variable name="lsp" select="$mpls/label-switched-path[to = $dest]"/><xsl:choose><xsl:when test="$lsp"><output><xsl:value-of select="concat('Found: ', $dest, ' (', $lsp/to, ') --> ', $lsp/name)"/></output></xsl:when><xsl:otherwise><xsl:variable name="name" select="jcs:hostname($dest)"/><output><xsl:value-of select="concat('Name: ', $name)"/></output><output><xsl:value-of select="concat('Missing: ', $dest)"/></output></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><output><xsl:value-of select="concat('Not a host route: ', .)"/></output></xsl:otherwise></xsl:choose></xsl:for-each></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></op-script-output></xsl:template></xsl:stylesheet>Testing ex-lsp.xsl
To test the example in this section, perform the following steps:
- From Finding LSPs to Multiple Destinations, copy the Extensible Stylesheet Language Transformations (XSLT) script into a text file, and name the file ex-lsp.xsl. Copy the ex-lsp.xsl file to the
/var/db/scripts/opdirectory on your routing platform.- Include the file ex-lsp.xsl statement at the
[edit system scripts op]hierarchy level:[edit system scripts op]file ex-lsp.xsl;- Issue the
commit and-quitcommand.- When you issue the
op ex-lspaddressaddresscommand, the output looks like this:user@R4>op ex-lsp address 10.168.215.0/24Found: 192.168.215.1 (10.168.215.1) --> R4>R1Found: 192.168.215.2 (10.168.215.2) --> R4>R2Name: R3Missing: 10.168.215.3Name: R5Missing: 10.168.215.4Name: R6Missing: 10.168.215.5