2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
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.
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
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
32 class LinuxNS3Simulator(LinuxApplication, NS3Simulator):
33 _rtype = "LinuxNS3Simulator"
36 def _register_attributes(cls):
37 socket_name = Attribute("socketName",
38 "Local socket name to communicate with the ns-3 server ",
41 cls._register_attribute(socket_name)
43 def __init__(self, ec, guid):
44 super(LinuxApplication, self).__init__(ec, guid)
45 super(NS3Simulator, self).__init__()
48 self._home = "ns3-simu-%s" % self.guid
51 if not self.node or self.node.state < ResourceState.READY:
52 self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
54 # ccnd needs to wait until node is deployed and running
55 self.ec.schedule(reschedule_delay, self.deploy)
57 # TODO: Create socket!!
58 socket_name = self.get("socketName")
59 self._client = LinuxNS3Client(socket_name)
67 command = self.get("command")
69 self.info("Starting ns-3 simulation")
75 # TODO! DESTROY SOCKET AND SHUTDOWN CLIENT