2008-10-28 18:25:53 +00:00
< ? php
2010-02-28 22:04:15 +00:00
if ( $config [ 'enable_pseudowires' ] && $device [ 'os_group' ] == " ios " ) {
2009-03-24 15:24:18 +00:00
2008-10-28 18:25:53 +00:00
unset ( $cpw_count );
2010-07-05 19:21:36 +00:00
unset ( $cpw_exists );
2008-10-28 18:25:53 +00:00
2010-02-28 22:04:15 +00:00
echo ( " Cisco Pseudowires : " );
2008-10-28 18:25:53 +00:00
2010-07-02 19:58:13 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " -M " . $config [ 'mibdir' ] . " -m CISCO-IETF-PW-MIB -CI -Ln -Osqn - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " cpwVcID " );
2008-10-28 18:25:53 +00:00
$oids = str_replace ( " .1.3.6.1.4.1.9.10.106.1.2.1.10. " , " " , $oids );
$oids = trim ( $oids );
foreach ( explode ( " \n " , $oids ) as $oid ) {
2010-07-05 19:21:36 +00:00
if ( $oid ) {
list ( $cpwOid , $cpwVcID ) = explode ( " " , $oid );
if ( $cpwOid ) {
list ( $cpw_remote_id ) = split ( " : " , shell_exec ( $config [ 'snmpget' ] . " -M " . $config [ 'mibdir' ] . " -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " cpwVcMplsPeerLdpID. " . $cpwOid ));
$interface_descr = trim ( shell_exec ( $config [ 'snmpwalk' ] . " -M " . $config [ 'mibdir' ] . " -m CISCO-IETF-PW-MIB -Oqvn - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " cpwVcName. " . $cpwOid ));
$cpw_remote_device = @ mysql_result ( mysql_query ( " SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ' " . $cpw_remote_id . " ' AND A.interface_id = I.interface_id " ), 0 );
$if_id = @ mysql_result ( mysql_query ( " SELECT `interface_id` FROM `ports` WHERE `ifDescr` = ' $interface_descr ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' " ), 0 );
if ( $cpw_remote_device && $if_id ) {
$hostname = gethostbyid ( $cpw_remote_device );
#echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))");
if ( mysql_result ( mysql_query ( " SELECT count(*) FROM pseudowires WHERE `interface_id` = ' $if_id '
AND `cpwVcID` = '".$cpwVcID."' " ),0)) {
echo ( " . " );
} else {
$insert_query = " INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`) " ;
$insert_query .= " VALUES (' $if_id ',' $cpw_remote_device ',' $cpw_remote_id ',' $cpwVcID ', ' $cpwOid ') " ;
mysql_query ( $insert_query );
echo ( " + " );
#echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n");
}
2008-11-19 12:12:54 +00:00
$cpw_exists [] = $device [ 'device_id' ] . " $cpwOid $cpw_remote_device $if_id $cpwVcID " ;
2010-07-05 19:21:36 +00:00
}
2008-10-28 18:25:53 +00:00
}
}
}
2010-07-05 19:21:36 +00:00
$sql = " SELECT * FROM pseudowires AS P, ports AS I, devices as D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id AND D.device_id = ' " . $device [ 'device_id' ] . " ' " ;
$query = mysql_query ( $sql );
2008-11-19 12:12:54 +00:00
2010-07-05 19:21:36 +00:00
while ( $cpw = mysql_fetch_array ( $query )) {
unset ( $exists );
$i = 0 ;
while ( $i < count ( $cpw_exists ) && ! $exists ) {
$this_cpw = $cpw [ 'device_id' ] . " " . $cpw [ 'cpwOid' ] . " " . $cpw [ 'peer_device_id' ] . " " . $cpw [ 'interface_id' ] . " " . $cpw [ 'cpwVcID' ];
if ( $cpw_exists [ $i ] == $this_cpw ) { $exists = 1 ;
2008-11-19 12:12:54 +00:00
# echo($cpw_exists[$i]. " || $this_cpw \n");
2010-07-05 19:21:36 +00:00
}
$i ++ ;
2008-11-19 12:12:54 +00:00
}
2010-07-05 19:21:36 +00:00
if ( ! $exists ) {
echo ( " - " );
2008-11-19 12:12:54 +00:00
# echo($this_cpw . "\n");
2010-07-05 19:21:36 +00:00
mysql_query ( " DELETE FROM pseudowires WHERE pseudowire_id = ' " . $cpw [ 'pseudowire_id' ] . " ' " );
}
2008-11-19 12:12:54 +00:00
}
2010-07-05 19:21:36 +00:00
echo ( " \n " );
2009-05-12 15:59:47 +00:00
2009-03-24 15:24:18 +00:00
}
2008-10-28 18:25:53 +00:00
?>