getBGPStatistics method

Map<String, dynamic> getBGPStatistics(
  1. BGPRoutingTable<T> routingTable
)

Gets BGP statistics for monitoring and analysis

routingTable - Routing table to analyze

Returns map with various statistics

Implementation

Map<String, dynamic> getBGPStatistics(BGPRoutingTable<T> routingTable) {
  final routes = routingTable.routes.values;
  final asPaths = routes.map((r) => r.asPathLength).toList();
  final origins = routes.map((r) => r.origin).toList();

  return {
    'totalRoutes': routes.length,
    'directlyConnected': routes.where((r) => r.isDirectlyConnected).length,
    'indirectRoutes': routes.where((r) => !r.isDirectlyConnected).length,
    'averageASPathLength':
        asPaths.isEmpty
            ? 0.0
            : asPaths.reduce((a, b) => a + b) / asPaths.length,
    'maxASPathLength':
        asPaths.isEmpty ? 0 : asPaths.reduce((a, b) => a > b ? a : b),
    'minASPathLength':
        asPaths.isEmpty ? 0 : asPaths.reduce((a, b) => a < b ? a : b),
    'originDistribution': Map.fromEntries(
      BGPOrigin.values.map(
        (origin) => MapEntry(
          origin.toString(),
          origins.where((o) => o == origin).length,
        ),
      ),
    ),
    'communityCount': routes.fold(
      0,
      (sum, route) => sum + route.communities.length,
    ),
    'totalAlternativeRoutes': routingTable.alternativeRoutes.values.fold(
      0,
      (sum, alternatives) => sum + alternatives.length,
    ),
  };
}