getLinkStateStatistics method
Gets comprehensive statistics for monitoring and analysis
routingTable - Routing table to analyze
Returns map with various statistics
Implementation
Map<String, dynamic> getLinkStateStatistics(
LinkStateRoutingTable<T> routingTable,
) {
final routes = routingTable.routes.values;
final costs = routes.map((r) => r.cost).toList();
final hopCounts = routes.map((r) => r.hopCount).toList();
return {
'totalRoutes': routes.length,
'totalNodes': routingTable.totalNodes,
'directlyConnected': routes.where((r) => r.isDirectlyConnected).length,
'indirectRoutes': routes.where((r) => !r.isDirectlyConnected).length,
'activeRoutes': routes.where((r) => r.isActive).length,
'averageCost':
costs.isEmpty ? 0.0 : costs.reduce((a, b) => a + b) / costs.length,
'maxCost': costs.isEmpty ? 0.0 : costs.reduce((a, b) => a > b ? a : b),
'minCost': costs.isEmpty ? 0.0 : costs.reduce((a, b) => a < b ? a : b),
'averageHopCount':
hopCounts.isEmpty
? 0.0
: hopCounts.reduce((a, b) => a + b) / hopCounts.length,
'maxHopCount':
hopCounts.isEmpty ? 0 : hopCounts.reduce((a, b) => a > b ? a : b),
'topologySize': routingTable.topology.totalLinks,
'activeLinks': routingTable.topology.activeLinkCount,
'failedLinks': routingTable.topology.failedLinkCount,
'networkDensity':
routingTable.topology.totalLinks /
(routingTable.totalNodes * (routingTable.totalNodes - 1)),
};
}