Blog Viewer

Scripting How-To: Turn a list of addresses into a list of MPLS LSPs

By Erdem posted 08-10-2015 12:21

  

Overview

Turn a list of addresses into a list of MPLS LSPs. This applies to SLAX version 1.0 and higher.

 

Description

 

We want a list of addresses to be turned into a list of MPLS LSPs.

 

Implementation

 

An apply-macro under [protocols mpls] is configured with a set of addresses and a 'color' parameter. Each address is turned into an LSP configuration, with the color as an admin-group.

 

Source Code


GitHub Links


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

Example Configuration

 

01	system {
02	    scripts {
03	    commit {
04	            allow-transients;
05	        file mpls-lsp.slax;
06	    }
07	    }
08	}
09	protocols {
10	    mpls {
11	        apply-macro blue-type-lsp {
12	            10.1.1.1;
13	            10.2.2.2;
14	            10.3.3.3;
15	            10.4.4.4;
16	            color blue;
17	        }
18	    }
19	}

 

Example Output

 

01	[edit]
02	phil@dent# show | display commit-scripts
03	## Last changed: 2007-10-09 15:42:23 EDT
04	system {
05	    scripts {
06	        commit {
07	            allow-transients;
08	            file mpls-lsp.slax;
09	        }
10	    }
11	    ## Warning: missing mandatory statement(s): 'root-authentication'
12	}
13	protocols {
14	    mpls {
15	        apply-macro blue-type-lsp {
16	            10.1.1.1;
17	            10.2.2.2;
18	            10.3.3.3;
19	            10.4.4.4;
20	            color blue;
21	        }
22	        label-switched-path blue-lsp-10.1.1.1 {
23	            to 10.1.1.1;
24	            admin-group include-any blue;
25	        }
26	        label-switched-path blue-lsp-10.2.2.2 {
27	            to 10.2.2.2;
28	            admin-group include-any blue;
29	        }
30	        label-switched-path blue-lsp-10.3.3.3 {
31	            to 10.3.3.3;
32	            admin-group include-any blue;
33	        }
34	        label-switched-path blue-lsp-10.4.4.4 {
35	            to 10.4.4.4;
36	            admin-group include-any blue;
37	        }
38	    }
39	}

 

SLAX Script Contents

 

01	/* Machine Crafted with Care (tm) by slaxWriter */
02	version 1.0;
03	 
04	 
05	/*
06	- $Id: mpls-lsp.slax,v 1.1 2007/10/17 18:37:04 phil Exp $
07	-
08	- Copyright (c) 2004-2005, Juniper Networks, Inc.
09	- All rights reserved.
10	-
11	 */
12	ns junos = "http://xml.juniper.net/junos/*/junos";
13	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
14	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
15	 
16	import "../import/junos.xsl";
17	 
18	/*
19	- This example turns a list of addresses into a list of MPLS LSPs.
20	- An apply-macro under [protocols mpls] is configured with a
21	- set of addresses and a 'color' parameter.  Each address is
22	- turned into an LSP configuration, with the color as an admin-group.
23	 */
24	match configuration {
25	    var $mpls = protocols/mpls;
26	     
27	    for-each ($mpls/apply-macro[data/name == "color"]) {
28	        var $color = data[name == "color"]/value;
29	        <transient-change> {
30	            <protocols> {
31	                <mpls> {
32	                     
33	                    for-each (data[not(value)]/name) {
34	                        <label-switched-path> {
35	                            <name> $color _ "-lsp-" _ .;
36	                            <to> .;
37	                            <admin-group> {
38	                                <include> $color;
39	                            }
40	                        }
41	                    }
42	                }
43	            }
44	        }
45	    }
46	}

 

XML Script Contents

 

01	<?xml version="1.0"?>
02	<script version="0.1">
03	  <title>mpls-lsp.slax</title>
04	  <alternate>mpls-lsp.xsl</alternate>
05	  <author>phil</author>
06	  <synopsis>Turn a list of addresses into a list of MPLS LSPs</synopsis>
07	  <keyword>MPLS</keyword>
08	  <keyword>LSP</keyword>
09	 
10	  <description>
11	    We want a list of addresses to be turned into a list
12	    of MPLS LSPs
13	  </description>
14	  <implementation>
15	    An apply-macro under [protocols mpls] is configured with a
16	    set of addresses and a 'color' parameter.  Each address is
17	    turned into an LSP configuration, with the color as an admin-group.
18	  </implementation>
19	 
20	  <example>
21	    <config>mpls-lsp.conf</config>
22	    <title>A simple configuration</title>
23	    <output>mpls-lsp.output</output>
24	  </example>
25	  <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
26	                src="../../../../../web/leaf.js" type="text/javascript"/>
27	</script>

 


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

Permalink