Example: Configure a Default Encapsulation Type
This commit script example configures default Cisco HDLC encapsulation on SONET/SDH interfaces not configured as aggregate interfaces.
Requirements
This example uses a device running Junos OS with SONET/SDH interfaces.
Overview and Commit Script
Point-to-Point Protocol (PPP) encapsulation is the default encapsulation type for physical interfaces. You do not need to configure encapsulation for any physical interfaces that support PPP encapsulation. If you do not configure encapsulation, PPP is used by default. For physical interfaces that do not support PPP encapsulation, you must configure an encapsulation to use for packets transmitted on the interface.
This example configures default Cisco HDLC encapsulation on
SONET/SDH interfaces not configured as aggregate interfaces. The tag
variable is passed to the jcs:emit-change
template as transient-change
, so this
change is not copied to the candidate configuration.
Simply including configuration groups in the configuration does
not enable you to test whether the aggregate
statement
is included for an interface at the [edit interfaces interface-name sonet-options]
hierarchy level. A
commit script can perform this test and set the encapsulation only
on nonaggregated interfaces. The script written to perform this test
has the following syntax:
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:for-each select="interfaces/interface[starts-with(name, 'so-') and not(sonet-options/aggregate)]"> <xsl:call-template name="jcs:emit-change"> <xsl:with-param name="tag" select="'transient-change'"/> <xsl:with-param name="content"> <encapsulation>cisco-hdlc</encapsulation> </xsl:with-param> </xsl:call-template> </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 { for-each (interfaces/interface[starts-with(name, 'so-') and not(sonet-options/aggregate)]) { call jcs:emit-change($tag = 'transient-change') { with $content = { <encapsulation> "cisco-hdlc"; } } } }
Configuration
Procedure
Step-by-Step Procedure
To download, enable, and test the script:
Copy the script into a text file, name the file so-encap.xsl or so-encap.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.
Select the following test 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 so-encap.slax.system { scripts { commit { allow-transients; file so-encap.xsl; } } } interfaces { so-1/2/2 { sonet-options { aggregate as0; } } so-1/2/3 { unit 0 { family inet { address 10.0.0.3/32; } } } so-1/2/4 { unit 0 { family inet { address 10.0.0.4/32; } } } }
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 by using the mouse and the paste icon.
Press Enter.
Press Ctrl+d.
Commit the configuration.
user@host# commit
Verification
Verifying the Configuration
Purpose
Verify that the script behaves as expected.
Action
When you issue the commit
command, the commit
script tests for SONET/SDH interfaces that are not configured as aggregate
interfaces and sets the default encapsulation type on the nonaggregated
interfaces to Cisco HDLC encapsulation. This is implemented as a transient-change
. Even though the transient changes
are in effect, they are not, by default, displayed in the normal output
of the show interfaces
command.
[edit] user@host# show interfaces so-1/2/2 { sonet-options { aggregate as0; } } so-1/2/3 { unit 0 { family inet { address 10.0.0.3/32; } } } so-1/2/4 { unit 0 { family inet { address 10.0.0.4/32; } } }
To view the configuration with the transient changes, issue
the show interfaces | display commit-scripts
command:
[edit] user@host# show interfaces | display commit-scripts so-1/2/2 { sonet-options { # The presence of these statements prevents the aggregate as0; # transient change from affecting this interface. } } so-1/2/3 { encapsulation cisco-hdlc; # Added by transient change. unit 0 { family inet { address 10.0.0.3/32; } } } so-1/2/4 { encapsulation cisco-hdlc; # Added by transient change. unit 0 { family inet { address 10.0.0.4/32; } } }