2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 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.resource import ResourceManager, clsinit_copy, \
22 ResourceState, reschedule_delay
23 from nepi.resources.linux.ccn.ccnpingserver import LinuxCCNPingServer
24 from nepi.util.timefuncs import tnow, tdiffsec
29 class LinuxCCNPing(LinuxCCNPingServer):
30 _rtype = "LinuxCCNPing"
33 def _register_attributes(cls):
34 interval = Attribute("i",
35 "Set ping interval in seconds (minimum 0.10 second) ",
39 count = Attribute("c",
40 "Total number of pings",
44 number = Attribute("n",
45 "Set the starting number, the number is incremented by 1 after each Interest ",
49 prefix = Attribute("prefix",
50 "Prefix to serve content (e.g. ccnx:/name/prefix)",
53 cls._register_attribute(interval)
54 cls._register_attribute(count)
55 cls._register_attribute(number)
56 cls._register_attribute(prefix)
58 def __init__(self, ec, guid):
59 super(LinuxCCNPing, self).__init__(ec, guid)
60 self._home = "ccnping-%s" % self.guid
63 def ccnpingserver(self):
64 ccnpingserver = self.get_connected(LinuxCCNPingServer.get_rtype())
65 if ccnpingserver: return ccnpingserver[0]
69 if not self.ccnpingserver or \
70 self.ccnpingserver.state < ResourceState.STARTED:
71 self.debug("---- RESCHEDULING START---- ccnpingserver state %s " % \
72 self.ccnpingserver.state )
73 self.ec.schedule(reschedule_delay, self.start)
75 super(LinuxCCNPing, self).do_start()
78 def _start_command(self):
80 args.append("ccnping")
81 args.append(self.get("prefix"))
83 args.append("-c %d" % self.get("c"))
85 args.append("-n %d" % self.get("n"))
87 args.append("-i %.2f" % self.get("i"))
89 command = " ".join(args)
93 def valid_connection(self, guid):