bf1a6e366b0299ea68df347fb628de2d068eecb1
[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         starttime = Attribute("StartTime",
45             "Time at which the application will start",
46             default = "+0.0ns",  
47             flags = Flags.Reserved | Flags.Construct)
48
49
50         stoptime = Attribute("StopTime",
51             "Time at which the application will stop",
52             default = "+0.0ns",  
53             flags = Flags.Reserved | Flags.Construct)
54
55         cls._register_attribute(sources)
56         cls._register_attribute(build)
57         cls._register_attribute(stoptime)
58         cls._register_attribute(starttime)
59
60     def _instantiate_object(self):
61         command = []
62         
63         sources = self.get("sources")
64         if sources:
65             self.info("Uploading sources %s " % sources)
66             scmd = self.simulation.upload_extra_sources(sources = sources)
67             if scmd:
68                 command.append(scmd)
69                 
70         build = self.get("build")
71         if build:
72             bcmd = self.simulation.build(build = build)
73             if bcmd:
74                 command.append(bcmd)
75
76         if command:
77             deploy_command = ";".join(command)
78             prefix = "%d_deploy" % self.guid 
79             self.simulation.execute_deploy_command(deploy_command, prefix=prefix)
80