My goal:
My script is to perform an audit on all multicast enabled M/MX devices to calculate how many PFEs are included in the replication tree to forward multicast for a particular S,G, in a particular routing-instance to all downstream interested subscribers.
So, the get-multicast-information API is the starting point for my audit.
The downstream interfaces node, filtered for only ge- and xe- interfaces provides the list of interfaces per S,G.
On the M/MX platfrom, the pic value, in xx-?/?/? represents the PFE value for an interface.
For example ge-1/1/0, ge-1/1/1 and ge-1/1/2 all share the same PFE, so given a list of interfaces as follows.
xe-0/0/0
xe-0/1/0
ge-1/1/0
ge-1/1/1
ge-1/1/2
The unique PFEs would be
xe-0/0
xe-0/1
ge-1/1
and hence the PFE replication tree diameter for this S,G would be 3.
Since my lab does not have a router with more than one downstream interface, per S,G entry, I am using the get-interface-information API to build the logic to find the unique PFE count.
Now, I'm a newbie to Junos scripting, so I am having difficulty manipulating the data, while trying to avoid loops and immutable variables. I've read the "This Week - Applying JUNOS Automation" and also have access to the reference guide for functions, elements and templates, but am still stuck here a bit.
My first problem is getting only the list of ge- and xe- interfaces into a list. I seem to get the whole name node and not just the name element.
var $command-set := {
<get-interface-information> {
<terse> ;
}
}
var $results := jcs:invoke ( $command-set );
var $interfaces := $results/physical-interface[ @name==jcs:regex("[xg]e.*", @name) ];
for-each ( $interfaces ) {
<output> .;
}
My output file using <xsl:document { copy-of $interfaces; }
<physical-interface xmlns="http://xml.juniper.net/junos/11.4R8/junos-interface" xmlns:junos="http://xml.juniper.net/junos/*/junos">
<name>xe-0/0/0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<description>MX960-1 xe-10/2/0 - ae1</description>
<logical-interface>
<name>xe-0/0/0.0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<filter-information>
</filter-information>
<address-family>
<address-family-name>aenet</address-family-name>
<ae-bundle-name>ae1.0</ae-bundle-name>
</address-family>
</logical-interface>
</physical-interface><physical-interface xmlns="http://xml.juniper.net/junos/11.4R8/junos-interface" xmlns:junos="http://xml.juniper.net/junos/*/junos">
<name>xe-0/1/0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<description>MX960-1 xe-10/3/0 - ae1</description>
<logical-interface>
<name>xe-0/1/0.0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<filter-information>
</filter-information>
<address-family>
<address-family-name>aenet</address-family-name>
<ae-bundle-name>ae1.0</ae-bundle-name>
</address-family>
</logical-interface>
</physical-interface><physical-interface xmlns="http://xml.juniper.net/junos/11.4R8/junos-interface" xmlns:junos="http://xml.juniper.net/junos/*/junos">
<name>xe-0/2/0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<description>MX240-2 xe-0/2/0 - ae0</description>
<logical-interface>
<name>xe-0/2/0.0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
<filter-information>
</filter-information>