feature: Added better BGP support for Arista (#6046)

* feature: Added better BGP support for Arista
This commit is contained in:
Neil Lathwood
2017-03-11 23:16:49 +00:00
committed by GitHub
parent 107ad9cc1f
commit 38cebc5fd7
9 changed files with 2215 additions and 217 deletions

View File

@@ -41,7 +41,7 @@ echo ' | Prefixes: ';
if ($vars['view'] == 'prefixes_ipv4unicast') { if ($vars['view'] == 'prefixes_ipv4unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` NOT LIKE '%:%'"; $extra_sql = " AND `bgpPeerIdentifier` NOT LIKE '%:%'";
} }
echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast')); echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast'));
@@ -64,7 +64,7 @@ echo ' | ';
if ($vars['view'] == 'prefixes_ipv6unicast') { if ($vars['view'] == 'prefixes_ipv6unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` LIKE '%:%'"; $extra_sql = " AND `bgpPeerIdentifier` LIKE '%:%'";
} }
echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast')); echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast'));
@@ -96,7 +96,7 @@ if ($vars['view'] == 'macaccounting_pkts') {
print_optionbar_end(); print_optionbar_end();
echo '<table border="0" cellspacing="0" cellpadding="5" width="100%">'; echo '<table border="0" cellspacing="0" cellpadding="5" width="100%">';
echo '<tr style="height: 30px"><td width=1></td><th></th><th>Peer address</th><th>Type</th><th>Remote AS</th><th>State</th><th>Uptime</th></tr>'; echo '<tr style="height: 30px"><th>Peer address</th><th>Type</th><th>Remote AS</th><th>State</th><th>Uptime</th></tr>';
$i = '1'; $i = '1';
@@ -218,7 +218,7 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
echo '<tr bgcolor="'.$bg_colour.'"'.($peer['alert'] ? ' bordercolor="#cc0000"' : '').($peer['disabled'] ? ' bordercolor="#cccccc"' : '').'> echo '<tr bgcolor="'.$bg_colour.'"'.($peer['alert'] ? ' bordercolor="#cc0000"' : '').($peer['disabled'] ? ' bordercolor="#cccccc"' : '').'>
'; ';
echo ' <td width=20><span class=list-large>'.$i.'</span></td> echo '
<td>'.$peeraddresslink.'<br />'.$peername."</td> <td>'.$peeraddresslink.'<br />'.$peername."</td>
<td>$peer_type</td> <td>$peer_type</td>
<td style='font-size: 10px; font-weight: bold; line-height: 10px;'>".(isset($peer['afi']) ? $peer['afi'] : '').'</td> <td style='font-size: 10px; font-weight: bold; line-height: 10px;'>".(isset($peer['afi']) ? $peer['afi'] : '').'</td>

View File

@@ -107,7 +107,7 @@ if ($_SESSION['userlevel'] < '5') {
echo ' | Prefixes: Unicast ('; echo ' | Prefixes: Unicast (';
if ($vars['graph'] == 'prefixes_ipv4unicast') { if ($vars['graph'] == 'prefixes_ipv4unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` NOT LIKE '%:%'"; $extra_sql = " AND `bgpPeerIdentifier` NOT LIKE '%:%'";
} }
echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast')); echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast'));
@@ -119,7 +119,7 @@ if ($_SESSION['userlevel'] < '5') {
if ($vars['graph'] == 'prefixes_ipv6unicast') { if ($vars['graph'] == 'prefixes_ipv6unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` LIKE '%:%'"; $extra_sql = " AND `bgpPeerIdentifier` LIKE '%:%'";
} }
echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast')); echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast'));

View File

@@ -2,6 +2,7 @@ os: arista_eos
text: 'Arista EOS' text: 'Arista EOS'
type: network type: network
icon: arista icon: arista
group: arista
over: over:
- { graph: device_bits, text: 'Device Traffic' } - { graph: device_bits, text: 'Device Traffic' }
- { graph: device_processor, text: 'CPU Usage' } - { graph: device_processor, text: 'CPU Usage' }

View File

@@ -1,7 +1,5 @@
<?php <?php
if ($config['enable_bgp']) { if ($config['enable_bgp']) {
// Discover BGP peers
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) { if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) {
$vrfs_lite_cisco = $device['vrf_lite_cisco']; $vrfs_lite_cisco = $device['vrf_lite_cisco'];
} else { } else {
@@ -11,7 +9,7 @@ if ($config['enable_bgp']) {
$bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB')); $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB'));
foreach ($vrfs_lite_cisco as $vrf) { foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name'] = $vrf['context_name']; $device['context_name'] = $vrf['context_name'];
if (is_numeric($bgpLocalAs)) { if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs "; echo "AS$bgpLocalAs ";
if ($bgpLocalAs != $device['bgpLocalAs']) { if ($bgpLocalAs != $device['bgpLocalAs']) {
@@ -19,69 +17,20 @@ if ($config['enable_bgp']) {
echo 'Updated AS '; echo 'Updated AS ';
} }
$peer2 = false; $peer2 = false;
if ($device['os'] !== 'junos') {
if ($device['os_group'] === 'arista') {
$peers_data = snmp_walk($device, 'aristaBgp4V2PeerRemoteAs', '-Oq', 'ARISTA-BGP4V2-MIB');
$peer2 = true;
} elseif ($device['os'] !== 'junos') {
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB'); $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB');
if (empty($peers_data)) { if (empty($peers_data)) {
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB'); $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB');
} else { } else {
$peer2 = true; $peer2 = true;
} }
d_echo("Peers : $peers_data \n");
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
foreach (explode("\n", $peers) as $peer) {
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
}
list($peer_ip, $peer_as) = explode(' ', $peer);
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
}
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
} elseif ($device['os'] == 'junos') { } elseif ($device['os'] == 'junos') {
// Juniper BGP4-V2 MIB $peers_data = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', 'junos');
// FIXME: needs a big cleanup! also see below.
// FIXME: is .0.ipv6 the only possible value here?
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', 'junos');
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result));
foreach (explode("\n", $peers) as $peer) {
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
$octets = count(explode(".", $peer_ip_snmp));
if ($octets > 11) {
// ipv6
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
} else {
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
}
if ($peer) {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
);
}
}
} }
} else { } else {
echo 'No BGP on host'; echo 'No BGP on host';
@@ -91,171 +40,100 @@ if ($config['enable_bgp']) {
} }
} }
// Process disovered peers $peerlist = build_bgp_peers($device, $peers_data, $peer2);
// Process discovered peers
if (isset($peerlist)) { if (isset($peerlist)) {
foreach ($peerlist as $peer) { foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']); $astext = get_astext($peer['as']);
$peer['astext'] = $astext;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { add_bgp_peer($device, $peer);
$bgpPeers = array(
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'bgpPeerRemoteAs' => $peer['as'],
'context_name' => $device['context_name'],
'astext' => $astext,
'bgpPeerState' => 'idle',
'bgpPeerAdminStatus' => 'stop',
'bgpLocalAddr' => '0.0.0.0',
'bgpPeerRemoteAddr' => '0.0.0.0',
'bgpPeerInUpdates' => 0,
'bgpPeerOutUpdates' => 0,
'bgpPeerInTotalMessages' => 0,
'bgpPeerOutTotalMessages' => 0,
'bgpPeerFsmEstablishedTime' => 0,
'bgpPeerInUpdateElapsedTime' => 0,
);
$add = dbInsert($bgpPeers, 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
$remote_device_id = discover_new_device($name, $device, 'BGP');
}
echo '+'; $af_data = array();
} else { $af_list = array();
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
if ($device['os_group'] == 'cisco') {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
if ($device['os_group'] == 'cisco') {
if (empty($af_data)) {
if ($peer2 === true) { if ($peer2 === true) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB'); $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB');
} else { } else {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB'); $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB');
} }
}
}
d_echo('afi data :: '); if ($device['os_group'] === 'arista') {
d_echo($af_data); if (empty($af_data)) {
$af_data = snmpwalk_cache_oid($device, 'aristaBgp4V2PrefixInPrefixes', $af_data, 'ARISTA-BGP4V2-MIB');
}
}
foreach ($af_data as $k => $v) { if (!empty($af_data)) {
if ($peer2 === true) { $af_list = build_cbgp_peers($device, $peer, $af_data, $peer2);
list(,$k) = explode('.', $k, 2); }
}
d_echo("AFISAFI = $k\n"); if ($device['os'] == 'junos') {
$safis[1] = 'unicast';
$safis[2] = 'multicast';
$afisafi_tmp = explode('.', $k); if (!isset($j_peerIndexes)) {
$safi = array_pop($afisafi_tmp); $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
$afi = array_pop($afisafi_tmp); d_echo($j_bgp);
$bgp_ip = str_replace(".$afi.$safi", '', $k); foreach ($j_bgp as $index => $entry) {
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip); switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); case 'ipv4':
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
if ($afi && $safi && $bgp_ip == $peer['ip']) { d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$af_list[$bgp_ip][$afi][$safi] = 1; $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { break;
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); case 'ipv6':
} $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
} }
} }
} }
if ($device['os'] == 'junos') { if (!isset($j_afisafi)) {
$safis[1] = 'unicast'; $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
$safis[2] = 'multicast'; foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
if (!isset($j_peerIndexes)) { $j_afisafi[$index][] = $afisafi;
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
d_echo($j_bgp);
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
}
}
if (!isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', 'junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
$safi = $safis[$safi];
$af_list[$peer['ip']][$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
$cbgp = array(
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'afi' => $afi,
'safi' => $safi,
'AcceptedPrefixes' => 0,
'DeniedPrefixes' => 0,
'PrefixAdminLimit' => 0,
'PrefixThreshold' => 0,
'PrefixClearThreshold' => 0,
'AdvertisedPrefixes' => 0,
'SuppressedPrefixes' => 0,
'WithdrawnPrefixes' => 0,
'AcceptedPrefixes_delta' => 0,
'AcceptedPrefixes_prev' => 0,
'DeniedPrefixes_delta' => 0,
'DeniedPrefixes_prev' => 0,
'AdvertisedPrefixes_delta' => 0,
'AdvertisedPrefixes_prev' => 0,
'SuppressedPrefixes_delta' => 0,
'SuppressedPrefixes_prev' => 0,
'WithdrawnPrefixes_delta' => 0,
'WithdrawnPrefixes_prev' => 0,
);
dbInsert($cbgp, 'bgpPeers_cbgp');
}
} }
} }
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
foreach (dbFetchRows($af_query) as $entry) { list ($afi,$safi) = explode('.', $afisafi);
$afi = $entry['afi']; $safi = $safis[$safi];
$safi = $entry['safi']; $af_list[$peer['ip']][$afi][$safi] = 1;
if (!$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { add_cbgp_peer($device, $peer, $afi, $safi);
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); }
} }
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'";
foreach (dbFetchRows($af_query) as $entry) {
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
} }
} }
} }
unset($j_afisafi); unset($j_afisafi);
unset($j_prefixes); unset($j_prefixes);
unset($j_bgp); unset($j_bgp);
unset($j_peerIndexes); unset($j_peerIndexes);
} }
// Delete removed peers // Delete removed peers
$sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND (context_name = '".$device['context_name']."' OR context_name IS NULL)"; $sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND (context_name = '".$device['context_name']."' OR context_name IS NULL)";
foreach (dbFetchRows($sql) as $entry) { foreach (dbFetchRows($sql) as $entry) {
unset($exists); unset($exists);
@@ -274,13 +152,14 @@ if ($config['enable_bgp']) {
echo '-'; echo '-';
} }
} }
echo "\n";
unset($peerlist); unset(
$device['context_name'],
echo "\n"; $peerlist
unset($device['context_name']); );
} }
unset($device['context_name']); unset(
unset($vrfs_c); $device['context_name'],
$vrfs_c
);
} }
echo "FIN BGP \n\n\n";

View File

@@ -1010,3 +1010,144 @@ function sensors($types, $device, $valid, $pre_cache = array())
echo "\n"; echo "\n";
} }
} }
function build_bgp_peers($device, $data, $peer2)
{
d_echo("Peers : $data\n");
$peers = trim(str_replace('ARISTA-BGP4V2-MIB::aristaBgp4V2PeerRemoteAs.1.', '', $data));
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $peers));
$peerlist = array();
$ver = '';
foreach (explode("\n", $peers) as $peer) {
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
}
list($peer_ip, $peer_as) = explode(' ', $peer);
if ($device['os'] === 'junos') {
$ver = '';
$octets = count(explode(".", $peer_ip));
if ($octets > 11) {
// ipv6
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip), (count(explode('.', $peer_ip)) - 16)))));
} else {
// ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip), (count(explode('.', $peer_ip)) - 4)));
}
} else {
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
}
}
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
return $peerlist;
}
function build_cbgp_peers($device, $peer, $af_data, $peer2)
{
d_echo('afi data :: ');
d_echo($af_data);
$af_list = array();
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
list(,$k) = explode('.', $k, 2);
}
d_echo("AFISAFI = $k\n");
$afisafi_tmp = explode('.', $k);
$safi = array_pop($afisafi_tmp);
$afi = array_pop($afisafi_tmp);
$bgp_ip = str_replace(".$afi.$safi", '', $k);
if ($device['os_group'] === 'arista') {
$bgp_ip = str_replace("$afi.", '', $bgp_ip);
}
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
if ($afi && $safi && $bgp_ip == $peer['ip']) {
$af_list[$bgp_ip][$afi][$safi] = 1;
add_cbgp_peer($device, $peer, $afi, $safi);
}
}
return $af_list;
}
function add_bgp_peer($device, $peer)
{
global $config;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$bgpPeers = array(
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'bgpPeerRemoteAs' => $peer['as'],
'context_name' => $device['context_name'],
'astext' => $peer['astext'],
'bgpPeerState' => 'idle',
'bgpPeerAdminStatus' => 'stop',
'bgpLocalAddr' => '0.0.0.0',
'bgpPeerRemoteAddr' => '0.0.0.0',
'bgpPeerInUpdates' => 0,
'bgpPeerOutUpdates' => 0,
'bgpPeerInTotalMessages' => 0,
'bgpPeerOutTotalMessages' => 0,
'bgpPeerFsmEstablishedTime' => 0,
'bgpPeerInUpdateElapsedTime' => 0,
);
dbInsert($bgpPeers, 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
discover_new_device($name, $device, 'BGP');
}
echo '+';
} else {
dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($peer['astext'])), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
}
function add_cbgp_peer($device, $peer, $afi, $safi)
{
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
$cbgp = array(
'device_id' => $device['device_id'],
'bgpPeerIdentifier' => $peer['ip'],
'afi' => $afi,
'safi' => $safi,
'context_name' => $device['context_name'],
'AcceptedPrefixes' => 0,
'DeniedPrefixes' => 0,
'PrefixAdminLimit' => 0,
'PrefixThreshold' => 0,
'PrefixClearThreshold' => 0,
'AdvertisedPrefixes' => 0,
'SuppressedPrefixes' => 0,
'WithdrawnPrefixes' => 0,
'AcceptedPrefixes_delta' => 0,
'AcceptedPrefixes_prev' => 0,
'DeniedPrefixes_delta' => 0,
'DeniedPrefixes_prev' => 0,
'AdvertisedPrefixes_delta' => 0,
'AdvertisedPrefixes_prev' => 0,
'SuppressedPrefixes_delta' => 0,
'SuppressedPrefixes_prev' => 0,
'WithdrawnPrefixes_delta' => 0,
'WithdrawnPrefixes_prev' => 0,
);
dbInsert($cbgp, 'bgpPeers_cbgp');
}
}

View File

@@ -8,13 +8,15 @@ if ($config['enable_bgp']) {
if (!empty($peers)) { if (!empty($peers)) {
if ($device['os'] == 'junos') { if ($device['os'] == 'junos') {
$peer_data_check = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerIndex', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', 'junos'); $peer_data_check = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerIndex', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', 'junos');
} elseif ($device['os_group'] === 'arista') {
$peer_data_check = snmpwalk_cache_oid($device, 'aristaBgp4V2PeerRemoteAs', array(), 'ARISTA-BGP4V2-MIB');
} else { } else {
$peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB'); $peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB');
} }
foreach ($peers as $peer) { foreach ($peers as $peer) {
//add context if exist //add context if exist
$device['context_name']= $peer['context_name']; $device['context_name'] = $peer['context_name'];
if (strstr(":", $peer['bgpPeerIdentifier'])) { if (strstr(":", $peer['bgpPeerIdentifier'])) {
$peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']);
} else { } else {
@@ -44,18 +46,28 @@ if ($config['enable_bgp']) {
$ip_ver = 'ipv4'; $ip_ver = 'ipv4';
} }
$peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident; if ($device['os_group'] === 'arista') {
$peer_data_tmp = snmp_get_multi( $peer_identifier = '1.'.$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident;
$device, $peer_data_tmp = snmp_get_multi(
' cbgpPeer2State.'.$peer_identifier.' cbgpPeer2AdminStatus.'.$peer_identifier.' cbgpPeer2InUpdates.'.$peer_identifier.' cbgpPeer2OutUpdates.'.$peer_identifier.' cbgpPeer2InTotalMessages.'.$peer_identifier.' cbgpPeer2OutTotalMessages.'.$peer_identifier.' cbgpPeer2FsmEstablishedTime.'.$peer_identifier.' cbgpPeer2InUpdateElapsedTime.'.$peer_identifier.' cbgpPeer2LocalAddr.'.$peer_identifier, $device,
'-OQUs', ' aristaBgp4V2PeerState.' . $peer_identifier . ' aristaBgp4V2PeerAdminStatus.' . $peer_identifier . ' aristaBgp4V2PeerInUpdates.' . $peer_identifier . ' aristaBgp4V2PeerOutUpdates.' . $peer_identifier . ' aristaBgp4V2PeerInTotalMessages.' . $peer_identifier . ' aristaBgp4V2PeerOutTotalMessages.' . $peer_identifier . ' aristaBgp4V2PeerFsmEstablishedTime.' . $peer_identifier . ' aristaBgp4V2PeerInUpdatesElapsedTime.' . $peer_identifier . ' aristaBgp4V2PeerLocalAddr.' . $peer_identifier,
'CISCO-BGP4-MIB' '-OQUs',
); 'ARISTA-BGP4V2-MIB'
);
} else {
$peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident;
$peer_data_tmp = snmp_get_multi(
$device,
' cbgpPeer2State.' . $peer_identifier . ' cbgpPeer2AdminStatus.' . $peer_identifier . ' cbgpPeer2InUpdates.' . $peer_identifier . ' cbgpPeer2OutUpdates.' . $peer_identifier . ' cbgpPeer2InTotalMessages.' . $peer_identifier . ' cbgpPeer2OutTotalMessages.' . $peer_identifier . ' cbgpPeer2FsmEstablishedTime.' . $peer_identifier . ' cbgpPeer2InUpdateElapsedTime.' . $peer_identifier . ' cbgpPeer2LocalAddr.' . $peer_identifier,
'-OQUs',
'CISCO-BGP4-MIB'
);
}
$ident = "$ip_ver.\"".$bgp_peer_ident.'"'; $ident = "$ip_ver.\"".$bgp_peer_ident.'"';
unset($peer_data); unset($peer_data);
$ident_key = array_keys($peer_data_tmp); $ident_key = array_keys($peer_data_tmp);
foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) {
if (strstr($k, 'cbgpPeer2LocalAddr')) { if (strstr($k, 'cbgpPeer2LocalAddr') || $k === 'aristaBgp4V2PeerLocalAddr') {
if ($ip_ver == 'ipv6') { if ($ip_ver == 'ipv6') {
$v = str_replace('"', '', $v); $v = str_replace('"', '', $v);
$v = rtrim($v); $v = rtrim($v);
@@ -178,7 +190,7 @@ if ($config['enable_bgp']) {
dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier']));
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { if ($device['os_group'] == 'cisco' || $device['os'] == 'junos' || $device['os_group'] === 'arista') {
// Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB)
$peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier']));
foreach ($peer_afis as $peer_afi) { foreach ($peer_afis as $peer_afi) {
@@ -280,6 +292,26 @@ if ($config['enable_bgp']) {
$cbgpPeerAdvertisedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.10.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]); $cbgpPeerAdvertisedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.10.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]);
}//end if }//end if
if ($device['os_group'] === 'arista') {
$safis['unicast'] = 1;
$safis['multicast'] = 2;
$afis['ipv4'] = 1;
$afis['ipv6'] = 2;
$type['ipv4'] = 4;
$type['ipv6'] = 16;
if (preg_match('/:/', $peer['bgpPeerIdentifier'])) {
$tmp_peer = str_replace(':', '', $peer['bgpPeerIdentifier']);
$tmp_peer = preg_replace('/([\w\d]{2})/', '\1:', $tmp_peer);
$tmp_peer = rtrim($tmp_peer, ':');
} else {
$tmp_peer = $peer['bgpPeerIdentifier'];
}
if (empty($a_prefixes)) {
$a_prefixes = snmpwalk_cache_multi_oid($device, 'aristaBgp4V2PrefixInPrefixesAccepted', $a_prefixes, 'ARISTA-BGP4V2-MIB', null, '-OQUs');
}
$cbgpPeerAcceptedPrefixes = $a_prefixes["1.$afi.$tmp_peer.$afi.$safi"]['aristaBgp4V2PrefixInPrefixesAccepted'];
}
// FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE!
$update = 'UPDATE bgpPeers_cbgp SET'; $update = 'UPDATE bgpPeers_cbgp SET';
$peer['c_update']['AcceptedPrefixes'] = set_numeric($cbgpPeerAcceptedPrefixes); $peer['c_update']['AcceptedPrefixes'] = set_numeric($cbgpPeerAcceptedPrefixes);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
-- extracted from draft-ietf-idr-bgp4-mibv2-tc-mib-03.txt
-- at Tue Jul 12 06:11:02 2011
-- Renumbered to sit underneath Arista's enterprise.
ARISTA-BGP4V2-TC-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY FROM SNMPv2-SMI
aristaExperiment FROM ARISTA-SMI-MIB
TEXTUAL-CONVENTION FROM SNMPv2-TC;
aristaBgp4V2TC MODULE-IDENTITY
LAST-UPDATED "201408150000Z"
ORGANIZATION "Arista Networks, Inc."
CONTACT-INFO
"Arista Networks, Inc.
Postal: 5453 Great America Parkway
Santa Clara, CA 95054
Tel: +1 408 547-5500
E-mail: snmp@arista.com"
DESCRIPTION
"Textual conventions for BGP-4.
This version was published in
draft-ietf-idr-bgp4-mibv2-13, and
modified to be homed inside the Arista
enterprise. There were no other
modifications.
Copyright (C) The IETF Trust (2011). This
version of this MIB module is part of
draft-ietf-idr-bgp4-mibv2-13.txt;
see the draft itself for full legal notices."
REVISION "201408150000Z"
DESCRIPTION
"Updated postal and e-mail addresses."
REVISION "201210190000Z"
DESCRIPTION
"Renumbered inside the Arista enterprise space."
REVISION "201101170000Z"
DESCRIPTION
"Initial version."
::= { aristaExperiment 2 }
--
-- Textual Conventions
--
AristaBgp4V2IdentifierTC ::= TEXTUAL-CONVENTION
DISPLAY-HINT "1d."
STATUS current
DESCRIPTION
"The representation of a BGP Identifier. BGP Identifiers
are presented in the received network byte order.
The BGP Identifier is displayed as if it is an IP address,
even if it would be an illegal one."
REFERENCE
"RFC 4273, Section 4.2"
SYNTAX OCTET STRING(SIZE (4))
AristaBgp4V2AddressFamilyIdentifierTC ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"The representation of a BGP AFI. The value of this object
should be restricted to be between the values of 0 and
65535."
REFERENCE
"RFC 4760, Section 3"
SYNTAX INTEGER {
ipv4(1),
ipv6(2)
}
AristaBgp4V2SubsequentAddressFamilyIdentifierTC ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"The representation of a BGP SAFI"
REFERENCE
"RFC 4760, Section 3. The value of this object should be
restricted to be between the values of 0 and 255."
SYNTAX INTEGER {
unicast(1),
multicast(2),
mpls(4)
}
END

View File

@@ -0,0 +1,68 @@
-- ARISTA-SMI_MIB: arista structure of management information
-- Copyright (c) 2008 Arista Networks, Inc. All rights reserved.
ARISTA-SMI-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY,
OBJECT-IDENTITY,
enterprises
FROM SNMPv2-SMI;
arista MODULE-IDENTITY
LAST-UPDATED "201408150000Z"
ORGANIZATION "Arista Networks, Inc."
CONTACT-INFO
"Arista Networks, Inc.
Postal: 5453 Great America Parkway
Santa Clara, CA 95054
Tel: +1 408 547-5500
E-mail: snmp@arista.com"
DESCRIPTION
"The Structure of Management Information for the
Arista Networks enterprise."
REVISION "201408150000Z"
DESCRIPTION
"Updated postal and e-mail addresses"
REVISION "201103311300Z"
DESCRIPTION
"Updated postal address and telephone"
REVISION "200810271830Z"
DESCRIPTION
"Initial version."
::= { enterprises 30065 } -- assigned by IANA
aristaProducts OBJECT-IDENTITY
STATUS current
DESCRIPTION
"aristaProducts is the root object identifier from
which sysObjectID values are assigned. Values are
defined in ARISTA-PRODUCTS-MIB."
::= { arista 1 }
aristaModules OBJECT-IDENTITY
STATUS current
DESCRIPTION
"aristaModules provides a root object identifier
from which MODULE-IDENTITY values may be assigned."
::= { arista 2 }
aristaMibs OBJECT-IDENTITY
STATUS current
DESCRIPTION
"aristaMibs provides a root object identifier
for management-related MIBs."
::= { arista 3 }
aristaExperiment OBJECT-IDENTITY
STATUS current
DESCRIPTION
"aristaExperiment provides a root object identifier
for experimental MIBs. The structure of information
for these MIBs can not be guaranteed between releases."
::= { arista 4 }
END