Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Example: Configuring an Interior Gateway Protocol on an Interface

 

This commit script example uses a macro to automatically include an interface at the [edit protocols] hierarchy level and to configure the proper interior gateway protocol (IGP) on the interface.

Requirements

This example uses a device running Junos OS.

Overview and Commit Script

When you add a new interface to an OSPF or IS-IS domain, you must configure the interface at multiple hierarchy levels, including [edit interfaces] and [edit protocols]. This example uses a commit script and macro to automatically include the interface at the [edit protocols] hierarchy level and to configure the proper IGP on the interface, either OSPF or IS-IS, depending on the content of an apply-macro statement that you include in the interface configuration. This macro allows you to perform more configuration tasks at a single hierarchy level.

In this example, the Junos OS management (mgd) process inspects the configuration, looking for apply-macro statements. For each apply-macro ifclass statement included at the [edit interfaces interface-name unit logical-unit-number] hierarchy level, the script tests whether the role parameter is defined as cpe. If so, the script checks the igp parameter.

If the igp parameter is defined as isis, the script includes the relevant interface name at the [edit protocols isis interface] hierarchy level.

If the igp parameter is defined as ospf, the script includes the relevant interface name at the [edit protocols ospf area address interface] hierarchy level. For OSPF, the script references the area parameter to determine the correct subnet address of the area.

The example script is shown in both XSLT and SLAX syntax:

XSLT Syntax

SLAX Syntax

Configuration

Step-by-Step Procedure

To download, enable, and test the script:

  1. Copy the script into a text file, name the file if-class.xsl or if-class.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.
  2. 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 if-class.slax.

  3. In configuration mode, issue the load merge terminal command to merge the stanzas into your device configuration.

    1. At the prompt, paste the contents of the clipboard by using the mouse and the paste icon.

    2. Press Enter.

    3. Press Ctrl+d.

  4. Issue the commit command to commit the configuration.

Verification

Verifying the Configuration

Purpose

Verify that the script behaves as expected.

Action

View the configuration to verify that the manual changes and the script-generated changes are present.

When you issue the show interfaces configuration mode command, the changes added by the sample configuration stanzas should be present in the configuration.

When you issue the show protocols configuration mode command, the script-generated changes should be present in the configuration.