Merge pull request #459 from coreemu/enhancement/transport-type-enum

turned transport type usages of raw and virtual across the board to a…
This commit is contained in:
bharnden 2020-05-29 23:44:11 -07:00 committed by GitHub
commit 13fb5db85d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 49 deletions

View file

@ -11,6 +11,7 @@ from lxml import etree
from core.config import ConfigGroup, Configuration from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest, emanemodel from core.emane import emanemanifest, emanemodel
from core.emane.nodes import EmaneNet from core.emane.nodes import EmaneNet
from core.emulator.enumerations import TransportType
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
from core.xml import emanexml from core.xml import emanexml
@ -79,9 +80,9 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
# create and write nem document # create and write nem document
nem_element = etree.Element("nem", name=f"{self.name} NEM", type="unstructured") nem_element = etree.Element("nem", name=f"{self.name} NEM", type="unstructured")
transport_type = "virtual" transport_type = TransportType.VIRTUAL
if interface and interface.transport_type == "raw": if interface and interface.transport_type == TransportType.RAW:
transport_type = "raw" transport_type = TransportType.RAW
transport_file = emanexml.transport_file_name(self.id, transport_type) transport_file = emanexml.transport_file_name(self.id, transport_type)
etree.SubElement(nem_element, "transport", definition=transport_file) etree.SubElement(nem_element, "transport", definition=transport_file)

View file

@ -30,6 +30,7 @@ from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNode, NodeBase from core.nodes.base import CoreNode, NodeBase
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
from core.nodes.network import CtrlNet from core.nodes.network import CtrlNet
from core.nodes.physical import Rj45Node
from core.xml import emanexml from core.xml import emanexml
if TYPE_CHECKING: if TYPE_CHECKING:
@ -596,7 +597,7 @@ class EmaneManager(ModelManager):
run_emane_on_host = False run_emane_on_host = False
for node in self.getnodes(): for node in self.getnodes():
if hasattr(node, "transport_type") and node.transport_type == "raw": if isinstance(node, Rj45Node):
run_emane_on_host = True run_emane_on_host = True
continue continue
path = self.session.session_dir path = self.session.session_dir
@ -655,7 +656,7 @@ class EmaneManager(ModelManager):
kill_transortd = "killall -q emanetransportd" kill_transortd = "killall -q emanetransportd"
stop_emane_on_host = False stop_emane_on_host = False
for node in self.getnodes(): for node in self.getnodes():
if hasattr(node, "transport_type") and node.transport_type == "raw": if isinstance(node, Rj45Node):
stop_emane_on_host = True stop_emane_on_host = True
continue continue

View file

@ -8,7 +8,7 @@ from typing import Dict, List
from core.config import ConfigGroup, Configuration from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest from core.emane import emanemanifest
from core.emane.nodes import EmaneNet from core.emane.nodes import EmaneNet
from core.emulator.enumerations import ConfigDataTypes from core.emulator.enumerations import ConfigDataTypes, TransportType
from core.errors import CoreError from core.errors import CoreError
from core.location.mobility import WirelessModel from core.location.mobility import WirelessModel
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
@ -111,9 +111,9 @@ class EmaneModel(WirelessModel):
server = interface.node.server server = interface.node.server
# check if this is external # check if this is external
transport_type = "virtual" transport_type = TransportType.VIRTUAL
if interface and interface.transport_type == "raw": if interface and interface.transport_type == TransportType.RAW:
transport_type = "raw" transport_type = TransportType.RAW
transport_name = emanexml.transport_file_name(self.id, transport_type) transport_name = emanexml.transport_file_name(self.id, transport_type)
# create nem xml file # create nem xml file

View file

@ -8,7 +8,13 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type
from core.emulator.data import LinkData from core.emulator.data import LinkData
from core.emulator.distributed import DistributedServer from core.emulator.distributed import DistributedServer
from core.emulator.enumerations import LinkTypes, MessageFlags, NodeTypes, RegisterTlvs from core.emulator.enumerations import (
LinkTypes,
MessageFlags,
NodeTypes,
RegisterTlvs,
TransportType,
)
from core.nodes.base import CoreNetworkBase from core.nodes.base import CoreNetworkBase
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
@ -173,7 +179,7 @@ class EmaneNet(CoreNetworkBase):
emanetransportd terminates. emanetransportd terminates.
""" """
for netif in self.netifs(): for netif in self.netifs():
if "virtual" in netif.transport_type.lower(): if netif.transport_type == TransportType.VIRTUAL:
netif.shutdown() netif.shutdown()
netif.poshook = None netif.poshook = None

View file

@ -117,3 +117,8 @@ class ExceptionLevels(Enum):
ERROR = 2 ERROR = 2
WARNING = 3 WARNING = 3
NOTICE = 4 NOTICE = 4
class TransportType(Enum):
RAW = "raw"
VIRTUAL = "virtual"

View file

@ -4,12 +4,12 @@ virtual ethernet classes that implement the interfaces available under Linux.
import logging import logging
import time import time
from typing import TYPE_CHECKING, Callable, Dict, List, Tuple from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
from core import utils from core import utils
from core.emulator.enumerations import MessageFlags from core.emulator.enumerations import MessageFlags, TransportType
from core.errors import CoreCommandError from core.errors import CoreCommandError
from core.nodes.netclient import get_net_client from core.nodes.netclient import LinuxNetClient, get_net_client
if TYPE_CHECKING: if TYPE_CHECKING:
from core.emulator.distributed import DistributedServer from core.emulator.distributed import DistributedServer
@ -42,32 +42,30 @@ class CoreInterface:
:param server: remote server node :param server: remote server node
will run on, default is None for localhost will run on, default is None for localhost
""" """
self.session = session self.session: "Session" = session
self.node = node self.node: "CoreNode" = node
self.name = name self.name: str = name
self.localname = localname self.localname: str = localname
self.up = False self.up: bool = False
if not isinstance(mtu, int): self.mtu: int = mtu
raise ValueError self.net: Optional[CoreNetworkBase] = None
self.mtu = mtu self.othernet: Optional[CoreNetworkBase] = None
self.net = None
self.othernet = None
self._params = {} self._params = {}
self.addrlist = [] self.addrlist: List[str] = []
self.hwaddr = None self.hwaddr: Optional[str] = None
# placeholder position hook # placeholder position hook
self.poshook = lambda x: None self.poshook: Callable[[CoreInterface], None] = lambda x: None
# used with EMANE # used with EMANE
self.transport_type = None self.transport_type: Optional[TransportType] = None
# node interface index # node interface index
self.netindex = None self.netindex: Optional[int] = None
# net interface index # net interface index
self.netifi = None self.netifi: Optional[int] = None
# index used to find flow data # index used to find flow data
self.flow_id = None self.flow_id: Optional[int] = None
self.server = server self.server: Optional["DistributedServer"] = server
use_ovs = session.options.get_config("ovs") == "True" use_ovs = session.options.get_config("ovs") == "True"
self.net_client = get_net_client(use_ovs, self.host_cmd) self.net_client: LinuxNetClient = get_net_client(use_ovs, self.host_cmd)
def host_cmd( def host_cmd(
self, self,
@ -330,7 +328,7 @@ 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 = "virtual" self.transport_type = TransportType.VIRTUAL
if start: if start:
self.startup() self.startup()
@ -516,7 +514,7 @@ class GreTap(CoreInterface):
sessionid = session.short_session_id() sessionid = session.short_session_id()
localname = f"gt.{self.id}.{sessionid}" localname = f"gt.{self.id}.{sessionid}"
super().__init__(session, node, name, localname, mtu, server) super().__init__(session, node, name, localname, mtu, server)
self.transport_type = "raw" self.transport_type = TransportType.RAW
if not start: if not start:
return return
if remoteip is None: if remoteip is None:

View file

@ -10,7 +10,7 @@ from typing import IO, TYPE_CHECKING, List, Optional, Tuple
from core import utils from core import utils
from core.constants import MOUNT_BIN, UMOUNT_BIN from core.constants import MOUNT_BIN, UMOUNT_BIN
from core.emulator.distributed import DistributedServer from core.emulator.distributed import DistributedServer
from core.emulator.enumerations import NodeTypes from core.emulator.enumerations import NodeTypes, TransportType
from core.errors import CoreCommandError, CoreError from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNetworkBase, CoreNodeBase from core.nodes.base import CoreNetworkBase, CoreNodeBase
from core.nodes.interface import CoreInterface, Veth from core.nodes.interface import CoreInterface, Veth
@ -281,7 +281,7 @@ class Rj45Node(CoreNodeBase):
""" """
super().__init__(session, _id, name, start, server) super().__init__(session, _id, name, start, server)
self.interface = CoreInterface(session, self, name, name, mtu, server) self.interface = CoreInterface(session, self, name, name, mtu, server)
self.interface.transport_type = "raw" self.interface.transport_type = TransportType.RAW
self.lock: threading.RLock = threading.RLock() self.lock: threading.RLock = threading.RLock()
self.ifindex: Optional[int] = None self.ifindex: Optional[int] = None
self.old_up: bool = False self.old_up: bool = False

View file

@ -9,6 +9,7 @@ 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.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
from core.nodes.network import CtrlNet from core.nodes.network import CtrlNet
from core.xml import corexml from core.xml import corexml
@ -182,7 +183,7 @@ def build_node_platform_xml(
transport_type = netif.transport_type transport_type = netif.transport_type
if not transport_type: if not transport_type:
logging.info("warning: %s interface type unsupported!", netif.name) logging.info("warning: %s interface type unsupported!", netif.name)
transport_type = "raw" transport_type = TransportType.RAW
transport_file = transport_file_name(node.id, transport_type) transport_file = transport_file_name(node.id, transport_type)
transport_element = etree.SubElement( transport_element = etree.SubElement(
nem_element, "transport", definition=transport_file nem_element, "transport", definition=transport_file
@ -196,7 +197,7 @@ def build_node_platform_xml(
# merging code # merging code
key = netif.node.id key = netif.node.id
if netif.transport_type == "raw": if netif.transport_type == TransportType.RAW:
key = "host" key = "host"
otadev = control_net.brname otadev = control_net.brname
eventdev = control_net.brname eventdev = control_net.brname
@ -276,8 +277,8 @@ def build_xml_files(emane_manager: "EmaneManager", node: EmaneNet) -> None:
# build XML for specific interface (NEM) configs # build XML for specific interface (NEM) configs
need_virtual = False need_virtual = False
need_raw = False need_raw = False
vtype = "virtual" vtype = TransportType.VIRTUAL
rtype = "raw" rtype = TransportType.RAW
for netif in node.netifs(): for netif in node.netifs():
# check for interface specific emane configuration and write xml files # check for interface specific emane configuration and write xml files
@ -286,7 +287,7 @@ def build_xml_files(emane_manager: "EmaneManager", node: EmaneNet) -> None:
node.model.build_xml_files(config, netif) node.model.build_xml_files(config, netif)
# check transport type needed for interface # check transport type needed for interface
if "virtual" in netif.transport_type: if netif.transport_type == TransportType.VIRTUAL:
need_virtual = True need_virtual = True
vtype = netif.transport_type vtype = netif.transport_type
else: else:
@ -301,7 +302,7 @@ def build_xml_files(emane_manager: "EmaneManager", node: EmaneNet) -> None:
def build_transport_xml( def build_transport_xml(
emane_manager: "EmaneManager", node: EmaneNet, transport_type: str emane_manager: "EmaneManager", node: EmaneNet, transport_type: TransportType
) -> None: ) -> None:
""" """
Build transport xml file for node and transport type. Build transport xml file for node and transport type.
@ -314,8 +315,8 @@ def build_transport_xml(
""" """
transport_element = etree.Element( transport_element = etree.Element(
"transport", "transport",
name=f"{transport_type.capitalize()} Transport", name=f"{transport_type.value.capitalize()} Transport",
library=f"trans{transport_type.lower()}", library=f"trans{transport_type.value.lower()}",
) )
# add bitrate # add bitrate
@ -325,7 +326,7 @@ def build_transport_xml(
config = emane_manager.get_configs(node.id, node.model.name) config = emane_manager.get_configs(node.id, node.model.name)
flowcontrol = config.get("flowcontrolenable", "0") == "1" flowcontrol = config.get("flowcontrolenable", "0") == "1"
if "virtual" in transport_type.lower(): if transport_type == TransportType.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"
@ -482,7 +483,7 @@ def create_event_service_xml(
create_file(event_element, "emaneeventmsgsvc", file_path, server) create_file(event_element, "emaneeventmsgsvc", file_path, server)
def transport_file_name(node_id: int, transport_type: str) -> str: def transport_file_name(node_id: int, transport_type: TransportType) -> str:
""" """
Create name for a transport xml file. Create name for a transport xml file.
@ -490,7 +491,7 @@ def transport_file_name(node_id: int, transport_type: str) -> str:
:param transport_type: transport type to generate transport file :param transport_type: transport type to generate transport file
:return: :return:
""" """
return f"n{node_id}trans{transport_type}.xml" return f"n{node_id}trans{transport_type.value}.xml"
def _basename(emane_model: "EmaneModel", interface: CoreInterface = None) -> str: def _basename(emane_model: "EmaneModel", interface: CoreInterface = None) -> str:
@ -521,7 +522,7 @@ def nem_file_name(emane_model: "EmaneModel", interface: CoreInterface = None) ->
""" """
basename = _basename(emane_model, interface) basename = _basename(emane_model, interface)
append = "" append = ""
if interface and interface.transport_type == "raw": if interface and interface.transport_type == TransportType.RAW:
append = "_raw" append = "_raw"
return f"{basename}nem{append}.xml" return f"{basename}nem{append}.xml"