refactored new apis to sit under the emulator module, also reverted moving files under a legacy module to help avoid breaking code using core internals for 5.0+

This commit is contained in:
Blake J. Harnden 2018-05-01 10:40:25 -07:00
parent 9cb1513933
commit f5bff494c7
17 changed files with 53 additions and 50 deletions

View file

@ -15,6 +15,9 @@ from core import logger
from core.api import coreapi
from core.data import ConfigData
from core.data import EventData
from core.emulator.emudata import InterfaceData
from core.emulator.emudata import LinkOptions
from core.emulator.emudata import NodeOptions
from core.enumerations import ConfigTlvs
from core.enumerations import EventTlvs
from core.enumerations import EventTypes
@ -29,9 +32,6 @@ from core.enumerations import NodeTlvs
from core.enumerations import NodeTypes
from core.enumerations import RegisterTlvs
from core.enumerations import SessionTlvs
from core.future.futuredata import InterfaceData
from core.future.futuredata import LinkOptions
from core.future.futuredata import NodeOptions
from core.misc import nodeutils
from core.misc import structutils
from core.misc import utils

View file

@ -4,7 +4,7 @@ Defines core server for handling TCP connections.
import SocketServer
from core.future.coreemu import CoreEmu
from core.emulator.coreemu import CoreEmu
class CoreServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):

View file

@ -8,11 +8,11 @@ from core import logger
from core.coreobj import PyCoreNet
from core.coreobj import PyCoreNode
from core.data import NodeData
from core.emulator.emudata import LinkOptions
from core.emulator.emudata import NodeOptions
from core.enumerations import EventTypes
from core.enumerations import LinkTypes
from core.enumerations import NodeTypes
from core.future.futuredata import LinkOptions
from core.future.futuredata import NodeOptions
from core.misc import nodemaps
from core.misc import nodeutils
from core.session import Session
@ -45,7 +45,7 @@ def create_interface(node, network, interface_data):
:param node: node to create interface for
:param network: network to associate interface with
:param core.future.futuredata.InterfaceData interface_data: interface data
:param core.emulator.emudata.InterfaceData interface_data: interface data
:return: created interface
"""
node.newnetif(
@ -64,7 +64,7 @@ def link_config(network, interface, link_options, devname=None, interface_two=No
:param network: network to configure link for
:param interface: interface to configure
:param core.future.futuredata.LinkOptions link_options: data to configure link with
:param core.emulator.emudata.LinkOptions link_options: data to configure link with
:param str devname: device name, default is None
:param interface_two: other interface associated, default is None
:return: nothing
@ -117,9 +117,9 @@ class IdGen(object):
return self.id
class FutureSession(Session):
class EmuSession(Session):
def __init__(self, session_id, config=None, mkdir=True):
super(FutureSession, self).__init__(session_id, config, mkdir)
super(EmuSession, self).__init__(session_id, config, mkdir)
# object management
self.node_id_gen = IdGen()
@ -220,9 +220,9 @@ class FutureSession(Session):
:param int node_one_id: node one id
:param int node_two_id: node two id
:param core.future.futuredata.InterfaceData interface_one: node one interface data, defaults to none
:param core.future.futuredata.InterfaceData interface_two: node two interface data, defaults to none
:param core.future.futuredata.LinkOptions link_options: data for creating link, defaults to no options
:param core.emulator.emudata.InterfaceData interface_one: node one interface data, defaults to none
:param core.emulator.emudata.InterfaceData interface_two: node two interface data, defaults to none
:param core.emulator.emudata.LinkOptions link_options: data for creating link, defaults to no options
:return:
"""
# get node objects identified by link data
@ -386,7 +386,7 @@ class FutureSession(Session):
:param int node_two_id: node two id
:param int interface_one_id: interface id for node one
:param int interface_two_id: interface id for node two
:param core.future.futuredata.LinkOptions link_options: data to update link with
:param core.emulator.emudata.LinkOptions link_options: data to update link with
:return: nothing
"""
# interface data
@ -467,7 +467,7 @@ class FutureSession(Session):
:param core.enumerations.NodeTypes _type: type of node to create
:param int _id: id for node, defaults to None for generated id
:param core.future.futuredata.NodeOptions node_options: data to create node with
:param core.emulator.emudata.NodeOptions node_options: data to create node with
:return: created node
"""
@ -531,7 +531,7 @@ class FutureSession(Session):
Update node information.
:param int node_id: id of node to update
:param core.future.futuredata.NodeOptions node_options: data to update node with
:param core.emulator.emudata.NodeOptions node_options: data to update node with
:return: True if node updated, False otherwise
:rtype: bool
"""
@ -573,7 +573,7 @@ class FutureSession(Session):
Set position for a node, use lat/lon/alt if needed.
:param node: node to set position for
:param core.future.futuredata.NodeOptions node_options: data for node
:param core.emulator.emudata.NodeOptions node_options: data for node
:return: nothing
"""
# extract location values
@ -627,9 +627,10 @@ class FutureSession(Session):
:return: nothing
"""
logger.info("session(%s) shutting down", self.session_id)
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
super(FutureSession, self).shutdown()
super(EmuSession, self).shutdown()
def custom_delete_object(self, object_id):
"""
@ -653,7 +654,7 @@ class FutureSession(Session):
:return: True if active, False otherwise
"""
result = self.state in {EventTypes.RUNTIME_STATE.value, EventTypes.DATACOLLECT_STATE.value}
logger.info("checking if session is active: %s", result)
logger.info("session(%s) checking if active: %s", self.session_id, result)
return result
def open_xml(self, file_name, start=False):
@ -775,7 +776,7 @@ class FutureSession(Session):
Create a wireless node for use within an wireless/EMANE networks.
:param int _id: int for node, defaults to None and will be generated
:param core.future.futuredata.NodeOptions node_options: options for emane node, model will always be "mdr"
:param core.emulator.emudata.NodeOptions node_options: options for emane node, model will always be "mdr"
:return: new emane node
:rtype: core.netns.nodes.CoreNode
"""
@ -789,7 +790,7 @@ class FutureSession(Session):
:param model: emane model to use for emane network
:param geo_reference: geo reference point to use for emane node locations
:param geo_scale: geo scale to use for emane node locations, defaults to 1.0
:param core.future.futuredata.NodeOptions node_options: options for emane node being created
:param core.emulator.emudata.NodeOptions node_options: options for emane node being created
:return: create emane network
"""
# required to be set for emane to function properly
@ -880,7 +881,7 @@ class CoreEmu(object):
:return: nothing
"""
logger.info("shutting down all session")
logger.info("shutting down all sessions")
sessions = self.sessions.copy()
self.sessions.clear()
for session in sessions.itervalues():
@ -893,7 +894,7 @@ class CoreEmu(object):
:param int _id: session id for new session
:param bool master: sets session to master
:return: created session
:rtype: FutureSession
:rtype: EmuSession
"""
session_id = _id
@ -903,7 +904,7 @@ class CoreEmu(object):
if session_id not in self.sessions:
break
session = FutureSession(session_id, config=self.config)
session = EmuSession(session_id, config=self.config)
logger.info("created session: %s", session_id)
if master:
session.master = True

View file

@ -1,5 +1,7 @@
from core.enumerations import LinkTypes
from core.misc.ipaddress import Ipv4Prefix, Ipv6Prefix, MacAddress
from core.misc.ipaddress import Ipv4Prefix
from core.misc.ipaddress import Ipv6Prefix
from core.misc.ipaddress import MacAddress
class NodeOptions(object):

View file

@ -6,9 +6,9 @@ import datetime
import parser
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.enumerations import EventTypes
from core.future.coreemu import CoreEmu
from core.future.futuredata import IpPrefixes
def example(options):

View file

@ -8,9 +8,9 @@
import datetime
import parser
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.enumerations import NodeTypes, EventTypes
from core.future.coreemu import CoreEmu
from core.future.futuredata import IpPrefixes
def example(options):

View file

@ -5,8 +5,8 @@
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep
from core.emulator.emudata import IpPrefixes
from core.enumerations import NodeTypes, EventTypes
from core.future.futuredata import IpPrefixes
def example(nodes):

View file

@ -8,9 +8,9 @@
import datetime
import parser
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.enumerations import NodeTypes, EventTypes
from core.future.coreemu import CoreEmu
from core.future.futuredata import IpPrefixes
from core.mobility import BasicRangeModel

View file

@ -13,8 +13,8 @@ import time
from core import constants
from core import enumerations
from core import logger
from core.legacy.corehandler import CoreHandler
from core.legacy.coreserver import CoreServer
from core.corehandlers import CoreHandler
from core.coreserver import CoreServer
from core.misc.utils import close_onexec
from core.service import ServiceManager

View file

@ -13,6 +13,10 @@ from core.api.coreapi import CoreEventMessage
from core.api.coreapi import CoreExecMessage
from core.api.coreapi import CoreLinkMessage
from core.api.coreapi import CoreNodeMessage
from core.corehandlers import CoreHandler
from core.coreserver import CoreServer
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.enumerations import CORE_API_PORT
from core.enumerations import ConfigTlvs
from core.enumerations import EventTlvs
@ -23,10 +27,6 @@ from core.enumerations import LinkTypes
from core.enumerations import MessageFlags
from core.enumerations import NodeTlvs
from core.enumerations import NodeTypes
from core.future.coreemu import CoreEmu
from core.future.futuredata import IpPrefixes
from core.legacy.corehandler import CoreHandler
from core.legacy.coreserver import CoreServer
from core.misc import ipaddress
from core.misc.ipaddress import MacAddress

View file

@ -11,8 +11,8 @@ import pytest
from mock import MagicMock
from core.data import ConfigData
from core.emulator.emudata import NodeOptions
from core.enumerations import MessageFlags, NodeTypes
from core.future.futuredata import NodeOptions
from core.mobility import BasicRangeModel
from core.netns.vnodeclient import VnodeClient
from core.service import ServiceManager
@ -250,7 +250,7 @@ class TestCore:
"""
Test basic wlan network.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
@ -283,7 +283,7 @@ class TestCore:
"""
Test basic wlan network.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""

View file

@ -10,7 +10,7 @@ from core.emane.commeffect import EmaneCommEffectModel
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emane.rfpipe import EmaneRfPipeModel
from core.emane.tdma import EmaneTdmaModel
from core.future.futuredata import NodeOptions
from core.emulator.emudata import NodeOptions
_EMANE_MODELS = [
EmaneIeee80211abgModel,
@ -27,7 +27,7 @@ class TestEmane:
"""
Test emane models within a basic network.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param model: emane model to test
:param ip_prefixes: generates ip addresses for nodes
"""

View file

@ -105,7 +105,7 @@ class TestGui:
"""
Test session broker creation.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param cored: cored daemon server to test with
"""

View file

@ -1,5 +1,5 @@
from core.emulator.emudata import LinkOptions
from core.enumerations import NodeTypes
from core.future.futuredata import LinkOptions
from core.misc import utils
@ -138,7 +138,7 @@ class TestLinks:
"""
Test ptp node network with modifying link bandwidth.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
@ -169,7 +169,7 @@ class TestLinks:
"""
Test ptp node network with modifying link packet loss.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
@ -200,7 +200,7 @@ class TestLinks:
"""
Test ptp node network with modifying link packet delay.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
@ -232,7 +232,7 @@ class TestLinks:
"""
Test ptp node network with modifying link packet jitter.
:param core.future.coreemu.FutureSession session: session for test
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""

View file

@ -3,8 +3,8 @@ import time
import pytest
from core.emulator.emudata import NodeOptions
from core.enumerations import NodeTypes
from core.future.futuredata import NodeOptions
from core.misc import utils
MODELS = [