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
29 class LinuxTraceroute(LinuxApplication):
30 _rtype = "LinuxTraceroute"
33 def _register_attributes(cls):
34 countinuous = Attribute("continuous",
35 "Run traceroute in a while loop",
40 print_timestamp = Attribute("printTimestamp",
41 "Print timestamp before running traceroute",
46 use_ip = Attribute("useIP",
47 "Use the IP address instead of the host domain name. "
48 "Useful for environments were dns resolution problems occur "
54 target = Attribute("target",
55 "Traceroute target host (host that will be pinged)",
58 cls._register_attribute(countinuous)
59 cls._register_attribute(print_timestamp)
60 cls._register_attribute(use_ip)
61 cls._register_attribute(target)
63 def __init__(self, ec, guid):
64 super(LinuxTraceroute, self).__init__(ec, guid)
65 self._home = "traceroute-%s" % self.guid
68 if not self.get("command"):
69 self.set("command", self._start_command)
71 if not self.get("depends"):
72 self.set("depends", "traceroute")
74 super(LinuxTraceroute, self).do_deploy()
77 def _start_command(self):
79 if self.get("continuous") == True:
80 args.append("while true; do ")
81 if self.get("printTimestamp") == True:
82 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
83 args.append("traceroute")
85 target = self.get("target")
86 if self.get("useIP") == True:
87 target = socket.gethostbyname(target)
90 if self.get("continuous") == True:
91 args.append("; sleep 2 ; done ")
93 command = " ".join(args)
97 def valid_connection(self, guid):