import os
import time
+import threading
@clsinit_copy
class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
ns3_version = Attribute("ns3Version",
"Version of ns-3 to install from nsam repo",
- default = "ns-3.19",
+ #default = "ns-3.19",
+ default = "ns-3-dev",
flags = Flags.Design)
enable_dce = Attribute("enableDCE",
pybindgen_version = Attribute("pybindgenVersion",
"Version of pybindgen to install from bazar repo",
- default = "834",
+ default = "868",
flags = Flags.Design)
populate_routing_tables = Attribute("populateRoutingTables",
self._client = None
self._home = "ns3-simu-%s" % self.guid
self._socket_name = "ns3-%s.sock" % os.urandom(4).encode('hex')
- self._dce_helper_uuid = None
+ self._dce_manager_helper_uuid = None
self._dce_application_helper_uuid = None
+
+ # Lock used to synchronize usage of DceManagerHelper
+ self.dce_manager_lock = threading.Lock()
+ # Lock used to synchronize usage of DceApplicationHelper
+ self.dce_application_lock = threading.Lock()
@property
def socket_name(self):
return os.path.join(self.run_home, self.socket_name)
@property
- def dce_helper_uuid(self):
- return self._dce_helper_uuid
+ def dce_manager_helper_uuid(self):
+ return self._dce_manager_helper_uuid
@property
def dce_application_helper_uuid(self):
self.invoke(GLOBAL_VALUE_UUID, "Bind", "SchedulerType", btrue)
if self.get("enableDCE"):
- self._dce_helper_uuid = self.create("DceManagerHelper")
+ self._dce_manager_helper_uuid = self.create("DceManagerHelper")
self._dce_application_helper_uuid = self.create("DceApplicationHelper")
def do_deploy(self):
" --prefix=%(ns3_build_home)s --with-ns3=%(ns3_build_home)s && "
" ./waf build && "
" ./waf install && "
- " mv %(ns3_build_home)s/lib/python*/site-packages/ns/dce.so %(ns3_build_home)s/lib/python/site-packages/ns/ "
+ " mv %(ns3_build_home)s/lib*/python*/site-packages/ns/dce.so %(ns3_build_home)s/lib/python/site-packages/ns/ "
" )"
) % {
'ns3_version': self.get("ns3Version"),
" mkdir -p %(ns3_build_home)s && "
" cd ${SRC}/ns-3/%(ns3_version)s && "
" ./waf configure -d %(build_mode)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
- " --prefix=%(ns3_build_home)s --includedir=%(ns3_build_home)s && "
+ " --prefix=%(ns3_build_home)s && "
" ./waf build && "
" ./waf install && "
- " mv %(ns3_build_home)s/lib/python* %(ns3_build_home)s/lib/python "
+ " mv %(ns3_build_home)s/lib*/python* %(ns3_build_home)s/lib/python "
" )"
") "
" && "
if node.uuid not in self.connected:
self._connected.add(node.uuid)
- self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "ResetArguments")
-
- self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "SetBinary", self.get("binary"))
+ # Preventing concurrent access to the DceApplicationHelper
+ # from different DceApplication RMs
+ with self.simulation.dce_application_lock:
+ self.simulation.invoke(self.simulation.dce_application_helper_uuid,
+ "ResetArguments")
- self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "SetStackSize", self.get("stackSize"))
+ self.simulation.invoke(self.simulation.dce_application_helper_uuid,
+ "SetBinary", self.get("binary"))
- arguments = self.get("arguments") or ""
- for arg in map(str.strip, arguments.split(";")):
self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "AddArgument", arg)
+ "SetStackSize", self.get("stackSize"))
- apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "InstallInNode", self.node.uuid)
+ arguments = self.get("arguments") or ""
+ for arg in map(str.strip, arguments.split(";")):
+ self.simulation.invoke(self.simulation.dce_application_helper_uuid,
+ "AddArgument", arg)
- app_uuid = self.simulation.invoke(apps_uuid, "Get", 0)
+ apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
+ "InstallInNode", self.node.uuid)
+
+ self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
if self.has_changed("StartTime"):
- self.simulation.ns3_set(app_uuid, "StartTime", self.get("StartTime"))
+ self.simulation.ns3_set(self.uuid, "StartTime", self.get("StartTime"))
if self.has_changed("StopTime"):
- self.simulation.ns3_set(app_uuid, "StopTime", self.get("StopTime"))
-
- self._uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
- "GetDCEApplication", app_uuid)
+ self.simulation.ns3_set(self.uuid, "StopTime", self.get("StopTime"))
def do_stop(self):
if self.state == ResourceState.STARTED:
self._start_time = self.simulation.start_time
def _configure_traces(self):
- pid = self.simulation.invoke(self.uuid, "GetPid")
+ # Preventing concurrent access to the DceApplicationHelper
+ # from different DceApplication RMs
+ with self.simulation.dce_application_lock:
+ pid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
+ "GetPid", self._uuid)
node_id = self.simulation.invoke(self.node.uuid, "GetId")
self._trace_filename["stdout"] = "files-%s/var/log/%s/stdout" % (node_id, pid)
self._trace_filename["stderr"] = "files-%s/var/log/%s/stderr" % (node_id, pid)
def _add_dce(self):
container_uuid = self.simulation.create("NodeContainer")
self.simulation.invoke(container_uuid, "Add", self.uuid)
- self.simulation.invoke(self.simulation.dce_helper_uuid, "Install",
- container_uuid)
+ with self.simulation.dce_manager_lock:
+ self.simulation.invoke(self.simulation.dce_manager_helper_uuid,
+ "Install", container_uuid)
result = method(*realargs, **realkwargs)
- if result is None or \
- isinstance(result, bool):
+ # If the result is not an object, no need to
+ # keep a reference. Directly return value.
+ if result is None or type(result) in [bool, float, long, str, int]:
return result
newuuid = self.make_uuid()
class LinuxNS3ClientTest(unittest.TestCase):
def setUp(self):
- #self.fedora_host = "nepi2.pl.sophia.inria.fr"
- self.fedora_host = "planetlabpc1.upf.edu"
- #self.fedora_host = "peeramide.irisa.fr"
- #self.fedora_user = "inria_nepi"
- self.fedora_user = "inria_alina"
+ #elf.fedora_host = "nepi2.pl.sophia.inria.fr"
+ #self.fedora_host = "planetlabpc1.upf.edu"
+ self.fedora_host = "peeramide.irisa.fr"
+ self.fedora_user = "inria_nepi"
+ #self.fedora_user = "inria_alina"
self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
def test_local_p2p_ping(self):
ec.deploy()
ec.wait_finished([udp_perf_client])
-
- stderr = ec.trace(simu, "stderr")
- print " CMDLINE", ec.trace(udp_perf, "cmdline")
- print " STATUS ", ec.trace(udp_perf, "status")
- print " OUT ", ec.trace(udp_perf, "stdout")
- print " ERROR ", ec.trace(udp_perf, "stderr")
+ expected = "udp-perf --duration=10 --nodes=2"
+ cmdline = ec.trace(udp_perf, "cmdline")
+ self.assertTrue(cmdline.find(expected) > -1, cmdline)
+
+ expected = "Start Time: NS3 Time: 1s ("
+ status = ec.trace(udp_perf, "status")
+ self.assertTrue(status.find(expected) > -1, status)
+
+ expected = "received=1500 bytes, 1 reads (@1500 bytes) 1500"
+ stdout = ec.trace(udp_perf, "stdout")
+ self.assertTrue(stdout.find(expected) > -1, stdout)
+
+ stderr = ec.trace(simu, "stderr")
expected = "DceApplication:StartApplication"
- self.assertTrue(stderr.find(expected) > -1)
+ self.assertTrue(stderr.find(expected) > -1, stderr)
ec.shutdown()