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.ns3dceapplication import NS3BaseDceApplication
27 class NS3BaseCCNDceApplication(NS3BaseDceApplication):
28 _rtype = "abstract::ns3::CCNDceApplication"
31 def _register_attributes(cls):
32 files = Attribute("files",
33 "Semi-colon separated list of 'key=value' pairs to set as "
34 "DCE files (AddFile). The key should be a path to a local file "
35 "and the key is the path to be set in DCE for that file" ,
38 stdinfile = Attribute("stdinFile",
39 "File to set as StdinFile. The value shoudl be either an empty "
40 "or a path to a local file ",
43 cls._register_attribute(files)
44 cls._register_attribute(stdinfile)
46 def _instantiate_object(self):
49 def _connect_object(self):
51 if node.uuid not in self.connected:
52 self._connected.add(node.uuid)
54 # Preventing concurrent access to the DceApplicationHelper
55 # from different DceApplication RMs
56 with self.simulation.dce_application_lock:
57 self.simulation.invoke(
58 self.simulation.ccn_client_helper_uuid,
61 self.simulation.invoke(
62 self.simulation.ccn_client_helper_uuid,
65 self.simulation.invoke(
66 self.simulation.ccn_client_helper_uuid,
67 "SetBinary", self.get("binary"))
69 self.simulation.invoke(
70 self.simulation.ccn_client_helper_uuid,
71 "SetStackSize", self.get("stackSize"))
73 arguments = self.get("arguments")
75 for arg in map(str.strip, arguments.split(";")):
76 self.simulation.invoke(
77 self.simulation.ccn_client_helper_uuid,
80 environment = self.get("environment")
82 for env in map(str.strip, environment.split(";")):
83 key, val = env.split("=")
84 self.simulation.invoke(
85 self.simulation.ccn_client_helper_uuid,
86 "AddEnvironment", key, val)
88 if self.has_attribute("files"):
89 files = self.get("files")
91 for files in map(str.strip, files.split(";")):
92 remotepath, dcepath = files.split("=")
93 localpath = "${SHARE}/" + os.path.basename(remotepath)
94 self.simulation.invoke(
95 self.simulation.ccn_client_helper_uuid,
96 "AddFile", localpath, dcepath)
98 if self.has_attribute("stdinFile"):
99 stdinfile = self.get("stdinFile")
102 stdinfile = "${SHARE}/" + os.path.basename(stdinfile)
104 self.simulation.invoke(
105 self.simulation.ccn_client_helper_uuid,
106 "SetStdinFile", stdinfile)
108 apps_uuid = self.simulation.invoke(
109 self.simulation.ccn_client_helper_uuid,
110 "InstallInNode", self.node.uuid)
112 self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
114 if self.has_changed("StartTime"):
115 self.simulation.ns3_set(self.uuid, "StartTime", self.get("StartTime"))
117 if self.has_changed("StopTime"):
118 self.simulation.ns3_set(self.uuid, "StopTime", self.get("StopTime"))