Example: Configuring Administrative Groups for LSPs
Administrative groups, also known as link coloring or resource classes, are manually assigned attributes that describe the color of links. Links with the same color conceptually belong to the same class. You can use administrative groups to implement a variety of policy-based label-switched path (LSP) setups.
In this example, the Junos OS management process (mgd) inspects the configuration, looking for apply-macro statements. For each apply-macro statement with the color parameter included at the [edit protocols mpls] hierarchy level, the script generates a transient change, using the data provided within the apply-macro statement to expand the macro into a standard Junos OS administrative group for LSPs.
For this example to work, an apply-macro statement must be included at the [edit protocols mpls] hierarchy level with a set of addresses, a color parameter, and a group-value parameter. The commit script converts each address to an LSP configuration and converts the color parameter into an administrative group. For the necessary configuration statements, see Testing the ex-lsp-admin Script.
For a line-by-line explanation of this script, see Example: Creating Custom Configuration Syntax with Macros.
XSLT Syntax
<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
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">
<xsl:import href="../import/junos.xsl"/>
<xsl:template match="configuration">
<xsl:variable name="mpls" select="protocols/mpls"/>
<xsl:for-each select="$mpls/apply-macro[data/name = 'color']">
<xsl:variable name="color" select="data[name = 'color']/value"/>
<xsl:for-each select="$mpls/apply-macro[data/name = 'group-value']">
<xsl:variable name="group-value" select="data[name =
'group-value']/value"/>
<transient-change>
<protocols>
<mpls>
<admin-groups>
<name>
<xsl:value-of select="$color"/>
</name>
<group-value>
<xsl:value-of select="$group-value"/>
</group-value>
</admin-groups>
<xsl:for-each select="data[not(value)]/name">
<label-switched-path>
<name>
<xsl:value-of select="concat($color, '-lsp-', .)"/>
</name>
<to><xsl:value-of select="."/></to>
<admin-group>
<include-any>
<xsl:value-of select="$color"/>
</include-any>
</admin-group>
</label-switched-path>
</xsl:for-each>
</mpls>
</protocols>
</transient-change>
</xsl:for-each>
</xsl:for-each>
</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";
import "../import/junos.xsl";
match configuration {
var $mpls = protocols/mpls;
for-each ($mpls/apply-macro[data/name = 'color']) {
var $color = data[name = 'color']/value;
for-each ($mpls/apply-macro[data/name = 'group-value']) {
var $group-value = data[name = 'group-value']/value;
<transient-change> {
<protocols> {
<mpls> {
<admin-groups> {
<name> $color;
<group-value> $group-value;
}
for-each (data[not(value)]/name) {
<label-switched-path> {
<name> $color _ '-lsp-' _ .;
<to> .;
<admin-group> {
<include-any> $color;
}
}
}
}
}
}
}
}
}
Testing the ex-lsp-admin Script
To test the ex-lsp-admin script,
perform the following steps:
- Copy the XSLT or SLAX script from Example: Configuring Administrative Groups for LSPs into a text file, name the file
ex-lsp-admin.xslorex-lsp-admin.slaxas appropriate, and copy it to the/var/db/scripts/commitdirectory on the device. Select the following configuration stanzas, and press Ctrl+c to copy them to the clipboard. If you are using the SLAX version of the script, change the filename at the [edit system scripts commit file] hierarchy level to ex-lsp-admin.slax.
system {scripts {commit {allow-transients;file ex-lsp-admin.xsl;}}}protocols {mpls {apply-macro blue-type-lsp {10.1.1.1;10.2.2.2;10.3.3.3;10.4.4.4;color blue;group-value 0;}}}In configuration mode, issue the load merge terminal command to merge the stanzas into your device configuration:
[edit]user@host# load merge terminal[Type ^D at a new line to end input]... Paste the contents of the clipboard here ...- At the prompt, paste the contents of the clipboard using the mouse and the paste icon.
- Press Enter.
- Press Ctrl+d.
Issue the commit command.
[edit]
user@host# commit
With Script-Generated Changes
When you issue the show protocols mpls | display commit-scripts configuration mode command, the following output appears:
Without Script-Generated Changes
The output of the show protocols mpls | display commit-scripts no-transients configuration mode command excludes the label-switched-path statements:
When you issue the show protocols mpls command without the piped display commit-scripts no-transients command, you see the same output because this script does not generate any persistent changes:
Hide Navigation Pane
Show Navigation Pane
Download
SHA1