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 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 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 ex-lsp-admin.xsl.
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;
}
}
}
}
}
}
}
}
}
To test the example in this section, perform the following steps:
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;
}
}
}
- [edit]
- user@host# load merge terminal
- [Type ^D at a new line to end input]
- > Paste the contents of the clipboard here<
- [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:
[edit]
user@host# show protocols mpls | display commit-scripts
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;
}
admin-groups {
blue 0;
}
label-switched-path blue-lsp-10.1.1.1 {
to 10.1.1.1;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.2.2.2 {
to 10.2.2.2;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.3.3.3 {
to 10.3.3.3;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.4.4.4 {
to 10.4.4.4;
admin-group include-any blue;
}
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:
[edit]
user@host# show protocols mpls | display commit-scripts no-transients
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;
}
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:
[edit]
user@host# show 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;
}