2009-09-07 11:07:59 +00:00
< ? php
2008-10-28 22:06:00 +00:00
2012-04-26 11:57:52 +00:00
// FIXME : dbFacile !
2011-04-11 18:54:15 +00:00
if ( $config [ 'enable_vrfs' ])
2010-07-04 18:47:55 +00:00
{
2012-01-12 11:16:38 +00:00
if ( $device [ 'os_group' ] == " cisco " || $device [ 'os_group' ] == " junos " || $device [ 'os' ] == " ironware " )
2011-04-11 18:54:15 +00:00
{
unset ( $vrf_count );
2008-10-28 22:06:00 +00:00
2011-04-11 18:54:15 +00:00
echo ( " VRFs : " );
2012-04-05 16:17:41 +00:00
/*
2012-04-02 17:29:54 +00:00
There are 2 MIBs for VPNs : MPLS - VPN - MIB ( oldest ) and MPLS - L3VPN - STD - MIB ( newest )
Unfortunately , there is no simple way to find out which one to use , unless we reference
all the possible devices and check what they support .
Therefore we start testing the MPLS - L3VPN - STD - MIB that is prefered if available .
*/
2008-10-28 22:06:00 +00:00
2012-04-02 17:29:54 +00:00
// Grab all the info first, then use it in the code.
// It removes load on the device and makes things much faster
2010-02-09 14:11:10 +00:00
2012-04-02 17:29:54 +00:00
$rds = snmp_walk ( $device , " mplsL3VpnVrfRD " , " -Osqn " , " MPLS-L3VPN-STD-MIB " , NULL );
2012-04-05 16:17:41 +00:00
2012-04-02 17:29:54 +00:00
if ( empty ( $rds ))
{
$rds = snmp_walk ( $device , " mplsVpnVrfRouteDistinguisher " , " -Osqn " , " MPLS-VPN-MIB " , NULL );
$vpnmib = " MPLS-VPN-MIB " ;
$rds = str_replace ( " .1.3.6.1.3.118.1.2.2.1.3. " , " " , $rds );
$descrs_oid = " .1.3.6.1.3.118.1.2.2.1.2 " ;
$ports_oid = " .1.3.6.1.3.118.1.2.1.1.2 " ;
}
else
{
$vpnmib = " MPLS-L3VPN-STD-MIB " ;
$rds = str_replace ( " .1.3.6.1.2.1.10.166.11.1.2.2.1.4. " , " " , $rds );
2012-04-05 16:17:41 +00:00
2012-04-02 17:29:54 +00:00
$descrs_oid = " .1.3.6.1.2.1.10.166.11.1.2.2.1.3 " ;
$ports_oid = " .1.3.6.1.2.1.10.166.11.1.2.1.1.2 " ;
}
2012-04-05 16:17:41 +00:00
if ( $debug )
{
2012-04-02 17:29:54 +00:00
echo ( " \n [DEBUG] \n Using $vpnmib\n[/DEBUG] \n " );
echo ( " \n [DEBUG OIDS] \n $rds\n[/DEBUG] \n " );
}
$rds = trim ( $rds );
$descrs = snmp_walk ( $device , $descrs_oid , " -Osqn " , $vpnmib , NULL );
$ports = snmp_walk ( $device , $ports_oid , " -Osqn " , $vpnmib , NULL );
2012-04-05 16:17:41 +00:00
2012-04-02 17:29:54 +00:00
$descrs = trim ( str_replace ( " $descrs_oid . " , " " , $descrs ));
$ports = trim ( str_replace ( " $ports_oid . " , " " , $ports ));
$descr_table = array ();
$port_table = array ();
2008-10-28 22:06:00 +00:00
2012-04-02 17:29:54 +00:00
foreach ( explode ( " \n " , $descrs ) as $descr )
2010-12-26 21:57:21 +00:00
{
2012-04-03 10:34:13 +00:00
$t = explode ( " " , $descr , 2 );
2012-04-02 17:29:54 +00:00
$descr_table [ $t [ 0 ]] = $t [ 1 ];
}
foreach ( explode ( " \n " , $ports ) as $port )
{
$t = explode ( " " , $port );
$dotpos = strrpos ( $t [ 0 ], " . " );
$vrf_oid = substr ( $t [ 0 ], 0 , $dotpos );
$port_id = substr ( $t [ 0 ], $dotpos + 1 );
if ( empty ( $port_table [ $vrf_oid ])) { $port_table [ $vrf_oid ][ 0 ] = $port_id ; }
else { array_push ( $port_table [ $vrf_oid ], $port_id );}
}
foreach ( explode ( " \n " , $rds ) as $oid )
{
echo " \n " ;
2011-04-11 18:54:15 +00:00
if ( $oid )
{
2012-04-02 17:29:54 +00:00
// 8.49.53.48.56.58.49.48.48 "1508:100"
// First digit gives number of chars in VRF Name, then it's ASCII
list ( $vrf_oid , $vrf_rd ) = explode ( " " , $oid );
$oid_values = explode ( " . " , $vrf_oid );
$vrf_name = " " ;
for ( $i = 1 ; $i <= $oid_values [ 0 ]; $i ++ ) { $vrf_name .= chr ( $oid_values [ $i ]);}
echo " \n [VRF $vrf_name ] OID - $vrf_oid " ;
echo " \n [VRF $vrf_name ] RD - $vrf_rd " ;
echo " \n [VRF $vrf_name ] DESC - " . $descr_table [ $vrf_oid ];
2008-10-28 22:06:00 +00:00
2014-01-13 17:43:58 +00:00
if ( dbFetchCell ( " SELECT COUNT(*) FROM vrfs WHERE device_id = ? AND `vrf_oid`=? " , array ( $device [ 'device_id' ], $vrf_oid )))
2011-04-11 18:54:15 +00:00
{
2014-01-13 17:43:58 +00:00
dbUpdate ( array ( 'mplsVpnVrfDescription' => $descr_table [ $vrf_oid ], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd ), 'vrfs' , 'device_id=? AND vrf_oid=?' , array ( $device [ 'device_id' ], $vrf_oid ));
2011-04-11 18:54:15 +00:00
}
else
{
2014-06-10 22:21:10 +01:00
dbInsert ( array ( 'vrf_oid' => $vrf_oid , 'vrf_name' => $vrf_name , 'mplsVpnVrfRouteDistinguisher' => $vrf_rd , 'mplsVpnVrfDescription' => $descr_table [ $vrf_oid ], 'device_id' => $device [ 'device_id' ]), 'vrfs' );
2011-04-11 18:54:15 +00:00
}
2014-01-13 17:43:58 +00:00
$vrf_id = dbFetchCell ( " SELECT vrf_id FROM vrfs WHERE device_id = ? AND `vrf_oid`=? " , array ( $device [ 'device_id' ], $vrf_oid ));
2011-04-11 18:54:15 +00:00
$valid_vrf [ $vrf_id ] = 1 ;
2012-04-02 17:29:54 +00:00
echo " \n [VRF $vrf_name ] PORTS - " ;
foreach ( $port_table [ $vrf_oid ] as $if_id )
2011-04-11 18:54:15 +00:00
{
2014-01-13 17:43:58 +00:00
$interface = dbFetchRow ( " SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? " , array ( $device [ 'device_id' ], $if_id ));
2011-04-11 18:54:15 +00:00
echo ( makeshortif ( $interface [ 'ifDescr' ]) . " " );
2014-01-13 17:43:58 +00:00
dbUpdate ( array ( 'ifVrf' => $vrf_id ), 'ports' , 'port_id=?' , array ( $interface [ 'port_id' ]));
2012-05-16 13:25:50 +00:00
$if = $interface [ 'port_id' ];
2011-04-11 18:54:15 +00:00
$valid_vrf_if [ $vrf_id ][ $if ] = 1 ;
}
2010-12-26 21:57:21 +00:00
}
2011-04-11 18:54:15 +00:00
}
2011-03-15 11:24:35 +00:00
2012-04-02 17:29:54 +00:00
echo " \n " ;
2011-04-11 18:54:15 +00:00
$sql = " SELECT * FROM ports WHERE device_id = ' " . $device [ 'device_id' ] . " ' " ;
2014-01-13 17:43:58 +00:00
foreach ( dbFetchRows ( $sql ) as $row )
2011-04-11 18:54:15 +00:00
{
2012-05-16 13:25:50 +00:00
$if = $row [ 'port_id' ];
2011-04-11 18:54:15 +00:00
$vrf_id = $row [ 'ifVrf' ];
if ( $row [ 'ifVrf' ])
2010-12-26 21:57:21 +00:00
{
2011-04-11 18:54:15 +00:00
if ( ! $valid_vrf_if [ $vrf_id ][ $if ])
{
echo ( " - " );
2014-01-13 17:43:58 +00:00
dbUpdate ( array ( 'ifVrf' => 'NULL' ), 'ports' , 'port_id=?' , array ( $if ));
2011-04-11 18:54:15 +00:00
}
else
{
echo ( " . " );
}
2010-12-26 21:57:21 +00:00
}
2008-10-28 22:06:00 +00:00
}
2011-04-11 18:54:15 +00:00
$sql = " SELECT * FROM vrfs WHERE device_id = ' " . $device [ 'device_id' ] . " ' " ;
2014-01-13 17:43:58 +00:00
foreach ( dbFetchRows ( $sql ) as $row )
2010-12-26 21:57:21 +00:00
{
2011-04-11 18:54:15 +00:00
$vrf_id = $row [ 'vrf_id' ];
if ( ! $valid_vrf [ $vrf_id ])
2010-12-26 21:57:21 +00:00
{
2009-06-03 05:05:58 +00:00
echo ( " - " );
2014-01-13 17:43:58 +00:00
dbDelete ( 'vrfs' , '`vrf_id` = ?' , array ( $vrf_id ));
2011-03-15 11:24:35 +00:00
}
2010-12-26 21:57:21 +00:00
else
{
echo ( " . " );
2011-03-15 11:24:35 +00:00
}
2009-06-03 05:05:58 +00:00
}
2011-04-11 18:54:15 +00:00
unset ( $valid_vrf_if );
unset ( $valid_vrf );
2009-06-03 05:05:58 +00:00
2011-04-11 18:54:15 +00:00
echo ( " \n " );
2012-01-12 11:16:38 +00:00
} # cisco/junos/ironware
2011-04-11 18:54:15 +00:00
} # enable_vrfs
2010-02-28 22:04:15 +00:00
2011-04-11 18:54:15 +00:00
?>