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

Controlling a Dual Routing Engine Configuration

If your routing platform has redundant (also called dual) Routing Engines, your JUNOS configuration can be complex. This example shows how you can use commit scripts to simplify and control the configuration of dual Routing Engine platforms.

The JUNOS software supports two special configuration groups: re0 and re1. When these groups are applied using the apply-groups [ re0 re1 ] statement, they take effect if the Routing Engine name matches the group name. Statements included at the [edit groups re0] hierarchy level are inherited only on the Routing Engine named RE0, and statements included at the [edit groups re1] hierarchy level are inherited only on the Routing Engine named RE1.

This example includes two commit scripts. The first script, ex-dual-re.xsl, emits a warning if the system host-name statement, any IP version 4 (IPv4) interface address, or the fxp0 interface configuration is configured in the target configuration instead of in a configuration group.

The second script, ex-dual-re2.xsl, first checks whether the hostname configuration is configured and then checks whether it is configured in a configuration group. The otherwise construct emits an error message if the hostname is not configured at all. The first when construct allows the script to do nothing if the hostname is already configured in a configuration group. The second when construct takes effect when the hostname is configured in the target configuration. In this case, the script generates a transient change that places the hostname configuration into the re0 and re1 configuration groups, copies the configured hostname into those groups, concatenates each group hostname with -RE0 and -RE1, and deactivates the hostname in the target configuration so the configuration group hostnames can be inherited.

XSLT Syntax: ex-dual-re.xsl Script

<?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:for-each select="system/host-name
                          | interfaces/interface/unit/family/inet/address
                          | interfaces/interface[name = 'fxp0']">
            <xsl:if test="not(@junos:group) or not(starts-with(@junos:group, 're'))">
                <xnm:warning>
                    <xsl:call-template name="jcs:edit-path">
                        <xsl:with-param name="dot" select=".."/>
                    </xsl:call-template>
                    <xsl:call-template name="jcs:statement"/>
                    <message>
                        <xsl:text>statement should not be in target</xsl:text>
                        <xsl:text> configuration on dual RE system</xsl:text>
                    </message>
                </xnm:warning>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

XSLT Syntax: ex-dual-re2.xsl Script

<?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="hn" select="system/host-name"/>
        <xsl:choose>
            <xsl:when test="$hn/@junos:group"/>
            <xsl:when test="$hn">
                <transient-change>
                    <groups>
                        <name>re0</name>
                        <system>
                            <host-name>
                                <xsl:value-of select="concat($hn, '-RE0')"/>
                            </host-name>
                        </system>
                    </groups>
                    <groups>
                        <name>re1</name>
                        <system>
                            <host-name>
                                <xsl:value-of select="concat($hn, '-RE1')"/>
                            </host-name>
                        </system>
                    </groups>
                    <system>
                        <host-name inactive="inactive"/>
                    </system>
                </transient-change>
            </xsl:when>
            <xsl:otherwise>
                <xnm:error>
                    <message>Missing [system host-name]</message>
                </xnm:error>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

SLAX Syntax: ex-dual-re.xsl Script

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 {
    for-each (system/host-name | interfaces/interface/unit/family/inet/address                                | interfaces/interface[name = 'fxp0']) {
        if (not(@junos:group) or not(starts-with(@junos:group, 're'))) {
            <xnm:warning> {
                call jcs:edit-path($dot = ..);
                call jcs:statement();
                <message> {
                    expr "statement should not be in target";
                    expr " configuration on dual RE system";
                }
            }
        }
    }
}

SLAX Syntax: ex-dual-re2.xsl Script

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 $hn = system/host-name;

    if ($hn/@junos:group) {
    }
    else if ($hn) {
        <transient-change> {
            <groups> {
                <name> "re0";
                <system> {
                    <host-name> $hn _ '-RE0';
                }
            }
            <groups> {
                <name> "re1";
                <system> {
                    <host-name> $hn _ '-RE1';
                }
            }
            <system> {
                <host-name inactive="inactive">;
            }
        }
        else {
            <xnm:error> {
                <message> "Missing [system host-name]";
            }
        }
    }
}

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