Changing reschedule_delay internals
[nepi.git] / src / nepi / resources / linux / ns3 / ccn / ns3ccndceapplication.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 INRIA
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy, ResourceState
22 from nepi.resources.ns3.ns3ccndceapplication import NS3BaseCCNDceApplication
23
24 @clsinit_copy
25 class LinuxNS3CCNDceApplication(NS3BaseCCNDceApplication):
26     _rtype = "ns3::LinuxCCNDceApplication"
27
28     @classmethod
29     def _register_attributes(cls):
30         sources = Attribute("sources",
31                 "Path to tar.gz file with sources for the application execute in DCE. "
32                 "Sources will be uploaded to ${SRC} and it is the responsibility of "
33                 "the build instructions (in the build attribute) to copy the compiled "
34                 "binaries to the ${BIN_DCE} directory",
35                 flags = Flags.Design)
36
37         build = Attribute("build",
38                 "Instructions to compile sources DCE-compatible way. "
39                 "Note that sources will be uploaded to ${SRC} and the "
40                 "build instructions are responsible for copying the "
41                 "binaries to the ${BIN_DCE} directory. ",
42                 flags = Flags.Design)
43
44         depends = Attribute("depends", 
45                 "Space-separated list of packages required to run the application",
46                 flags = Flags.Design)
47
48         files = Attribute("files", 
49                 "Semi-colon separated list of 'key=value' pairs to set as "
50                 "DCE files (AddFile). The key should be a path to a local file "
51                 "and the key is the path to be set in DCE for that file" ,
52                 flags = Flags.Design)
53
54         stdinfile = Attribute("stdinFile", 
55                 "File to set as StdinFile. The value shoudl be either an empty "
56                 "or a path to a local file ",
57                 flags = Flags.Design)
58         
59         cls._register_attribute(sources)
60         cls._register_attribute(build)
61         cls._register_attribute(depends)
62         cls._register_attribute(files)
63         cls._register_attribute(stdinfile)
64
65     def _instantiate_object(self):
66         command = []
67
68         # Install package dependencies required to run the binary 
69         depends = self.get("depends")
70         if depends:
71             dcmd = self.simulation.install_dependencies(depends = depends)
72             if dcmd:
73                 command.append(dcmd)
74        
75         # Upload sources to generate the binary
76         sources = self.get("sources")
77         if sources:
78             scmd = self.simulation.upload_extra_sources(sources = sources)
79             if scmd:
80                 command.append(scmd)
81                 
82         # Upload instructions to build the binary
83         build = self.get("build")
84         if build:
85             bcmd = self.simulation.build(build = build)
86             if bcmd:
87                 command.append(bcmd)
88
89         # Upload CCN files (e.g. repo)
90         files = self.get("files")
91         if files:
92             upload = []
93             for file in map(str.strip, files.split(";")):
94                 localpath, dcepath = files.split("=")
95                 upload.append(localpath)
96
97             sources = ";".join(upload)
98             fcmd = self.simulation.upload_extra_sources(sources = sources,
99                     src_dir = self.simulation.app_home)
100
101             if fcmd:
102                 command.append(fcmd)
103
104         if command:
105             deploy_command = ";".join(command)
106             prefix = "%d_deploy" % self.guid 
107             self.simulation.execute_deploy_command(deploy_command, prefix=prefix)
108