validateLinkStateTable method

List<String> validateLinkStateTable(
  1. LinkStateRoutingTable<T> routingTable,
  2. Map<T, Map<T, num>> network
)

Validates link-state routing table consistency

routingTable - Routing table to validate network - Network topology for validation

Returns list of validation errors (empty if valid)

Implementation

List<String> validateLinkStateTable(
  LinkStateRoutingTable<T> routingTable,
  Map<T, Map<T, num>> network,
) {
  final errors = <String>[];

  // Check if source node exists in network
  if (!network.containsKey(routingTable.sourceNode)) {
    errors.add('Source node ${routingTable.sourceNode} not found in network');
  }

  // Check for invalid costs
  for (final route in routingTable.routes.values) {
    if (route.cost < 0) {
      errors.add(
        'Invalid cost ${route.cost} for destination ${route.destination}',
      );
    }
    if (route.cost > _maxCost) {
      errors.add(
        'Cost ${route.cost} exceeds maximum cost $_maxCost for destination ${route.destination}',
      );
    }
  }

  // Check for circular routes
  for (final route in routingTable.routes.values) {
    if (route.path.length > 1 && route.path.first == route.path.last) {
      errors.add('Circular route detected: ${route.path}');
    }
  }

  // Check topology consistency
  for (final route in routingTable.routes.values) {
    for (int i = 0; i < route.path.length - 1; i++) {
      final current = route.path[i];
      final next = route.path[i + 1];
      if (!routingTable.topology.hasLink(current, next)) {
        errors.add(
          'Invalid path: link $current -> $next does not exist in topology',
        );
      }
    }
  }

  return errors;
}