Blog Viewer

Scripting How-To: Enable MPLS on iso-enabled interfaces

By Erdem posted 08-11-2015 21:32

  

Enable MPLS on iso-enabled Interfaces

 

For SLAX version 1.0 and higher, you can enable MPLS on iso-enabled interfaces. Ensure that any interface that you set up as iso-enabled also has MPLS enabled. If MPLS is not enabled, then the check-iso script adds it.

 

For every logical unit with iso-enabled, test if MPLS is enabled. If it isn't, the script calls jcs:emit-change() to add it.

 

Source Code and GitHub Links

 

 The source code below is also available from the following GitHub locations:

 

Example Configuration

 

01	system {
02	    scripts {
03	    commit {
04	        file check-iso.xsl;
05	    }
06	    }
07	}
08	interfaces {
09	    so-1/2/3 {
10	        unit 0 {
11	            family iso;
12	        }
13	    }
14	    so-1/3/2 {
15	        unit 0 {
16	            family iso;
17	        }
18	    }
19	}
20	protocols {
21	    mpls {
22	        enable;
23	    }
24	}

 

Example Output

 

1	re0:
2	[edit interfaces interface so-1/2/3 unit 0]
3	  warning: Adding 'family mpls' to iso-enabled interface
4	[edit interfaces interface so-1/2/3 unit 0]
5	  warning: Adding iso-enabled interface so-1/2/3.0 to [protocols mpls]
6	[edit interfaces interface so-1/3/2 unit 0]
7	  warning: Adding 'family mpls' to iso-enabled interface
8	[edit interfaces interface so-1/3/2 unit 0]
9	  warning: Adding iso-enabled interface so-1/3/2.0 to [protocols mpls]

 

SLAX Script Contents

 

01	/*
02	 * $Id: check-iso.slax,v 1.2 2007/10/18 03:08:07 phil Exp $
03	 */
04	 
05	version 1.0;
06	ns xsl = "http://www.w3.org/1999/XSL/Transform";
07	ns junos = "http://xml.juniper.net/junos/*/junos";
08	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
09	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
10	 
11	import "../import/junos.xsl";
12	 
13	/*
14	 * This example performs two related tasks.  If an interface has
15	 * [family iso] configured but not [family mpls], a configuration
16	 * change is made (using the "jcs:emit-change" template) to enable
17	 * MPLS.
18	 *
19	 * Secondly, if the interface is not configured under [protocols mpls],
20	 * an additional change is made to add the interface there.
21	 *
22	 * Both changes are accompanied with appropriate warning messages.
23	 */
24	match configuration {
25	    var $mpls = protocols/mpls;
26	 
27	    for-each (interfaces/interface/unit[family/iso]) {
28	        var $ifname = concat(../name, '.', name);
29	        if (not(family/mpls)) {
30	            var $message = "Adding 'family mpls' to iso-enabled interface";
31	        var $content = <family> { <mpls>; };
32	            call jcs:emit-change($message, $content);
33	        }
34	        if ($mpls and not($mpls/interface[name = $ifname])) {
35	            var $message = "Adding iso-enabled interface "
36	                         + $ifname + " to [protocols mpls]";
37	            var $content = <interface> { <name> $ifname; };
38	            call jcs:emit-change($message, $content);
39	        }
40	    }
41	}

 

XML Script Contents

 

01	<?xml version="1.0"?>
02	<script version="0.1">
03	  <title>check-iso.slax</title>
04	  <alternate>check-iso.xsl</alternate>
05	  <author>phil</author>
06	  <synopsis>
07	    Enable mpls on iso-enabled interfaces
08	  </synopsis>
09	  <keyword>mpls</keyword>
10	  <keyword>iso</keyword>
11	  <keyword>interface</keyword>
12	  <keyword>protocol</keyword>
13	 
14	  <description>
15	    We want to ensure that the interface setup as iso
16	    has mpls enabled. If it is not enabled the script makes it so.
17	  </description>
18	  <implementation>
19	    For every logical unit with iso enabled, we test to see if
20	    mpls is enabled.  If it isn't, we call jcs:emit-change()
21	    to add it for us.
22	  </implementation>
23	 
24	  <example>
25	    <config>check-iso.conf</config>
26	    <output>check-iso.output</output>
27	  </example>
28	  <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
29	                src="../../../../../web/leaf.js" type="text/javascript"/>
30	</script>

 


#MPLS
#ScriptingHow-To
#How-To
#commitscript
#Slax

Permalink