2008-10-28 18:25:53 +00:00
< ? php
2017-09-11 15:26:41 -05:00
use LibreNMS\Config ;
if ( Config :: get ( 'enable_pseudowires' ) && $device [ 'os_group' ] == 'cisco' ) {
2018-07-13 17:08:00 -05:00
$pws_db = [];
2012-05-25 12:24:34 +00:00
// Pre-cache the existing state of pseudowires for this device from the database
2012-05-02 17:23:27 +00:00
$pws_db_raw = dbFetchRows ( 'SELECT * FROM `pseudowires` WHERE `device_id` = ?' , [ $device [ 'device_id' ]]);
2012-05-02 22:02:30 +00:00
foreach ( $pws_db_raw as $pw_db ) {
2018-07-13 17:08:00 -05:00
$pws_db [ $pw_db [ 'cpwVcID' ]] = $pw_db [ 'pseudowire_id' ];
2012-05-02 17:23:27 +00:00
}
2015-07-13 20:10:26 +02:00
2012-05-02 17:23:27 +00:00
$pws = snmpwalk_cache_oid ( $device , 'cpwVcID' , [], 'CISCO-IETF-PW-MPLS-MIB' );
$pws = snmpwalk_cache_oid ( $device , 'cpwVcName' , $pws , 'CISCO-IETF-PW-MPLS-MIB' );
$pws = snmpwalk_cache_oid ( $device , 'cpwVcType' , $pws , 'CISCO-IETF-PW-MPLS-MIB' );
$pws = snmpwalk_cache_oid ( $device , 'cpwVcPsnType' , $pws , 'CISCO-IETF-PW-MPLS-MIB' );
$pws = snmpwalk_cache_oid ( $device , 'cpwVcDescr' , $pws , 'CISCO-IETF-PW-MPLS-MIB' );
2015-07-13 20:10:26 +02:00
2012-05-25 12:24:34 +00:00
// For MPLS pseudowires
2012-05-02 17:23:27 +00:00
$pws = snmpwalk_cache_oid ( $device , 'cpwVcMplsPeerLdpID' , $pws , 'CISCO-IETF-PW-MPLS-MIB' );
2015-07-13 20:10:26 +02:00
2012-05-02 22:02:30 +00:00
foreach ( $pws as $pw_id => $pw ) {
2020-07-06 14:59:53 +01:00
// Added By Oirbsiu
// To correct Interface names that use escaped '/' e.g. GigabitEthernet0_4_0_12
// and translate the underscore back to a slash - e.g. GigabitEthernet0/4/0/12
// Thank you @murrant
$pw [ 'cpwVcName' ] = preg_replace ( '/(?<=\d)_(?=\d)/' , '/' , $pw [ 'cpwVcName' ]);
// END
2012-05-02 17:23:27 +00:00
[ $cpw_remote_id ] = explode ( ':' , $pw [ 'cpwVcMplsPeerLdpID' ]);
2024-08-03 19:57:33 +02:00
if ( \LibreNMS\Util\IPv4 :: isValid ( $cpw_remote_id )) {
//If cpwVcMplsPeerLdpID is in the IP form, then convert it to number to store it in DB to avoid failing
$cpw_remote_id = ip2long ( $cpw_remote_id );
}
2014-01-13 17:43:58 +00:00
$cpw_remote_device = dbFetchCell ( 'SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id' , [ $cpw_remote_id ]);
$if_id = dbFetchCell ( 'SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?' , [ $pw [ 'cpwVcName' ], $device [ 'device_id' ]]);
2018-07-13 17:08:00 -05:00
if ( ! empty ( $pws_db [ $pw [ 'cpwVcID' ]])) {
$pseudowire_id = $pws_db [ $pw [ 'cpwVcID' ]];
2012-05-02 17:23:27 +00:00
echo '.' ;
2016-08-28 12:32:58 -05:00
} else {
2012-05-16 13:25:50 +00:00
$pseudowire_id = dbInsert (
2020-09-21 15:40:17 +02:00
[
2024-01-05 05:39:12 +01:00
'device_id' => $device [ 'device_id' ],
'port_id' => $if_id ,
2012-05-16 13:25:50 +00:00
'peer_device_id' => $cpw_remote_device ,
2024-01-05 05:39:12 +01:00
'peer_ldp_id' => $cpw_remote_id ,
'cpwVcID' => $pw [ 'cpwVcID' ],
'cpwOid' => $pw_id ,
'pw_type' => $pw [ 'cpwVcType' ],
'pw_descr' => $pw [ 'cpwVcDescr' ],
'pw_psntype' => $pw [ 'cpwVcPsnType' ],
2012-05-02 17:23:27 +00:00
],
'pseudowires'
);
echo '+' ;
}
2015-07-13 20:10:26 +02:00
2012-05-02 17:23:27 +00:00
$device [ 'pws' ][ $pw [ 'cpwVcID' ]] = $pseudowire_id ;
2012-05-02 22:02:30 +00:00
} //end foreach
2009-05-12 15:59:47 +00:00
2012-01-12 11:16:38 +00:00
// Cycle the list of pseudowires we cached earlier and make sure we saw them again.
2018-07-13 17:08:00 -05:00
foreach ( $pws_db as $pw_id => $pseudowire_id ) {
2012-05-02 22:02:30 +00:00
if ( empty ( $device [ 'pws' ][ $pw_id ])) {
2017-01-07 17:32:38 +00:00
dbDelete ( 'pseudowires' , '`pseudowire_id` = ?' , [ $pseudowire_id ]);
2012-01-12 11:16:38 +00:00
}
2015-07-13 20:10:26 +02:00
}
2009-03-24 15:24:18 +00:00
2015-07-13 20:10:26 +02:00
echo " \n " ;
} //end if
2018-07-13 17:08:00 -05:00
unset ( $pws_db , $pws_db_raw , $pw_db );