001 /*
002 *
003 * NAME: show-trunk.slax
004 * PURPOSE: Created to provide vlan information for all interfaces
005 * that are defined as trunk interfaces.
006 *
007 * CREATED: 02/12/09
008 * BY: Jay Wilson (Solutions Architect - Western Area)
009 * LAST MOD: 02/12/09
010 * BY: Jay Wilson
011 * VERSION: 1.00
012 *
013 * MODIFICATION HISTORY:
014 * V1.00 = Initial release
015 *
016 */
017 version 1.0;
018 ns junos = "http://xml.juniper.net/junos/*/junos";
019 ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
020 ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
021 import "../import/junos.xsl";
022
023 match / {
024 <op-script-results> {
025 /*
026 *
027 * RPC that returns the "show ethernet-switching interface" output
028 *
029 */
030 var $rpc = <get-ethernet-switching-interface-information> {
031 }
032 var $switch-output = jcs:invoke($rpc);
033 /*
034 *
035 * RPC that returns the "show interface" output
036 *
037 */
038 var $rpc2 = <get-interface-information> {
039 }
040 var $physical-output = jcs:invoke($rpc2);
041 /*
042 *
043 * Print out the Header line
044 *
045 */
046
047 <output> jcs:printf("%-12s %-8s %-23s %-13s %-s\n","Interface","State","VLAN Member","Blocked","Description");
048
049 /*
050 *
051 * Get all the interfaces, but only look at "ge", "xe", and "ae"
052 *
053 */
054
055 for-each ($switch-output/interface) {
056 if (contains(interface-name,"ge") || contains(interface-name,"xe") || contains(interface-name,"ae")) {
057 /*
058 *
059 * Output has unit appended to the interface name. Drop it because
060 * it is always 0 for "family ethernet-switching", which are the
061 * only interfaces returned from the RPC call above.
062 *
063 */
064 var $interface = substring-before(interface-name,".");
065 var $raw-interface = interface-name;
066 /*
067 *
068 * Before processing the vlan information, varify that the interface
069 * is set for "port-mode trunk".
070 *
071 */
072 if ($physical-output/physical-interface[name=$interface]/logical-interface[name=$raw-interface]/address-family[address-family-name="eth-switch"]/address-family-flags/ifff-port-mode-trunk) {
073 call mash-up($interface = $interface, $physical-output = $physical-output, $switch-output = .);
074 }
075 }
076 }
077 }
078 }
079 /*
080 * NAME: MASH-UP
081 * PURPOSE: To combine the ethernet-switching-interface-information output
082 * with the interface-information output.
083 * CALLED: Called for all "ge", "xe", or "ae"that are returned by the RPC
084 * to ethernet-switching-interface-information and that match any
085 * additional criteria, such as "port-mode trunk"
086 *
087 * PARMS PASSED:
088 * $interface = interface to mash-up
089 * $physical-output = the structure that is returned with the
090 * RPC interface-information call.
091 * $switch-output = the structure that goes with the interface
092 * that was returned with the RPC
093 * ethernet-switching-interface-information.
094 *
095 */
096 template mash-up($interface, $physical-output, $switch-output) {
097
098
099
100 /*
101 *
102 * Save the initial information into a formated string.
103 * This is needed to prevent a newline from being inserted before
104 * the initial string is complete.
105 *
106 */
107 var $phy-prnt = { if ($physical-output/physical-interface/name == $interface) {
108 expr jcs:printf("%-12s %-8s ",$interface, $switch-output/interface-state);
109 }
110 }
111 if ($phy-prnt) {
112 /*
113 *
114 * Vlan membership for each interface comes back as a list, so
115 * a for loop is needed to process it.
116 *
117 * IF THE SCRIPT IS NOT OUTPUTTING ANY DATA,
118 * NOTE THE VERSION OF JUNOS BEING USED AND
119 * CHANGE THE NEXT FOR-EACH!!!!!!!!!!!!!!
120 *
121 * interface-vlan-member was returned in JUNOS 9.1
122 * as a leaf, so interface-vlan-name did not
123 * exist as a leaf and block-status was 1 leaf up.
124 * interface-vlan-member was returned in JUNOS 9.3
125 * as a node set with interface-vlan-name and
126 * bock-status as leafs.
127 *
128 */
129
130 /*
131 *
132 * If the interface is set to "port-mode trunk", but no vlans are
133 * defined to the trunk, then only print out the interface number.
134 *
135 */
136 if (count($switch-output/interface-vlan-member-list/interface-vlan-member) > 0) {
137 for-each($switch-output/interface-vlan-member-list/interface-vlan-member) {
138 /*
139 *
140 * Reduce the length of blocked status by using a shorter string.
141 *
142 */
143 var $status = { if (contains(blocking-status,"STP")) {
144 expr "STP Blocked";
145 }
146 else if (contains(blocking-status,"RTG")) {
147 expr "RTG Blocked";
148 }
149 else {
150 expr blocking-status;
151 }
152 }
153 /*
154 *
155 * The first line for each interface is different than the other
156 * output lines. Check for the first time in the for loop and
157 * add the safed initial string from above.
158 */
159 var $first = position();
160 if ($first == 1) {
161 <output> jcs:printf("%-22s%-23s %-12s %-s\n", $phy-prnt, interface-vlan-name, $status, $physical-output/physical-interface[name=$interface]/description);
162 }
163 else {
164 /*
165 *
166 * printf may look odd, but it is correct. It must account for the
167 * embedded spaces in the initial string.
168 */
169 <output> jcs:printf("%-22s%-23s %-12s\n", " ", interface-vlan-name, $status);
170 }
171
172 }
173 }
174 else {
175 <output> jcs:printf("%-22s\n",$phy-prnt);
176 }
177 }
178 }
XML Script Contents
01 <?xml version="1.0"?>
02 <script>
03 <title>show-trunk.slax</title>
04 <author>jayw</author>
05 <synopsis>
06 Provide vlan information for all interfaces that are defined as trunk interfaces
07 </synopsis>
08 <coe>op</coe>
09 <type>display</type>
10
11 <description>
12 This op-script displays vlan information for all interfaces that are defined as trunk
13
14
15 </description>
16
17 <keyword>slax</keyword>
18 <keyword>vlan</keyword>
19 <keyword>trunk</keyword>
20 <keyword>ex</keyword>
21 <example>
22 <title>Output</title>
23 <output>example-1.conf</output>
24 </example>
25
26 <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
27 src="../../../../../web/leaf.js"
28 type="text/javascript"/>
29 </script>