updateFromTopologyChanges method
LinkStateRoutingTable<T> ?
updateFromTopologyChanges(
- LinkStateRoutingTable<
T> currentTable, - List<
LinkStateEntry< topologyChanges,T> > - Map<
T, Map< networkT, num> >
Updates routing table based on topology changes
currentTable - Current routing table
topologyChanges - Changes in network topology
network - Current network topology
Returns updated routing table if changes occurred
Implementation
LinkStateRoutingTable<T>? updateFromTopologyChanges(
LinkStateRoutingTable<T> currentTable,
List<LinkStateEntry<T>> topologyChanges,
Map<T, Map<T, num>> network,
) {
// Check if any of the topology changes are significant using the helper method
final tempNodeLinks = <T, List<LinkStateEntry<T>>>{};
for (var entry in topologyChanges) {
tempNodeLinks[entry.sourceNode] = [entry];
}
if (!_hasSignificantChanges(
currentTable.topology,
LinkStateDatabase<T>(
nodeLinks: tempNodeLinks,
lastUpdate: DateTime.now(),
totalLinks: topologyChanges.length,
totalNodes: tempNodeLinks.length,
),
)) {
return null;
}
// Apply topology changes to LSDB
final updatedLSDB = _applyTopologyChanges(
currentTable.topology,
topologyChanges,
);
// Recompute routes using the updated LSDB
final updatedRoutes = _computeOptimalRoutes(
updatedLSDB,
currentTable.sourceNode,
);
// Compress paths if enabled
if (enablePathCompression) {
_compressPaths(updatedRoutes);
}
return LinkStateRoutingTable<T>(
sourceNode: currentTable.sourceNode,
routes: Map.unmodifiable(updatedRoutes),
topology: updatedLSDB,
lastUpdate: DateTime.now(),
totalRoutes: updatedRoutes.length,
totalNodes: currentTable.totalNodes,
);
}