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


Finding LSPs to Multiple Destinations

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

<?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>

Testing ex-lsp.xsl

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

  1. 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/op directory on your routing platform.
  2. Include the file ex-lsp.xsl statement at the [edit system scripts op] hierarchy level:
  3. [edit system scripts op]
    
    file ex-lsp.xsl;
    
    
    
  4. Issue the commit and-quit command.
  5. When you issue the op ex-lsp address address command, the output looks like this:
  6. 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]