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 LinuxPing(LinuxApplication):
32 def _register_attributes(cls):
33 count = Attribute("count",
34 "Sets ping -c option. Determines the number of ECHO_REQUEST "
35 "packates to send before stopping.",
36 flags = Flags.ExecReadOnly)
38 mark = Attribute("mark",
39 "Sets ping -m option. Uses 'mark' to tag outgoing packets. ",
40 flags = Flags.ExecReadOnly)
42 interval = Attribute("interval",
43 "Sets ping -i option. Leaves interval seconds between "
44 "successive ECHO_REUQEST packets. ",
45 flags = Flags.ExecReadOnly)
47 address = Attribute("address",
48 "Sets ping -I option. Sets ECHO_REQUEST packets souce address "
49 "to the specified interface address ",
50 flags = Flags.ExecReadOnly)
52 preload = Attribute("preload",
53 "Sets ping -l option. Sends preload amount of packets "
54 "without waiting for a reply ",
55 flags = Flags.ExecReadOnly)
57 numeric = Attribute("numeric",
58 "Sets ping -n option. Disables resolution of host addresses into "
62 flags = Flags.ExecReadOnly)
64 pattern = Attribute("pattern",
65 "Sets ping -p option. Species a up to 16 ''pad'' bytes to fill "
67 flags = Flags.ExecReadOnly)
69 printtmp = Attribute("printTimestamp",
70 "Sets ping -D option. Prints timestamp befor each line as: "
71 "unix time + microseconds as in gettimeofday ",
74 flags = Flags.ExecReadOnly)
76 tos = Attribute("tos",
77 "Sets ping -Q option. Sets Quality of Service related bits in ICMP "
78 "datagrams. tos can be either a decimal or hexadecime number ",
79 flags = Flags.ExecReadOnly)
81 quiet = Attribute("quiet",
82 "Sets ping -q option. Disables ping standard output ",
85 flags = Flags.ExecReadOnly)
87 rec_route = Attribute("recordRoute",
88 "Sets ping -R option. Includes the RECORD_ROUTE option in the "
89 "ECHO REQUEST packet and displays route buffer on the Disables "
90 "ping standard output.",
93 flags = Flags.ExecReadOnly)
95 route_bypass = Attribute("routeBypass",
96 "Sets ping -r option. Bypasses normal routing tables and sends "
97 "ECHO REQUEST packets directly yo a host on an attached interface. ",
100 flags = Flags.ExecReadOnly)
102 packetsize = Attribute("packetSize",
103 "Sets ping -s option. Specifies the number of data bytes to be "
104 "sent. Defaults to 56. ",
105 flags = Flags.ExecReadOnly)
107 sendbuff = Attribute("sendBuff",
108 "Sets ping -S option. Specifies the number of packets to buffer. "
110 flags = Flags.ExecReadOnly)
112 ttl = Attribute("ttl",
113 "Sets ping -t option. Specifies the IP Time to Live for the "
115 flags = Flags.ExecReadOnly)
117 timestamp = Attribute("timestamp",
118 "Sets ping -T option. Sets special IP timestamp options. ",
119 flags = Flags.ExecReadOnly)
121 hint = Attribute("hint",
122 "Sets ping -M option. Selects Path MTU Discovery strategy. ",
123 flags = Flags.ExecReadOnly)
125 full_latency = Attribute("fullLatency",
126 "Sets ping -U option. Calculates round trip time taking into "
127 "account the full user-to-user latency instead of only the "
128 "network round trip time. ",
131 flags = Flags.ExecReadOnly)
133 verbose = Attribute("verbose",
134 "Sets ping -v option. Verbose output. ",
137 flags = Flags.ExecReadOnly)
139 flood = Attribute("flood",
140 "Sets ping -f option. Flood ping. ",
143 flags = Flags.ExecReadOnly)
145 deadline = Attribute("deadline",
146 "Sets ping -w option. Specify a timeout, in seconds, before ping "
147 "exits regardless of how many packets have been sent or received.",
148 flags = Flags.ExecReadOnly)
150 timeout = Attribute("timeout",
151 "Sets ping -W option. Time to wait for a respone in seconds .",
152 flags = Flags.ExecReadOnly)
154 target = Attribute("target",
155 "The host to ping .",
156 flags = Flags.ExecReadOnly)
158 cls._register_attribute(count)
159 cls._register_attribute(mark)
160 cls._register_attribute(interval)
161 cls._register_attribute(address)
162 cls._register_attribute(preload)
163 cls._register_attribute(numeric)
164 cls._register_attribute(pattern)
165 cls._register_attribute(printtmp)
166 cls._register_attribute(tos)
167 cls._register_attribute(quiet)
168 cls._register_attribute(rec_route)
169 cls._register_attribute(route_bypass)
170 cls._register_attribute(packetsize)
171 cls._register_attribute(sendbuff)
172 cls._register_attribute(ttl)
173 cls._register_attribute(timestamp)
174 cls._register_attribute(hint)
175 cls._register_attribute(full_latency)
176 cls._register_attribute(verbose)
177 cls._register_attribute(flood)
178 cls._register_attribute(deadline)
179 cls._register_attribute(timeout)
180 cls._register_attribute(target)
182 def __init__(self, ec, guid):
183 super(LinuxPing, self).__init__(ec, guid)
184 self._home = "ping-%s" % self.guid
187 if not self.get("command"):
188 self.set("command", self._start_command)
190 super(LinuxPing, self).deploy()
193 def _start_command(self):
196 if self.get("printTimestamp") == True:
197 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
201 if self.get("count"):
202 args.append("-c %s" % self.get("count"))
204 args.append("-m %s" % self.get("mark"))
205 if self.get("interval"):
206 args.append("-i %s" % self.get("interval"))
207 if self.get("address"):
208 args.append("-I %s" % self.get("address"))
209 if self.get("preload"):
210 args.append("-l %s" % self.get("preload"))
211 if self.get("numeric") == True:
213 if self.get("pattern"):
214 args.append("-p %s" % self.get("pattern"))
216 args.append("-Q %s" % self.get("tos"))
217 if self.get("quiet"):
218 args.append("-q %s" % self.get("quiet"))
219 if self.get("recordRoute") == True:
221 if self.get("routeBypass") == True:
223 if self.get("packetSize"):
224 args.append("-s %s" % self.get("packetSize"))
225 if self.get("sendBuff"):
226 args.append("-S %s" % self.get("sendBuff"))
228 args.append("-t %s" % self.get("ttl"))
229 if self.get("timestamp"):
230 args.append("-T %s" % self.get("timestamp"))
232 args.append("-M %s" % self.get("hint"))
233 if self.get("fullLatency") == True:
235 if self.get("verbose") == True:
237 if self.get("flood") == True:
239 if self.get("deadline"):
240 args.append("-w %s" % self.get("deadline"))
241 if self.get("timeout"):
242 args.append("-W %s" % self.get("timeout"))
243 args.append(self.get("target"))
245 command = " ".join(args)
249 def valid_connection(self, guid):