updateFromBGPUpdate method

BGPRoutingTable<T>? updateFromBGPUpdate(
  1. BGPRoutingTable<T> currentTable,
  2. Map<T, BGPRouteEntry<T>> updates,
  3. Map<T, Map<T, num>> asTopology
)

Updates routing table based on received BGP updates

currentTable - Current routing table updates - BGP route updates from neighbors asTopology - Current AS topology

Returns updated routing table if changes occurred

Implementation

BGPRoutingTable<T>? updateFromBGPUpdate(
  BGPRoutingTable<T> currentTable,
  Map<T, BGPRouteEntry<T>> updates,
  Map<T, Map<T, num>> asTopology,
) {
  bool hasChanges = false;
  final updatedRoutes = Map<T, BGPRouteEntry<T>>.from(currentTable.routes);

  for (final entry in updates.entries) {
    final destination = entry.key;
    final updateRoute = entry.value;

    // Check if we have a better route
    if (!updatedRoutes.containsKey(destination) ||
        _isBetterRoute(updateRoute, updatedRoutes[destination]!)) {
      updatedRoutes[destination] = updateRoute;
      hasChanges = true;
    }
  }

  if (!hasChanges) return null;

  // Recompute routing table with new information
  return computeRoutes(asTopology, currentTable.sourceAS);
}