[Contents] [Prev] [Next] [Index] [Report an Error]

Finding LSPs to Multiple Destinations

This example checks for label-switched paths (LSPs) to multiple destinations.

XSLT Syntax

<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet
    xmlns: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, ') --&gt; ', $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>

SLAX Syntax

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";

var $arguments = {
    <argument> {
        <name> "address";
        <description> "LSP endpoint";
    }
}
param $address;

match / {
    <op-script-output> {
        if ($address = '') {
            <xnm:error> {
                <message> "missing mandatory argument 'address'";
            }

        } else {
            var $get-configuration = {
                <get-configuration database="committed"> {
                    <configuration> {
                        <protocols> {
                            <mpls>;
                        }
                    }
                }
            }
            var $config = jcs:invoke($get-configuration);
            var $mpls = $config/protocols/mpls;
            var $get-route-information = {
                <get-route-information> {
                    <terse>;
                    <destination> $address;
                }
            }
            var $rpc-out = jcs:invoke($get-route-information);

            if ($rpc-out//xnm:error) {
                copy-of $rpc-out//xnm:error;

            } else {
                for-each ($rpc-out/route-table/rt/rt-destination) {
                    if (contains(.,'/32')) {
                        var $dest = substring-before(.,'/');
                        var $lsp = $mpls/label-switched-path[to = $dest];

                        if ($lsp) {
                            <output> 'Found: ' _ $dest _ ' (' _ $lsp/to _ ') --> ' _                                      $lsp/name;

                        } else {
                            var $name = jcs:hostname($dest);
                            <output> 'Name: ' _ $name;
                            <output> 'Missing: ' _ $dest;
                        }

                    } else {
                        <output> 'Not a host route: ' _ .;
                    }
                }
            }
        }
    }
}

Testing ex-lsp.xsl

To test the example in this section, perform the following steps:

  1. From Finding LSPs to Multiple Destinations, copy the XSLT or SLAX script into a text file, and name the file ex-lsp.xsl. Copy the ex-lsp.xsl file to the /var/db/scripts/op directory on your routing platform.
  2. Include the file ex-lsp.xsl statement at the [edit system scripts op] hierarchy level. If you are using the SLAX version of the script, change the filename to filename.slax.
    [edit system scripts op]
    file ex-lsp.xsl;
  3. Issue the commit and-quit command.
  4. When you issue the op ex-lsp address address command, the output looks like this:
    user@R4> op ex-lsp address 10.168.215.0/24
    Found: 192.168.215.1 (10.168.215.1) --> R4>R1
    Found: 192.168.215.2 (10.168.215.2) --> R4>R2
    Name: R3
    Missing: 10.168.215.3
    Name: R5
    Missing: 10.168.215.4
    Name: R6
    Missing: 10.168.215.5

[Contents] [Prev] [Next] [Index] [Report an Error]