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 version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import ResourceManager, clsinit_copy, \
22 from nepi.resources.linux.ccn.ccnpingserver import LinuxCCNPingServer
23 from nepi.util.timefuncs import tnow, tdiffsec
28 class LinuxCCNPing(LinuxCCNPingServer):
29 _rtype = "linux::CCNPing"
32 def _register_attributes(cls):
33 interval = Attribute("i",
34 "Set ping interval in seconds (minimum 0.10 second) ",
38 count = Attribute("c",
39 "Total number of pings",
43 number = Attribute("n",
44 "Set the starting number, the number is incremented by 1 after each Interest ",
48 prefix = Attribute("prefix",
49 "Prefix to serve content (e.g. ccnx:/name/prefix)",
52 cls._register_attribute(interval)
53 cls._register_attribute(count)
54 cls._register_attribute(number)
55 cls._register_attribute(prefix)
57 def __init__(self, ec, guid):
58 super(LinuxCCNPing, self).__init__(ec, guid)
59 self._home = "ccnping-%s" % self.guid
62 def ccnpingserver(self):
63 ccnpingserver = self.get_connected(LinuxCCNPingServer.get_rtype())
64 if ccnpingserver: return ccnpingserver[0]
68 if not self.ccnpingserver or \
69 self.ccnpingserver.state < ResourceState.STARTED:
70 self.debug("---- RESCHEDULING START---- ccnpingserver state %s " % \
71 self.ccnpingserver.state )
72 self.ec.schedule(self.reschedule_delay, self.start)
74 super(LinuxCCNPing, self).do_start()
77 def _start_command(self):
79 args.append("ccnping")
80 args.append(self.get("prefix"))
82 args.append("-c %d" % self.get("c"))
84 args.append("-n %d" % self.get("n"))
86 args.append("-i %.2f" % self.get("i"))
88 command = " ".join(args)
92 def valid_connection(self, guid):