added test script and test for mobility script testing

This commit is contained in:
Blake J. Harnden 2017-08-02 16:39:38 -07:00
parent 05ce19b0c0
commit b62076c240
5 changed files with 67 additions and 3 deletions

View file

@ -212,7 +212,7 @@ class MobilityManager(ConfigurableManager):
try:
n = self.session.get_object(nodenum)
except KeyError:
logger.exception("error getting session object")
logger.exception("error getting session object, this was ignored before")
continue
if n.model:
n.model.update(moved, moved_netifs)
@ -759,6 +759,7 @@ class WayPointMobility(WirelessModel):
:return: nothing
"""
logger.info("running mobility scenario")
self.timezero = time.time()
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
self.movenodesinitial()
@ -1194,6 +1195,7 @@ class Ns2ScriptedMobility(WayPointMobility):
:return: nothing
"""
logger.info("starting script")
laststate = self.state
super(Ns2ScriptedMobility, self).start()
if laststate == self.STATE_PAUSED:

View file

@ -382,7 +382,7 @@ class WlanNode(LxBrNet):
:param config: model configuration
:return: nothing
"""
logger.info("adding model %s" % model.name)
logger.info("adding model: %s", model.name)
if model.config_type == RegisterTlvs.WIRELESS.value:
self.model = model(session=self.session, object_id=self.objid, values=config)
if self.model.position_callback:

View file

@ -865,6 +865,7 @@ class Session(object):
# this is called from instantiate() after receiving an event message
# for the instantiation state, and from the broker when distributed
# nodes have been started
logger.info("checking runtime: %s", self.state)
if self.state == EventTypes.RUNTIME_STATE.value:
logger.info("valid runtime state found, returning")
return

View file

@ -0,0 +1,5 @@
# nodes: 3, max time: 35.000000, max x: 600.00, max y: 600.00
$node_(2) set X_ 144.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.00
$ns_ at 1.00 "$node_(2) setdest 130.0 280.0 15.0"

View file

@ -2,6 +2,8 @@
Unit tests for testing basic CORE networks.
"""
import os
import threading
import time
import pytest
@ -11,13 +13,17 @@ from xml.etree import ElementTree
from mock import MagicMock
from conftest import EMANE_SERVICES
from core.enumerations import MessageFlags
from core.data import ConfigData
from core.data import EventData
from core.enumerations import MessageFlags, ConfigTlvs, EventTypes
from core.mobility import BasicRangeModel
from core.netns import nodes
from core.netns import vnodeclient
from core.phys.pnodes import PhysicalNode
from core.xml import xmlsession
_PATH = os.path.abspath(os.path.dirname(__file__))
_MOBILITY_FILE = os.path.join(_PATH, "mobility.scen")
_XML_VERSIONS = ["0.0", "1.0"]
_NODE_CLASSES = [nodes.PtpNet, nodes.HubNode, nodes.SwitchNode]
@ -316,6 +322,56 @@ class TestCore:
status = core.ping("n1", "n2")
assert status
def test_mobility(self, core):
"""
Test basic wlan network.
:param conftest.Core core: core fixture to test with
"""
# create wlan
wlan_node = core.session.add_object(cls=nodes.WlanNode)
values = BasicRangeModel.getdefaultvalues()
wlan_node.setmodel(BasicRangeModel, values)
# create nodes
core.create_node("n1", objid=1, position=(0, 0), services=EMANE_SERVICES, model="mdr")
core.create_node("n2", objid=2, position=(0, 0), services=EMANE_SERVICES, model="mdr")
# add interfaces
interface_one = core.add_interface(wlan_node, "n1")
interface_two = core.add_interface(wlan_node, "n2")
# link nodes in wlan
core.link(wlan_node, interface_one, interface_two)
# configure mobility script for session
config = ConfigData(
node=wlan_node.objid,
object="ns2script",
type=0,
data_types=(10, 3, 11, 10, 10, 10, 10, 10, 0),
data_values="file=%s|refresh_ms=50|loop=1|autostart=0.0|"
"map=|script_start=|script_pause=|script_stop=" % _MOBILITY_FILE
)
core.session.config_object(config)
# add handler for receiving node updates
event = threading.Event()
def node_update(_):
event.set()
core.session.node_handlers.append(node_update)
# instantiate session
core.session.instantiate()
# assert node directories created
core.assert_nodes()
# validate we receive a node message for updating its location
assert event.wait(5)
def test_link_bandwidth(self, core):
"""
Test ptp node network with modifying link bandwidth.