Commit cdde1e57 authored by Alberts S's avatar Alberts S
Browse files

Refactoring ControllerStatic

parent 6fef9492
import asyncio
import ipaddress
from datetime import datetime
from typing import Type
import networkx as nx
from CapybaraNetty import CapybaraNetty
from Router import Router
class ControllerStatic(CapybaraNetty):
......@@ -17,7 +20,8 @@ class ControllerStatic(CapybaraNetty):
async def run(self):
if len(self.pinger_data) > 0:
G = self.get_latency_graph()
G = nx.Graph()
G = self.get_latency_graph(G)
self.find_viable_paths(G)
current_best_routes = await self.get_viable_external_routes(G)
await self.install_viable_external_routes(current_best_routes)
......@@ -25,8 +29,7 @@ class ControllerStatic(CapybaraNetty):
# print(G)
# G_simple = await self.get_host_latency_overview()
def get_latency_graph(self):
G = nx.Graph()
def get_latency_graph(self, G: nx.Graph):
for result in self.pinger_data:
host = result["from_name"]
dest = result["to_name"]
......@@ -118,11 +121,15 @@ class ControllerStatic(CapybaraNetty):
# Compare existing routes and the ones which are CURRENT best routes
# If there are any existing routes which are not used in CURRENT - delete them
for router, new_routes in current_best_routes.items():
for router, new_route_candidates in current_best_routes.items():
# Convert dict to list of routes
current_managed_routes = list(router.managed_routes.values())
routes_to_be_deleted = [old_route for old_route in current_managed_routes if old_route not in new_routes]
routes_to_be_added = [new_route for new_route in new_routes if new_route not in current_managed_routes]
routes_to_be_deleted = [
old_route for old_route in current_managed_routes if old_route not in new_route_candidates
]
routes_to_be_added = [
new_route for new_route in new_route_candidates if new_route not in current_managed_routes
]
self.__logger.debug(f"{router.log_name()} has {len(routes_to_be_deleted)} DEL ROUTE actions")
self.__logger.debug(f"{router.log_name()} has {len(routes_to_be_added)} ADD ROUTE actions")
coroutines.append(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment