validateRoutingTable method
Validates routing table consistency and integrity
routingTable - Routing table to validate
network - Network topology for validation
Returns list of validation errors (empty if valid)
Implementation
List<String> validateRoutingTable(
RoutingTable<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 > _maxHops) {
errors.add(
'Cost ${route.cost} exceeds maximum hops $_maxHops for destination ${route.destination}',
);
}
}
// Check for circular routes
for (final route in routingTable.routes.values) {
if (route.nextHop != null && route.nextHop == routingTable.sourceNode) {
errors.add(
'Circular route detected: ${route.destination} -> ${route.nextHop}',
);
}
}
return errors;
}