Blogs

What does the ospf-interfaces script do?

By Erdem posted 08-14-2015 10:12

  
This applies to SLAX version 1.0 and higher.
 
Overview

Ensure consistent configuration for OSPF protocol and interfaces.

Description

This commit-script ensures that all interfaces configured under protocols/ospf have family/mpls configured and are in protocols/mpls, protocols/ldp and protocols/rsvp.

Source
GitHub Links

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

SLAX Script Contents

   
001
version 1.0;
002
ns junos = "http://xml.juniper.net/junos/*/junos";
003
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
004
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
005
ns ext = "http://xmlsoft.org/XSLT/namespace";
006
 
007
import "../import/junos.xsl";
008
 
009
/*
010
 * This commit-script ensures that all interfaces configured
011
 * under protocols/ospf have family/mpls configured and are
012
 * in protocols/mpls, protocols/ldp and protocols/rsvp.
013
 */
014
 
015
match configuration {
016
        var $ospfIntsRaw = { call ospfInterfaces(); }
017
        var $ospfInts = ext:node-set($ospfIntsRaw);
018
 
019
        var $rsvpIntsRaw = { call rsvpInterfaces(); }
020
        var $rsvpInts = ext:node-set($rsvpIntsRaw);
021
 
022
        var $ldpIntsRaw = { call ldpInterfaces(); }
023
        var $ldpInts = ext:node-set($ldpIntsRaw);
024
 
025
        var $mplsIntsRaw = { call mplsInterfaces(); }
026
        var $mplsInts = ext:node-set($mplsIntsRaw);
027
 
028
        for-each (interfaces/interface) {
029
                var $int = name;
030
                var $unit = unit/name;
031
                var $fullint = $int _ "." _ $unit;
032
                var $ospf = $ospfInts/ospfInts[@name == $fullint]/@value;
033
                var $rsvp = $rsvpInts/rsvpInts[@name == $fullint]/@value;
034
                var $mpls = $mplsInts/mplsInts[@name == $fullint]/@value;
035
                var $ldp = $ldpInts/ldpInts[@name == $fullint]/@value;
036
                if ($ospf == 1) {
037
                        var $intMpls = count (unit/family/mpls);
038
                        if (not ($intMpls == 1) && (not (contains ($int, "lo0")))) {
039
                                <xnm:warning> {
040
                                        <message> {
041
                                                expr "OSPF interface ";
042
                                                expr $int;
043
                                                expr ".";
044
                                                expr $unit;
045
                                                expr " is not configured for MPLS";
046
                                        }
047
                                }
048
                        }
049
                        if (not ($mpls == 1)) {
050
                                <xnm:warning> {
051
                                        <message> {
052
                                                expr "OSPF interface ";
053
                                                expr $int;
054
                                                expr ".";
055
                                                expr $unit;
056
                                                expr " is not configured under protocols MPLS";
057
                                        }
058
                                }
059
                        }
060
                        if (not ($ldp == 1)) {
061
                                <xnm:warning> {
062
                                        <message> {
063
                                                expr "OSPF interface ";
064
                                                expr $int;
065
                                                expr ".";
066
                                                expr $unit;
067
                                                expr " is not configured under protocols LDP";
068
                                        }
069
                                }
070
                        }
071
                        if (not ($rsvp == 1)) {
072
                                <xnm:warning> {
073
                                        <message> {
074
                                                expr "OSPF interface ";
075
                                                expr $int;
076
                                                expr ".";
077
                                                expr $unit;
078
                                                expr " is not configured under protocols RSVP";
079
                                        }
080
                                }
081
                        }
082
                }
083
        }
084
}
085
 
086
template ospfInterfaces () {
087
        for-each (protocols/ospf/area/interface) {
088
                var $int = name;
089
                <ospfInts name=$int value=1>;
090
        }
091
}
092
template rsvpInterfaces () {
093
        for-each (protocols/rsvp/interface) {
094
                var $int = name;
095
                <rsvpInts name=$int value=1>;
096
        }
097
}
098
template ldpInterfaces () {
099
        for-each (protocols/ldp/interface) {
100
                var $int = name;
101
                <ldpInts name=$int value=1>;
102
        }
103
}
104
template mplsInterfaces () {
105
        for-each (protocols/mpls/interface) {
106
                var $int = name;
107
                <mplsInts name=$int value=1>;
108
        }
109
}
XML Script Contents
 
01 <?xml version="1.0"?>
02 <script>
03 <title>ospf-interfaces.slax</title>
04 <author>jpanagos</author>
05 <synopsis>
06 Ensure consistent configuration for OSPF protocol and interfaces
07 </synopsis>
08 <coe>commit</coe>
09 <type>interfaces</type>
10  
11 <description>
12 This commit-script ensures that all interfaces configured under protocols/ospf have family/mpls configured and are in protocols/mpls, protocols/ldp and protocols/rsvp
13 </description>
14  
15 <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
16 src="../../../../../web/leaf.js"
17 type="text/javascript"/>
18 </script>

 


#MPLS
#Slax
#ospf
#commit-script
#rsvp
#How-To