只有hello包实现多跳,还没加入业务数据

具体的还要看opencode和gpt记录接着优化
This commit is contained in:
sinlatansen
2026-02-24 17:17:45 +08:00
parent 375febb4c0
commit d357a25076
14 changed files with 1690 additions and 58 deletions

View File

@@ -0,0 +1,57 @@
"""
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,
}