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 clsinit_copy
22 from nepi.resources.linux.application import LinuxApplication
23 from nepi.util.timefuncs import tnow
28 class LinuxMtr(LinuxApplication):
32 def _register_attributes(cls):
33 report_cycles = Attribute("reportCycles",
34 "sets mtr --report-cycles (-c) option. Determines the number of "
35 "pings sent to determine both machines in the networks. Each "
36 "cycle lasts one sencond.",
37 flags = Flags.ExecReadOnly)
39 no_dns = Attribute("noDns",
40 "sets mtr --no-dns (-n) option. Forces mtr to display IPs intead of "
41 "trying to resolve to host names ",
44 flags = Flags.ExecReadOnly)
46 address = Attribute("address",
47 "sets mtr --address (-a) option. Binds the socket to send outgoing "
48 "packets to the interface of the specified address, so that any "
49 "any packets are sent through this interface. ",
50 flags = Flags.ExecReadOnly)
52 interval = Attribute("interval",
53 "sets mtr --interval (-i) option. Specifies the number of seconds "
54 "between ICMP ECHO requests. Default value is one second ",
55 flags = Flags.ExecReadOnly)
57 target = Attribute("target",
58 "mtr target host (host that will be pinged)",
59 flags = Flags.ExecReadOnly)
61 cls._register_attribute(report_cycles)
62 cls._register_attribute(no_dns)
63 cls._register_attribute(address)
64 cls._register_attribute(interval)
65 cls._register_attribute(target)
67 def __init__(self, ec, guid):
68 super(LinuxMtr, self).__init__(ec, guid)
69 self._home = "mtr-%s" % self.guid
72 if not self.get("command"):
73 self.set("command", self._start_command)
75 if not self.get("depends"):
76 self.set("depends", "mtr")
78 super(LinuxMtr, self).deploy()
81 def _start_command(self):
83 if self.get("reportCycles"):
84 args.append("-c %s" % self.get("reportCycles"))
85 if self.get("noDns") == True:
87 if self.get("address"):
88 args.append("-a %s" % self.get("address"))
89 args.append(self.get("target"))
91 command = """echo "Starting mtr `date +'%Y%m%d%H%M%S'`"; """
92 command += " sudo -S mtr --report "
93 command += " ".join(args)
97 def valid_connection(self, guid):