Skip to content

Commit

Permalink
Addresses review comments, fixes tests
Browse files Browse the repository at this point in the history
Removes patches of private functions
Uses MAX_GATES-1 as gate index for default routes
  • Loading branch information
saltiyazan committed Sep 18, 2023
1 parent 8b88d00 commit f83da1d
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 166 deletions.
29 changes: 17 additions & 12 deletions conf/route_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ class RouteController:
Listens for netlink events and handling them.
Creates BESS modules for route entries."""

MAX_GATES = 8192
def __init__(
self,
bess_controller: BessController,
Expand Down Expand Up @@ -363,9 +365,9 @@ def bootstrap_routes(self) -> None:
if route["event"] == KEY_NEW_ROUTE_ACTION:
if route_entry := self._parse_route_entry_msg(route):
with self._lock:
self._handle_new_route_entry(route_entry)
self.add_new_route_entry(route_entry)

def _handle_new_route_entry(self, route_entry: RouteEntry) -> None:
def add_new_route_entry(self, route_entry: RouteEntry) -> None:
"""Handles a new route entry.
Args:
Expand All @@ -384,18 +386,22 @@ def _handle_new_route_entry(self, route_entry: RouteEntry) -> None:
def _add_neighbor(
self, route_entry: RouteEntry, next_hop_mac: str
) -> None:
"""Adds the route to next hop in BESS.
"""Adds the route in BESS module.
Creates required BESS modules.
Args:
route_entry (RouteEntry)
next_hop_mac (str): The MAC address of the next hop.
"""
route_module_name = self.get_route_module_name(route_entry.interface)
if route_entry.prefix_len == 0 and route_entry.dest_prefix == "0.0.0.0":
gate_idx = self.MAX_GATES - 1
else:
gate_idx = self._get_gate_idx(route_entry, route_module_name)
try:
self._bess_controller.add_route_to_module(
route_entry,
self._get_gate_idx(route_entry, route_module_name),
gate_idx=gate_idx,
module_name=route_module_name,
)

Expand All @@ -418,7 +424,6 @@ def _add_neighbor(
destination_mac=next_hop_mac,
update_module_name=update_module_name,
)
gate_idx = self._get_gate_idx(route_entry, route_module_name)
self._create_module_links(
gate_idx=gate_idx,
update_module_name=update_module_name,
Expand Down Expand Up @@ -459,9 +464,11 @@ def _create_update_module(
)
return

def _parse_new_neighbor(self, netlink_message: dict) -> None:
def add_unresolved_new_neighbor(self, netlink_message: dict) -> None:
"""Handle new neighbor event.
It will add the neighbor if it was in the unresolved ARP queries cache.
Args:
netlink_message (dict): The netlink message.
"""
Expand All @@ -471,11 +478,9 @@ def _parse_new_neighbor(self, netlink_message: dict) -> None:
)
gateway_mac = attr_dict[KEY_LINK_LAYER_ADDRESS]
if route_entry:

self._add_neighbor(
route_entry, gateway_mac
)

del self._unresolved_arp_queries_cache[
route_entry.next_hop_ip
]
Expand Down Expand Up @@ -519,7 +524,7 @@ def _create_module_links(
)
return

def _delete_route(self, route_entry: RouteEntry) -> None:
def delete_route_entry(self, route_entry: RouteEntry) -> None:
"""Deletes a route entry from BESS and the neighbor cache."""
next_hop = self._neighbor_cache.get(route_entry.next_hop_ip)

Expand Down Expand Up @@ -632,15 +637,15 @@ def _netlink_event_listener(
route_entry = self._parse_route_entry_msg(netlink_message)
if action == KEY_NEW_ROUTE_ACTION and route_entry:
with self._lock:
self._handle_new_route_entry(route_entry)
self.add_new_route_entry(route_entry)

elif action == KEY_DELETE_ROUTE_ACTION and route_entry:
with self._lock:
self._delete_route(route_entry)
self.delete_route_entry(route_entry)

elif action == KEY_NEW_NEIGHBOR_ACTION:
with self._lock:
self._parse_new_neighbor(netlink_message)
self.add_unresolved_new_neighbor(netlink_message)

def cleanup(self, number: int) -> None:
"""Unregisters the netlink event listener callback and exits."""
Expand Down
Loading

0 comments on commit f83da1d

Please sign in to comment.