2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay
22 from nepi.resources.ns3.ns3application import NS3BaseApplication
25 class NS3BaseDceApplication(NS3BaseApplication):
26 _rtype = "abstract::ns3::DceApplication"
29 def _register_attributes(cls):
30 binary = Attribute("binary",
31 "Name of binary to execute",
34 stack_size = Attribute("stackSize",
40 arguments = Attribute("arguments",
41 "Semi-colon separated list of arguments for the application",
44 cls._register_attribute(binary)
45 cls._register_attribute(stack_size)
46 cls._register_attribute(arguments)
50 from nepi.resources.ns3.ns3node import NS3BaseNode
51 nodes = self.get_connected(NS3BaseNode.get_rtype())
54 msg = "DceApplication not connected to node"
56 raise RuntimeError, msg
58 if nodes[0].get("enableDCE") == False:
59 raise RuntimeError("DceApplication not connected to DCE enabled node")
63 def _instantiate_object(self):
66 def _connect_object(self):
68 if node.uuid not in self.connected:
69 self._connected.add(node.uuid)
71 # Preventing concurrent access to the DceApplicationHelper
72 # from different DceApplication RMs
73 with self.simulation.dce_application_lock:
74 self.simulation.invoke(self.simulation.dce_application_helper_uuid,
77 self.simulation.invoke(self.simulation.dce_application_helper_uuid,
78 "SetBinary", self.get("binary"))
80 self.simulation.invoke(self.simulation.dce_application_helper_uuid,
81 "SetStackSize", self.get("stackSize"))
83 arguments = self.get("arguments") or ""
84 for arg in map(str.strip, arguments.split(";")):
85 self.simulation.invoke(self.simulation.dce_application_helper_uuid,
88 apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
89 "InstallInNode", self.node.uuid)
91 self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
93 if self.has_changed("StartTime"):
94 self.simulation.ns3_set(self.uuid, "StartTime", self.get("StartTime"))
96 if self.has_changed("StopTime"):
97 self.simulation.ns3_set(self.uuid, "StopTime", self.get("StopTime"))
100 if self.state == ResourceState.STARTED:
101 # No need to do anything, simulation.Destroy() will stop every object
102 self.info("Stopping command '%s'" % command)
103 self.simulation.invoke(self.uuid, "Stop")
107 if self.simulation.state < ResourceState.STARTED:
108 self.debug("---- RESCHEDULING START ----" )
109 self.ec.schedule(reschedule_delay, self.start)
111 self._configure_traces()
112 super(NS3BaseApplication, self).do_start()
113 self._start_time = self.simulation.start_time
115 def _configure_traces(self):
116 # Preventing concurrent access to the DceApplicationHelper
117 # from different DceApplication RMs
118 with self.simulation.dce_application_lock:
119 pid = self.simulation.invoke(self.simulation.dce_application_helper_uuid,
120 "GetPid", self._uuid)
121 node_id = self.simulation.invoke(self.node.uuid, "GetId")
122 self._trace_filename["stdout"] = "files-%s/var/log/%s/stdout" % (node_id, pid)
123 self._trace_filename["stderr"] = "files-%s/var/log/%s/stderr" % (node_id, pid)
124 self._trace_filename["status"] = "files-%s/var/log/%s/status" % (node_id, pid)
125 self._trace_filename["cmdline"] = "files-%s/var/log/%s/cmdline" % (node_id, pid)