Merge pull request #453 from coreemu/enhancement/type-checking-node-retrieval
Enhancement/type checking node retrieval
This commit is contained in:
commit
ffc60e5808
40 changed files with 461 additions and 399 deletions
|
@ -123,7 +123,8 @@ def create_nodes(
|
|||
funcs = []
|
||||
for node_proto in node_protos:
|
||||
_type, _id, options = add_node_data(node_proto)
|
||||
args = (_type, _id, options)
|
||||
_class = session.get_node_class(_type)
|
||||
args = (_class, _id, options)
|
||||
funcs.append((session.add_node, args, {}))
|
||||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
|
|
|
@ -6,7 +6,7 @@ import tempfile
|
|||
import threading
|
||||
import time
|
||||
from concurrent import futures
|
||||
from typing import Type, TypeVar
|
||||
from typing import Type
|
||||
|
||||
import grpc
|
||||
from grpc import ServicerContext
|
||||
|
@ -109,7 +109,7 @@ from core.emulator.coreemu import CoreEmu
|
|||
from core.emulator.data import LinkData
|
||||
from core.emulator.emudata import LinkOptions, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, LinkTypes, MessageFlags
|
||||
from core.emulator.session import Session
|
||||
from core.emulator.session import NT, Session
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.nodes.base import CoreNode, CoreNodeBase, NodeBase
|
||||
|
@ -118,7 +118,6 @@ from core.services.coreservices import ServiceManager
|
|||
|
||||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
|
||||
_INTERFACE_REGEX = re.compile(r"veth(?P<node>[0-9a-fA-F]+)")
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||
|
@ -174,36 +173,22 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
return session
|
||||
|
||||
def get_node(
|
||||
self,
|
||||
session: Session,
|
||||
node_id: int,
|
||||
context: ServicerContext,
|
||||
node_class: Type[T],
|
||||
) -> T:
|
||||
self, session: Session, node_id: int, context: ServicerContext, _class: Type[NT]
|
||||
) -> NT:
|
||||
"""
|
||||
Retrieve node given session and node id
|
||||
|
||||
:param session: session that has the node
|
||||
:param node_id: node id
|
||||
:param context: request
|
||||
:param node_class: type of node we are expecting
|
||||
:param _class: type of node we are expecting
|
||||
:return: node object that satisfies. If node not found then raise an exception.
|
||||
:raises Exception: raises grpc exception when node does not exist
|
||||
"""
|
||||
try:
|
||||
node = session.get_node(node_id)
|
||||
if isinstance(node, node_class):
|
||||
return node
|
||||
else:
|
||||
actual = node.__class__.__name__
|
||||
expected = node_class.__name__
|
||||
context.abort(
|
||||
grpc.StatusCode.NOT_FOUND,
|
||||
f"node({node_id}) class({actual}) "
|
||||
f"was not expected class({expected})",
|
||||
)
|
||||
except CoreError:
|
||||
context.abort(grpc.StatusCode.NOT_FOUND, f"node {node_id} not found")
|
||||
return session.get_node(node_id, _class)
|
||||
except CoreError as e:
|
||||
context.abort(grpc.StatusCode.NOT_FOUND, str(e))
|
||||
|
||||
def validate_service(
|
||||
self, name: str, context: ServicerContext
|
||||
|
@ -682,7 +667,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
logging.debug("add node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
_type, _id, options = grpcutils.add_node_data(request.node)
|
||||
node = session.add_node(_type=_type, _id=_id, options=options)
|
||||
_class = session.get_node_class(_type)
|
||||
node = session.add_node(_class, _id, options)
|
||||
return core_pb2.AddNodeResponse(node_id=node.id)
|
||||
|
||||
def GetNode(
|
||||
|
|
|
@ -41,6 +41,7 @@ from core.emulator.enumerations import (
|
|||
)
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.location.mobility import BasicRangeModel
|
||||
from core.nodes.base import CoreNode, CoreNodeBase, NodeBase
|
||||
from core.nodes.network import WlanNode
|
||||
from core.services.coreservices import ServiceManager, ServiceShim
|
||||
|
||||
|
@ -681,10 +682,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
logging.warning("ignoring invalid message: add and delete flag both set")
|
||||
return ()
|
||||
|
||||
node_type = None
|
||||
_class = CoreNode
|
||||
node_type_value = message.get_tlv(NodeTlvs.TYPE.value)
|
||||
if node_type_value is not None:
|
||||
node_type = NodeTypes(node_type_value)
|
||||
_class = self.session.get_node_class(node_type)
|
||||
|
||||
node_id = message.get_tlv(NodeTlvs.NUMBER.value)
|
||||
|
||||
|
@ -719,7 +721,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
options.services = services.split("|")
|
||||
|
||||
if message.flags & MessageFlags.ADD.value:
|
||||
node = self.session.add_node(node_type, node_id, options)
|
||||
node = self.session.add_node(_class, node_id, options)
|
||||
if node:
|
||||
if message.flags & MessageFlags.STRING.value:
|
||||
self.node_status_request[node.id] = True
|
||||
|
@ -836,7 +838,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
return ()
|
||||
|
||||
try:
|
||||
node = self.session.get_node(node_num)
|
||||
node = self.session.get_node(node_num, CoreNodeBase)
|
||||
|
||||
# build common TLV items for reply
|
||||
tlv_data = b""
|
||||
|
@ -1228,7 +1230,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if not node_id:
|
||||
return replies
|
||||
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
if node is None:
|
||||
logging.warning(
|
||||
"request to configure service for unknown node %s", node_id
|
||||
|
@ -1373,7 +1375,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.mobility.set_model_config(node_id, object_name, parsed_config)
|
||||
if self.session.state == EventTypes.RUNTIME_STATE and parsed_config:
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, WlanNode)
|
||||
if object_name == BasicRangeModel.name:
|
||||
node.updatemodel(parsed_config)
|
||||
except CoreError:
|
||||
|
@ -1553,7 +1555,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
logging.debug("handling event %s at %s", event_type.name, time.ctime())
|
||||
if event_type.value <= EventTypes.SHUTDOWN_STATE.value:
|
||||
if node_id is not None:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, NodeBase)
|
||||
|
||||
# configure mobility models for WLAN added during runtime
|
||||
if event_type == EventTypes.INSTANTIATION_STATE and isinstance(
|
||||
|
@ -1647,7 +1649,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
name = event_data.name
|
||||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
except CoreError:
|
||||
logging.warning(
|
||||
"ignoring event for service '%s', unknown node '%s'", name, node_id
|
||||
|
@ -1883,7 +1885,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
data_types = tuple(
|
||||
repeat(ConfigDataTypes.STRING.value, len(ServiceShim.keys))
|
||||
)
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
values = ServiceShim.tovaluelist(node, service)
|
||||
config_data = ConfigData(
|
||||
message_type=0,
|
||||
|
|
|
@ -10,6 +10,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.nodes.interface import CoreInterface
|
||||
from core.xml import emanexml
|
||||
|
||||
|
@ -137,7 +138,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
|
|||
# TODO: batch these into multiple events per transmission
|
||||
# TODO: may want to split out seconds portion of delay and jitter
|
||||
event = CommEffectEvent()
|
||||
emane_node = self.session.get_node(self.id)
|
||||
emane_node = self.session.get_node(self.id, EmaneNet)
|
||||
nemid = emane_node.getnemid(netif)
|
||||
nemid2 = emane_node.getnemid(netif2)
|
||||
mbw = bw
|
||||
|
|
|
@ -21,7 +21,7 @@ from core.emane.rfpipe import EmaneRfPipeModel
|
|||
from core.emane.tdma import EmaneTdmaModel
|
||||
from core.emulator.enumerations import ConfigDataTypes, RegisterTlvs
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.base import CoreNode, NodeBase
|
||||
from core.nodes.interface import CoreInterface
|
||||
from core.nodes.network import CtrlNet
|
||||
from core.xml import emanexml
|
||||
|
@ -801,8 +801,8 @@ class EmaneManager(ModelManager):
|
|||
zbit_check = z.bit_length() > 16 or z < 0
|
||||
if any([xbit_check, ybit_check, zbit_check]):
|
||||
logging.error(
|
||||
"Unable to build node location message, received lat/long/alt exceeds coordinate "
|
||||
"space: NEM %s (%d, %d, %d)",
|
||||
"Unable to build node location message, received lat/long/alt "
|
||||
"exceeds coordinate space: NEM %s (%d, %d, %d)",
|
||||
nemid,
|
||||
x,
|
||||
y,
|
||||
|
@ -812,7 +812,7 @@ class EmaneManager(ModelManager):
|
|||
|
||||
# generate a node message for this location update
|
||||
try:
|
||||
node = self.session.get_node(n)
|
||||
node = self.session.get_node(n, NodeBase)
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
"location event NEM %s has no corresponding node %s", nemid, n
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import Dict, List
|
|||
|
||||
from core.config import ConfigGroup, Configuration
|
||||
from core.emane import emanemanifest
|
||||
from core.emane.nodes import EmaneNet
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
from core.errors import CoreError
|
||||
from core.location.mobility import WirelessModel
|
||||
|
@ -148,7 +149,7 @@ class EmaneModel(WirelessModel):
|
|||
:return: nothing
|
||||
"""
|
||||
try:
|
||||
wlan = self.session.get_node(self.id)
|
||||
wlan = self.session.get_node(self.id, EmaneNet)
|
||||
wlan.setnempositions(moved_netifs)
|
||||
except CoreError:
|
||||
logging.exception("error during update")
|
||||
|
|
|
@ -244,7 +244,7 @@ class DistributedController:
|
|||
)
|
||||
return key & 0xFFFFFFFF
|
||||
|
||||
def get_tunnel(self, n1_id: int, n2_id: int) -> Tuple[GreTap, GreTap]:
|
||||
def get_tunnel(self, n1_id: int, n2_id: int) -> GreTap:
|
||||
"""
|
||||
Return the GreTap between two nodes if it exists.
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import subprocess
|
|||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, TypeVar
|
||||
|
||||
from core import constants, utils
|
||||
from core.emane.emanemanager import EmaneManager
|
||||
|
@ -75,8 +75,10 @@ NODES = {
|
|||
NodeTypes.LXC: LxcNode,
|
||||
}
|
||||
NODES_TYPE = {NODES[x]: x for x in NODES}
|
||||
CONTAINER_NODES = {DockerNode, LxcNode}
|
||||
CTRL_NET_ID = 9001
|
||||
LINK_COLORS = ["green", "blue", "orange", "purple", "turquoise"]
|
||||
NT = TypeVar("NT", bound=NodeBase)
|
||||
|
||||
|
||||
class Session:
|
||||
|
@ -194,7 +196,7 @@ class Session:
|
|||
def _link_nodes(
|
||||
self, node_one_id: int, node_two_id: int
|
||||
) -> Tuple[
|
||||
CoreNode, CoreNode, CoreNetworkBase, CoreNetworkBase, Tuple[GreTap, GreTap]
|
||||
Optional[NodeBase], Optional[NodeBase], CoreNetworkBase, CoreNetworkBase, GreTap
|
||||
]:
|
||||
"""
|
||||
Convenience method for retrieving nodes within link data.
|
||||
|
@ -212,8 +214,8 @@ class Session:
|
|||
net_two = None
|
||||
|
||||
# retrieve node one
|
||||
node_one = self.get_node(node_one_id)
|
||||
node_two = self.get_node(node_two_id)
|
||||
node_one = self.get_node(node_one_id, NodeBase)
|
||||
node_two = self.get_node(node_two_id, NodeBase)
|
||||
|
||||
# both node ids are provided
|
||||
tunnel = self.distributed.get_tunnel(node_one_id, node_two_id)
|
||||
|
@ -225,6 +227,7 @@ class Session:
|
|||
else:
|
||||
node_two = None
|
||||
# physical node connected via gre tap tunnel
|
||||
# TODO: double check this cases type
|
||||
elif tunnel:
|
||||
if tunnel.remotenum == node_one_id:
|
||||
node_one = None
|
||||
|
@ -346,7 +349,7 @@ class Session:
|
|||
node_two.name,
|
||||
)
|
||||
start = self.state.should_start()
|
||||
net_one = self.create_node(cls=PtpNet, start=start)
|
||||
net_one = self.create_node(_class=PtpNet, start=start)
|
||||
|
||||
# node to network
|
||||
if node_one and net_one:
|
||||
|
@ -660,32 +663,21 @@ class Session:
|
|||
node_two.lock.release()
|
||||
|
||||
def add_node(
|
||||
self,
|
||||
_type: NodeTypes = NodeTypes.DEFAULT,
|
||||
_id: int = None,
|
||||
options: NodeOptions = None,
|
||||
_cls: Type[NodeBase] = None,
|
||||
) -> NodeBase:
|
||||
self, _class: Type[NT], _id: int = None, options: NodeOptions = None
|
||||
) -> NT:
|
||||
"""
|
||||
Add a node to the session, based on the provided node data.
|
||||
|
||||
:param _type: type of node to create
|
||||
:param _class: node class to create
|
||||
:param _id: id for node, defaults to None for generated id
|
||||
:param options: data to create node with
|
||||
:param _cls: optional custom class to use for a created node
|
||||
:return: created node
|
||||
:raises core.CoreError: when an invalid node type is given
|
||||
"""
|
||||
# validate node type, get class, or throw error
|
||||
if _cls is None:
|
||||
node_class = self.get_node_class(_type)
|
||||
else:
|
||||
node_class = _cls
|
||||
|
||||
# set node start based on current session state, override and check when rj45
|
||||
start = self.state.should_start()
|
||||
enable_rj45 = self.options.get_config("enablerj45") == "1"
|
||||
if _type == NodeTypes.RJ45 and not enable_rj45:
|
||||
if _class == Rj45Node and not enable_rj45:
|
||||
start = False
|
||||
|
||||
# determine node id
|
||||
|
@ -701,7 +693,7 @@ class Session:
|
|||
options.set_position(0, 0)
|
||||
name = options.name
|
||||
if not name:
|
||||
name = f"{node_class.__name__}{_id}"
|
||||
name = f"{_class.__name__}{_id}"
|
||||
|
||||
# verify distributed server
|
||||
server = self.distributed.servers.get(options.server)
|
||||
|
@ -711,24 +703,15 @@ class Session:
|
|||
# create node
|
||||
logging.info(
|
||||
"creating node(%s) id(%s) name(%s) start(%s)",
|
||||
node_class.__name__,
|
||||
_class.__name__,
|
||||
_id,
|
||||
name,
|
||||
start,
|
||||
)
|
||||
if _type in [NodeTypes.DOCKER, NodeTypes.LXC]:
|
||||
node = self.create_node(
|
||||
cls=node_class,
|
||||
_id=_id,
|
||||
name=name,
|
||||
start=start,
|
||||
image=options.image,
|
||||
server=server,
|
||||
)
|
||||
else:
|
||||
node = self.create_node(
|
||||
cls=node_class, _id=_id, name=name, start=start, server=server
|
||||
)
|
||||
kwargs = dict(_id=_id, name=name, start=start, server=server)
|
||||
if _class in CONTAINER_NODES:
|
||||
kwargs["image"] = options.image
|
||||
node = self.create_node(_class, **kwargs)
|
||||
|
||||
# set node attributes
|
||||
node.icon = options.icon
|
||||
|
@ -777,7 +760,7 @@ class Session:
|
|||
:raises core.CoreError: when node to update does not exist
|
||||
"""
|
||||
# get node to update
|
||||
node = self.get_node(node_id)
|
||||
node = self.get_node(node_id, NodeBase)
|
||||
|
||||
# set node position and broadcast it
|
||||
self.set_node_position(node, options)
|
||||
|
@ -908,9 +891,7 @@ class Session:
|
|||
:param data: file data
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
node = self.get_node(node_id)
|
||||
|
||||
node = self.get_node(node_id, CoreNodeBase)
|
||||
if source_name is not None:
|
||||
node.addfile(source_name, file_name)
|
||||
elif data is not None:
|
||||
|
@ -1363,17 +1344,17 @@ class Session:
|
|||
break
|
||||
return node_id
|
||||
|
||||
def create_node(self, cls: Type[NodeBase], *args: Any, **kwargs: Any) -> NodeBase:
|
||||
def create_node(self, _class: Type[NT], *args: Any, **kwargs: Any) -> NT:
|
||||
"""
|
||||
Create an emulation node.
|
||||
|
||||
:param cls: node class to create
|
||||
:param _class: node class to create
|
||||
:param args: list of arguments for the class to create
|
||||
:param kwargs: dictionary of arguments for the class to create
|
||||
:return: the created node instance
|
||||
:raises core.CoreError: when id of the node to create already exists
|
||||
"""
|
||||
node = cls(self, *args, **kwargs)
|
||||
node = _class(self, *args, **kwargs)
|
||||
with self._nodes_lock:
|
||||
if node.id in self.nodes:
|
||||
node.shutdown()
|
||||
|
@ -1381,17 +1362,23 @@ class Session:
|
|||
self.nodes[node.id] = node
|
||||
return node
|
||||
|
||||
def get_node(self, _id: int) -> NodeBase:
|
||||
def get_node(self, _id: int, _class: Type[NT]) -> NT:
|
||||
"""
|
||||
Get a session node.
|
||||
|
||||
:param _id: node id to retrieve
|
||||
:param _class: expected node class
|
||||
:return: node for the given id
|
||||
:raises core.CoreError: when node does not exist
|
||||
"""
|
||||
if _id not in self.nodes:
|
||||
raise CoreError(f"unknown node id {_id}")
|
||||
return self.nodes[_id]
|
||||
node = self.nodes[_id]
|
||||
if not isinstance(node, _class):
|
||||
actual = node.__class__.__name__
|
||||
expected = _class.__name__
|
||||
raise CoreError(f"node class({actual}) is not expected({expected})")
|
||||
return node
|
||||
|
||||
def delete_node(self, _id: int) -> bool:
|
||||
"""
|
||||
|
@ -1709,10 +1696,7 @@ class Session:
|
|||
:return: control net
|
||||
:raises CoreError: when control net is not found
|
||||
"""
|
||||
node = self.get_node(CTRL_NET_ID + net_index)
|
||||
if not isinstance(node, CtrlNet):
|
||||
raise CoreError("node is not a valid CtrlNet: %s", node.name)
|
||||
return node
|
||||
return self.get_node(CTRL_NET_ID + net_index, CtrlNet)
|
||||
|
||||
def add_remove_control_net(
|
||||
self, net_index: int, remove: bool = False, conf_required: bool = True
|
||||
|
@ -1788,7 +1772,7 @@ class Session:
|
|||
server_interface,
|
||||
)
|
||||
control_net = self.create_node(
|
||||
cls=CtrlNet,
|
||||
_class=CtrlNet,
|
||||
_id=_id,
|
||||
prefix=prefix,
|
||||
assign_address=True,
|
||||
|
@ -1959,7 +1943,7 @@ class Session:
|
|||
if not node_id:
|
||||
utils.mute_detach(data)
|
||||
else:
|
||||
node = self.get_node(node_id)
|
||||
node = self.get_node(node_id, CoreNodeBase)
|
||||
node.cmd(data, wait=False)
|
||||
|
||||
def get_link_color(self, network_id: int) -> str:
|
||||
|
|
|
@ -24,6 +24,7 @@ from core.emulator.enumerations import (
|
|||
from core.errors import CoreError
|
||||
from core.nodes.base import CoreNode, NodeBase
|
||||
from core.nodes.interface import CoreInterface
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
@ -75,7 +76,7 @@ class MobilityManager(ModelManager):
|
|||
)
|
||||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, WlanNode)
|
||||
except CoreError:
|
||||
logging.warning(
|
||||
"skipping mobility configuration for unknown node: %s", node_id
|
||||
|
@ -103,9 +104,8 @@ class MobilityManager(ModelManager):
|
|||
event_type = event_data.event_type
|
||||
node_id = event_data.node
|
||||
name = event_data.name
|
||||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, WlanNode)
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
"Ignoring event for model '%s', unknown node '%s'", name, node_id
|
||||
|
@ -190,7 +190,7 @@ class MobilityManager(ModelManager):
|
|||
"""
|
||||
for node_id in self.nodes():
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, WlanNode)
|
||||
except CoreError:
|
||||
continue
|
||||
if node.model:
|
||||
|
@ -299,7 +299,7 @@ class BasicRangeModel(WirelessModel):
|
|||
"""
|
||||
super().__init__(session, _id)
|
||||
self.session = session
|
||||
self.wlan = session.get_node(_id)
|
||||
self.wlan = session.get_node(_id, WlanNode)
|
||||
self._netifs = {}
|
||||
self._netifslock = threading.Lock()
|
||||
self.range = 0
|
||||
|
@ -590,7 +590,7 @@ class WayPointMobility(WirelessModel):
|
|||
self.initial = {}
|
||||
self.lasttime = None
|
||||
self.endtime = None
|
||||
self.wlan = session.get_node(_id)
|
||||
self.wlan = session.get_node(_id, WlanNode)
|
||||
# these are really set in child class via confmatrix
|
||||
self.loop = False
|
||||
self.refresh_ms = 50
|
||||
|
|
|
@ -433,6 +433,28 @@ class CoreNodeBase(NodeBase):
|
|||
common.append((netif1.net, netif1, netif2))
|
||||
return common
|
||||
|
||||
def nodefile(self, filename: str, contents: str, mode: int = 0o644) -> None:
|
||||
"""
|
||||
Create a node file with a given mode.
|
||||
|
||||
:param filename: name of file to create
|
||||
:param contents: contents of file
|
||||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def addfile(self, srcname: str, filename: str) -> None:
|
||||
"""
|
||||
Add a file.
|
||||
|
||||
:param srcname: source file name
|
||||
:param filename: file name to add
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
||||
"""
|
||||
Runs a command within a node container.
|
||||
|
|
|
@ -296,7 +296,6 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
self.localname = name
|
||||
self.old_up = False
|
||||
self.old_addrs = []
|
||||
|
||||
if start:
|
||||
self.startup()
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ class Sdt:
|
|||
"""
|
||||
result = False
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, NodeBase)
|
||||
result = isinstance(node, (WlanNode, EmaneNet))
|
||||
except CoreError:
|
||||
pass
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from core.emane.nodes import EmaneNet
|
||||
from core.errors import CoreError
|
||||
from core.services.coreservices import CoreService
|
||||
from core.xml import emanexml
|
||||
|
||||
|
@ -20,8 +21,8 @@ class EmaneTransportService(CoreService):
|
|||
if filename == cls.configs[0]:
|
||||
transport_commands = []
|
||||
for interface in node.netifs(sort=True):
|
||||
network_node = node.session.get_node(interface.net.id)
|
||||
if isinstance(network_node, EmaneNet):
|
||||
try:
|
||||
network_node = node.session.get_node(interface.net.id, EmaneNet)
|
||||
config = node.session.emane.get_configs(
|
||||
network_node.id, network_node.model.name
|
||||
)
|
||||
|
@ -32,6 +33,8 @@ class EmaneTransportService(CoreService):
|
|||
% nem_id
|
||||
)
|
||||
transport_commands.append(command)
|
||||
except CoreError:
|
||||
pass
|
||||
transport_commands = "\n".join(transport_commands)
|
||||
return """
|
||||
emanegentransportxml -o ../ ../platform%s.xml
|
||||
|
|
|
@ -10,7 +10,7 @@ from core.emulator.data import LinkData
|
|||
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.errors import CoreXmlError
|
||||
from core.nodes.base import CoreNetworkBase, CoreNodeBase, NodeBase
|
||||
from core.nodes.base import CoreNodeBase, NodeBase
|
||||
from core.nodes.docker import DockerNode
|
||||
from core.nodes.lxd import LxcNode
|
||||
from core.nodes.network import CtrlNet, WlanNode
|
||||
|
@ -505,9 +505,9 @@ class CoreXmlWriter:
|
|||
ip6_mask: int,
|
||||
) -> etree.Element:
|
||||
interface = etree.Element(element_name)
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, NodeBase)
|
||||
interface_name = None
|
||||
if not isinstance(node, CoreNetworkBase):
|
||||
if isinstance(node, CoreNodeBase):
|
||||
node_interface = node.netif(interface_id)
|
||||
interface_name = node_interface.name
|
||||
|
||||
|
@ -523,7 +523,6 @@ class CoreXmlWriter:
|
|||
add_attribute(interface, "ip4_mask", ip4_mask)
|
||||
add_attribute(interface, "ip6", ip6)
|
||||
add_attribute(interface, "ip6_mask", ip6_mask)
|
||||
|
||||
return interface
|
||||
|
||||
def create_link_element(self, link_data: LinkData) -> etree.Element:
|
||||
|
@ -560,8 +559,8 @@ class CoreXmlWriter:
|
|||
link_element.append(interface_two)
|
||||
|
||||
# check for options, don't write for emane/wlan links
|
||||
node_one = self.session.get_node(link_data.node1_id)
|
||||
node_two = self.session.get_node(link_data.node2_id)
|
||||
node_one = self.session.get_node(link_data.node1_id, NodeBase)
|
||||
node_two = self.session.get_node(link_data.node2_id, NodeBase)
|
||||
is_node_one_wireless = isinstance(node_one, (WlanNode, EmaneNet))
|
||||
is_node_two_wireless = isinstance(node_two, (WlanNode, EmaneNet))
|
||||
if not any([is_node_one_wireless, is_node_two_wireless]):
|
||||
|
@ -841,6 +840,7 @@ class CoreXmlReader:
|
|||
node_type = NodeTypes.DOCKER
|
||||
elif clazz == "lxc":
|
||||
node_type = NodeTypes.LXC
|
||||
_class = self.session.get_node_class(node_type)
|
||||
|
||||
service_elements = device_element.find("services")
|
||||
if service_elements is not None:
|
||||
|
@ -866,12 +866,13 @@ class CoreXmlReader:
|
|||
options.set_location(lat, lon, alt)
|
||||
|
||||
logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name)
|
||||
self.session.add_node(_type=node_type, _id=node_id, options=options)
|
||||
self.session.add_node(_class, node_id, options)
|
||||
|
||||
def read_network(self, network_element: etree.Element) -> None:
|
||||
node_id = get_int(network_element, "id")
|
||||
name = network_element.get("name")
|
||||
node_type = NodeTypes[network_element.get("type")]
|
||||
_class = self.session.get_node_class(node_type)
|
||||
icon = network_element.get("icon")
|
||||
options = NodeOptions(name)
|
||||
options.icon = icon
|
||||
|
@ -892,7 +893,7 @@ class CoreXmlReader:
|
|||
logging.info(
|
||||
"reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name
|
||||
)
|
||||
self.session.add_node(_type=node_type, _id=node_id, options=options)
|
||||
self.session.add_node(_class, node_id, options)
|
||||
|
||||
def read_configservice_configs(self) -> None:
|
||||
configservice_configs = self.scenario.find("configservice_configurations")
|
||||
|
@ -902,7 +903,7 @@ class CoreXmlReader:
|
|||
for configservice_element in configservice_configs.iterchildren():
|
||||
name = configservice_element.get("name")
|
||||
node_id = get_int(configservice_element, "node")
|
||||
node = self.session.get_node(node_id)
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
service = node.config_services[name]
|
||||
|
||||
configs_element = configservice_element.find("configs")
|
||||
|
|
|
@ -2,7 +2,9 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -13,16 +15,16 @@ if __name__ == "__main__":
|
|||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch = session.add_node(SwitchNode)
|
||||
|
||||
# node one
|
||||
options.config_services = ["DefaultRoute", "IPForward"]
|
||||
node_one = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
interface = prefixes.create_interface(node_one)
|
||||
session.add_link(node_one.id, switch.id, interface_one=interface)
|
||||
|
||||
# node two
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
interface = prefixes.create_interface(node_two)
|
||||
session.add_link(node_two.id, switch.id, interface_one=interface)
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.docker import DockerNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -15,11 +17,11 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(model=None, image="ubuntu")
|
||||
|
||||
# create node one
|
||||
node_one = session.add_node(_type=NodeTypes.DOCKER, options=options)
|
||||
node_one = session.add_node(DockerNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# create node two
|
||||
node_two = session.add_node()
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# add link
|
||||
|
|
|
@ -2,7 +2,8 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.docker import DockerNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -17,11 +18,11 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(model=None, image="ubuntu")
|
||||
|
||||
# create node one
|
||||
node_one = session.add_node(_type=NodeTypes.DOCKER, options=options)
|
||||
node_one = session.add_node(DockerNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# create node two
|
||||
node_two = session.add_node(_type=NodeTypes.DOCKER, options=options)
|
||||
node_two = session.add_node(DockerNode, options=options)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# add link
|
||||
|
|
|
@ -2,7 +2,10 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.docker import DockerNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -16,18 +19,18 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(model=None, image="ubuntu")
|
||||
|
||||
# create switch
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch = session.add_node(SwitchNode)
|
||||
|
||||
# node one
|
||||
node_one = session.add_node(_type=NodeTypes.DOCKER, options=options)
|
||||
node_one = session.add_node(DockerNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# node two
|
||||
node_two = session.add_node(_type=NodeTypes.DOCKER, options=options)
|
||||
node_two = session.add_node(DockerNode, options=options)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# node three
|
||||
node_three = session.add_node()
|
||||
node_three = session.add_node(CoreNode)
|
||||
interface_three = prefixes.create_interface(node_three)
|
||||
|
||||
# add links
|
||||
|
|
|
@ -2,7 +2,9 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.lxd import LxcNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -15,11 +17,11 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(image="ubuntu")
|
||||
|
||||
# create node one
|
||||
node_one = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_one = session.add_node(LxcNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# create node two
|
||||
node_two = session.add_node()
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# add link
|
||||
|
|
|
@ -2,7 +2,8 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.lxd import LxcNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
@ -17,11 +18,11 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(image="ubuntu:18.04")
|
||||
|
||||
# create node one
|
||||
node_one = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_one = session.add_node(LxcNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# create node two
|
||||
node_two = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_two = session.add_node(LxcNode, options=options)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# add link
|
||||
|
|
|
@ -2,7 +2,10 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.lxd import LxcNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
@ -16,18 +19,18 @@ if __name__ == "__main__":
|
|||
options = NodeOptions(image="ubuntu")
|
||||
|
||||
# create switch
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch = session.add_node(SwitchNode)
|
||||
|
||||
# node one
|
||||
node_one = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_one = session.add_node(LxcNode, options=options)
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
||||
# node two
|
||||
node_two = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_two = session.add_node(LxcNode, options=options)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
|
||||
# node three
|
||||
node_three = session.add_node()
|
||||
node_three = session.add_node(CoreNode)
|
||||
interface_three = prefixes.create_interface(node_three)
|
||||
|
||||
# add links
|
||||
|
|
|
@ -7,9 +7,11 @@ import argparse
|
|||
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.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
|
||||
def parse(name):
|
||||
|
@ -50,11 +52,11 @@ def main(args):
|
|||
# create local node, switch, and remote nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
node_one = session.add_node(options=options)
|
||||
emane_net = session.add_node(_type=NodeTypes.EMANE)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
emane_net = session.add_node(EmaneNet)
|
||||
session.emane.set_model(emane_net, EmaneIeee80211abgModel)
|
||||
options.server = server_name
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# create node interfaces and link
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
|
|
@ -8,7 +8,8 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.lxd import LxcNode
|
||||
|
||||
|
||||
def parse(name):
|
||||
|
@ -42,9 +43,9 @@ def main(args):
|
|||
|
||||
# create local node, switch, and remote nodes
|
||||
options = NodeOptions(image="ubuntu:18.04")
|
||||
node_one = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_one = session.add_node(LxcNode, options=options)
|
||||
options.server = server_name
|
||||
node_two = session.add_node(_type=NodeTypes.LXC, options=options)
|
||||
node_two = session.add_node(LxcNode, options=options)
|
||||
|
||||
# create node interfaces and link
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
|
|
@ -9,6 +9,7 @@ import logging
|
|||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
|
||||
def parse(name):
|
||||
|
@ -42,9 +43,9 @@ def main(args):
|
|||
|
||||
# create local node, switch, and remote nodes
|
||||
options = NodeOptions()
|
||||
node_one = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
options.server = server_name
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# create node interfaces and link
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
|
|
@ -8,7 +8,9 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
|
||||
def parse(name):
|
||||
|
@ -43,11 +45,11 @@ def main(args):
|
|||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create local node, switch, and remote nodes
|
||||
node_one = session.add_node()
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_one = session.add_node(CoreNode)
|
||||
switch = session.add_node(SwitchNode)
|
||||
options = NodeOptions()
|
||||
options.server = server_name
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# create node interfaces and link
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
|
|
|
@ -8,9 +8,11 @@ import logging
|
|||
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.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
NODES = 2
|
||||
EMANE_DELAY = 10
|
||||
|
@ -32,13 +34,13 @@ def main():
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.set_position(80, 50)
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options, _id=100)
|
||||
emane_network = session.add_node(EmaneNet, options=options, _id=100)
|
||||
session.emane.set_model(emane_network, EmaneIeee80211abgModel)
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
for i in range(NODES):
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
node.setposition(x=150 * (i + 1), y=150)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, emane_network.id, interface_one=interface)
|
||||
|
@ -51,8 +53,8 @@ def main():
|
|||
time.sleep(EMANE_DELAY)
|
||||
|
||||
# get nodes to run example
|
||||
first_node = session.get_node(1)
|
||||
last_node = session.get_node(NODES)
|
||||
first_node = session.get_node(1, CoreNode)
|
||||
last_node = session.get_node(NODES, CoreNode)
|
||||
address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c 3 {address}")
|
||||
|
|
|
@ -7,7 +7,9 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
NODES = 2
|
||||
|
||||
|
@ -24,11 +26,11 @@ def main():
|
|||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create switch network node
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH, _id=100)
|
||||
switch = session.add_node(SwitchNode, _id=100)
|
||||
|
||||
# create nodes
|
||||
for _ in range(NODES):
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface_one=interface)
|
||||
|
||||
|
@ -36,8 +38,8 @@ def main():
|
|||
session.instantiate()
|
||||
|
||||
# get nodes to run example
|
||||
first_node = session.get_node(1)
|
||||
last_node = session.get_node(NODES)
|
||||
first_node = session.get_node(1, CoreNode)
|
||||
last_node = session.get_node(NODES, CoreNode)
|
||||
address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c 3 {address}")
|
||||
|
|
|
@ -7,8 +7,11 @@ same CoreEmu instance the GUI is using.
|
|||
|
||||
import logging
|
||||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
NODES = 2
|
||||
|
||||
|
@ -18,18 +21,18 @@ def main():
|
|||
prefixes = IpPrefixes("10.83.0.0/16")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = globals()["coreemu"]
|
||||
coreemu: CoreEmu = globals()["coreemu"]
|
||||
session = coreemu.create_session()
|
||||
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create switch network node
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch = session.add_node(SwitchNode)
|
||||
|
||||
# create nodes
|
||||
for _ in range(NODES):
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface_one=interface)
|
||||
|
||||
|
|
|
@ -7,8 +7,10 @@ import logging
|
|||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.location.mobility import BasicRangeModel
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
NODES = 2
|
||||
|
||||
|
@ -25,14 +27,14 @@ def main():
|
|||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create wlan network node
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN, _id=100)
|
||||
wlan = session.add_node(WlanNode, _id=100)
|
||||
session.mobility.set_model(wlan, BasicRangeModel)
|
||||
|
||||
# create nodes, must set a position for wlan basic range model
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
for _ in range(NODES):
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, wlan.id, interface_one=interface)
|
||||
|
||||
|
@ -40,8 +42,8 @@ def main():
|
|||
session.instantiate()
|
||||
|
||||
# get nodes for example run
|
||||
first_node = session.get_node(1)
|
||||
last_node = session.get_node(NODES)
|
||||
first_node = session.get_node(1, CoreNode)
|
||||
last_node = session.get_node(NODES, CoreNode)
|
||||
address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c 3 {address}")
|
||||
|
|
|
@ -9,11 +9,12 @@ import pytest
|
|||
from core.emane.bypass import EmaneBypassModel
|
||||
from core.emane.commeffect import EmaneCommEffectModel
|
||||
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 NodeOptions
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
_EMANE_MODELS = [
|
||||
EmaneIeee80211abgModel,
|
||||
|
@ -50,7 +51,7 @@ class TestEmane:
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.set_position(80, 50)
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
session.emane.set_model(emane_network, model)
|
||||
|
||||
# configure tdma
|
||||
|
@ -64,9 +65,9 @@ class TestEmane:
|
|||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(150, 150)
|
||||
node_one = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
options.set_position(300, 150)
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
for i, node in enumerate([node_one, node_two]):
|
||||
node.setposition(x=150 * (i + 1), y=150)
|
||||
|
@ -92,7 +93,7 @@ class TestEmane:
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.set_position(80, 50)
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
config_key = "txpower"
|
||||
config_value = "10"
|
||||
session.emane.set_model(
|
||||
|
@ -102,9 +103,9 @@ class TestEmane:
|
|||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(150, 150)
|
||||
node_one = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
options.set_position(300, 150)
|
||||
node_two = session.add_node(options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
for i, node in enumerate([node_one, node_two]):
|
||||
node.setposition(x=150 * (i + 1), y=150)
|
||||
|
@ -133,9 +134,9 @@ class TestEmane:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
@ -146,7 +147,7 @@ class TestEmane:
|
|||
)
|
||||
|
||||
# verify nodes and configuration were restored
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(emane_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
assert session.get_node(emane_id, EmaneNet)
|
||||
assert value == config_value
|
||||
|
|
|
@ -7,8 +7,9 @@ from core.config import (
|
|||
ModelManager,
|
||||
)
|
||||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||
from core.emulator.enumerations import ConfigDataTypes, NodeTypes
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
from core.location.mobility import BasicRangeModel
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
|
||||
class TestConfigurableOptions(ConfigurableOptions):
|
||||
|
@ -147,7 +148,7 @@ class TestConf:
|
|||
|
||||
def test_model_set(self, session):
|
||||
# given
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
|
||||
# when
|
||||
session.mobility.set_model(wlan_node, BasicRangeModel)
|
||||
|
@ -157,7 +158,7 @@ class TestConf:
|
|||
|
||||
def test_model_set_error(self, session):
|
||||
# given
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
|
||||
# when / then
|
||||
with pytest.raises(ValueError):
|
||||
|
@ -165,7 +166,7 @@ class TestConf:
|
|||
|
||||
def test_get_models(self, session):
|
||||
# given
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
session.mobility.set_model(wlan_node, BasicRangeModel)
|
||||
|
||||
# when
|
||||
|
|
|
@ -8,13 +8,15 @@ import threading
|
|||
import pytest
|
||||
|
||||
from core.emulator.emudata import NodeOptions
|
||||
from core.emulator.enumerations import MessageFlags, NodeTypes
|
||||
from core.emulator.enumerations import MessageFlags
|
||||
from core.errors import CoreCommandError
|
||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import HubNode, PtpNet, SwitchNode, WlanNode
|
||||
|
||||
_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
_MOBILITY_FILE = os.path.join(_PATH, "mobility.scen")
|
||||
_WIRED = [NodeTypes.PEER_TO_PEER, NodeTypes.HUB, NodeTypes.SWITCH]
|
||||
_WIRED = [PtpNet, HubNode, SwitchNode]
|
||||
|
||||
|
||||
def ping(from_node, to_node, ip_prefixes):
|
||||
|
@ -39,11 +41,11 @@ class TestCore:
|
|||
"""
|
||||
|
||||
# create net node
|
||||
net_node = session.add_node(_type=net_type)
|
||||
net_node = session.add_node(net_type)
|
||||
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to net node
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -66,11 +68,11 @@ class TestCore:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create ptp
|
||||
ptp_node = session.add_node(_type=NodeTypes.PEER_TO_PEER)
|
||||
ptp_node = session.add_node(PtpNet)
|
||||
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to ptp net
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -99,11 +101,11 @@ class TestCore:
|
|||
"""
|
||||
|
||||
# create ptp
|
||||
ptp_node = session.add_node(_type=NodeTypes.PEER_TO_PEER)
|
||||
ptp_node = session.add_node(PtpNet)
|
||||
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to ptp net
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -143,14 +145,14 @@ class TestCore:
|
|||
"""
|
||||
|
||||
# create wlan
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
session.mobility.set_model(wlan_node, BasicRangeModel)
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
node_one = session.add_node(options=options)
|
||||
node_two = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# link nodes
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -173,14 +175,14 @@ class TestCore:
|
|||
"""
|
||||
|
||||
# create wlan
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
session.mobility.set_model(wlan_node, BasicRangeModel)
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
node_one = session.add_node(options=options)
|
||||
node_two = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# link nodes
|
||||
for node in [node_one, node_two]:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from core.emulator.emudata import NodeOptions
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import HubNode
|
||||
|
||||
|
||||
class TestDistributed:
|
||||
|
@ -12,7 +13,7 @@ class TestDistributed:
|
|||
session.distributed.add_server(server_name, host)
|
||||
options = NodeOptions()
|
||||
options.server = server_name
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
session.instantiate()
|
||||
|
||||
# then
|
||||
|
@ -30,7 +31,7 @@ class TestDistributed:
|
|||
session.distributed.add_server(server_name, host)
|
||||
options = NodeOptions()
|
||||
options.server = server_name
|
||||
node = session.add_node(_type=NodeTypes.HUB, options=options)
|
||||
node = session.add_node(HubNode, options=options)
|
||||
session.instantiate()
|
||||
|
||||
# then
|
||||
|
|
|
@ -14,11 +14,14 @@ from core.api.grpc.wlan_pb2 import WlanConfig
|
|||
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
|
||||
from core.emulator.emudata import NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, ExceptionLevels, NodeTypes
|
||||
from core.errors import CoreError
|
||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode, WlanNode
|
||||
from core.xml.corexml import CoreXmlWriter
|
||||
|
||||
|
||||
|
@ -194,7 +197,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
session.add_node()
|
||||
session.add_node(CoreNode)
|
||||
session.set_state(EventTypes.DEFINITION_STATE)
|
||||
|
||||
# then
|
||||
|
@ -355,13 +358,13 @@ class TestGrpc:
|
|||
|
||||
# then
|
||||
assert response.node_id is not None
|
||||
assert session.get_node(response.node_id) is not None
|
||||
assert session.get_node(response.node_id, CoreNode) is not None
|
||||
|
||||
def test_get_node(self, grpc_server):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
@ -374,7 +377,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
x, y = 10, 10
|
||||
|
@ -392,7 +395,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
@ -402,7 +405,7 @@ class TestGrpc:
|
|||
assert response.result is expected
|
||||
if expected is True:
|
||||
with pytest.raises(CoreError):
|
||||
assert session.get_node(node.id)
|
||||
assert session.get_node(node.id, CoreNode)
|
||||
|
||||
def test_node_command(self, request, grpc_server):
|
||||
if request.config.getoption("mock"):
|
||||
|
@ -413,7 +416,7 @@ class TestGrpc:
|
|||
session = grpc_server.coreemu.create_session()
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
options = NodeOptions(model="Host")
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
session.instantiate()
|
||||
output = "hello world"
|
||||
|
||||
|
@ -431,7 +434,7 @@ class TestGrpc:
|
|||
session = grpc_server.coreemu.create_session()
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
options = NodeOptions(model="Host")
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
session.instantiate()
|
||||
|
||||
# then
|
||||
|
@ -508,8 +511,8 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node = session.add_node()
|
||||
switch = session.add_node(SwitchNode)
|
||||
node = session.add_node(CoreNode)
|
||||
interface = ip_prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface)
|
||||
|
||||
|
@ -524,8 +527,8 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node = session.add_node()
|
||||
switch = session.add_node(SwitchNode)
|
||||
node = session.add_node(CoreNode)
|
||||
interface = ip_prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface)
|
||||
|
||||
|
@ -538,8 +541,8 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node = session.add_node()
|
||||
switch = session.add_node(SwitchNode)
|
||||
node = session.add_node(CoreNode)
|
||||
assert len(switch.all_link_data()) == 0
|
||||
|
||||
# then
|
||||
|
@ -555,7 +558,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
interface = interface_helper.create_interface(node.id, 0)
|
||||
|
@ -567,8 +570,8 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node = session.add_node()
|
||||
switch = session.add_node(SwitchNode)
|
||||
node = session.add_node(CoreNode)
|
||||
interface = ip_prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface)
|
||||
options = core_pb2.LinkOptions(bandwidth=30000)
|
||||
|
@ -590,9 +593,9 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node_one = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
node_two = session.add_node()
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
||||
link_node = None
|
||||
|
@ -617,7 +620,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
@ -631,7 +634,7 @@ class TestGrpc:
|
|||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
wlan.setmodel(BasicRangeModel, BasicRangeModel.default_values())
|
||||
session.instantiate()
|
||||
range_key = "range"
|
||||
|
@ -694,7 +697,7 @@ class TestGrpc:
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.emane = EmaneIeee80211abgModel.name
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
session.emane.set_model(emane_network, EmaneIeee80211abgModel)
|
||||
config_key = "platform_id_start"
|
||||
config_value = "2"
|
||||
|
@ -721,7 +724,7 @@ class TestGrpc:
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.emane = EmaneIeee80211abgModel.name
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
session.emane.set_model(emane_network, EmaneIeee80211abgModel)
|
||||
config_key = "bandwidth"
|
||||
config_value = "900000"
|
||||
|
@ -749,7 +752,7 @@ class TestGrpc:
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.emane = EmaneIeee80211abgModel.name
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
session.emane.set_model(emane_network, EmaneIeee80211abgModel)
|
||||
|
||||
# then
|
||||
|
@ -777,7 +780,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
session.mobility.set_model_config(wlan.id, Ns2ScriptedMobility.name, {})
|
||||
|
||||
# then
|
||||
|
@ -794,7 +797,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
session.mobility.set_model_config(wlan.id, Ns2ScriptedMobility.name, {})
|
||||
|
||||
# then
|
||||
|
@ -808,7 +811,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
config_key = "refresh_ms"
|
||||
config_value = "60"
|
||||
|
||||
|
@ -827,7 +830,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(WlanNode)
|
||||
session.mobility.set_model_config(wlan.id, Ns2ScriptedMobility.name, {})
|
||||
session.instantiate()
|
||||
|
||||
|
@ -880,7 +883,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
service_name = "DefaultRoute"
|
||||
session.services.set_service(node.id, service_name)
|
||||
|
||||
|
@ -898,7 +901,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
@ -911,7 +914,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
@ -926,7 +929,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
service_name = "DefaultRoute"
|
||||
validate = ["echo hello"]
|
||||
|
||||
|
@ -947,7 +950,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
service_name = "DefaultRoute"
|
||||
file_name = "defaultroute.sh"
|
||||
file_data = "echo hello"
|
||||
|
@ -967,7 +970,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
service_name = "DefaultRoute"
|
||||
|
||||
# then
|
||||
|
@ -983,7 +986,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
queue = Queue()
|
||||
|
||||
def handle_event(event_data):
|
||||
|
@ -1004,8 +1007,8 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
node = session.add_node()
|
||||
wlan = session.add_node(WlanNode)
|
||||
node = session.add_node(CoreNode)
|
||||
interface = ip_prefixes.create_interface(node)
|
||||
session.add_link(node.id, wlan.id, interface)
|
||||
link_data = wlan.all_link_data()[0]
|
||||
|
@ -1126,7 +1129,7 @@ class TestGrpc:
|
|||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
queue = Queue()
|
||||
|
||||
def handle_event(event_data):
|
||||
|
|
|
@ -24,6 +24,8 @@ from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
|||
from core.emulator.enumerations import EventTypes, MessageFlags, NodeTypes, RegisterTlvs
|
||||
from core.errors import CoreError
|
||||
from core.location.mobility import BasicRangeModel
|
||||
from core.nodes.base import CoreNode, NodeBase
|
||||
from core.nodes.network import SwitchNode, WlanNode
|
||||
|
||||
|
||||
def dict_to_str(values):
|
||||
|
@ -57,12 +59,11 @@ class TestGui:
|
|||
)
|
||||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
assert coretlv.session.get_node(node_id) is not None
|
||||
assert coretlv.session.get_node(node_id, NodeBase) is not None
|
||||
|
||||
def test_node_update(self, coretlv):
|
||||
node_id = 1
|
||||
coretlv.session.add_node(_id=node_id)
|
||||
coretlv.session.add_node(CoreNode, _id=node_id)
|
||||
x = 50
|
||||
y = 100
|
||||
message = coreapi.CoreNodeMessage.create(
|
||||
|
@ -76,14 +77,14 @@ class TestGui:
|
|||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
node = coretlv.session.get_node(node_id)
|
||||
node = coretlv.session.get_node(node_id, NodeBase)
|
||||
assert node is not None
|
||||
assert node.position.x == x
|
||||
assert node.position.y == y
|
||||
|
||||
def test_node_delete(self, coretlv):
|
||||
node_id = 1
|
||||
coretlv.session.add_node(_id=node_id)
|
||||
coretlv.session.add_node(CoreNode, _id=node_id)
|
||||
message = coreapi.CoreNodeMessage.create(
|
||||
MessageFlags.DELETE.value, [(NodeTlvs.NUMBER, node_id)]
|
||||
)
|
||||
|
@ -91,13 +92,13 @@ class TestGui:
|
|||
coretlv.handle_message(message)
|
||||
|
||||
with pytest.raises(CoreError):
|
||||
coretlv.session.get_node(node_id)
|
||||
coretlv.session.get_node(node_id, NodeBase)
|
||||
|
||||
def test_link_add_node_to_net(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
switch = 2
|
||||
coretlv.session.add_node(_id=switch, _type=NodeTypes.SWITCH)
|
||||
coretlv.session.add_node(SwitchNode, _id=switch)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
message = coreapi.CoreLinkMessage.create(
|
||||
|
@ -113,15 +114,15 @@ class TestGui:
|
|||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
|
||||
def test_link_add_net_to_node(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
switch = 2
|
||||
coretlv.session.add_node(_id=switch, _type=NodeTypes.SWITCH)
|
||||
coretlv.session.add_node(SwitchNode, _id=switch)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
message = coreapi.CoreLinkMessage.create(
|
||||
|
@ -137,15 +138,15 @@ class TestGui:
|
|||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
|
||||
def test_link_add_node_to_node(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
node_two = 2
|
||||
coretlv.session.add_node(_id=node_two)
|
||||
coretlv.session.add_node(CoreNode, _id=node_two)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
interface_two = str(ip_prefix[node_two])
|
||||
|
@ -173,9 +174,9 @@ class TestGui:
|
|||
|
||||
def test_link_update(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
switch = 2
|
||||
coretlv.session.add_node(_id=switch, _type=NodeTypes.SWITCH)
|
||||
coretlv.session.add_node(SwitchNode, _id=switch)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
message = coreapi.CoreLinkMessage.create(
|
||||
|
@ -189,7 +190,7 @@ class TestGui:
|
|||
],
|
||||
)
|
||||
coretlv.handle_message(message)
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
link = all_links[0]
|
||||
|
@ -207,7 +208,7 @@ class TestGui:
|
|||
)
|
||||
coretlv.handle_message(message)
|
||||
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
link = all_links[0]
|
||||
|
@ -215,9 +216,9 @@ class TestGui:
|
|||
|
||||
def test_link_delete_node_to_node(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
node_two = 2
|
||||
coretlv.session.add_node(_id=node_two)
|
||||
coretlv.session.add_node(CoreNode, _id=node_two)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
interface_two = str(ip_prefix[node_two])
|
||||
|
@ -259,9 +260,9 @@ class TestGui:
|
|||
|
||||
def test_link_delete_node_to_net(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
switch = 2
|
||||
coretlv.session.add_node(_id=switch, _type=NodeTypes.SWITCH)
|
||||
coretlv.session.add_node(SwitchNode, _id=switch)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
message = coreapi.CoreLinkMessage.create(
|
||||
|
@ -275,7 +276,7 @@ class TestGui:
|
|||
],
|
||||
)
|
||||
coretlv.handle_message(message)
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
|
||||
|
@ -289,15 +290,15 @@ class TestGui:
|
|||
)
|
||||
coretlv.handle_message(message)
|
||||
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 0
|
||||
|
||||
def test_link_delete_net_to_node(self, coretlv):
|
||||
node_one = 1
|
||||
coretlv.session.add_node(_id=node_one)
|
||||
coretlv.session.add_node(CoreNode, _id=node_one)
|
||||
switch = 2
|
||||
coretlv.session.add_node(_id=switch, _type=NodeTypes.SWITCH)
|
||||
coretlv.session.add_node(SwitchNode, _id=switch)
|
||||
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
||||
interface_one = str(ip_prefix[node_one])
|
||||
message = coreapi.CoreLinkMessage.create(
|
||||
|
@ -311,7 +312,7 @@ class TestGui:
|
|||
],
|
||||
)
|
||||
coretlv.handle_message(message)
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 1
|
||||
|
||||
|
@ -325,7 +326,7 @@ class TestGui:
|
|||
)
|
||||
coretlv.handle_message(message)
|
||||
|
||||
switch_node = coretlv.session.get_node(switch)
|
||||
switch_node = coretlv.session.get_node(switch, SwitchNode)
|
||||
all_links = switch_node.all_link_data()
|
||||
assert len(all_links) == 0
|
||||
|
||||
|
@ -395,7 +396,7 @@ class TestGui:
|
|||
assert file_data == data
|
||||
|
||||
def test_file_service_file_set(self, coretlv):
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
service = "DefaultRoute"
|
||||
file_name = "defaultroute.sh"
|
||||
file_data = "echo hello"
|
||||
|
@ -418,7 +419,7 @@ class TestGui:
|
|||
|
||||
def test_file_node_file_copy(self, request, coretlv):
|
||||
file_name = "/var/log/test/node.log"
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
node.makenodedir()
|
||||
file_data = "echo hello"
|
||||
message = coreapi.CoreFileMessage.create(
|
||||
|
@ -440,7 +441,7 @@ class TestGui:
|
|||
|
||||
def test_exec_node_tty(self, coretlv):
|
||||
coretlv.dispatch_replies = mock.MagicMock()
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreExecMessage.create(
|
||||
MessageFlags.TTY.value,
|
||||
[
|
||||
|
@ -461,7 +462,7 @@ class TestGui:
|
|||
pytest.skip("mocking calls")
|
||||
|
||||
coretlv.dispatch_replies = mock.MagicMock()
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
cmd = "echo hello"
|
||||
message = coreapi.CoreExecMessage.create(
|
||||
MessageFlags.TEXT.value | MessageFlags.LOCAL.value,
|
||||
|
@ -480,7 +481,7 @@ class TestGui:
|
|||
|
||||
def test_exec_node_command(self, coretlv):
|
||||
coretlv.dispatch_replies = mock.MagicMock()
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
cmd = "echo hello"
|
||||
message = coreapi.CoreExecMessage.create(
|
||||
MessageFlags.TEXT.value,
|
||||
|
@ -515,7 +516,7 @@ class TestGui:
|
|||
|
||||
def test_event_schedule(self, coretlv):
|
||||
coretlv.session.add_event = mock.MagicMock()
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreEventMessage.create(
|
||||
MessageFlags.ADD.value,
|
||||
[
|
||||
|
@ -534,7 +535,7 @@ class TestGui:
|
|||
def test_event_save_xml(self, coretlv, tmpdir):
|
||||
xml_file = tmpdir.join("coretlv.session.xml")
|
||||
file_path = xml_file.strpath
|
||||
coretlv.session.add_node()
|
||||
coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreEventMessage.create(
|
||||
0,
|
||||
[(EventTlvs.TYPE, EventTypes.FILE_SAVE.value), (EventTlvs.NAME, file_path)],
|
||||
|
@ -547,7 +548,7 @@ class TestGui:
|
|||
def test_event_open_xml(self, coretlv, tmpdir):
|
||||
xml_file = tmpdir.join("coretlv.session.xml")
|
||||
file_path = xml_file.strpath
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
coretlv.session.save_xml(file_path)
|
||||
coretlv.session.delete_node(node.id)
|
||||
message = coreapi.CoreEventMessage.create(
|
||||
|
@ -556,8 +557,7 @@ class TestGui:
|
|||
)
|
||||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
assert coretlv.session.get_node(node.id)
|
||||
assert coretlv.session.get_node(node.id, NodeBase)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"state",
|
||||
|
@ -571,7 +571,7 @@ class TestGui:
|
|||
)
|
||||
def test_event_service(self, coretlv, state):
|
||||
coretlv.session.broadcast_event = mock.MagicMock()
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreEventMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -609,7 +609,7 @@ class TestGui:
|
|||
def test_register_xml(self, coretlv, tmpdir):
|
||||
xml_file = tmpdir.join("coretlv.session.xml")
|
||||
file_path = xml_file.strpath
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
coretlv.session.save_xml(file_path)
|
||||
coretlv.session.delete_node(node.id)
|
||||
message = coreapi.CoreRegMessage.create(
|
||||
|
@ -619,15 +619,16 @@ class TestGui:
|
|||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
assert coretlv.coreemu.sessions[1].get_node(node.id)
|
||||
assert coretlv.coreemu.sessions[1].get_node(node.id, CoreNode)
|
||||
|
||||
def test_register_python(self, coretlv, tmpdir):
|
||||
xml_file = tmpdir.join("test.py")
|
||||
file_path = xml_file.strpath
|
||||
with open(file_path, "w") as f:
|
||||
f.write("from core.nodes.base import CoreNode\n")
|
||||
f.write("coreemu = globals()['coreemu']\n")
|
||||
f.write(f"session = coreemu.sessions[{coretlv.session.id}]\n")
|
||||
f.write("session.add_node()\n")
|
||||
f.write("session.add_node(CoreNode)\n")
|
||||
message = coreapi.CoreRegMessage.create(
|
||||
0, [(RegisterTlvs.EXECUTE_SERVER, file_path)]
|
||||
)
|
||||
|
@ -773,7 +774,7 @@ class TestGui:
|
|||
coretlv.handle_broadcast_config.assert_called_once()
|
||||
|
||||
def test_config_services_request_specific(self, coretlv):
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -790,7 +791,7 @@ class TestGui:
|
|||
coretlv.handle_broadcast_config.assert_called_once()
|
||||
|
||||
def test_config_services_request_specific_file(self, coretlv):
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -807,7 +808,7 @@ class TestGui:
|
|||
coretlv.session.broadcast_file.assert_called_once()
|
||||
|
||||
def test_config_services_reset(self, coretlv):
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
service = "DefaultRoute"
|
||||
coretlv.session.services.set_service(node.id, service)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
|
@ -824,7 +825,7 @@ class TestGui:
|
|||
assert coretlv.session.services.get_service(node.id, service) is None
|
||||
|
||||
def test_config_services_set(self, coretlv):
|
||||
node = coretlv.session.add_node()
|
||||
node = coretlv.session.add_node(CoreNode)
|
||||
service = "DefaultRoute"
|
||||
values = {"meta": "metadata"}
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
|
@ -844,7 +845,7 @@ class TestGui:
|
|||
assert coretlv.session.services.get_service(node.id, service) is not None
|
||||
|
||||
def test_config_mobility_reset(self, coretlv):
|
||||
wlan = coretlv.session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = coretlv.session.add_node(WlanNode)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -860,7 +861,7 @@ class TestGui:
|
|||
assert len(coretlv.session.mobility.node_configurations) == 0
|
||||
|
||||
def test_config_mobility_model_request(self, coretlv):
|
||||
wlan = coretlv.session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = coretlv.session.add_node(WlanNode)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -876,7 +877,7 @@ class TestGui:
|
|||
coretlv.handle_broadcast_config.assert_called_once()
|
||||
|
||||
def test_config_mobility_model_update(self, coretlv):
|
||||
wlan = coretlv.session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = coretlv.session.add_node(WlanNode)
|
||||
config_key = "range"
|
||||
config_value = "1000"
|
||||
values = {config_key: config_value}
|
||||
|
@ -898,7 +899,7 @@ class TestGui:
|
|||
assert config[config_key] == config_value
|
||||
|
||||
def test_config_emane_model_request(self, coretlv):
|
||||
wlan = coretlv.session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = coretlv.session.add_node(WlanNode)
|
||||
message = coreapi.CoreConfMessage.create(
|
||||
0,
|
||||
[
|
||||
|
@ -914,7 +915,7 @@ class TestGui:
|
|||
coretlv.handle_broadcast_config.assert_called_once()
|
||||
|
||||
def test_config_emane_model_update(self, coretlv):
|
||||
wlan = coretlv.session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = coretlv.session.add_node(WlanNode)
|
||||
config_key = "distance"
|
||||
config_value = "50051"
|
||||
values = {config_key: config_value}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from core.emulator.emudata import LinkOptions
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
|
||||
def create_ptp_network(session, ip_prefixes):
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to net node
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
|
@ -21,8 +22,8 @@ def create_ptp_network(session, ip_prefixes):
|
|||
class TestLinks:
|
||||
def test_ptp(self, session, ip_prefixes):
|
||||
# given
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
|
||||
|
@ -35,8 +36,8 @@ class TestLinks:
|
|||
|
||||
def test_node_to_net(self, session, ip_prefixes):
|
||||
# given
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(SwitchNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
|
||||
# when
|
||||
|
@ -48,8 +49,8 @@ class TestLinks:
|
|||
|
||||
def test_net_to_node(self, session, ip_prefixes):
|
||||
# given
|
||||
node_one = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(SwitchNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
|
||||
# when
|
||||
|
@ -61,8 +62,8 @@ class TestLinks:
|
|||
|
||||
def test_net_to_net(self, session):
|
||||
# given
|
||||
node_one = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_one = session.add_node(SwitchNode)
|
||||
node_two = session.add_node(SwitchNode)
|
||||
|
||||
# when
|
||||
session.add_link(node_one.id, node_two.id)
|
||||
|
@ -77,8 +78,8 @@ class TestLinks:
|
|||
per = 25
|
||||
dup = 25
|
||||
jitter = 10
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(SwitchNode)
|
||||
interface_one_data = ip_prefixes.create_interface(node_one)
|
||||
session.add_link(node_one.id, node_two.id, interface_one_data)
|
||||
interface_one = node_one.netif(interface_one_data.id)
|
||||
|
@ -111,8 +112,8 @@ class TestLinks:
|
|||
|
||||
def test_link_delete(self, session, ip_prefixes):
|
||||
# given
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import pytest
|
||||
|
||||
from core.emulator.emudata import NodeOptions
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.errors import CoreError
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import HubNode, SwitchNode, WlanNode
|
||||
|
||||
MODELS = ["router", "host", "PC", "mdr"]
|
||||
NET_TYPES = [NodeTypes.SWITCH, NodeTypes.HUB, NodeTypes.WIRELESS_LAN]
|
||||
NET_TYPES = [SwitchNode, HubNode, WlanNode]
|
||||
|
||||
|
||||
class TestNodes:
|
||||
|
@ -15,7 +16,7 @@ class TestNodes:
|
|||
options = NodeOptions(model=model)
|
||||
|
||||
# when
|
||||
node = session.add_node(options=options)
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
|
||||
# then
|
||||
assert node
|
||||
|
@ -24,7 +25,7 @@ class TestNodes:
|
|||
|
||||
def test_node_update(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
position_value = 100
|
||||
update_options = NodeOptions()
|
||||
update_options.set_position(x=position_value, y=position_value)
|
||||
|
@ -38,18 +39,18 @@ class TestNodes:
|
|||
|
||||
def test_node_delete(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# when
|
||||
session.delete_node(node.id)
|
||||
|
||||
# then
|
||||
with pytest.raises(CoreError):
|
||||
session.get_node(node.id)
|
||||
session.get_node(node.id, CoreNode)
|
||||
|
||||
def test_node_sethwaddr(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
index = node.newnetif()
|
||||
interface = node.netif(index)
|
||||
mac = "aa:aa:aa:ff:ff:ff"
|
||||
|
@ -62,7 +63,7 @@ class TestNodes:
|
|||
|
||||
def test_node_sethwaddr_exception(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
index = node.newnetif()
|
||||
node.netif(index)
|
||||
mac = "aa:aa:aa:ff:ff:fff"
|
||||
|
@ -73,7 +74,7 @@ class TestNodes:
|
|||
|
||||
def test_node_addaddr(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
index = node.newnetif()
|
||||
interface = node.netif(index)
|
||||
addr = "192.168.0.1/24"
|
||||
|
@ -86,7 +87,7 @@ class TestNodes:
|
|||
|
||||
def test_node_addaddr_exception(self, session):
|
||||
# given
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
index = node.newnetif()
|
||||
node.netif(index)
|
||||
addr = "256.168.0.1/24"
|
||||
|
@ -100,7 +101,7 @@ class TestNodes:
|
|||
# given
|
||||
|
||||
# when
|
||||
node = session.add_node(_type=net_type)
|
||||
node = session.add_node(net_type)
|
||||
|
||||
# then
|
||||
assert node
|
||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
|||
from mock import MagicMock
|
||||
|
||||
from core.errors import CoreCommandError
|
||||
from core.nodes.base import CoreNode
|
||||
from core.services.coreservices import CoreService, ServiceDependencies, ServiceManager
|
||||
|
||||
_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
|
@ -52,7 +53,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
file_name = "myservice.sh"
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# when
|
||||
session.services.set_service_file(node.id, SERVICE_ONE, file_name, "# test")
|
||||
|
@ -66,7 +67,7 @@ class TestServices:
|
|||
def test_service_all_configs(self, session):
|
||||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# when
|
||||
session.services.set_service(node.id, SERVICE_ONE)
|
||||
|
@ -80,7 +81,7 @@ class TestServices:
|
|||
def test_service_add_services(self, session):
|
||||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
total_service = len(node.services)
|
||||
|
||||
# when
|
||||
|
@ -94,7 +95,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
file_name = my_service.configs[0]
|
||||
file_path = node.hostfilename(file_name)
|
||||
|
||||
|
@ -109,7 +110,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
|
||||
# when
|
||||
|
@ -122,7 +123,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_TWO)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
node.cmd = MagicMock(side_effect=CoreCommandError(-1, "invalid"))
|
||||
|
||||
|
@ -136,7 +137,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
|
||||
# when
|
||||
|
@ -149,7 +150,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_TWO)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
node.cmd = MagicMock(side_effect=CoreCommandError(-1, "invalid"))
|
||||
|
||||
|
@ -163,7 +164,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
|
||||
# when
|
||||
|
@ -176,7 +177,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_TWO)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
session.services.create_service_files(node, my_service)
|
||||
node.cmd = MagicMock(side_effect=CoreCommandError(-1, "invalid"))
|
||||
|
||||
|
@ -190,7 +191,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# when
|
||||
session.services.set_service(node.id, my_service.name)
|
||||
|
@ -204,8 +205,8 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
file_name = my_service.configs[0]
|
||||
file_data_one = "# custom file one"
|
||||
file_data_two = "# custom file two"
|
||||
|
@ -234,7 +235,7 @@ class TestServices:
|
|||
# given
|
||||
ServiceManager.add_services(_SERVICES_PATH)
|
||||
my_service = ServiceManager.get(SERVICE_ONE)
|
||||
node = session.add_node()
|
||||
node = session.add_node(CoreNode)
|
||||
|
||||
# when
|
||||
no_service = session.services.get_service(node.id, SERVICE_ONE)
|
||||
|
|
|
@ -3,9 +3,11 @@ from xml.etree import ElementTree
|
|||
import pytest
|
||||
|
||||
from core.emulator.emudata import LinkOptions, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.errors import CoreError
|
||||
from core.location.mobility import BasicRangeModel
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import PtpNet, SwitchNode, WlanNode
|
||||
from core.services.utility import SshService
|
||||
|
||||
|
||||
|
@ -59,11 +61,11 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create ptp
|
||||
ptp_node = session.add_node(_type=NodeTypes.PEER_TO_PEER)
|
||||
ptp_node = session.add_node(PtpNet)
|
||||
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to ptp net
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -91,16 +93,16 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
||||
# verify nodes have been recreated
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
|
||||
def test_xml_ptp_services(self, session, tmpdir, ip_prefixes):
|
||||
"""
|
||||
|
@ -111,12 +113,12 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create ptp
|
||||
ptp_node = session.add_node(_type=NodeTypes.PEER_TO_PEER)
|
||||
ptp_node = session.add_node(PtpNet)
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(model="host")
|
||||
node_one = session.add_node(options=options)
|
||||
node_two = session.add_node()
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
||||
# link nodes to ptp net
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -152,9 +154,9 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
@ -163,8 +165,8 @@ class TestXml:
|
|||
service = session.services.get_service(node_one.id, SshService.name)
|
||||
|
||||
# verify nodes have been recreated
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
assert service.config_data.get(service_file) == file_data
|
||||
|
||||
def test_xml_mobility(self, session, tmpdir, ip_prefixes):
|
||||
|
@ -176,14 +178,14 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create wlan
|
||||
wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan_node = session.add_node(WlanNode)
|
||||
session.mobility.set_model(wlan_node, BasicRangeModel, {"test": "1"})
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
node_one = session.add_node(options=options)
|
||||
node_two = session.add_node(options=options)
|
||||
node_one = session.add_node(CoreNode, options=options)
|
||||
node_two = session.add_node(CoreNode, options=options)
|
||||
|
||||
# link nodes
|
||||
for node in [node_one, node_two]:
|
||||
|
@ -212,9 +214,9 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
@ -223,9 +225,9 @@ class TestXml:
|
|||
value = str(session.mobility.get_config("test", wlan_id, BasicRangeModel.name))
|
||||
|
||||
# verify nodes and configuration were restored
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(wlan_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
assert session.get_node(wlan_id, WlanNode)
|
||||
assert value == "1"
|
||||
|
||||
def test_network_to_network(self, session, tmpdir):
|
||||
|
@ -236,8 +238,8 @@ class TestXml:
|
|||
:param tmpdir: tmpdir to create data in
|
||||
"""
|
||||
# create nodes
|
||||
switch_one = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch_two = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch_one = session.add_node(SwitchNode)
|
||||
switch_two = session.add_node(SwitchNode)
|
||||
|
||||
# link nodes
|
||||
session.add_link(switch_one.id, switch_two.id)
|
||||
|
@ -263,16 +265,16 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, SwitchNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, SwitchNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
||||
# verify nodes have been recreated
|
||||
switch_one = session.get_node(n1_id)
|
||||
switch_two = session.get_node(n2_id)
|
||||
switch_one = session.get_node(n1_id, SwitchNode)
|
||||
switch_two = session.get_node(n2_id, SwitchNode)
|
||||
assert switch_one
|
||||
assert switch_two
|
||||
assert len(switch_one.all_link_data() + switch_two.all_link_data()) == 1
|
||||
|
@ -286,9 +288,9 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
switch = session.add_node(SwitchNode)
|
||||
|
||||
# create link
|
||||
link_options = LinkOptions()
|
||||
|
@ -322,16 +324,16 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, SwitchNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
||||
# verify nodes have been recreated
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, SwitchNode)
|
||||
links = []
|
||||
for node_id in session.nodes:
|
||||
node = session.nodes[node_id]
|
||||
|
@ -352,9 +354,9 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
node_two = session.add_node()
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
|
||||
# create link
|
||||
|
@ -389,16 +391,16 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
||||
# verify nodes have been recreated
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
links = []
|
||||
for node_id in session.nodes:
|
||||
node = session.nodes[node_id]
|
||||
|
@ -419,9 +421,9 @@ class TestXml:
|
|||
:param ip_prefixes: generates ip addresses for nodes
|
||||
"""
|
||||
# create nodes
|
||||
node_one = session.add_node()
|
||||
node_one = session.add_node(CoreNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
node_two = session.add_node()
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
|
||||
# create link
|
||||
|
@ -471,16 +473,16 @@ class TestXml:
|
|||
|
||||
# verify nodes have been removed from session
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n1_id)
|
||||
assert not session.get_node(n1_id, CoreNode)
|
||||
with pytest.raises(CoreError):
|
||||
assert not session.get_node(n2_id)
|
||||
assert not session.get_node(n2_id, CoreNode)
|
||||
|
||||
# load saved xml
|
||||
session.open_xml(file_path, start=True)
|
||||
|
||||
# verify nodes have been recreated
|
||||
assert session.get_node(n1_id)
|
||||
assert session.get_node(n2_id)
|
||||
assert session.get_node(n1_id, CoreNode)
|
||||
assert session.get_node(n2_id, CoreNode)
|
||||
links = []
|
||||
for node_id in session.nodes:
|
||||
node = session.nodes[node_id]
|
||||
|
|
|
@ -28,35 +28,54 @@ connections.
|
|||
Here are the basic elements of a CORE Python script:
|
||||
|
||||
```python
|
||||
"""
|
||||
This is a standalone script to run a small switch based scenario and will not
|
||||
interact with the GUI.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import SwitchNode
|
||||
|
||||
# ip generator for example
|
||||
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
||||
NODES = 2
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
def main():
|
||||
# ip generator for example
|
||||
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
||||
|
||||
# create switch network node
|
||||
switch = session.add_node(_type=NodeTypes.SWITCH)
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# create nodes
|
||||
for _ in range(2):
|
||||
node = session.add_node()
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface_one=interface)
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
# create switch network node
|
||||
switch = session.add_node(SwitchNode, _id=100)
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
# create nodes
|
||||
for _ in range(NODES):
|
||||
node = session.add_node(CoreNode)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, switch.id, interface_one=interface)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
|
||||
# run any desired logic here
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
main()
|
||||
```
|
||||
|
||||
The above script creates a CORE session having two nodes connected with a
|
||||
|
@ -136,7 +155,7 @@ session = coreemu.create_session()
|
|||
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
||||
options = NodeOptions()
|
||||
options.set_position(80, 50)
|
||||
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
||||
emane_network = session.add_node(EmaneNet, options=options)
|
||||
|
||||
# set custom emane model config
|
||||
config = {}
|
||||
|
|
Loading…
Reference in a new issue