re-arrenging ns-3 classes
[nepi.git] / src / nepi / resources / ns3 / ns3base.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.resource import ResourceManager, clsinit_copy, \
21         ResourceState, reschedule_delay
22
23 from nepi.resources.ns3.simulator import NS3Simulator
24
25 @clsinit_copy
26 class NS3Base(ResourceManager):
27     _rtype = "NS3Base"
28
29     @property
30     def simulator(self):
31         simulator = self.get_connected(NS3Simulator.get_rtype())
32         if simulator: return simulator[0]
33         return None
34
35     def do_deploy(self):
36         if not self.simulator or self.simulator.state < ResourceState.READY:
37             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.simulator.state )
38             
39             # ccnd needs to wait until node is deployed and running
40             self.ec.schedule(reschedule_delay, self.deploy)
41         else:
42             # TODO: CREATE AND CONFIGURE NS-3 C++ OBJECT
43             self.do_discover()
44             self.do_provision()
45
46             self.debug("----- READY ---- ")
47             self.set_ready()
48
49     def do_start(self):
50         if self.state == ResourceState.READY:
51             ## TODO!!!
52             self.info("Starting ...")
53
54             self.set_started()
55         else:
56             msg = " Failed "
57             self.error(msg, out, err)
58             raise RuntimeError, msg
59
60     def do_stop(self):
61         if self.state == ResourceState.STARTED:
62             self.info("Stopping command '%s'" % command)
63             ## TODO!!!
64
65             self.set_stopped()
66     
67     @property
68     def state(self):
69         # First check if the ccnd has failed
70         # TODO!!!
71         return self._state
72