';
$ospf_version = $instance['ospfVersionNumber'];
$area_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?", [$device['device_id'], $ospf_version]);
if ($ospf_version !== 'version3') {
$instance_id = $instance['ospfRouterId'];
if ($device_routing_count['ospf'] > 1) {
$instance_id .= ' V2';
}
// V2 always have 5 part index, ie: 95.130.232.140.0
$port_params = [$device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){4}$'];
// V2 always have 5 part index, ie: .95.130.232.130.0
$nbr_params = [$device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){4}$'];
} else {
$instance_id = long2ip($instance['ospfRouterId']);
if ($device_routing_count['ospf'] > 1) {
$instance_id .= ' V3';
}
// V3 always have 2 part index, ie: 6.0
$port_params = [$device['device_id'], '^[[:digit:]]+\.[[:digit:]]+$'];
// V3 always have 3 part index, ie: .4.0.1602414725
$nbr_params = [$device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){2}$'];
}
$port_count = 0;
$port_count_enabled = 0;
$sql = 'SELECT `ospfIfAdminStat`, COUNT(*) AS `count` FROM `ospf_ports`' .
' WHERE `device_id` = ? AND `ospf_port_id` REGEXP ? GROUP BY `ospfIfAdminStat`';
foreach (dbFetchRows($sql, $port_params) as $entry) {
if ($entry['ospfIfAdminStat'] === 'enabled') {
$port_count_enabled = (int)$entry['count'];
}
$port_count += (int)$entry['count'];
}
$nbr_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?", $nbr_params);
if ($instance['ospfAdminStat'] === "enabled") {
$enabled = 'enabled';
$row_class = 'up';
} else {
$enabled = 'disabled';
$row_class = "disabled";
}
if ($instance['ospfAreaBdrRtrStatus'] === "true") {
$abr = 'yes';
} else {
$abr = 'no';
}
if ($instance['ospfASBdrRtrStatus'] === "true") {
$asbr = 'yes';
} else {
$asbr = 'no';
}
$cols = [
[NULL, 'class="state-marker"'],
['Router Id', 'style="width: 160px;"'],
'Status',
'ABR',
'ASBR',
'Areas',
'Ports',
'Neighbours'
//'descr' => array('Description', 'style="width: 400px;"'),
//'rule' => 'Rule',
];
echo get_table_header($cols, $vars);
//echo(' | Router Id | Status | ABR | ASBR | Areas | Ports | Neighbours |
');
echo('
');
echo(' | ');
echo(' ' . $instance_id . ' | ');
echo(' ' . $enabled . ' | ');
echo(' ' . $abr . ' | ');
echo(' ' . $asbr . ' | ');
echo(' ' . $area_count . ' | ');
echo(' ' . $port_count . '(' . $port_count_enabled . ') | ');
echo(' ' . $nbr_count . ' | ');
echo('
');
echo '';
echo generate_box_close();
/// Global Areas Table
/// FIXME -- humanize_ospf_area()
echo generate_box_open(['title' => 'Areas']);
echo('');
$cols = [
[NULL, 'class="state-marker"'],
['Area Id', 'style="width: 160px;"'],
'Status',
'Auth Type',
'AS External',
'Area LSAs',
'Area Summary',
'Ports'
];
echo get_table_header($cols, $vars);
//echo(' | Area Id | Status | Auth Type | AS External | Area LSAs | Area Summary | Ports |
');
/// Loop Areas
foreach (dbFetchRows("SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?", [$device['device_id'], $ospf_version]) as $area) {
$port_params[] = $area['ospfAreaId'];
$area_port_count = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` REGEXP ? AND `ospfIfAreaId` = ?", $port_params);
$area_port_count_enabled = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports` WHERE `ospfIfAdminStat` = 'enabled' AND `device_id` = ? AND `ospf_port_id` REGEXP ? AND `ospfIfAreaId` = ?", $port_params);
$area_id = $ospf_version === 'version3' ? long2ip($area['ospfAreaId']) : $area['ospfAreaId'];
$area_row_class = $area['ospfAreaStatus'] === 'active' ? 'up' : 'disabled';
$enabled = $area['ospfAreaStatus'] === 'active' ? '' . $area['ospfAreaStatus'] . '' : '' . $area['ospfAreaStatus'] . '';
echo('');
echo(' | ');
echo(' ' . $area_id . ' | ');
echo(' ' . $enabled . ' | ');
echo ' ' . $area['ospfAuthType'] . ' | ';
echo ' ' . $area['ospfImportAsExtern'] . ' | ';
echo ' ' . $area['ospfAreaLsaCount'] . ' | ';
echo ' ' . $area['ospfAreaSummary'] . ' | ';
echo(' ' . $area_port_count . '(' . $area_port_count_enabled . ') | ');
echo('
');
echo('');
echo('');
/// Per-Area Ports Table
/// FIXME -- humanize_ospf_port()
echo generate_box_open();
echo('');
$cols = [
[NULL, 'class="state-marker"'],
['Port', 'style="width: 160px;"'],
['Status', 'style="width: 160px;"'],
'Port Type',
'Port State'
];
echo get_table_header($cols, $vars);
//echo(' | Port | Status | Port Type | Port State | ');
// Loop Ports
$p_sql = 'SELECT * FROM `ospf_ports` LEFT JOIN `ports` USING (`device_id`, `port_id`)' .
' WHERE `device_id` = ? AND `ospf_port_id` REGEXP ? AND `ospfIfAreaId` = ? AND `ospfIfAdminStat` = \'enabled\'';
//$p_sql = "SELECT * FROM `ospf_ports` AS O, `ports` AS P WHERE O.`ospfIfAdminStat` = 'enabled' AND O.`device_id` = ? AND O.`ospfIfAreaId` = ? AND P.port_id = O.port_id";
foreach (dbFetchRows($p_sql, $port_params) as $ospfport) {
if ($ospfport['ospfIfAdminStat'] === "enabled") {
$port_enabled = 'enabled';
$port_row_class = 'up';
} else {
$port_enabled = '' . $ospfport['ospfIfAdminStat'] . '';
$port_row_class = 'disabled';
}
echo('');
echo(' | ');
echo(' ' . generate_port_link($ospfport) . ' | ');
echo(' ' . $port_enabled . ' | ');
echo(' ' . $ospfport['ospfIfType'] . ' | ');
echo(' ' . $ospfport['ospfIfState'] . ' | ');
echo(' ');
} // End loop Ports
echo(' ');
echo generate_box_close();
} // End loop areas
echo ' |
';
echo generate_box_close();
/// Global Neighbour Table
/// FIXME -- humanize_ospf_neighbour()
echo generate_box_open(['title' => 'Neighbours']);
echo '';
$cols = [
[NULL, 'class="state-marker"'],
['Router Id', 'style="width: 160px;"'],
['Device', 'style="width: 160px;"'],
'IP Address',
'Status'
];
echo get_table_header($cols, $vars);
//echo ' | Router Id | Device | IP Address | Status |
';
// Loop Neighbours
foreach (dbFetchRows("SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?", $nbr_params) as $nbr) {
if ($ospf_version !== 'version3') {
$nbr_router_id = $nbr['ospfNbrRtrId'];
} else {
$nbr_router_id = long2ip($nbr['ospfNbrRtrId']);
}
$host = dbFetchRow("SELECT `device_id`, `port_id` FROM `ipv4_addresses` WHERE `ipv4_address` = ?", [$nbr_router_id]);
if (is_array($host)) {
$rtr_id = generate_device_link($host);
} else {
$rtr_id = 'unknown';
}
echo('');
echo(' | ');
echo(' ' . $nbr_router_id . ' | ');
echo(' ' . $rtr_id . ' | ');
echo(' ' . ip_compress($nbr['ospfNbrIpAddr']) . ' | ');
echo(' ');
switch ($nbr['ospfNbrState']) {
case 'full':
echo('' . $nbr['ospfNbrState'] . '');
break;
case 'down':
echo('' . $nbr['ospfNbrState'] . '');
break;
default:
echo('' . $nbr['ospfNbrState'] . '');
break;
}
echo(' | ');
echo('
');
}
echo('
');
echo generate_box_close();
} // End loop instances
// EOF