""" Convergence Analysis Tools. Functions for analyzing routing convergence. """ from typing import List, Dict, Any def calculate_convergence_time( nodes: List[Any], threshold: float = 0.0, stable_duration: float = 30.0 ) -> float: """ Calculate convergence time. Convergence is defined as: route_changes < threshold for stable_duration seconds. Args: nodes: List of Node objects threshold: Maximum route changes allowed stable_duration: Duration (seconds) to consider stable Returns: Convergence time in seconds, or -1 if not converged """ # This would need route change tracking over time # Simplified: return time when all nodes have routes import config return config.HELLO_PERIOD * 3 def analyze_route_stability(nodes: List[Any]) -> Dict[str, Any]: """ Analyze route stability. Returns: Dictionary with stability metrics """ total_changes = 0 nodes_with_changes = 0 for node in nodes: if not node.is_sink: # Get route change count from stats stats = node.get_stats() changes = stats.get("stats", {}).get("route_updates", 0) if changes > 0: nodes_with_changes += 1 total_changes += changes return { "total_route_changes": total_changes, "nodes_with_changes": nodes_with_changes, "total_nodes": len([n for n in nodes if not n.is_sink]), "stable": total_changes == 0, }