'routing', 'protocol' => 'bgp');
print_optionbar_start('', '');
echo('BGP » ');
if (!$vars['type']) { $vars['type'] = "all"; }
if ($vars['type'] == "all") { echo(""); }
echo(" | ");
if ($vars['type'] == "internal") { echo(""); }
echo(" | ");
if ($vars['type'] == "external") { echo(""); }
echo(" | ");
if ($vars['adminstatus'] == "stop")
{
echo("");
} else {
echo(generate_link("Shutdown",$vars, array('adminstatus' => 'stop')));
}
echo(" | ");
if ($vars['adminstatus'] == "start")
{
echo("");
} else {
echo(generate_link("Enabled",$vars, array('adminstatus' => 'start')));
}
echo(" | ");
if ($vars['state'] == "down")
{
echo("");
} else {
echo(generate_link("Down",$vars, array('state' => 'down')));
}
## End BGP Menu
if (!isset($vars['view'])) { $vars['view'] = 'details'; }
echo('
');
if ($vars['view'] == "details") { echo(""); }
echo(" | ");
if ($vars['graph'] == "updates") { echo(""); }
echo(" | Prefixes: Unicast (");
if ($vars['graph'] == "prefixes_ipv4unicast") { echo(""); }
echo("|");
if ($vars['graph'] == "prefixes_ipv6unicast") { echo(""); }
echo("|");
if ($vars['graph'] == "prefixes_ipv4vpn") { echo(""); }
echo(")");
echo(" | Multicast (");
if ($vars['graph'] == "prefixes_ipv4multicast") { echo(""); }
echo("|");
if ($vars['graph'] == "prefixes_ipv6multicast") { echo(""); }
echo(")");
echo(" | MAC (");
if ($vars['graph'] == "macaccounting_bits") { echo(""); }
echo("|");
if ($vars['graph'] == "macaccounting_pkts") { echo(""); }
echo(")");
echo('
');
print_optionbar_end();
echo("");
echo(' | Local address | | Peer address | Type | Family | Remote AS | State | Uptime / Updates |
');
$i = "1";
if ($vars['type'] == "external")
{
$where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs";
} elseif ($vars['type'] == "internal") {
$where = "AND D.bgpLocalAs = B.bgpPeerRemoteAs";
}
if ($vars['adminstatus'] == "stop")
{
$where .= " AND (B.bgpPeerAdminStatus = 'stop')";
} elseif ($vars['adminstatus'] == "start")
{
$where .= " AND (B.bgpPeerAdminStatus = 'start')";
}
if ($vars['state'] == "down")
{
$where .= " AND (B.bgpPeerState != 'established')";
}
$peer_query = "select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id ".$where." ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier";
foreach (dbFetchRows($peer_query) as $peer)
{
unset ($alert, $bg_image);
if (!is_integer($i/2)) { $bg_colour = $list_colour_b; } else { $bg_colour = $list_colour_a; }
if ($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $peer['alert']=1; }
if ($peer['bgpPeerAdminStatus'] == "start" || $peer['bgpPeerAdminStatus'] == "running") { $admin_col = "green"; } else { $admin_col = "gray"; }
if ($peer['bgpPeerAdminStatus'] == "stop") { $peer['alert']=0; $peer['disabled']=1; }
if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP";
if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = "Priv eBGP"; }
}
$peerhost = dbFetchRow("SELECT * FROM ipaddr AS A, ports AS I, devices AS D WHERE A.addr = ? AND I.interface_id = A.interface_id AND D.device_id = I.device_id", array($peer['bgpPeerIdentifier']));
if ($peerhost) { $peername = generate_device_link($peerhost, shorthost($peerhost['hostname'])); } else { unset($peername); }
// display overlib graphs
$graph_type = "bgp_updates";
$local_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=$day&to=$now&width=500&height=150&&afi=ipv4&safi=unicast";
$localaddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer['bgpLocalAddr'] . "";
$graph_type = "bgp_updates";
$peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=$day&to=$now&width=500&height=150";
$peeraddresslink = "', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . "";
echo('");
unset($sep);
foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi)
{
$afi = $afisafi['afi'];
$safi = $afisafi['safi'];
$this_afisafi = $afi.$safi;
$peer['afi'] .= $sep . $afi .".".$safi;
$sep = "
";
$peer['afisafi'][$this_afisafi] = 1; ## Build a list of valid AFI/SAFI for this peer
}
unset($sep);
echo(" |
" . $localaddresslink . " ".generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp'))." |
» |
" . $peeraddresslink . " |
$peer_type |
".$peer['afi']." |
AS" . $peer['bgpPeerRemoteAs'] . " " . $peer['astext'] . " |
" . $peer['bgpPeerAdminStatus'] . " " . $peer['bgpPeerState'] . " |
" .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
Updates " . format_si($peer['bgpPeerInUpdates']) . "
" . format_si($peer['bgpPeerOutUpdates']) . " |
");
unset($invalid);
switch ($vars['graph'])
{
case 'prefixes_ipv4unicast':
case 'prefixes_ipv4multicast':
case 'prefixes_ipv4vpn':
case 'prefixes_ipv6unicast':
case 'prefixes_ipv6multicast':
list(,$afisafi) = explode("_", $vars['graph']);
if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; }
case 'updates':
$graph_array['type'] = "bgp_" . $vars['graph'];
$graph_array['id'] = $peer['bgpPeer_id'];
}
switch ($vars['graph'])
{
case 'macaccounting_bits':
case 'macaccounting_pkts':
$acc = dbFetchRow("SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.interface_id = M.interface_id AND D.device_id = P.device_id", array($peer['bgpPeerIdentifier']));
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
if (is_array($acc) && is_file($database))
{
$peer['graph'] = 1;
$graph_array['id'] = $acc['ma_id'];
$graph_array['type'] = $vars['graph'];
}
}
if ($vars['graph'] == 'updates') { $peer['graph'] = 1; }
if ($peer['graph'])
{
$graph_array['height'] = "100";
$graph_array['width'] = "218";
$graph_array['to'] = $now;
echo('');
include("includes/print-quadgraphs.inc.php");
echo(" |
");
}
$i++;
}
echo("
");
}
?>