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 version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import clsinit_copy, ResourceState
21 from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
27 class NS3BaseCCNDceApplication(NS3BaseDceApplication):
28 _rtype = "abstract::ns3::CCNDceApplication"
30 # Lock used to synchronize usage of CcnClientHelper
31 ccn_client_lock = threading.Lock()
32 _ccn_client_helper_uuid = None
35 def ccn_client_helper_uuid(self):
36 if not self._ccn_client_helper_uuid:
37 self._ccn_client_helper_uuid = self.simulation.create("CcnClientHelper")
38 return self._ccn_client_helper_uuid
40 def _instantiate_object(self):
43 def _connect_object(self):
45 if node.uuid not in self.connected:
46 self._connected.add(node.uuid)
48 # Preventing concurrent access to the DceApplicationHelper
49 # from different DceApplication RMs
50 with self.ccn_client_lock:
51 self.simulation.invoke(
52 self.ccn_client_helper_uuid,
55 self.simulation.invoke(
56 self.ccn_client_helper_uuid,
59 self.simulation.invoke(
60 self.ccn_client_helper_uuid,
61 "SetBinary", self.get("binary"))
63 self.simulation.invoke(
64 self.ccn_client_helper_uuid,
65 "SetStackSize", self.get("stackSize"))
67 arguments = self.get("arguments")
69 for arg in map(str.strip, arguments.split(";")):
70 self.simulation.invoke(
71 self.ccn_client_helper_uuid,
74 environment = self.get("environment")
76 for env in map(str.strip, environment.split(";")):
77 key, val = env.split("=")
78 self.simulation.invoke(
79 self.ccn_client_helper_uuid,
80 "AddEnvironment", key, val)
82 if self.has_attribute("files"):
83 files = self.get("files")
85 for file in map(str.strip, files.split(";")):
86 remotepath, dcepath = file.split("=")
87 localpath = os.path.join(self.simulation.app_home,
88 os.path.basename(remotepath))
89 self.simulation.invoke(
90 self.ccn_client_helper_uuid,
91 "AddFile", localpath, dcepath)
93 if self.has_attribute("stdinFile"):
94 stdinfile = self.get("stdinFile")
96 # stdinfile might be an empty text that should be set as
98 self.simulation.invoke(
99 self.ccn_client_helper_uuid,
100 "SetStdinFile", stdinfile)
102 apps_uuid = self.simulation.invoke(
103 self.ccn_client_helper_uuid,
104 "InstallInNode", self.node.uuid)
107 container_uuid = self.simulation.create("NodeContainer")
108 self.simulation.invoke(container_uuid, "Add", self.node.uuid)
109 apps_uuid = self.simulation.invoke(
110 self.ccn_client_helper_uuid,
111 "Install", container_uuid)
114 self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
116 if self.has_changed("StartTime"):
117 self.simulation.ns3_set(self.uuid, "StartTime", self.get("StartTime"))
119 if self.has_changed("StopTime"):
120 self.simulation.ns3_set(self.uuid, "StopTime", self.get("StopTime"))