combined core.emulator.data and core.emulator.emudata, updated LinkData to leverage InterfaceData, instead of repeated interface fields, removed session from LinkData and LinkOptions

This commit is contained in:
Blake Harnden 2020-06-16 12:50:24 -07:00
parent 0725199d6d
commit eeca33e722
39 changed files with 332 additions and 399 deletions

View file

@ -92,7 +92,7 @@ from core.api.grpc.wlan_pb2 import (
WlanLinkRequest,
WlanLinkResponse,
)
from core.emulator.emudata import IpPrefixes
from core.emulator.data import IpPrefixes
class InterfaceHelper:

View file

@ -11,8 +11,7 @@ from core.api.grpc import common_pb2, core_pb2
from core.api.grpc.services_pb2 import NodeServiceData, ServiceConfig
from core.config import ConfigurableOptions
from core.emane.nodes import EmaneNet
from core.emulator.data import LinkData
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.data import InterfaceData, LinkData, LinkOptions, NodeOptions
from core.emulator.enumerations import LinkTypes, NodeTypes
from core.emulator.session import Session
from core.nodes.base import CoreNode, NodeBase
@ -308,6 +307,18 @@ def parse_emane_model_id(_id: int) -> Tuple[int, int]:
return node_id, iface_id
def convert_iface(iface_data: InterfaceData) -> core_pb2.Interface:
return core_pb2.Interface(
id=iface_data.id,
name=iface_data.name,
mac=iface_data.mac,
ip4=iface_data.ip4,
ip4mask=iface_data.ip4_mask,
ip6=iface_data.ip6,
ip6mask=iface_data.ip6_mask,
)
def convert_link(link_data: LinkData) -> core_pb2.Link:
"""
Convert link_data into core protobuf link.
@ -316,27 +327,11 @@ def convert_link(link_data: LinkData) -> core_pb2.Link:
:return: core protobuf Link
"""
iface1 = None
if link_data.iface1_id is not None:
iface1 = core_pb2.Interface(
id=link_data.iface1_id,
name=link_data.iface1_name,
mac=convert_value(link_data.iface1_mac),
ip4=convert_value(link_data.iface1_ip4),
ip4mask=link_data.iface1_ip4_mask,
ip6=convert_value(link_data.iface1_ip6),
ip6mask=link_data.iface1_ip6_mask,
)
if link_data.iface1 is not None:
iface1 = convert_iface(link_data.iface1)
iface2 = None
if link_data.iface2_id is not None:
iface2 = core_pb2.Interface(
id=link_data.iface2_id,
name=link_data.iface2_name,
mac=convert_value(link_data.iface2_mac),
ip4=convert_value(link_data.iface2_ip4),
ip4mask=link_data.iface2_ip4_mask,
ip6=convert_value(link_data.iface2_ip6),
ip6mask=link_data.iface2_ip6_mask,
)
if link_data.iface2 is not None:
iface2 = convert_iface(link_data.iface2)
options = core_pb2.LinkOptions(
opaque=link_data.opaque,
jitter=link_data.jitter,

View file

@ -108,8 +108,7 @@ from core.api.grpc.wlan_pb2 import (
WlanLinkResponse,
)
from core.emulator.coreemu import CoreEmu
from core.emulator.data import LinkData
from core.emulator.emudata import LinkOptions, NodeOptions
from core.emulator.data import LinkData, LinkOptions, NodeOptions
from core.emulator.enumerations import EventTypes, LinkTypes, MessageFlags
from core.emulator.session import NT, Session
from core.errors import CoreCommandError, CoreError

View file

@ -29,8 +29,15 @@ from core.api.tlv.enumerations import (
NodeTlvs,
SessionTlvs,
)
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.data import (
ConfigData,
EventData,
ExceptionData,
FileData,
InterfaceData,
LinkOptions,
NodeOptions,
)
from core.emulator.enumerations import (
ConfigDataTypes,
EventTypes,
@ -342,6 +349,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
dup = ""
if link_data.dup is not None:
dup = str(link_data.dup)
iface1 = link_data.iface1
if iface1 is None:
iface1 = InterfaceData()
iface2 = link_data.iface2
if iface2 is None:
iface2 = InterfaceData()
tlv_data = structutils.pack_values(
coreapi.CoreLinkTlv,
@ -355,7 +368,6 @@ class CoreHandler(socketserver.BaseRequestHandler):
(LinkTlvs.JITTER, link_data.jitter),
(LinkTlvs.MER, link_data.mer),
(LinkTlvs.BURST, link_data.burst),
(LinkTlvs.SESSION, link_data.session),
(LinkTlvs.MBURST, link_data.mburst),
(LinkTlvs.TYPE, link_data.link_type.value),
(LinkTlvs.GUI_ATTRIBUTES, link_data.gui_attributes),
@ -363,18 +375,18 @@ class CoreHandler(socketserver.BaseRequestHandler):
(LinkTlvs.EMULATION_ID, link_data.emulation_id),
(LinkTlvs.NETWORK_ID, link_data.network_id),
(LinkTlvs.KEY, link_data.key),
(LinkTlvs.IFACE1_NUMBER, link_data.iface1_id),
(LinkTlvs.IFACE1_IP4, link_data.iface1_ip4),
(LinkTlvs.IFACE1_IP4_MASK, link_data.iface1_ip4_mask),
(LinkTlvs.IFACE1_MAC, link_data.iface1_mac),
(LinkTlvs.IFACE1_IP6, link_data.iface1_ip6),
(LinkTlvs.IFACE1_IP6_MASK, link_data.iface1_ip6_mask),
(LinkTlvs.IFACE2_NUMBER, link_data.iface2_id),
(LinkTlvs.IFACE2_IP4, link_data.iface2_ip4),
(LinkTlvs.IFACE2_IP4_MASK, link_data.iface2_ip4_mask),
(LinkTlvs.IFACE2_MAC, link_data.iface2_mac),
(LinkTlvs.IFACE2_IP6, link_data.iface2_ip6),
(LinkTlvs.IFACE2_IP6_MASK, link_data.iface2_ip6_mask),
(LinkTlvs.IFACE1_NUMBER, iface1.id),
(LinkTlvs.IFACE1_IP4, iface1.ip4),
(LinkTlvs.IFACE1_IP4_MASK, iface1.ip4_mask),
(LinkTlvs.IFACE1_MAC, iface1.mac),
(LinkTlvs.IFACE1_IP6, iface1.ip6),
(LinkTlvs.IFACE1_IP6_MASK, iface1.ip6_mask),
(LinkTlvs.IFACE2_NUMBER, iface2.id),
(LinkTlvs.IFACE2_IP4, iface2.ip4),
(LinkTlvs.IFACE2_IP4_MASK, iface2.ip4_mask),
(LinkTlvs.IFACE2_MAC, iface2.mac),
(LinkTlvs.IFACE2_IP6, iface2.ip6),
(LinkTlvs.IFACE2_IP6_MASK, iface2.ip6_mask),
(LinkTlvs.OPAQUE, link_data.opaque),
],
)
@ -774,7 +786,6 @@ class CoreHandler(socketserver.BaseRequestHandler):
options = LinkOptions(type=link_type)
options.delay = message.get_tlv(LinkTlvs.DELAY.value)
options.bandwidth = message.get_tlv(LinkTlvs.BANDWIDTH.value)
options.session = message.get_tlv(LinkTlvs.SESSION.value)
options.loss = message.get_tlv(LinkTlvs.LOSS.value)
options.dup = message.get_tlv(LinkTlvs.DUP.value)
options.jitter = message.get_tlv(LinkTlvs.JITTER.value)

View file

@ -11,7 +11,7 @@ from lxml import etree
from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest, emanemodel
from core.emane.nodes import EmaneNet
from core.emulator.emudata import LinkOptions
from core.emulator.data import LinkOptions
from core.emulator.enumerations import TransportType
from core.nodes.interface import CoreInterface
from core.xml import emanexml

View file

@ -8,7 +8,7 @@ from typing import Dict, List, Optional, Set
from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest
from core.emane.nodes import EmaneNet
from core.emulator.emudata import LinkOptions
from core.emulator.data import LinkOptions
from core.emulator.enumerations import ConfigDataTypes, TransportType
from core.errors import CoreError
from core.location.mobility import WirelessModel

View file

@ -6,9 +6,8 @@ share the same MAC+PHY model.
import logging
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type
from core.emulator.data import LinkData
from core.emulator.data import LinkData, LinkOptions
from core.emulator.distributed import DistributedServer
from core.emulator.emudata import LinkOptions
from core.emulator.enumerations import (
LinkTypes,
MessageFlags,

View file

@ -1,10 +1,12 @@
"""
CORE data objects.
"""
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, List, Optional, Tuple
from dataclasses import dataclass
from typing import List, Tuple
import netaddr
from core import utils
from core.emulator.enumerations import (
EventTypes,
ExceptionLevels,
@ -13,6 +15,9 @@ from core.emulator.enumerations import (
NodeTypes,
)
if TYPE_CHECKING:
from core.nodes.base import CoreNode
@dataclass
class ConfigData:
@ -93,6 +98,57 @@ class NodeData:
source: str = None
@dataclass
class InterfaceData:
"""
Convenience class for storing interface data.
"""
id: int = None
name: str = None
mac: str = None
ip4: str = None
ip4_mask: int = None
ip6: str = None
ip6_mask: int = None
def get_addresses(self) -> List[str]:
"""
Returns a list of ip4 and ip6 addresses when present.
:return: list of addresses
"""
addresses = []
if self.ip4 and self.ip4_mask:
addresses.append(f"{self.ip4}/{self.ip4_mask}")
if self.ip6 and self.ip6_mask:
addresses.append(f"{self.ip6}/{self.ip6_mask}")
return addresses
@dataclass
class LinkOptions:
"""
Options for creating and updating links within core.
"""
type: LinkTypes = LinkTypes.WIRED
delay: int = None
bandwidth: int = None
loss: float = None
dup: int = None
jitter: int = None
mer: int = None
burst: int = None
mburst: int = None
gui_attributes: str = None
unidirectional: bool = None
emulation_id: int = None
network_id: int = None
key: int = None
opaque: str = None
@dataclass
class LinkData:
message_type: MessageFlags = None
@ -106,7 +162,6 @@ class LinkData:
jitter: float = None
mer: float = None
burst: float = None
session: int = None
mburst: float = None
link_type: LinkTypes = None
gui_attributes: str = None
@ -114,19 +169,151 @@ class LinkData:
emulation_id: int = None
network_id: int = None
key: int = None
iface1_id: int = None
iface1_name: str = None
iface1_ip4: str = None
iface1_ip4_mask: int = None
iface1_mac: str = None
iface1_ip6: str = None
iface1_ip6_mask: int = None
iface2_id: int = None
iface2_name: str = None
iface2_ip4: str = None
iface2_ip4_mask: int = None
iface2_mac: str = None
iface2_ip6: str = None
iface2_ip6_mask: int = None
iface1: InterfaceData = None
iface2: InterfaceData = None
opaque: str = None
color: str = None
class IpPrefixes:
"""
Convenience class to help generate IP4 and IP6 addresses for nodes within CORE.
"""
def __init__(self, ip4_prefix: str = None, ip6_prefix: str = None) -> None:
"""
Creates an IpPrefixes object.
:param ip4_prefix: ip4 prefix to use for generation
:param ip6_prefix: ip6 prefix to use for generation
:raises ValueError: when both ip4 and ip6 prefixes have not been provided
"""
if not ip4_prefix and not ip6_prefix:
raise ValueError("ip4 or ip6 must be provided")
self.ip4 = None
if ip4_prefix:
self.ip4 = netaddr.IPNetwork(ip4_prefix)
self.ip6 = None
if ip6_prefix:
self.ip6 = netaddr.IPNetwork(ip6_prefix)
def ip4_address(self, node_id: int) -> str:
"""
Convenience method to return the IP4 address for a node.
:param node_id: node id to get IP4 address for
:return: IP4 address or None
"""
if not self.ip4:
raise ValueError("ip4 prefixes have not been set")
return str(self.ip4[node_id])
def ip6_address(self, node_id: int) -> str:
"""
Convenience method to return the IP6 address for a node.
:param node_id: node id to get IP6 address for
:return: IP4 address or None
"""
if not self.ip6:
raise ValueError("ip6 prefixes have not been set")
return str(self.ip6[node_id])
def gen_iface(self, node_id: int, name: str = None, mac: str = None):
"""
Creates interface data for linking nodes, using the nodes unique id for
generation, along with a random mac address, unless provided.
:param node_id: node id to create an interface for
:param name: name to set for interface, default is eth{id}
:param mac: mac address to use for this interface, default is random
generation
:return: new interface data for the provided node
"""
# generate ip4 data
ip4 = None
ip4_mask = None
if self.ip4:
ip4 = self.ip4_address(node_id)
ip4_mask = self.ip4.prefixlen
# generate ip6 data
ip6 = None
ip6_mask = None
if self.ip6:
ip6 = self.ip6_address(node_id)
ip6_mask = self.ip6.prefixlen
# random mac
if not mac:
mac = utils.random_mac()
return InterfaceData(
name=name, ip4=ip4, ip4_mask=ip4_mask, ip6=ip6, ip6_mask=ip6_mask, mac=mac
)
def create_iface(
self, node: "CoreNode", name: str = None, mac: str = None
) -> InterfaceData:
"""
Creates interface data for linking nodes, using the nodes unique id for
generation, along with a random mac address, unless provided.
:param node: node to create interface for
:param name: name to set for interface, default is eth{id}
:param mac: mac address to use for this interface, default is random
generation
:return: new interface data for the provided node
"""
iface_data = self.gen_iface(node.id, name, mac)
iface_data.id = node.next_iface_id()
return iface_data
@dataclass
class NodeOptions:
"""
Options for creating and updating nodes within core.
"""
name: str = None
model: Optional[str] = "PC"
canvas: int = None
icon: str = None
opaque: str = None
services: List[str] = field(default_factory=list)
config_services: List[str] = field(default_factory=list)
x: float = None
y: float = None
lat: float = None
lon: float = None
alt: float = None
emulation_id: int = None
server: str = None
image: str = None
emane: str = None
def set_position(self, x: float, y: float) -> None:
"""
Convenience method for setting position.
:param x: x position
:param y: y position
:return: nothing
"""
self.x = x
self.y = y
def set_location(self, lat: float, lon: float, alt: float) -> None:
"""
Convenience method for setting location.
:param lat: latitude
:param lon: longitude
:param alt: altitude
:return: nothing
"""
self.lat = lat
self.lon = lon
self.alt = alt

View file

@ -1,206 +0,0 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, List, Optional
import netaddr
from core import utils
from core.emulator.enumerations import LinkTypes
if TYPE_CHECKING:
from core.nodes.base import CoreNode
@dataclass
class NodeOptions:
"""
Options for creating and updating nodes within core.
"""
name: str = None
model: Optional[str] = "PC"
canvas: int = None
icon: str = None
opaque: str = None
services: List[str] = field(default_factory=list)
config_services: List[str] = field(default_factory=list)
x: float = None
y: float = None
lat: float = None
lon: float = None
alt: float = None
emulation_id: int = None
server: str = None
image: str = None
emane: str = None
def set_position(self, x: float, y: float) -> None:
"""
Convenience method for setting position.
:param x: x position
:param y: y position
:return: nothing
"""
self.x = x
self.y = y
def set_location(self, lat: float, lon: float, alt: float) -> None:
"""
Convenience method for setting location.
:param lat: latitude
:param lon: longitude
:param alt: altitude
:return: nothing
"""
self.lat = lat
self.lon = lon
self.alt = alt
@dataclass
class LinkOptions:
"""
Options for creating and updating links within core.
"""
type: LinkTypes = LinkTypes.WIRED
session: int = None
delay: int = None
bandwidth: int = None
loss: float = None
dup: int = None
jitter: int = None
mer: int = None
burst: int = None
mburst: int = None
gui_attributes: str = None
unidirectional: bool = None
emulation_id: int = None
network_id: int = None
key: int = None
opaque: str = None
@dataclass
class InterfaceData:
"""
Convenience class for storing interface data.
"""
id: int = None
name: str = None
mac: str = None
ip4: str = None
ip4_mask: int = None
ip6: str = None
ip6_mask: int = None
def get_addresses(self) -> List[str]:
"""
Returns a list of ip4 and ip6 addresses when present.
:return: list of addresses
"""
addresses = []
if self.ip4 and self.ip4_mask:
addresses.append(f"{self.ip4}/{self.ip4_mask}")
if self.ip6 and self.ip6_mask:
addresses.append(f"{self.ip6}/{self.ip6_mask}")
return addresses
class IpPrefixes:
"""
Convenience class to help generate IP4 and IP6 addresses for nodes within CORE.
"""
def __init__(self, ip4_prefix: str = None, ip6_prefix: str = None) -> None:
"""
Creates an IpPrefixes object.
:param ip4_prefix: ip4 prefix to use for generation
:param ip6_prefix: ip6 prefix to use for generation
:raises ValueError: when both ip4 and ip6 prefixes have not been provided
"""
if not ip4_prefix and not ip6_prefix:
raise ValueError("ip4 or ip6 must be provided")
self.ip4 = None
if ip4_prefix:
self.ip4 = netaddr.IPNetwork(ip4_prefix)
self.ip6 = None
if ip6_prefix:
self.ip6 = netaddr.IPNetwork(ip6_prefix)
def ip4_address(self, node_id: int) -> str:
"""
Convenience method to return the IP4 address for a node.
:param node_id: node id to get IP4 address for
:return: IP4 address or None
"""
if not self.ip4:
raise ValueError("ip4 prefixes have not been set")
return str(self.ip4[node_id])
def ip6_address(self, node_id: int) -> str:
"""
Convenience method to return the IP6 address for a node.
:param node_id: node id to get IP6 address for
:return: IP4 address or None
"""
if not self.ip6:
raise ValueError("ip6 prefixes have not been set")
return str(self.ip6[node_id])
def gen_iface(self, node_id: int, name: str = None, mac: str = None):
"""
Creates interface data for linking nodes, using the nodes unique id for
generation, along with a random mac address, unless provided.
:param node_id: node id to create an interface for
:param name: name to set for interface, default is eth{id}
:param mac: mac address to use for this interface, default is random
generation
:return: new interface data for the provided node
"""
# generate ip4 data
ip4 = None
ip4_mask = None
if self.ip4:
ip4 = self.ip4_address(node_id)
ip4_mask = self.ip4.prefixlen
# generate ip6 data
ip6 = None
ip6_mask = None
if self.ip6:
ip6 = self.ip6_address(node_id)
ip6_mask = self.ip6.prefixlen
# random mac
if not mac:
mac = utils.random_mac()
return InterfaceData(
name=name, ip4=ip4, ip4_mask=ip4_mask, ip6=ip6, ip6_mask=ip6_mask, mac=mac
)
def create_iface(
self, node: "CoreNode", name: str = None, mac: str = None
) -> InterfaceData:
"""
Creates interface data for linking nodes, using the nodes unique id for
generation, along with a random mac address, unless provided.
:param node: node to create interface for
:param name: name to set for interface, default is eth{id}
:param mac: mac address to use for this interface, default is random
generation
:return: new interface data for the provided node
"""
iface_data = self.gen_iface(node.id, name, mac)
iface_data.id = node.next_iface_id()
return iface_data

View file

@ -22,11 +22,13 @@ from core.emulator.data import (
EventData,
ExceptionData,
FileData,
InterfaceData,
LinkData,
LinkOptions,
NodeData,
NodeOptions,
)
from core.emulator.distributed import DistributedController
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.enumerations import (
EventTypes,
ExceptionLevels,

View file

@ -13,8 +13,7 @@ from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
from core import utils
from core.config import ConfigGroup, ConfigurableOptions, Configuration, ModelManager
from core.emulator.data import EventData, LinkData
from core.emulator.emudata import LinkOptions
from core.emulator.data import EventData, LinkData, LinkOptions
from core.emulator.enumerations import (
ConfigDataTypes,
EventTypes,

View file

@ -14,8 +14,7 @@ import netaddr
from core import utils
from core.configservice.dependencies import ConfigServiceDependencies
from core.constants import MOUNT_BIN, VNODED_BIN
from core.emulator.data import LinkData, NodeData
from core.emulator.emudata import InterfaceData, LinkOptions
from core.emulator.data import InterfaceData, LinkData, LinkOptions, NodeData
from core.emulator.enumerations import LinkTypes, MessageFlags, NodeTypes
from core.errors import CoreCommandError, CoreError
from core.nodes.client import VnodeClient
@ -1096,19 +1095,18 @@ class CoreNetworkBase(NodeBase):
if uni:
unidirectional = 1
iface2_ip4 = None
iface2_ip4_mask = None
iface2_ip6 = None
iface2_ip6_mask = None
iface2 = InterfaceData(
id=linked_node.get_iface_id(iface), name=iface.name, mac=iface.hwaddr
)
for address in iface.addrlist:
ip, _sep, mask = address.partition("/")
mask = int(mask)
if netaddr.valid_ipv4(ip):
iface2_ip4 = ip
iface2_ip4_mask = mask
iface2.ip4 = ip
iface2.ip4_mask = mask
else:
iface2_ip6 = ip
iface2_ip6_mask = mask
iface2.ip6 = ip
iface2.ip6_mask = mask
link_data = LinkData(
message_type=flags,
@ -1116,13 +1114,7 @@ class CoreNetworkBase(NodeBase):
node2_id=linked_node.id,
link_type=self.linktype,
unidirectional=unidirectional,
iface2_id=linked_node.get_iface_id(iface),
iface2_name=iface.name,
iface2_mac=iface.hwaddr,
iface2_ip4=iface2_ip4,
iface2_ip4_mask=iface2_ip4_mask,
iface2_ip6=iface2_ip6,
iface2_ip6_mask=iface2_ip6_mask,
iface2=iface2,
delay=iface.getparam("delay"),
bandwidth=iface.getparam("bw"),
dup=iface.getparam("duplicate"),

View file

@ -11,8 +11,7 @@ import netaddr
from core import utils
from core.constants import EBTABLES_BIN, TC_BIN
from core.emulator.data import LinkData, NodeData
from core.emulator.emudata import InterfaceData, LinkOptions
from core.emulator.data import InterfaceData, LinkData, LinkOptions, NodeData
from core.emulator.enumerations import (
LinkTypes,
MessageFlags,
@ -894,33 +893,31 @@ class PtpNet(CoreNetwork):
if iface1.getparams() != iface2.getparams():
unidirectional = 1
iface1_ip4 = None
iface1_ip4_mask = None
iface1_ip6 = None
iface1_ip6_mask = None
iface1_data = InterfaceData(
id=iface1.node.get_iface_id(iface1), name=iface1.name, mac=iface1.hwaddr
)
for address in iface1.addrlist:
ip, _sep, mask = address.partition("/")
mask = int(mask)
if netaddr.valid_ipv4(ip):
iface1_ip4 = ip
iface1_ip4_mask = mask
iface1.ip4 = ip
iface1.ip4_mask = mask
else:
iface1_ip6 = ip
iface1_ip6_mask = mask
iface1.ip6 = ip
iface1.ip6_mask = mask
iface2_ip4 = None
iface2_ip4_mask = None
iface2_ip6 = None
iface2_ip6_mask = None
iface2_data = InterfaceData(
id=iface2.node.get_iface_id(iface2), name=iface2.name, mac=iface2.hwaddr
)
for address in iface2.addrlist:
ip, _sep, mask = address.partition("/")
mask = int(mask)
if netaddr.valid_ipv4(ip):
iface2_ip4 = ip
iface2_ip4_mask = mask
iface2.ip4 = ip
iface2.ip4_mask = mask
else:
iface2_ip6 = ip
iface2_ip6_mask = mask
iface2.ip6 = ip
iface2.ip6_mask = mask
link_data = LinkData(
message_type=flags,
@ -933,26 +930,16 @@ class PtpNet(CoreNetwork):
loss=iface1.getparam("loss"),
dup=iface1.getparam("duplicate"),
jitter=iface1.getparam("jitter"),
iface1_id=iface1.node.get_iface_id(iface1),
iface1_name=iface1.name,
iface1_mac=iface1.hwaddr,
iface1_ip4=iface1_ip4,
iface1_ip4_mask=iface1_ip4_mask,
iface1_ip6=iface1_ip6,
iface1_ip6_mask=iface1_ip6_mask,
iface2_id=iface2.node.get_iface_id(iface2),
iface2_name=iface2.name,
iface2_mac=iface2.hwaddr,
iface2_ip4=iface2_ip4,
iface2_ip4_mask=iface2_ip4_mask,
iface2_ip6=iface2_ip6,
iface2_ip6_mask=iface2_ip6_mask,
iface1=iface1_data,
iface2=iface2_data,
)
all_links.append(link_data)
# build a 2nd link message for the upstream link parameters
# (swap if1 and if2)
if unidirectional:
iface1_data = InterfaceData(id=iface2.node.get_iface_id(iface2))
iface2_data = InterfaceData(id=iface1.node.get_iface_id(iface1))
link_data = LinkData(
message_type=MessageFlags.NONE,
link_type=self.linktype,
@ -964,8 +951,8 @@ class PtpNet(CoreNetwork):
dup=iface2.getparam("duplicate"),
jitter=iface2.getparam("jitter"),
unidirectional=1,
iface1_id=iface2.node.get_iface_id(iface2),
iface2_id=iface1.node.get_iface_id(iface1),
iface1=iface1_data,
iface2=iface2_data,
)
all_links.append(link_data)
return all_links

View file

@ -9,8 +9,8 @@ from typing import IO, TYPE_CHECKING, List, Optional, Tuple
from core import utils
from core.constants import MOUNT_BIN, UMOUNT_BIN
from core.emulator.data import InterfaceData, LinkOptions
from core.emulator.distributed import DistributedServer
from core.emulator.emudata import InterfaceData, LinkOptions
from core.emulator.enumerations import NodeTypes, TransportType
from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNetworkBase, CoreNodeBase

View file

@ -6,8 +6,7 @@ from lxml import etree
import core.nodes.base
import core.nodes.physical
from core.emane.nodes import EmaneNet
from core.emulator.data import LinkData
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.data import InterfaceData, LinkData, LinkOptions, NodeOptions
from core.emulator.enumerations import EventTypes, NodeTypes
from core.errors import CoreXmlError
from core.nodes.base import CoreNodeBase, NodeBase
@ -482,12 +481,10 @@ class CoreXmlWriter:
# add link data
for link_data in links:
# skip basic range links
if link_data.iface1_id is None and link_data.iface2_id is None:
if link_data.iface1 is None and link_data.iface2 is None:
continue
link_element = self.create_link_element(link_data)
link_elements.append(link_element)
if link_elements.getchildren():
self.scenario.append(link_elements)
@ -496,36 +493,24 @@ class CoreXmlWriter:
self.devices.append(device.element)
def create_iface_element(
self,
element_name: str,
node_id: int,
iface_id: int,
mac: str,
ip4: str,
ip4_mask: int,
ip6: str,
ip6_mask: int,
self, element_name: str, node_id: int, iface_data: InterfaceData
) -> etree.Element:
iface = etree.Element(element_name)
iface_element = etree.Element(element_name)
node = self.session.get_node(node_id, NodeBase)
iface_name = None
if isinstance(node, CoreNodeBase):
node_iface = node.get_iface(iface_id)
iface_name = node_iface.name
iface = node.get_iface(iface_data.id)
# check if emane interface
if isinstance(node_iface.net, EmaneNet):
nem = node_iface.net.getnemid(node_iface)
add_attribute(iface, "nem", nem)
add_attribute(iface, "id", iface_id)
add_attribute(iface, "name", iface_name)
add_attribute(iface, "mac", mac)
add_attribute(iface, "ip4", ip4)
add_attribute(iface, "ip4_mask", ip4_mask)
add_attribute(iface, "ip6", ip6)
add_attribute(iface, "ip6_mask", ip6_mask)
return iface
if isinstance(iface.net, EmaneNet):
nem = iface.net.getnemid(iface)
add_attribute(iface_element, "nem", nem)
add_attribute(iface_element, "id", iface_data.id)
add_attribute(iface_element, "name", iface_data.name)
add_attribute(iface_element, "mac", iface_data.mac)
add_attribute(iface_element, "ip4", iface_data.ip4)
add_attribute(iface_element, "ip4_mask", iface_data.ip4_mask)
add_attribute(iface_element, "ip6", iface_data.ip6)
add_attribute(iface_element, "ip6_mask", iface_data.ip6_mask)
return iface_element
def create_link_element(self, link_data: LinkData) -> etree.Element:
link_element = etree.Element("link")
@ -533,30 +518,16 @@ class CoreXmlWriter:
add_attribute(link_element, "node2", link_data.node2_id)
# check for interface one
if link_data.iface1_id is not None:
if link_data.iface1 is not None:
iface1 = self.create_iface_element(
"interface1",
link_data.node1_id,
link_data.iface1_id,
link_data.iface1_mac,
link_data.iface1_ip4,
link_data.iface1_ip4_mask,
link_data.iface1_ip6,
link_data.iface1_ip6_mask,
"interface1", link_data.node1_id, link_data.iface1
)
link_element.append(iface1)
# check for interface two
if link_data.iface2_id is not None:
if link_data.iface2 is not None:
iface2 = self.create_iface_element(
"interface2",
link_data.node2_id,
link_data.iface2_id,
link_data.iface2_mac,
link_data.iface2_ip4,
link_data.iface2_ip4_mask,
link_data.iface2_ip6,
link_data.iface2_ip6_mask,
"interface2", link_data.node2_id, link_data.iface2
)
link_element.append(iface2)
@ -582,7 +553,6 @@ class CoreXmlWriter:
add_attribute(options, "network_id", link_data.network_id)
add_attribute(options, "key", link_data.key)
add_attribute(options, "opaque", link_data.opaque)
add_attribute(options, "session", link_data.session)
if options.items():
link_element.append(options)
@ -969,7 +939,6 @@ class CoreXmlReader:
if options.loss is None:
options.loss = get_float(options_element, "per")
options.unidirectional = get_int(options_element, "unidirectional")
options.session = options_element.get("session")
options.emulation_id = get_int(options_element, "emulation_id")
options.network_id = get_int(options_element, "network_id")
options.opaque = options_element.get("opaque")

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.docker import DockerNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.docker import DockerNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.docker import DockerNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.lxd import LxcNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.lxd import LxcNode

View file

@ -1,7 +1,7 @@
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.lxd import LxcNode

View file

@ -9,7 +9,7 @@ import logging
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.nodes import EmaneNet
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode

View file

@ -7,7 +7,7 @@ import argparse
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.lxd import LxcNode

View file

@ -7,7 +7,7 @@ import argparse
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode

View file

@ -7,7 +7,7 @@ import argparse
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

View file

@ -10,7 +10,7 @@ import time
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.nodes import EmaneNet
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode

View file

@ -6,7 +6,7 @@ interact with the GUI.
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.emulator.data import IpPrefixes
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

View file

@ -8,7 +8,7 @@ same CoreEmu instance the GUI is using.
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.emulator.data import IpPrefixes
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

View file

@ -6,7 +6,7 @@ interact with the GUI.
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.location.mobility import BasicRangeModel
from core.nodes.base import CoreNode

View file

@ -14,8 +14,8 @@ from core.api.grpc.server import CoreGrpcServer
from core.api.tlv.corehandlers import CoreHandler
from core.emane.emanemanager import EmaneManager
from core.emulator.coreemu import CoreEmu
from core.emulator.data import IpPrefixes
from core.emulator.distributed import DistributedServer
from core.emulator.emudata import IpPrefixes
from core.emulator.enumerations import EventTypes
from core.emulator.session import Session
from core.nodes.base import CoreNode

View file

@ -15,7 +15,7 @@ from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.nodes import EmaneNet
from core.emane.rfpipe import EmaneRfPipeModel
from core.emane.tdma import EmaneTdmaModel
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.session import Session
from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNode

View file

@ -8,7 +8,7 @@ from typing import Type
import pytest
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import MessageFlags
from core.emulator.session import Session
from core.errors import CoreCommandError

View file

@ -1,4 +1,4 @@
from core.emulator.emudata import NodeOptions
from core.emulator.data import NodeOptions
from core.emulator.session import Session
from core.nodes.base import CoreNode
from core.nodes.network import HubNode

View file

@ -18,8 +18,7 @@ from core.api.tlv.dataconversion import ConfigShim
from core.api.tlv.enumerations import ConfigFlags
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.nodes import EmaneNet
from core.emulator.data import EventData, NodeData
from core.emulator.emudata import IpPrefixes, NodeOptions
from core.emulator.data import EventData, IpPrefixes, NodeData, NodeOptions
from core.emulator.enumerations import EventTypes, ExceptionLevels, NodeTypes
from core.errors import CoreError
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility

View file

@ -1,6 +1,6 @@
from typing import Tuple
from core.emulator.emudata import IpPrefixes, LinkOptions
from core.emulator.data import IpPrefixes, LinkOptions
from core.emulator.session import Session
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

View file

@ -1,6 +1,6 @@
import pytest
from core.emulator.emudata import InterfaceData, NodeOptions
from core.emulator.data import InterfaceData, NodeOptions
from core.emulator.session import Session
from core.errors import CoreError
from core.nodes.base import CoreNode

View file

@ -3,7 +3,7 @@ from xml.etree import ElementTree
import pytest
from core.emulator.emudata import IpPrefixes, LinkOptions, NodeOptions
from core.emulator.data import IpPrefixes, LinkOptions, NodeOptions
from core.emulator.enumerations import EventTypes
from core.emulator.session import Session
from core.errors import CoreError

View file

@ -36,7 +36,7 @@ interact with the GUI.
import logging
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.emulator.data import IpPrefixes
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode