# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
from nepi.execution.attribute import Attribute, Flags, Types
-from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay
+from nepi.execution.resource import clsinit_copy, ResourceState
from nepi.resources.ns3.ns3application import NS3BaseApplication
+from nepi.resources.ns3.ns3wrapper import SIMULATOR_UUID
+
import os
+import time
import threading
@clsinit_copy
"DCE environment variables.",
flags = Flags.Design)
+ use_dlm = Attribute("useDlmLoader",
+ "Use ns3::DlmLoaderFactory as library loader",
+ type = Types.Bool,
+ flags = Flags.Design)
+
starttime = Attribute("StartTime",
"Time at which the application will start",
default = "+0.0ns",
cls._register_attribute(stack_size)
cls._register_attribute(arguments)
cls._register_attribute(environment)
+ cls._register_attribute(use_dlm)
cls._register_attribute(stoptime)
cls._register_attribute(starttime)
@property
def dce_manager_helper_uuid(self):
if not self._dce_manager_helper_uuid:
- self._dce_manager_helper_uuid = self.simulation.create("DceManagerHelper")
+ self._dce_manager_helper_uuid = self.simulation.create(
+ "DceManagerHelper")
+
+ if self.get("useDlmLoader"):
+ self.simulation.invoke(
+ self._dce_manager_helper_uuid, "SetLoader",
+ "ns3::DlmLoaderFactory")
+
return self._dce_manager_helper_uuid
@property
def do_start(self):
if self.simulation.state < ResourceState.STARTED:
self.debug("---- RESCHEDULING START ----" )
- self.ec.schedule(reschedule_delay, self.start)
+ self.ec.schedule(self.reschedule_delay, self.start)
else:
self._configure_traces()
super(NS3BaseApplication, self).do_start()
self._start_time = self.simulation.start_time
def _configure_traces(self):
- # Preventing concurrent access to the DceApplicationHelper
+ # Waiting until dce application is actually started
+ is_running = False
+ for i in xrange(200):
+ is_running = self.simulation.invoke(self.uuid, "isAppRunning")
+ is_finished = self.simulation.invoke(SIMULATOR_UUID, "isFinished")
+
+ if is_running or is_finished:
+ break
+ else:
+ time.sleep(1)
+ else:
+ if not is_running:
+ msg = " Application did not start"
+ self.error(msg)
+ raise RuntimeError
+
+ # Using lock to prevent concurrent access to the DceApplicationHelper
# from different DceApplication RMs
with self.dce_application_lock:
pid = self.simulation.invoke(self.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)