computeRoutes method

OSPFRoutingTable<T> computeRoutes(
  1. Map<T, Map<T, num>> network,
  2. T sourceRouter, {
  3. int areaId = 0,
})

Computes complete routing table for a source router using Dijkstra's algorithm

network - Network topology as adjacency list with link costs sourceRouter - Source router for routing table computation areaId - OSPF area ID (0 for backbone area)

Returns a complete OSPF routing table with optimal paths

Throws ArgumentError if source router doesn't exist in network

Implementation

OSPFRoutingTable<T> computeRoutes(
  Map<T, Map<T, num>> network,
  T sourceRouter, {
  int areaId = 0,
}) {
  // Input validation
  if (!network.containsKey(sourceRouter)) {
    throw ArgumentError('Source router $sourceRouter not found in network');
  }

  // Build link-state database from network topology
  final lsdb = _buildLinkStateDatabase(network, sourceRouter, areaId);

  // Compute shortest paths using Dijkstra's algorithm
  final routes = _computeShortestPaths(network, sourceRouter, lsdb, areaId);

  // Organize routes by area
  final areaRoutes = _organizeRoutesByArea(routes, areaId);

  return OSPFRoutingTable<T>(
    sourceRouter: sourceRouter,
    routes: Map.unmodifiable(routes),
    areaRoutes: Map.unmodifiable(areaRoutes),
    lastUpdate: DateTime.now(),
    totalAreas: areaRoutes.length,
  );
}