Skip to content

Commit

Permalink
daemon: adjustments to get control manager in working order and actua…
Browse files Browse the repository at this point in the history
…lly creating all possible configured control nets, as well as avoiding issues when emane has already created these interfaces
  • Loading branch information
bharnden committed Sep 28, 2023
1 parent f67af05 commit b548869
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
37 changes: 29 additions & 8 deletions daemon/core/emulator/controlnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def get_net(self, index: int) -> Optional[CtrlNet]:
except CoreError:
return None

def setup_nets(self) -> None:
"""
Setup all configured control nets.
:return: nothing
"""
for index, prefix in self.net_prefixes.items():
if prefix:
self.add_net(index)

def add_net(self, index: int, conf_required: bool = True) -> Optional[CtrlNet]:
"""
Create a control network bridge as necessary. The conf_reqd flag,
Expand Down Expand Up @@ -187,17 +197,28 @@ def add_net(self, index: int, conf_required: bool = True) -> Optional[CtrlNet]:
control_net.startup()
return control_net

def remove_net(self, index: int) -> None:
def remove_nets(self) -> None:
"""
Removes control net.
Removes control nets.
:param index: index of control net to remove
:return: nothing
"""
control_net = self.get_net(index)
if control_net:
logger.info("removing control net index(%s)", index)
self.session.delete_node(control_net.id)
for index in self.net_prefixes:
control_net = self.get_net(index)
if control_net:
logger.info("removing control net index(%s)", index)
self.session.delete_node(control_net.id)

def setup_ifaces(self, node: CoreNode) -> None:
"""
Setup all configured control net interfaces for node.
:param node: node to configure control net interfaces for
:return: nothing
"""
for index in self.net_prefixes:
if self.get_net(index):
self.add_iface(node, index)

def add_iface(self, node: CoreNode, index: int) -> None:
"""
Expand All @@ -214,7 +235,7 @@ def add_iface(self, node: CoreNode, index: int) -> None:
raise CoreError(f"control net index({index}) does not exist")
iface_id = CTRL_NET_IFACE_ID + index
if node.ifaces.get(iface_id):
raise CoreError(f"control iface({iface_id}) already exists")
return
try:
logger.info(
"node(%s) adding control net index(%s) interface(%s)",
Expand Down
2 changes: 1 addition & 1 deletion daemon/core/emulator/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def create_gre_tunnel(
def tunnel_key(self, node1_id: int, node2_id: int) -> int:
"""
Compute a 32-bit key used to uniquely identify a GRE tunnel.
The hash(n1num), hash(n2num) values are used, so node numbers may be
The hash(node1_id), hash(node2_id) values are used, so node numbers may be
None or string values (used for e.g. "ctrlnet").
:param node1_id: node one id
Expand Down
35 changes: 14 additions & 21 deletions daemon/core/emulator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ def add_node(
self.mobility.set_model_config(node.id, BasicRangeModel.name)
# boot core nodes after runtime
if self.is_running() and isinstance(node, CoreNode):
self.control_net_manager.add_iface(node, 0)
self.boot_node(node)
self.sdt.add_node(node)
return node
Expand Down Expand Up @@ -910,10 +909,6 @@ def instantiate(self) -> list[Exception]:
if self.is_running():
logger.warning("ignoring instantiate, already in runtime state")
return []
# create control net interfaces and network tunnels
# which need to exist for emane to sync on location events
# in distributed scenarios
self.control_net_manager.add_net(0)
# initialize distributed tunnels
self.distributed.start()
# instantiate will be invoked again upon emane configure
Expand Down Expand Up @@ -985,9 +980,8 @@ def data_collect(self) -> None:
# update control interface hosts
self.control_net_manager.clear_etc_hosts()

# remove all four possible control networks
for i in range(4):
self.control_net_manager.remove_net(i)
# remove control networks
self.control_net_manager.remove_nets()

def short_session_id(self) -> str:
"""
Expand All @@ -1012,7 +1006,9 @@ def boot_node(self, node: CoreNode) -> None:
node.name,
", ".join(node.services.keys()),
)
node.start_services()
self.control_net_manager.setup_ifaces(node)
with self.nodes_lock:
node.start_services()

def boot_nodes(self) -> list[Exception]:
"""
Expand All @@ -1022,18 +1018,15 @@ def boot_nodes(self) -> list[Exception]:
:return: service boot exceptions
"""
with self.nodes_lock:
funcs = []
start = time.monotonic()
control_net = self.control_net_manager.add_net(0)
for node in self.nodes.values():
if isinstance(node, CoreNode):
if control_net:
self.control_net_manager.add_iface(node, 0)
funcs.append((self.boot_node, (node,), {}))
results, exceptions = utils.threadpool(funcs)
total = time.monotonic() - start
logger.debug("boot run time: %s", total)
funcs = []
start = time.monotonic()
self.control_net_manager.setup_nets()
for node in self.nodes.values():
if isinstance(node, CoreNode):
funcs.append((self.boot_node, (node,), {}))
results, exceptions = utils.threadpool(funcs)
total = time.monotonic() - start
logger.debug("boot run time: %s", total)
if not exceptions:
self.control_net_manager.update_etc_hosts()
return exceptions
Expand Down

0 comments on commit b548869

Please sign in to comment.