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
22 from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
28 class NS3BaseCCNDceApplication(NS3BaseDceApplication):
29 _rtype = "abstract::ns3::CCNDceApplication"
31 # Lock used to synchronize usage of CcnClientHelper
32 ccn_client_lock = threading.Lock()
33 _ccn_client_helper_uuid = None
36 def ccn_client_helper_uuid(self):
37 if not self._ccn_client_helper_uuid:
38 self._ccn_client_helper_uuid = self.simulation.create("CcnClientHelper")
39 return self._ccn_client_helper_uuid
41 def _instantiate_object(self):
44 def _connect_object(self):
46 if node.uuid not in self.connected:
47 self._connected.add(node.uuid)
49 # Preventing concurrent access to the DceApplicationHelper
50 # from different DceApplication RMs
51 with self.ccn_client_lock:
52 self.simulation.invoke(
53 self.ccn_client_helper_uuid,
56 self.simulation.invoke(
57 self.ccn_client_helper_uuid,
60 self.simulation.invoke(
61 self.ccn_client_helper_uuid,
62 "SetBinary", self.get("binary"))
64 self.simulation.invoke(
65 self.ccn_client_helper_uuid,
66 "SetStackSize", self.get("stackSize"))
68 arguments = self.get("arguments")
70 for arg in map(str.strip, arguments.split(";")):
71 self.simulation.invoke(
72 self.ccn_client_helper_uuid,
75 environment = self.get("environment")
77 for env in map(str.strip, environment.split(";")):
78 key, val = env.split("=")
79 self.simulation.invoke(
80 self.ccn_client_helper_uuid,
81 "AddEnvironment", key, val)
83 if self.has_attribute("files"):
84 files = self.get("files")
86 for file in map(str.strip, files.split(";")):
87 remotepath, dcepath = file.split("=")
88 localpath = os.path.join(self.simulation.app_home,
89 os.path.basename(remotepath))
90 self.simulation.invoke(
91 self.ccn_client_helper_uuid,
92 "AddFile", localpath, dcepath)
94 if self.has_attribute("stdinFile"):
95 stdinfile = self.get("stdinFile")
97 # stdinfile might be an empty text that should be set as
99 self.simulation.invoke(
100 self.ccn_client_helper_uuid,
101 "SetStdinFile", stdinfile)
103 apps_uuid = self.simulation.invoke(
104 self.ccn_client_helper_uuid,
105 "InstallInNode", self.node.uuid)
108 container_uuid = self.simulation.create("NodeContainer")
109 self.simulation.invoke(container_uuid, "Add", self.node.uuid)
110 apps_uuid = self.simulation.invoke(
111 self.ccn_client_helper_uuid,
112 "Install", container_uuid)
115 self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
117 if self.has_changed("StartTime"):
118 self.simulation.ns3_set(self.uuid, "StartTime", self.get("StartTime"))
120 if self.has_changed("StopTime"):
121 self.simulation.ns3_set(self.uuid, "StopTime", self.get("StopTime"))