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:
Blake Harnden 2020-07-03 09:08:36 -07:00
parent ac1c27b1c8
commit fcda1f9f14
3 changed files with 26 additions and 33 deletions

View file

@ -26,7 +26,6 @@ from core.emulator.enumerations import (
LinkTypes,
MessageFlags,
RegisterTlvs,
TransportType,
)
from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNode, NodeBase
@ -536,8 +535,7 @@ class EmaneManager(ModelManager):
if realtime:
emanecmd += " -r"
node = iface.node
transport_type = emanexml.get_transport_type(iface)
if not transport_type == TransportType.RAW:
if iface.is_virtual():
otagroup, _otaport = self.get_config("otamanagergroup").split(":")
otadev = self.get_config("otamanagerdevice")
otanetidx = self.session.get_control_net_index(otadev)
@ -590,8 +588,7 @@ class EmaneManager(ModelManager):
node = iface.node
if not node.up:
continue
transport_type = emanexml.get_transport_type(iface)
if transport_type == TransportType.RAW:
if iface.is_raw():
node.host_cmd(kill_emaned, wait=False)
else:
node.cmd(kill_emaned, wait=False)
@ -614,7 +611,7 @@ class EmaneManager(ModelManager):
for key in sorted(self._emane_nets):
emane_net = self._emane_nets[key]
for iface in emane_net.get_ifaces():
if iface.transport_type == TransportType.VIRTUAL:
if iface.is_virtual():
iface.shutdown()
iface.poshook = None

View file

@ -60,7 +60,7 @@ class CoreInterface:
# placeholder position hook
self.poshook: Callable[[CoreInterface], None] = lambda x: None
# used with EMANE
self.transport_type: Optional[TransportType] = None
self.transport_type: TransportType = TransportType.VIRTUAL
# id of interface for node
self.node_id: Optional[int] = None
# id of interface for network
@ -310,6 +310,22 @@ class CoreInterface:
"""
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):
"""
@ -404,7 +420,6 @@ class TunTap(CoreInterface):
:param start: start flag
"""
super().__init__(session, node, name, localname, mtu, server)
self.transport_type = TransportType.VIRTUAL
if start:
self.startup()

View file

@ -9,7 +9,6 @@ from core import utils
from core.config import Configuration
from core.emane.nodes import EmaneNet
from core.emulator.distributed import DistributedServer
from core.emulator.enumerations import TransportType
from core.errors import CoreError
from core.nodes.interface import CoreInterface
from core.nodes.network import CtrlNet
@ -92,8 +91,7 @@ def create_iface_file(
:return:
"""
node = iface.node
transport_type = get_transport_type(iface)
if transport_type == TransportType.RAW:
if iface.is_raw():
file_path = os.path.join(node.session.session_dir, file_name)
else:
file_path = os.path.join(node.nodedir, file_name)
@ -185,12 +183,11 @@ def build_platform_xml(
)
add_param(transport_element, "device", iface.name)
transport_type = get_transport_type(iface)
transport_configs = {"otamanagerdevice", "eventservicedevice"}
platform_element = etree.Element("platform")
for configuration in emane_manager.emane_config.emulator_config:
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
else:
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
:return: nothing
"""
transport_type = get_transport_type(iface)
transport_type = iface.transport_type
transport_element = etree.Element(
"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
flowcontrol = config.get("flowcontrolenable", "0") == "1"
if transport_type == TransportType.VIRTUAL:
if iface.is_virtual():
device_path = "/dev/net/tun_flowctl"
if not os.path.exists(device_path):
device_path = "/dev/net/tun"
@ -338,19 +335,6 @@ def create_event_service_xml(
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:
"""
Create name for a transport xml file.
@ -358,8 +342,7 @@ def transport_file_name(iface: CoreInterface) -> str:
:param iface: interface running emane
:return: transport xml file name
"""
transport_type = get_transport_type(iface)
return f"{iface.name}-trans-{transport_type.value}.xml"
return f"{iface.name}-trans-{iface.transport_type.value}.xml"
def nem_file_name(iface: CoreInterface) -> str:
@ -369,9 +352,7 @@ def nem_file_name(iface: CoreInterface) -> str:
:param iface: interface running emane
:return: nem xm file name
"""
append = ""
if iface and iface.transport_type == TransportType.RAW:
append = "-raw"
append = "-raw" if iface.is_raw() else ""
return f"{iface.name}-nem{append}.xml"