Simplifying code of sshfuncs.py. Removing not used functionality
[nepi.git] / src / nepi / resources / linux / ns3 / ns3simulator.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.trace import Trace, TraceAttr
22 from nepi.execution.resource import ResourceManager, clsinit_copy, \
23         ResourceState, reschedule_delay
24 from nepi.resources.linux.application import LinuxApplication
25 from nepi.util.timefuncs import tnow, tdiffsec
26 from nepi.resources.ns3.ns3simulator import NS3Simulator
27 from nepi.resources.linux.ns3.ns3client import LinuxNS3Client
28
29 import os
30
31 @clsinit_copy
32 class LinuxNS3Simulator(LinuxApplication, NS3Simulator):
33     _rtype = "LinuxNS3Simulator"
34
35     @classmethod
36     def _register_attributes(cls):
37         socket_name = Attribute("socketName",
38             "Local socket name to communicate with the ns-3 server ",
39             flags = Flags.Design)
40
41         cls._register_attribute(socket_name)
42
43     def __init__(self, ec, guid):
44         super(LinuxApplication, self).__init__(ec, guid)
45         super(NS3Simulator, self).__init__()
46
47         self._client = None
48         self._home = "ns3-simu-%s" % self.guid
49
50     def do_deploy(self):
51         if not self.node or self.node.state < ResourceState.READY:
52             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
53             
54             # ccnd needs to wait until node is deployed and running
55             self.ec.schedule(reschedule_delay, self.deploy)
56         else:
57             # TODO: Create socket!!
58             socket_name = self.get("socketName")
59             self._client = LinuxNS3Client(socket_name)
60
61             #self.do_discover()
62             #self.do_provision()
63
64             self.set_ready()
65
66     def do_start(self):
67         command = self.get("command")
68
69         self.info("Starting ns-3 simulation")
70         
71         self._client.start()
72
73         self.set_started()
74
75     # TODO! DESTROY SOCKET AND SHUTDOWN CLIENT