X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnepi%2Fresources%2Fns3%2Fns3dceapplication.py;h=1922bb1dde2bc18bbaa9bb82b2efda0c2108f133;hb=392caf57c8567c7198321f1414aee43ee31d1e42;hp=b2dc46520b9fcf4e55fd8fbdb9d321cd1f0d01fa;hpb=e405b1997e739c7aa8de43a5f7639e6670964b92;p=nepi.git diff --git a/src/nepi/resources/ns3/ns3dceapplication.py b/src/nepi/resources/ns3/ns3dceapplication.py index b2dc4652..1922bb1d 100644 --- a/src/nepi/resources/ns3/ns3dceapplication.py +++ b/src/nepi/resources/ns3/ns3dceapplication.py @@ -21,10 +21,21 @@ from nepi.execution.attribute import Attribute, Flags, Types from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay from nepi.resources.ns3.ns3application import NS3BaseApplication +import os +import threading + @clsinit_copy class NS3BaseDceApplication(NS3BaseApplication): _rtype = "abstract::ns3::DceApplication" + # Lock used to synchronize usage of DceManagerHelper + dce_manager_lock = threading.Lock() + # Lock used to synchronize usage of DceApplicationHelper + dce_application_lock = threading.Lock() + + _dce_manager_helper_uuid = None + _dce_application_helper_uuid = None + @classmethod def _register_attributes(cls): binary = Attribute("binary", @@ -41,9 +52,27 @@ class NS3BaseDceApplication(NS3BaseApplication): "Semi-colon separated list of arguments for the application", flags = Flags.Design) + environment = Attribute("environment", + "Semi-colon separated list of 'key=value' pairs to set as " + "DCE environment variables.", + flags = Flags.Design) + + starttime = Attribute("StartTime", + "Time at which the application will start", + default = "+0.0ns", + flags = Flags.Reserved | Flags.Construct) + + stoptime = Attribute("StopTime", + "Time at which the application will stop", + default = "+0.0ns", + flags = Flags.Reserved | Flags.Construct) + cls._register_attribute(binary) cls._register_attribute(stack_size) cls._register_attribute(arguments) + cls._register_attribute(environment) + cls._register_attribute(stoptime) + cls._register_attribute(starttime) @property def node(self): @@ -55,11 +84,20 @@ class NS3BaseDceApplication(NS3BaseApplication): self.error(msg) raise RuntimeError, msg - if nodes[0].get("enableDCE") == False: - raise RuntimeError("DceApplication not connected to DCE enabled node") - return nodes[0] - + + @property + def dce_manager_helper_uuid(self): + if not self._dce_manager_helper_uuid: + self._dce_manager_helper_uuid = self.simulation.create("DceManagerHelper") + return self._dce_manager_helper_uuid + + @property + def dce_application_helper_uuid(self): + if not self._dce_application_helper_uuid: + self._dce_application_helper_uuid = self.simulation.create("DceApplicationHelper") + return self._dce_application_helper_uuid + def _instantiate_object(self): pass @@ -70,24 +108,50 @@ class NS3BaseDceApplication(NS3BaseApplication): # 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, + with self.dce_application_lock: + self.simulation.invoke( + self.dce_application_helper_uuid, "ResetArguments") - self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.dce_application_helper_uuid, + "ResetEnvironment") + + self.simulation.invoke( + self.dce_application_helper_uuid, "SetBinary", self.get("binary")) - self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.dce_application_helper_uuid, "SetStackSize", self.get("stackSize")) - arguments = self.get("arguments") or "" - for arg in map(str.strip, arguments.split(";")): - self.simulation.invoke(self.simulation.dce_application_helper_uuid, - "AddArgument", arg) - - apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid, + arguments = self.get("arguments") + if arguments: + for arg in map(str.strip, arguments.split(";")): + self.simulation.invoke( + self.dce_application_helper_uuid, + "AddArgument", arg) + + environment = self.get("environment") + if environment: + for env in map(str.strip, environment.split(";")): + key, val = env.split("=") + self.simulation.invoke( + self.dce_application_helper_uuid, + "AddEnvironment", key, val) + + apps_uuid = self.simulation.invoke( + self.dce_application_helper_uuid, "InstallInNode", self.node.uuid) + """ + container_uuid = self.simulation.create("NodeContainer") + self.simulation.invoke(container_uuid, "Add", self.node.uuid) + apps_uuid = self.simulation.invoke( + self.dce_application_helper_uuid, + "Install", container_uuid) + """ + self._uuid = self.simulation.invoke(apps_uuid, "Get", 0) if self.has_changed("StartTime"): @@ -115,9 +179,10 @@ class NS3BaseDceApplication(NS3BaseApplication): def _configure_traces(self): # 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) + 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)