Automation
Automation

Scripting How-To: Classify interfaces using the check-atm-interfaces script

by Cordelia on ‎08-11-2015 09:23 PM - edited on ‎09-11-2017 05:49 PM by Administrator Administrator
08.11.15   |   09:23 PM

Classify Interfaces by Their VC Numbers

 
For SLAX version 1.0 and higher, you can use the check-atm-interfaces script to classify interfaces by their VC numbers and place them into groups.

 

Using this script, you can allocate bandwidth to interfaces with more traffic. The script sets classifications based on VC numbers and adds bronze, sliver, or gold variables to each interface.

 

You can use this script for a connection with large traffic to organize its bandwidth based on priority. 

 

Source Code and GitHub Links

 

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

 

Example Configuration

 

001	groups {
002	    class-gold {
003	        interfaces {
004	            <*> {
005	                unit <*> {
006	                    family inet {
007	                        filter {
008	                            input gold-filter;
009	                            output gold-filter;
010	                        }
011	                    }
012	                }
013	            }
014	        }
015	    }
016	    class-silver {
017	        interfaces {
018	            <*> {
019	                unit <*> {
020	                    family inet {
021	                        filter {
022	                            input silver-filter;
023	                            output silver-filter;
024	                        }
025	                    }
026	                }
027	            }
028	        }
029	    }
030	    class-bronze {
031	        interfaces {
032	            <*> {
033	                unit <*> {
034	                    family inet {
035	                        filter {
036	                            input bronze-filter;
037	                            output bronze-filter;
038	                        }
039	                    }
040	                }
041	            }
042	        }
043	    }
044	}
045	system {
046	    scripts {
047	    commit {
048	        file check-atm.slax;
049	    }
050	    }
051	}
052	interfaces {
053	    apply-macro limits {
054	        bronze-max 60;
055	        gold-max 20;
056	        silver-max 40;
057	    }
058	    at-1/2/3 {
059	        atm-options {
060	            pic-type atm1;
061	            vpi 0 {
062	                maximum-vcs 100;
063	            }
064	        }
065	 
066	        unit 15 {
067	            family inet {
068	                address 10.12.13.14/20;
069	            }
070	        }
071	        unit 16 {
072	            family inet {
073	                address 10.12.13.15/20;
074	            }
075	        }
076	        unit 17 {
077	            family inet {
078	                address 10.12.13.16/20;
079	            }
080	        }
081	        unit 18 {
082	            family inet {
083	                address 10.12.13.17/20;
084	            }
085	        }
086	        unit 19 {
087	            family inet {
088	                address 10.12.13.18/20;
089	            }
090	        }
091	        unit 20 {
092	            family inet {
093	                address 10.12.13.19/20;
094	            }
095	        }
096	        unit 21 {
097	            family inet {
098	                address 10.12.13.20/20;
099	            }
100	        }
101	        unit 22 {
102	            family inet {
103	                address 10.12.13.21/20;
104	            }
105	        }
106	        unit 23 {
107	            family inet {
108	                address 10.12.13.22/20;
109	            }
110	        }
111	        unit 24 {
112	            family inet {
113	                address 10.12.13.23/20;
114	            }
115	        }
116	        unit 25 {
117	            family inet {
118	                address 10.12.13.24/20;
119	            }
120	        }
121	        unit 26 {
122	            family inet {
123	                address 10.12.13.25/20;
124	            }
125	        }
126	        unit 27 {
127	            family inet {
128	                address 10.12.13.26/20;
129	            }
130	        }
131	        unit 28 {
132	            family inet {
133	                address 10.12.13.27/20;
134	            }
135	        }
136	        unit 29 {
137	            family inet {
138	                address 10.12.13.28/20;
139	            }
140	        }
141	        unit 30 {
142	            family inet {
143	                address 10.12.13.29/20;
144	            }
145	        }
146	        unit 31 {
147	            family inet {
148	                address 10.12.13.30/20;
149	            }
150	        }
151	        unit 32 {
152	            family inet {
153	                address 10.12.13.31/20;
154	            }
155	        }
156	        unit 33 {
157	            family inet {
158	                address 10.12.13.32/20;
159	            }
160	        }
161	        unit 34 {
162	            family inet {
163	                address 10.12.13.33/20;
164	            }
165	        }
166	        unit 35 {
167	            family inet {
168	                address 10.12.13.34/20;
169	            }
170	        }
171	        unit 36 {
172	            family inet {
173	                address 10.12.13.35/20;
174	            }
175	        }
176	        unit 37 {
177	            family inet {
178	                address 10.12.13.36/20;
179	            }
180	        }
181	        unit 38 {
182	            family inet {
183	                address 10.12.13.37/20;
184	            }
185	        }
186	        unit 39 {
187	            family inet {
188	                address 10.12.13.38/20;
189	            }
190	        }
191	        unit 40 {
192	            family inet {
193	                address 10.12.13.39/20;
194	            }
195	        }
196	        unit 41 {
197	            family inet {
198	                address 10.12.13.40/20;
199	            }
200	        }
201	        unit 42 {
202	            family inet {
203	                address 10.12.13.41/20;
204	            }
205	        }
206	        unit 43 {
207	            family inet {
208	                address 10.12.13.42/20;
209	            }
210	        }
211	        unit 44 {
212	            family inet {
213	                address 10.12.13.43/20;
214	            }
215	        }
216	        unit 45 {
217	            family inet {
218	                address 10.12.13.44/20;
219	            }
220	        }
221	        unit 46 {
222	            family inet {
223	                address 10.12.13.45/20;
224	            }
225	        }
226	        unit 47 {
227	            family inet {
228	                address 10.12.13.46/20;
229	            }
230	        }
231	        unit 48 {
232	            family inet {
233	                address 10.12.13.47/20;
234	            }
235	        }
236	        unit 49 {
237	            family inet {
238	                address 10.12.13.48/20;
239	            }
240	        }
241	        unit 50 {
242	            family inet {
243	                address 10.12.13.49/20;
244	            }
245	        }
246	        unit 51 {
247	            family inet {
248	                address 10.12.13.50/20;
249	            }
250	        }
251	        unit 52 {
252	            family inet {
253	                address 10.12.13.51/20;
254	            }
255	        }
256	        unit 53 {
257	            family inet {
258	                address 10.12.13.52/20;
259	            }
260	        }
261	        unit 54 {
262	            family inet {
263	                address 10.12.13.53/20;
264	            }
265	        }
266	        unit 55 {
267	            family inet {
268	                address 10.12.13.54/20;
269	            }
270	        }
271	        unit 56 {
272	            family inet {
273	                address 10.12.13.55/20;
274	            }
275	        }
276	        unit 57 {
277	            family inet {
278	                address 10.12.13.56/20;
279	            }
280	        }
281	        unit 58 {
282	            family inet {
283	                address 10.12.13.57/20;
284	            }
285	        }
286	        unit 59 {
287	            family inet {
288	                address 10.12.13.58/20;
289	            }
290	        }
291	        unit 60 {
292	            family inet {
293	                address 10.12.13.59/20;
294	            }
295	        }
296	        unit 61 {
297	            family inet {
298	                address 10.12.13.60/20;
299	            }
300	        }
301	        unit 62 {
302	            family inet {
303	                address 10.12.13.61/20;
304	            }
305	        }
306	        unit 63 {
307	            family inet {
308	                address 10.12.13.62/20;
309	            }
310	        }
311	        unit 64 {
312	            family inet {
313	                address 10.12.13.63/20;
314	            }
315	        }
316	        unit 65 {
317	            family inet {
318	                address 10.12.13.64/20;
319	            }
320	        }
321	    }
322	}
323	firewall {
324	    filter gold-filter {
325	        term one {
326	            then forwarding-class assured-forwarding;
327	        }
328	    }
329	    filter silver-filter {
330	        term one {
331	            then forwarding-class expedited-forwarding;
332	        }
333	    }
334	    filter bronze-filter {
335	        term one {
336	            then forwarding-class best-effort;
337	        }
338	    }
339	}

 

Example Output

 

001	[edit]
002	phil@dent# show | display commit-scripts
003	## Last changed: 2007-10-09 15:38:27 EDT
004	groups {
005	    class-gold {
006	        interfaces {
007	            <*> {
008	                unit <*> {
009	                    family inet {
010	                        filter {
011	                            input gold-filter;
012	                            output gold-filter;
013	                        }
014	                    }
015	                }
016	            }
017	        }
018	    }
019	    class-silver {
020	        interfaces {
021	            <*> {
022	                unit <*> {
023	                    family inet {
024	                        filter {
025	                            input silver-filter;
026	                            output silver-filter;
027	                        }
028	                    }
029	                }
030	            }
031	        }
032	    }
033	    class-bronze {
034	        interfaces {
035	            <*> {
036	                unit <*> {
037	                    family inet {
038	                        filter {
039	                            input bronze-filter;
040	                            output bronze-filter;
041	                        }
042	                    }
043	                }
044	            }
045	        }
046	    }
047	}
048	system {
049	    scripts {
050	        commit {
051	            file check-atm.slax;
052	        }
053	    }
054	    ## Warning: missing mandatory statement(s): 'root-authentication'
055	}
056	interfaces {
057	    apply-macro limits {
058	        bronze-max 60;
059	        gold-max 20;
060	        silver-max 40;
061	    }
062	    at-1/2/3 {
063	        atm-options {
064	            pic-type atm1;
065	            vpi 0 {
066	                maximum-vcs 100;
067	            }
068	        }
069	        unit 15 {
070	            apply-groups class-gold;
071	            vci 15;
072	            family inet {
073	                address 10.12.13.14/20;
074	            }
075	        }
076	        unit 16 {
077	            apply-groups class-gold;
078	            vci 16;
079	            family inet {
080	                address 10.12.13.15/20;
081	            }
082	        }
083	        unit 17 {
084	            apply-groups class-gold;
085	            vci 17;
086	            family inet {
087	                address 10.12.13.16/20;
088	            }
089	        }
090	        unit 18 {
091	            apply-groups class-gold;
092	            vci 18;
093	            family inet {
094	                address 10.12.13.17/20;
095	            }
096	        }
097	        unit 19 {
098	            apply-groups class-gold;
099	            vci 19;
100	            family inet {
101	                address 10.12.13.18/20;
102	            }
103	        }
104	        unit 20 {
105	            apply-groups class-gold;
106	            vci 20;
107	            family inet {
108	                address 10.12.13.19/20;
109	            }
110	        }
111	        unit 21 {
112	            apply-groups class-silver;
113	            vci 21;
114	            family inet {
115	                address 10.12.13.20/20;
116	            }
117	        }
118	        unit 22 {
119	            apply-groups class-silver;
120	            vci 22;
121	            family inet {
122	                address 10.12.13.21/20;
123	            }
124	        }
125	        unit 23 {
126	            apply-groups class-silver;
127	            vci 23;
128	            family inet {
129	                address 10.12.13.22/20;
130	            }
131	        }
132	        unit 24 {
133	            apply-groups class-silver;
134	            vci 24;
135	            family inet {
136	                address 10.12.13.23/20;
137	            }
138	        }
139	        unit 25 {
140	            apply-groups class-silver;
141	            vci 25;
142	            family inet {
143	                address 10.12.13.24/20;
144	            }
145	        }
146	        unit 26 {
147	            apply-groups class-silver;
148	            vci 26;
149	            family inet {
150	                address 10.12.13.25/20;
151	            }
152	        }
153	        unit 27 {
154	            apply-groups class-silver;
155	            vci 27;
156	            family inet {
157	                address 10.12.13.26/20;
158	            }
159	        }
160	        unit 28 {
161	            apply-groups class-silver;
162	            vci 28;
163	            family inet {
164	                address 10.12.13.27/20;
165	            }
166	        }
167	        unit 29 {  
168	            apply-groups class-silver;
169	            vci 29;
170	            family inet {
171	                address 10.12.13.28/20;
172	            }
173	        }
174	        unit 30 {
175	            apply-groups class-silver;
176	            vci 30;
177	            family inet {
178	                address 10.12.13.29/20;
179	            }
180	        }
181	        unit 31 {
182	            apply-groups class-silver;
183	            vci 31;
184	            family inet {
185	                address 10.12.13.30/20;
186	            }
187	        }
188	        unit 32 {
189	            apply-groups class-silver;
190	            vci 32;
191	            family inet {
192	                address 10.12.13.31/20;
193	            }
194	        }
195	        unit 33 {
196	            apply-groups class-silver;
197	            vci 33;
198	            family inet {
199	                address 10.12.13.32/20;
200	            }
201	        }
202	        unit 34 {
203	            apply-groups class-silver;
204	            vci 34;
205	            family inet {
206	                address 10.12.13.33/20;
207	            }
208	        }          
209	        unit 35 {
210	            apply-groups class-silver;
211	            vci 35;
212	            family inet {
213	                address 10.12.13.34/20;
214	            }
215	        }
216	        unit 36 {
217	            apply-groups class-silver;
218	            vci 36;
219	            family inet {
220	                address 10.12.13.35/20;
221	            }
222	        }
223	        unit 37 {
224	            apply-groups class-silver;
225	            vci 37;
226	            family inet {
227	                address 10.12.13.36/20;
228	            }
229	        }
230	        unit 38 {
231	            apply-groups class-silver;
232	            vci 38;
233	            family inet {
234	                address 10.12.13.37/20;
235	            }
236	        }
237	        unit 39 {
238	            apply-groups class-silver;
239	            vci 39;
240	            family inet {
241	                address 10.12.13.38/20;
242	            }
243	        }
244	        unit 40 {
245	            apply-groups class-silver;
246	            vci 40;
247	            family inet {
248	                address 10.12.13.39/20;
249	            }      
250	        }
251	        unit 41 {
252	            apply-groups class-bronze;
253	            vci 41;
254	            family inet {
255	                address 10.12.13.40/20;
256	            }
257	        }
258	        unit 42 {
259	            apply-groups class-bronze;
260	            vci 42;
261	            family inet {
262	                address 10.12.13.41/20;
263	            }
264	        }
265	        unit 43 {
266	            apply-groups class-bronze;
267	            vci 43;
268	            family inet {
269	                address 10.12.13.42/20;
270	            }
271	        }
272	        unit 44 {
273	            apply-groups class-bronze;
274	            vci 44;
275	            family inet {
276	                address 10.12.13.43/20;
277	            }
278	        }
279	        unit 45 {
280	            apply-groups class-bronze;
281	            vci 45;
282	            family inet {
283	                address 10.12.13.44/20;
284	            }
285	        }
286	        unit 46 {
287	            apply-groups class-bronze;
288	            vci 46;
289	            family inet {
290	                address 10.12.13.45/20;
291	            }
292	        }
293	        unit 47 {
294	            apply-groups class-bronze;
295	            vci 47;
296	            family inet {
297	                address 10.12.13.46/20;
298	            }
299	        }
300	        unit 48 {
301	            apply-groups class-bronze;
302	            vci 48;
303	            family inet {
304	                address 10.12.13.47/20;
305	            }
306	        }
307	        unit 49 {
308	            apply-groups class-bronze;
309	            vci 49;
310	            family inet {
311	                address 10.12.13.48/20;
312	            }
313	        }
314	        unit 50 {
315	            apply-groups class-bronze;
316	            vci 50;
317	            family inet {
318	                address 10.12.13.49/20;
319	            }
320	        }
321	        unit 51 {
322	            apply-groups class-bronze;
323	            vci 51;
324	            family inet {
325	                address 10.12.13.50/20;
326	            }
327	        }
328	        unit 52 {
329	            apply-groups class-bronze;
330	            vci 52;
331	            family inet {
332	                address 10.12.13.51/20;
333	            }
334	        }
335	        unit 53 {
336	            apply-groups class-bronze;
337	            vci 53;
338	            family inet {
339	                address 10.12.13.52/20;
340	            }
341	        }
342	        unit 54 {
343	            apply-groups class-bronze;
344	            vci 54;
345	            family inet {
346	                address 10.12.13.53/20;
347	            }
348	        }
349	        unit 55 {
350	            apply-groups class-bronze;
351	            vci 55;
352	            family inet {
353	                address 10.12.13.54/20;
354	            }
355	        }
356	        unit 56 {
357	            apply-groups class-bronze;
358	            vci 56;
359	            family inet {
360	                address 10.12.13.55/20;
361	            }
362	        }
363	        unit 57 {
364	            apply-groups class-bronze;
365	            vci 57;
366	            family inet {
367	                address 10.12.13.56/20;
368	            }
369	        }
370	        unit 58 {
371	            apply-groups class-bronze;
372	            vci 58;
373	            family inet {
374	                address 10.12.13.57/20;
375	            }
376	        }
377	        unit 59 {
378	            apply-groups class-bronze;
379	            vci 59;
380	            family inet {
381	                address 10.12.13.58/20;
382	            }
383	        }
384	        unit 60 {
385	            apply-groups class-bronze;
386	            vci 60;
387	            family inet {
388	                address 10.12.13.59/20;
389	            }
390	        }
391	        unit 61 {
392	            vci 61;
393	            family inet {
394	                address 10.12.13.60/20;
395	            }
396	        }
397	        unit 62 {
398	            vci 62;
399	            family inet {
400	                address 10.12.13.61/20;
401	            }
402	        }
403	        unit 63 {
404	            vci 63;
405	            family inet {
406	                address 10.12.13.62/20;
407	            }
408	        }
409	        unit 64 {
410	            vci 64;
411	            family inet {
412	                address 10.12.13.63/20;
413	            }
414	        }
415	        unit 65 {
416	            vci 65;
417	            family inet {
418	                address 10.12.13.64/20;
419	            }
420	        }
421	    }
422	}
423	firewall {
424	    filter gold-filter {
425	        term one {
426	            then forwarding-class assured-forwarding;
427	        }
428	    }
429	    filter silver-filter {
430	        term one {
431	            then forwarding-class expedited-forwarding;
432	        }
433	    }
434	    filter bronze-filter {
435	        term one {
436	            then forwarding-class best-effort;
437	        }
438	    }
439	}

 

SLAX Script Contents

 

01	/* Machine Crafted with Care (tm) by slaxWriter */
02	version 1.0;
03	 
04	 
05	/*
06	- $Id: check-atm.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	match configuration {
19	    apply-templates interfaces {
20	        mode "limit";
21	    }
22	}
23	 
24	match * {
25	    mode "limit";
26	     
27	    var $limits = apply-macro[name == "limits"];
28	    var $gold-max = $limits/data[name == "gold-max"]/value;
29	    var $silver-max = $limits/data[name == "silver-max"]/value;
30	    var $bronze-max = $limits/data[name == "bronze-max"]/value;
31	     
32	    for-each (interface[starts-with(name, "at-")]) {
33	        var $ifdev = name;
34	         
35	        for-each (unit) {
36	            var $class = {
37	                if (name <= $gold-max) {
38	                    expr "gold";
39	                 
40	                } else if (name <= $silver-max) {
41	                    expr "silver";
42	                 
43	                } else if (name <= $bronze-max) {
44	                    expr "bronze";
45	                }
46	            }
47	             
48	            call jcs:emit-change() {
49	                with $content = {
50	                    <vci> name;
51	                    if (string-length($class) > 0) {
52	                        <apply-groups> {
53	                            expr "class-";
54	                            expr $class;
55	                        }
56	                    }
57	                 }
58	            }
59	        }
60	    }

 

XML Script Contents

 

01	<?xml version="1.0"?>
02	<script version="0.1">
03	  <title>check-atm.slax</title>
04	  <alternate>check-atm.xsl</alternate>
05	  <author>phil</author>
06	  <synopsis>
07	    Classifies interfaces by their vc numbers and places them into groups
08	  </synopsis>
09	  <keyword>vc</keyword>
10	  <keyword>interface</keyword>
11	  <keyword>atm</keyword>
12	 
13	  <description>
14	    We want to allocate bandwith to interfaces with more
15	    traffic. The script sets classifications based on vc numbers and adds
16	    bronze, sliver, or gold variables to each interface.
17	  </description>
18	  <implementation>
19	    A connection with large traffic will want to organize its bandwith
20	    based on priority.
21	  </implementation>
22	 
23	  <example>
24	    <config>check-atm.conf</config>
25	    <title>A simple configuration</title>
26	    <output>check-atm.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>