validateBGPTable method

List<String> validateBGPTable(
  1. BGPRoutingTable<T> routingTable,
  2. Map<T, Map<T, num>> asTopology
)

Validates BGP routing table consistency

routingTable - Routing table to validate asTopology - AS topology for validation

Returns list of validation errors (empty if valid)

Implementation

List<String> validateBGPTable(
  BGPRoutingTable<T> routingTable,
  Map<T, Map<T, num>> asTopology,
) {
  final errors = <String>[];

  // Check if source AS exists in topology
  if (!asTopology.containsKey(routingTable.sourceAS)) {
    errors.add('Source AS ${routingTable.sourceAS} not found in topology');
  }

  // Check for invalid AS path lengths
  for (final route in routingTable.routes.values) {
    if (route.asPathLength < 0) {
      errors.add(
        'Invalid AS path length ${route.asPathLength} for destination ${route.destination}',
      );
    }
    if (route.asPathLength > _maxASPathLength) {
      errors.add(
        'AS path length ${route.asPathLength} exceeds maximum $_maxASPathLength for destination ${route.destination}',
      );
    }
  }

  // Check for AS path loops
  for (final route in routingTable.routes.values) {
    if (_hasASPathLoop(route.asPath)) {
      errors.add(
        'AS path loop detected for destination ${route.destination}: ${route.asPath}',
      );
    }
  }

  return errors;
}