From 058935a202d646d6083bc3c487df16be6cd82fb5 Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Wed, 21 Feb 2024 20:49:48 -0800 Subject: [PATCH] Partially address issue with registrer_handler --- conf/route_control.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/conf/route_control.py b/conf/route_control.py index 8aa97e635f..4446494970 100755 --- a/conf/route_control.py +++ b/conf/route_control.py @@ -14,6 +14,7 @@ from threading import Lock, Thread from typing import Dict, List, Optional, Tuple +from pr2modules.netlink.rtnl.ifinfmsg import ifinfmsg from pybess.bess import * from pyroute2 import NDB, IPRoute from scapy.all import ICMP, IP, send @@ -345,6 +346,13 @@ def __init__( self._event_callback = None self._interfaces = interfaces + def register_handlers(self) -> None: + """Register handler function.""" + logger.info("Registering netlink event listener handler...") + self._event_callback = self._ndb.task_manager.register_handler(ifinfmsg, + self._netlink_event_listener + ) + def start_pinging_missing_entries(self) -> None: """Starts a new thread for ping missing entries.""" if not self._ping_missing_thread or not self._ping_missing_thread.is_alive(): @@ -596,12 +604,11 @@ def _get_gate_idx(self, route_entry: RouteEntry, module_name: str) -> int: return self._module_gate_count_cache[module_name] def _netlink_event_listener( - self, ndb: NDB, netlink_message: dict, action: str + self, netlink_message: dict, action: str ) -> None: """Listens for netlink events and handles them. Args: - ndb (NDB): The NDB object. netlink_message (dict): The netlink message. action (str): The action. """ @@ -620,8 +627,10 @@ def _netlink_event_listener( self.add_unresolved_new_neighbor(netlink_message) def cleanup(self, number: int) -> None: - """Exits execution.""" + """Unregisters the netlink event listener callback and exits.""" logger.info("Received: %i Exiting", number) + self._ndb.task_manager.unregister_callback(self._event_callback) + logger.info("Unregistered netlink event listener callback") sys.exit() def reconfigure(self, number: int) -> None: @@ -799,6 +808,7 @@ def register_signal_handlers(route_controller: RouteController) -> None: interfaces=interface_arg, ) route_controller.bootstrap_routes() + route_controller.register_handlers() route_controller.start_pinging_missing_entries() register_signal_handlers(route_controller=route_controller) logger.info("Sleep until a signal is received")