daemon: CoreInterface now defaults to a virtual transport type, added utility methods to check if an interface is virtual/raw, cleaned up all emane code using these types of checks
This commit is contained in:
parent
ac1c27b1c8
commit
fcda1f9f14
3 changed files with 26 additions and 33 deletions
|
@ -26,7 +26,6 @@ from core.emulator.enumerations import (
|
||||||
LinkTypes,
|
LinkTypes,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
RegisterTlvs,
|
RegisterTlvs,
|
||||||
TransportType,
|
|
||||||
)
|
)
|
||||||
from core.errors import CoreCommandError, CoreError
|
from core.errors import CoreCommandError, CoreError
|
||||||
from core.nodes.base import CoreNode, NodeBase
|
from core.nodes.base import CoreNode, NodeBase
|
||||||
|
@ -536,8 +535,7 @@ class EmaneManager(ModelManager):
|
||||||
if realtime:
|
if realtime:
|
||||||
emanecmd += " -r"
|
emanecmd += " -r"
|
||||||
node = iface.node
|
node = iface.node
|
||||||
transport_type = emanexml.get_transport_type(iface)
|
if iface.is_virtual():
|
||||||
if not transport_type == TransportType.RAW:
|
|
||||||
otagroup, _otaport = self.get_config("otamanagergroup").split(":")
|
otagroup, _otaport = self.get_config("otamanagergroup").split(":")
|
||||||
otadev = self.get_config("otamanagerdevice")
|
otadev = self.get_config("otamanagerdevice")
|
||||||
otanetidx = self.session.get_control_net_index(otadev)
|
otanetidx = self.session.get_control_net_index(otadev)
|
||||||
|
@ -590,8 +588,7 @@ class EmaneManager(ModelManager):
|
||||||
node = iface.node
|
node = iface.node
|
||||||
if not node.up:
|
if not node.up:
|
||||||
continue
|
continue
|
||||||
transport_type = emanexml.get_transport_type(iface)
|
if iface.is_raw():
|
||||||
if transport_type == TransportType.RAW:
|
|
||||||
node.host_cmd(kill_emaned, wait=False)
|
node.host_cmd(kill_emaned, wait=False)
|
||||||
else:
|
else:
|
||||||
node.cmd(kill_emaned, wait=False)
|
node.cmd(kill_emaned, wait=False)
|
||||||
|
@ -614,7 +611,7 @@ class EmaneManager(ModelManager):
|
||||||
for key in sorted(self._emane_nets):
|
for key in sorted(self._emane_nets):
|
||||||
emane_net = self._emane_nets[key]
|
emane_net = self._emane_nets[key]
|
||||||
for iface in emane_net.get_ifaces():
|
for iface in emane_net.get_ifaces():
|
||||||
if iface.transport_type == TransportType.VIRTUAL:
|
if iface.is_virtual():
|
||||||
iface.shutdown()
|
iface.shutdown()
|
||||||
iface.poshook = None
|
iface.poshook = None
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class CoreInterface:
|
||||||
# placeholder position hook
|
# placeholder position hook
|
||||||
self.poshook: Callable[[CoreInterface], None] = lambda x: None
|
self.poshook: Callable[[CoreInterface], None] = lambda x: None
|
||||||
# used with EMANE
|
# used with EMANE
|
||||||
self.transport_type: Optional[TransportType] = None
|
self.transport_type: TransportType = TransportType.VIRTUAL
|
||||||
# id of interface for node
|
# id of interface for node
|
||||||
self.node_id: Optional[int] = None
|
self.node_id: Optional[int] = None
|
||||||
# id of interface for network
|
# id of interface for network
|
||||||
|
@ -310,6 +310,22 @@ class CoreInterface:
|
||||||
"""
|
"""
|
||||||
return id(self) < id(other)
|
return id(self) < id(other)
|
||||||
|
|
||||||
|
def is_raw(self) -> bool:
|
||||||
|
"""
|
||||||
|
Used to determine if this interface is considered a raw interface.
|
||||||
|
|
||||||
|
:return: True if raw interface, False otherwise
|
||||||
|
"""
|
||||||
|
return self.transport_type == TransportType.RAW
|
||||||
|
|
||||||
|
def is_virtual(self) -> bool:
|
||||||
|
"""
|
||||||
|
Used to determine if this interface is considered a virtual interface.
|
||||||
|
|
||||||
|
:return: True if virtual interface, False otherwise
|
||||||
|
"""
|
||||||
|
return self.transport_type == TransportType.VIRTUAL
|
||||||
|
|
||||||
|
|
||||||
class Veth(CoreInterface):
|
class Veth(CoreInterface):
|
||||||
"""
|
"""
|
||||||
|
@ -404,7 +420,6 @@ class TunTap(CoreInterface):
|
||||||
:param start: start flag
|
:param start: start flag
|
||||||
"""
|
"""
|
||||||
super().__init__(session, node, name, localname, mtu, server)
|
super().__init__(session, node, name, localname, mtu, server)
|
||||||
self.transport_type = TransportType.VIRTUAL
|
|
||||||
if start:
|
if start:
|
||||||
self.startup()
|
self.startup()
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ from core import utils
|
||||||
from core.config import Configuration
|
from core.config import Configuration
|
||||||
from core.emane.nodes import EmaneNet
|
from core.emane.nodes import EmaneNet
|
||||||
from core.emulator.distributed import DistributedServer
|
from core.emulator.distributed import DistributedServer
|
||||||
from core.emulator.enumerations import TransportType
|
|
||||||
from core.errors import CoreError
|
from core.errors import CoreError
|
||||||
from core.nodes.interface import CoreInterface
|
from core.nodes.interface import CoreInterface
|
||||||
from core.nodes.network import CtrlNet
|
from core.nodes.network import CtrlNet
|
||||||
|
@ -92,8 +91,7 @@ def create_iface_file(
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
node = iface.node
|
node = iface.node
|
||||||
transport_type = get_transport_type(iface)
|
if iface.is_raw():
|
||||||
if transport_type == TransportType.RAW:
|
|
||||||
file_path = os.path.join(node.session.session_dir, file_name)
|
file_path = os.path.join(node.session.session_dir, file_name)
|
||||||
else:
|
else:
|
||||||
file_path = os.path.join(node.nodedir, file_name)
|
file_path = os.path.join(node.nodedir, file_name)
|
||||||
|
@ -185,12 +183,11 @@ def build_platform_xml(
|
||||||
)
|
)
|
||||||
add_param(transport_element, "device", iface.name)
|
add_param(transport_element, "device", iface.name)
|
||||||
|
|
||||||
transport_type = get_transport_type(iface)
|
|
||||||
transport_configs = {"otamanagerdevice", "eventservicedevice"}
|
transport_configs = {"otamanagerdevice", "eventservicedevice"}
|
||||||
platform_element = etree.Element("platform")
|
platform_element = etree.Element("platform")
|
||||||
for configuration in emane_manager.emane_config.emulator_config:
|
for configuration in emane_manager.emane_config.emulator_config:
|
||||||
name = configuration.id
|
name = configuration.id
|
||||||
if transport_type == TransportType.RAW and name in transport_configs:
|
if iface.is_raw() and name in transport_configs:
|
||||||
value = control_net.brname
|
value = control_net.brname
|
||||||
else:
|
else:
|
||||||
value = emane_manager.get_config(name)
|
value = emane_manager.get_config(name)
|
||||||
|
@ -214,7 +211,7 @@ def create_transport_xml(iface: CoreInterface, config: Dict[str, str]) -> None:
|
||||||
:param config: all current configuration values
|
:param config: all current configuration values
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
transport_type = get_transport_type(iface)
|
transport_type = iface.transport_type
|
||||||
transport_element = etree.Element(
|
transport_element = etree.Element(
|
||||||
"transport",
|
"transport",
|
||||||
name=f"{transport_type.value.capitalize()} Transport",
|
name=f"{transport_type.value.capitalize()} Transport",
|
||||||
|
@ -224,7 +221,7 @@ def create_transport_xml(iface: CoreInterface, config: Dict[str, str]) -> None:
|
||||||
|
|
||||||
# get emane model cnfiguration
|
# get emane model cnfiguration
|
||||||
flowcontrol = config.get("flowcontrolenable", "0") == "1"
|
flowcontrol = config.get("flowcontrolenable", "0") == "1"
|
||||||
if transport_type == TransportType.VIRTUAL:
|
if iface.is_virtual():
|
||||||
device_path = "/dev/net/tun_flowctl"
|
device_path = "/dev/net/tun_flowctl"
|
||||||
if not os.path.exists(device_path):
|
if not os.path.exists(device_path):
|
||||||
device_path = "/dev/net/tun"
|
device_path = "/dev/net/tun"
|
||||||
|
@ -338,19 +335,6 @@ def create_event_service_xml(
|
||||||
create_file(event_element, "emaneeventmsgsvc", file_path, server)
|
create_file(event_element, "emaneeventmsgsvc", file_path, server)
|
||||||
|
|
||||||
|
|
||||||
def get_transport_type(iface: CoreInterface) -> TransportType:
|
|
||||||
"""
|
|
||||||
Get transport type for a given interface.
|
|
||||||
|
|
||||||
:param iface: interface to get transport type for
|
|
||||||
:return: transport type
|
|
||||||
"""
|
|
||||||
transport_type = TransportType.VIRTUAL
|
|
||||||
if iface.transport_type == TransportType.RAW:
|
|
||||||
transport_type = TransportType.RAW
|
|
||||||
return transport_type
|
|
||||||
|
|
||||||
|
|
||||||
def transport_file_name(iface: CoreInterface) -> str:
|
def transport_file_name(iface: CoreInterface) -> str:
|
||||||
"""
|
"""
|
||||||
Create name for a transport xml file.
|
Create name for a transport xml file.
|
||||||
|
@ -358,8 +342,7 @@ def transport_file_name(iface: CoreInterface) -> str:
|
||||||
:param iface: interface running emane
|
:param iface: interface running emane
|
||||||
:return: transport xml file name
|
:return: transport xml file name
|
||||||
"""
|
"""
|
||||||
transport_type = get_transport_type(iface)
|
return f"{iface.name}-trans-{iface.transport_type.value}.xml"
|
||||||
return f"{iface.name}-trans-{transport_type.value}.xml"
|
|
||||||
|
|
||||||
|
|
||||||
def nem_file_name(iface: CoreInterface) -> str:
|
def nem_file_name(iface: CoreInterface) -> str:
|
||||||
|
@ -369,9 +352,7 @@ def nem_file_name(iface: CoreInterface) -> str:
|
||||||
:param iface: interface running emane
|
:param iface: interface running emane
|
||||||
:return: nem xm file name
|
:return: nem xm file name
|
||||||
"""
|
"""
|
||||||
append = ""
|
append = "-raw" if iface.is_raw() else ""
|
||||||
if iface and iface.transport_type == TransportType.RAW:
|
|
||||||
append = "-raw"
|
|
||||||
return f"{iface.name}-nem{append}.xml"
|
return f"{iface.name}-nem{append}.xml"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue