added test script and test for mobility script testing
This commit is contained in:
parent
05ce19b0c0
commit
b62076c240
5 changed files with 67 additions and 3 deletions
|
@ -212,7 +212,7 @@ class MobilityManager(ConfigurableManager):
|
||||||
try:
|
try:
|
||||||
n = self.session.get_object(nodenum)
|
n = self.session.get_object(nodenum)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.exception("error getting session object")
|
logger.exception("error getting session object, this was ignored before")
|
||||||
continue
|
continue
|
||||||
if n.model:
|
if n.model:
|
||||||
n.model.update(moved, moved_netifs)
|
n.model.update(moved, moved_netifs)
|
||||||
|
@ -759,6 +759,7 @@ class WayPointMobility(WirelessModel):
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
|
logger.info("running mobility scenario")
|
||||||
self.timezero = time.time()
|
self.timezero = time.time()
|
||||||
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
|
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
|
||||||
self.movenodesinitial()
|
self.movenodesinitial()
|
||||||
|
@ -1194,6 +1195,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
|
logger.info("starting script")
|
||||||
laststate = self.state
|
laststate = self.state
|
||||||
super(Ns2ScriptedMobility, self).start()
|
super(Ns2ScriptedMobility, self).start()
|
||||||
if laststate == self.STATE_PAUSED:
|
if laststate == self.STATE_PAUSED:
|
||||||
|
|
|
@ -382,7 +382,7 @@ class WlanNode(LxBrNet):
|
||||||
:param config: model configuration
|
:param config: model configuration
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logger.info("adding model %s" % model.name)
|
logger.info("adding model: %s", model.name)
|
||||||
if model.config_type == RegisterTlvs.WIRELESS.value:
|
if model.config_type == RegisterTlvs.WIRELESS.value:
|
||||||
self.model = model(session=self.session, object_id=self.objid, values=config)
|
self.model = model(session=self.session, object_id=self.objid, values=config)
|
||||||
if self.model.position_callback:
|
if self.model.position_callback:
|
||||||
|
|
|
@ -865,6 +865,7 @@ class Session(object):
|
||||||
# this is called from instantiate() after receiving an event message
|
# this is called from instantiate() after receiving an event message
|
||||||
# for the instantiation state, and from the broker when distributed
|
# for the instantiation state, and from the broker when distributed
|
||||||
# nodes have been started
|
# nodes have been started
|
||||||
|
logger.info("checking runtime: %s", self.state)
|
||||||
if self.state == EventTypes.RUNTIME_STATE.value:
|
if self.state == EventTypes.RUNTIME_STATE.value:
|
||||||
logger.info("valid runtime state found, returning")
|
logger.info("valid runtime state found, returning")
|
||||||
return
|
return
|
||||||
|
|
5
daemon/tests/mobility.scen
Normal file
5
daemon/tests/mobility.scen
Normal 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"
|
|
@ -2,6 +2,8 @@
|
||||||
Unit tests for testing basic CORE networks.
|
Unit tests for testing basic CORE networks.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -11,13 +13,17 @@ from xml.etree import ElementTree
|
||||||
from mock import MagicMock
|
from mock import MagicMock
|
||||||
|
|
||||||
from conftest import EMANE_SERVICES
|
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.mobility import BasicRangeModel
|
||||||
from core.netns import nodes
|
from core.netns import nodes
|
||||||
from core.netns import vnodeclient
|
from core.netns import vnodeclient
|
||||||
from core.phys.pnodes import PhysicalNode
|
from core.phys.pnodes import PhysicalNode
|
||||||
from core.xml import xmlsession
|
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"]
|
_XML_VERSIONS = ["0.0", "1.0"]
|
||||||
_NODE_CLASSES = [nodes.PtpNet, nodes.HubNode, nodes.SwitchNode]
|
_NODE_CLASSES = [nodes.PtpNet, nodes.HubNode, nodes.SwitchNode]
|
||||||
|
|
||||||
|
@ -316,6 +322,56 @@ class TestCore:
|
||||||
status = core.ping("n1", "n2")
|
status = core.ping("n1", "n2")
|
||||||
assert status
|
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):
|
def test_link_bandwidth(self, core):
|
||||||
"""
|
"""
|
||||||
Test ptp node network with modifying link bandwidth.
|
Test ptp node network with modifying link bandwidth.
|
||||||
|
|
Loading…
Add table
Reference in a new issue