ns-3 CCN tests
[nepi.git] / src / nepi / resources / linux / ns3 / ns3dceapplication.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, reschedule_delay
22 from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
23
24 @clsinit_copy
25 class NS3LinuxDceApplication(NS3BaseDceApplication):
26     _rtype = "ns3::LinuxDceApplication"
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         starttime = Attribute("StartTime",
60             "Time at which the application will start",
61             default = "+0.0ns",  
62             flags = Flags.Reserved | Flags.Construct)
63
64         stoptime = Attribute("StopTime",
65             "Time at which the application will stop",
66             default = "+0.0ns",  
67             flags = Flags.Reserved | Flags.Construct)
68
69         cls._register_attribute(sources)
70         cls._register_attribute(build)
71         cls._register_attribute(depends)
72         cls._register_attribute(files)
73         cls._register_attribute(stoptime)
74         cls._register_attribute(starttime)
75         cls._register_attribute(stdinfile)
76
77     def _instantiate_object(self):
78         command = []
79
80         # Install package dependencies required to run the binary 
81         depends = self.get("depends")
82         if depends:
83             dcmd = self.simulation.install_dependencies(depends = depends)
84             if dcmd:
85                 command.append(dcmd)
86        
87         # Upload sources to generate the binary
88         sources = self.get("sources")
89         if sources:
90             scmd = self.simulation.upload_extra_sources(sources = sources)
91             if scmd:
92                 command.append(scmd)
93                 
94         # Upload files to the remote machine. These files will 
95         # be added to the DceApplication by invoking dce.AddFile()
96         files = self.get("files") or ""
97         if files:
98             upfiles = []
99             for files in map(str.strip, files.split(";")):
100                 localpath, dcepath = env.split("=")
101                 upfiles.append(localpath)
102
103             if upfiles:
104                 fcmd = self.siumlation.upload_files(files = upfiles)
105                 if fcmd:
106                     command.append(fcmd)
107
108         # Upload files to the remote machine. These files will 
109         # be added to the DceApplication by invoking dce.AddFile()
110         stdinfile = self.get("stdinFile")
111         if stdinfile and stdinfile != "":
112             stdincmd = self.siumlation.upload_files(files = stdinfile)
113             if stdincmd:
114                 command.append(stdincmd)
115
116
117         # Upload instructions to build the binary
118         build = self.get("build")
119         if build:
120             bcmd = self.simulation.build(build = build)
121             if bcmd:
122                 command.append(bcmd)
123
124         if command:
125             deploy_command = ";".join(command)
126             prefix = "%d_deploy" % self.guid 
127             self.simulation.execute_deploy_command(deploy_command, prefix=prefix)
128