Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Example: Controlling LDP Configuration

 

This commit script example generates a warning on LDP-enabled devices for any interfaces that are configured at either the [edit protocols ospf] or [edit protocols isis] hierarchy level but are not configured at the [edit protocols ldp] hierarchy level. A second test ensures that all LDP-enabled interfaces are configured for an interior gateway protocol (IGP). The example also provides instructions for excluding a particular interface from the commit script LDP test.

Requirements

This example uses a router running Junos OS.

Overview and Commit Script

If you want to enable LDP on an interface, you must configure the interface at both the [edit protocols routing-protocol-name] and [edit protocols ldp] hierarchy levels. This example shows how to use commit scripts to ensure that the interface is configured at both levels.

This example tests for interfaces that are configured at either the [edit protocols ospf] or [edit protocols isis] hierarchy level but not at the [edit protocols ldp] hierarchy level. If LDP is not enabled on the device, there is no problem. Otherwise, a warning is generated with the message that the interface does not have LDP enabled.

In case you want some interfaces to be exempt from the LDP test, this script allows you to tag those interfaces as not requiring LDP by including the apply-macro no-ldp statement at the [edit protocols isis interface interface-name] or [edit protocols ospf area area-id interface interface-name] hierarchy level. For example:

If the apply-macro no-ldp statement is included, the warning is not generated.

A second test ensures that all LDP-enabled interfaces are configured for an interior gateway protocol (IGP). As for LDP, you can exempt some interfaces from the test by including the apply-macro no-igp statement at the [edit protocols ldp interface interface-name] hierarchy level. If that statement is not included and no IGP is configured, a warning is generated.

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 ldp.xsl or ldp.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 ldp.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 Script Execution

Purpose

Verify that the script behaves as expected.

Action

Review the output of the commit command. The sample configuration stanzas enable LDP on the device and configure the so-1/2/2 and so-1/2/3 interfaces at the [edit protocols isis] hierarchy level and the ge-3/2/1 and ge-2/2/1 interfaces at the [edit protocols ospf] hierarchy level.

Because ge-2/2/1 is also configured at the [edit protocols ldp] hierarchy level, the script does not issue a warning message for this interface during the commit operation. The configuration includes the apply-macro no-ldp statement under the so-1/2/2 interface, so the script does not test this interface or issue a warning message for it, even though it is not configured at the [edit protocols ldp] hierarchy.

Neither so-1/2/3 nor ge-3/2/1 is configured at the [edit protocols ldp] hierarchy level as required by the commit script, so a warning is issued for both interfaces. The ge-1/2/1 interface is configured at the [edit protocols ldp] hierarchy. However, it is not configured for an IGP, so the commit script also issues a warning for the ge-1/2/1 interface.