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, ResourceState, \
23 from nepi.resources.linux.application import LinuxApplication
24 from nepi.util.timefuncs import tnow
29 class LinuxUdpTest(LinuxApplication):
30 """ Uses the hpcbench udptest tool to gather UDP measurements.
31 Measurements require two ends, a server and a client RM.
33 http://hpcbench.sourceforge.net/
35 _rtype = "LinuxUdpTest"
38 def _register_attributes(cls):
40 "Runs in server mode. ",
43 flags = Flags.ExecReadOnly)
46 "Port to listen to in server mode, or to connect to in client mode. "
49 flags = Flags.ExecReadOnly)
52 "Client option. Perform UDP Round Trip Time (latency) ",
54 flags = Flags.ExecReadOnly)
58 "Message size for UDP RTT test. "
59 "UDP RTT (latency) test with specified message size.",
61 flags = Flags.ExecReadOnly)
65 "Client UDP buffer size in bytes. Using system default "
66 "value if not defined.",
68 flags = Flags.ExecReadOnly)
72 "Server UDP buffer size in bytes. The same as cleint's by default.",
74 flags = Flags.ExecReadOnly)
78 "CPU log option. Tracing system info during the test. "
79 "Only available when output is defined. ",
81 flags = Flags.ExecReadOnly)
85 "Data size of each read/write in bytes. The same as packet size "
88 flags = Flags.ExecReadOnly)
92 "Exponential test (data size of each sending increasing from 1 "
93 "byte to packet size). ",
95 flags = Flags.ExecReadOnly)
99 "UDP traffic generator (Keep sending data to a host). "
100 "Work without server's support.",
102 flags = Flags.ExecReadOnly)
104 target = Attribute("target",
106 "Hostname or IP address of UDP server. Must be specified.",
107 flags = Flags.ExecReadOnly)
111 "Bidirectional UDP throuhgput test. Default is unidirection "
114 flags = Flags.ExecReadOnly)
118 "UDP datagram (packet) size in bytes ( < udp-buffer-szie ). "
120 type = Types.Integer,
121 flags = Flags.ExecReadOnly)
125 "Total message size in bytes. 1048576 by default.",
126 type = Types.Integer,
127 flags = Flags.ExecReadOnly)
131 "Output file name. ",
132 flags = Flags.ExecReadOnly)
136 "Write the plot file for gnuplot. Only enable when the output "
139 flags = Flags.ExecReadOnly)
143 "Define the TOS field of IP packets. "
144 "Six values can be used for this setting:\n"
145 " 1:(IPTOS)-Minimize delay\n"
146 " 2:(IPTOS)-Maximize throughput\n"
147 " 3:(DiffServ)-Class1 with low drop probability\n"
148 " 4:(DiffServ)-class1 with high drop probability\n"
149 " 5:(DiffServ)-Class4 with low drop probabiltiy\n"
150 " 6:(DiffServ)-Class4 with high drop probabiltiy\n"
151 "Write the plot file for gnuplot. Only enable when the output "
153 type = Types.Enumerate,
154 allowed = ["1", "2", "3", "4", "5", "6"],
155 flags = Flags.ExecReadOnly)
159 "Repetition of tests. 10 by default. ",
160 type = Types.Integer,
161 flags = Flags.ExecReadOnly)
165 "Test time constraint in seconds. 5 by default. ",
166 type = Types.Integer,
167 flags = Flags.ExecReadOnly)
171 "Throughput constraint for UDP generator or throughput "
172 "test. Unlimited by default. ",
173 type = Types.Integer,
174 flags = Flags.ExecReadOnly)
176 continuous = Attribute("continuous",
177 "Run nping in a while loop",
180 flags = Flags.ExecReadOnly)
182 print_timestamp = Attribute("printTimestamp",
183 "Print timestamp before running nping",
186 flags = Flags.ExecReadOnly)
188 cls._register_attribute(s)
189 cls._register_attribute(p)
190 cls._register_attribute(a)
191 cls._register_attribute(A)
192 cls._register_attribute(b)
193 cls._register_attribute(B)
194 cls._register_attribute(c)
195 cls._register_attribute(d)
196 cls._register_attribute(e)
197 cls._register_attribute(g)
198 cls._register_attribute(target)
199 cls._register_attribute(g)
200 cls._register_attribute(i)
201 cls._register_attribute(l)
202 cls._register_attribute(m)
203 cls._register_attribute(o)
204 cls._register_attribute(P)
205 cls._register_attribute(q)
206 cls._register_attribute(r)
207 cls._register_attribute(t)
208 cls._register_attribute(T)
209 cls._register_attribute(continuous)
210 cls._register_attribute(print_timestamp)
212 def __init__(self, ec, guid):
213 super(LinuxUdpTest, self).__init__(ec, guid)
214 self._home = "udptest-%s" % self.guid
217 if not self.get("command"):
218 self.set("command", self._start_command)
220 if not self.get("sources"):
221 self.set("sources", self._sources)
223 if not self.get("install"):
224 self.set("install", self._install)
226 if not self.get("build"):
227 self.set("build", self._build)
229 if not self.get("env"):
230 self.set("env", self._environment)
232 if not self.get("depends"):
233 self.set("depends", self._depends)
235 super(LinuxUdpTest, self).do_deploy()
237 def upload_start_command(self):
238 super(LinuxUdpTest, self).upload_start_command()
240 if self.get("s") == True:
241 # We want to make sure the server is running
242 # before the client starts.
243 # Run the command as a bash script in background,
244 # in the host ( but wait until the command has
245 # finished to continue )
246 self._run_in_background()
249 if self.get("s") == True:
250 # Server is already running
251 if self.state == ResourceState.READY:
252 command = self.get("command")
253 self.info("Starting command '%s'" % command)
257 msg = " Failed to execute command '%s'" % command
258 self.error(msg, out, err)
259 raise RuntimeError, err
261 super(LinuxUdpTest, self).do_start()
264 def _start_command(self):
266 if self.get("continuous") == True:
267 args.append("while true; do ")
269 if self.get("printTimestamp") == True:
270 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
272 if self.get("s") == True:
273 args.append("udpserver")
275 args.append("udptest")
278 args.append("-p %d" % self.get("p"))
279 if self.get("a") == True:
282 args.append("-A %d" % self.get("A"))
284 args.append("-b %d" % self.get("b"))
286 args.append("-B %d" % self.get("B"))
287 if self.get("c") == True:
290 args.append("-d %d" % self.get("d"))
291 if self.get("e") == True:
293 if self.get("g") == True:
295 if self.get("target"):
296 args.append("-h %s" % self.get("target"))
297 if self.get("i") == True:
300 args.append("-l %d" % self.get("l"))
302 args.append("-m %d" % self.get("m"))
304 args.append("-o %d" % self.get("o"))
306 args.append("-P %d" % self.get("P"))
308 args.append("-q %s" % self.get("q"))
310 args.append("-r %d" % self.get("r"))
312 args.append("-t %d" % self.get("t"))
314 args.append("-T %d" % self.get("T"))
316 if self.get("continuous") == True:
317 args.append("; done ")
319 command = " ".join(args)
325 return "http://hpcbench.sourceforge.net/udp.tar.gz"
333 sources = self.get("sources").split(" ")[0]
334 sources = os.path.basename(sources)
337 # Evaluate if ccnx binaries are already installed
339 " test -f ${BIN}/udptest && "
340 " echo 'binaries found, nothing to do' "
342 # If not, untar and build
344 " mkdir -p ${SRC}/udptest && "
345 " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/udptest "
347 "cd ${SRC}/udptest && "
348 # Just execute and silence warnings...
350 " )") % ({ 'sources': sources,
356 # Evaluate if ccnx binaries are already installed
358 " test -f ${BIN}/udptest && "
359 " echo 'binaries found, nothing to do' "
362 " mv ${SRC}/udptest ${BIN} "
366 def _environment(self):
367 return "PATH=$PATH:${BIN}/udptest"
369 def valid_connection(self, guid):