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 clsinit_copy, ResourceState
21 from nepi.resources.linux.application import LinuxApplication
22 from nepi.util.timefuncs import tnow
27 class LinuxUdpTest(LinuxApplication):
28 """ Uses the hpcbench udptest tool to gather UDP measurements.
29 Measurements require two ends, a server and a client RM.
31 http://hpcbench.sourceforge.net/
33 _rtype = "linux::UdpTest"
36 def _register_attributes(cls):
38 "Runs in server mode. ",
44 "Port to listen to in server mode, or to connect to in client mode. "
50 "Client option. Perform UDP Round Trip Time (latency) ",
56 "Message size for UDP RTT test. "
57 "UDP RTT (latency) test with specified message size.",
63 "Client UDP buffer size in bytes. Using system default "
64 "value if not defined.",
70 "Server UDP buffer size in bytes. The same as cleint's by default.",
76 "CPU log option. Tracing system info during the test. "
77 "Only available when output is defined. ",
83 "Data size of each read/write in bytes. The same as packet size "
90 "Exponential test (data size of each sending increasing from 1 "
91 "byte to packet size). ",
97 "UDP traffic generator (Keep sending data to a host). "
98 "Work without server's support.",
100 flags = Flags.Design)
102 target = Attribute("target",
104 "Hostname or IP address of UDP server. Must be specified.",
105 flags = Flags.Design)
109 "Bidirectional UDP throuhgput test. Default is unidirection "
112 flags = Flags.Design)
116 "UDP datagram (packet) size in bytes ( < udp-buffer-szie ). "
118 type = Types.Integer,
119 flags = Flags.Design)
123 "Total message size in bytes. 1048576 by default.",
124 type = Types.Integer,
125 flags = Flags.Design)
129 "Output file name. ",
130 flags = Flags.Design)
134 "Write the plot file for gnuplot. Only enable when the output "
137 flags = Flags.Design)
141 "Define the TOS field of IP packets. "
142 "Six values can be used for this setting:\n"
143 " 1:(IPTOS)-Minimize delay\n"
144 " 2:(IPTOS)-Maximize throughput\n"
145 " 3:(DiffServ)-Class1 with low drop probability\n"
146 " 4:(DiffServ)-class1 with high drop probability\n"
147 " 5:(DiffServ)-Class4 with low drop probabiltiy\n"
148 " 6:(DiffServ)-Class4 with high drop probabiltiy\n"
149 "Write the plot file for gnuplot. Only enable when the output "
151 type = Types.Enumerate,
152 allowed = ["1", "2", "3", "4", "5", "6"],
153 flags = Flags.Design)
157 "Repetition of tests. 10 by default. ",
158 type = Types.Integer,
159 flags = Flags.Design)
163 "Test time constraint in seconds. 5 by default. ",
164 type = Types.Integer,
165 flags = Flags.Design)
169 "Throughput constraint for UDP generator or throughput "
170 "test. Unlimited by default. ",
171 type = Types.Integer,
172 flags = Flags.Design)
174 continuous = Attribute("continuous",
175 "Run nping in a while loop",
178 flags = Flags.Design)
180 print_timestamp = Attribute("printTimestamp",
181 "Print timestamp before running nping",
184 flags = Flags.Design)
186 cls._register_attribute(s)
187 cls._register_attribute(p)
188 cls._register_attribute(a)
189 cls._register_attribute(A)
190 cls._register_attribute(b)
191 cls._register_attribute(B)
192 cls._register_attribute(c)
193 cls._register_attribute(d)
194 cls._register_attribute(e)
195 cls._register_attribute(g)
196 cls._register_attribute(target)
197 cls._register_attribute(g)
198 cls._register_attribute(i)
199 cls._register_attribute(l)
200 cls._register_attribute(m)
201 cls._register_attribute(o)
202 cls._register_attribute(P)
203 cls._register_attribute(q)
204 cls._register_attribute(r)
205 cls._register_attribute(t)
206 cls._register_attribute(T)
207 cls._register_attribute(continuous)
208 cls._register_attribute(print_timestamp)
210 def __init__(self, ec, guid):
211 super(LinuxUdpTest, self).__init__(ec, guid)
212 self._home = "udptest-%s" % self.guid
215 if not self.get("command"):
216 self.set("command", self._start_command)
218 if not self.get("sources"):
219 self.set("sources", self._sources)
221 if not self.get("install"):
222 self.set("install", self._install)
224 if not self.get("build"):
225 self.set("build", self._build)
227 if not self.get("env"):
228 self.set("env", self._environment)
230 if not self.get("depends"):
231 self.set("depends", self._depends)
233 super(LinuxUdpTest, self).do_deploy()
235 def upload_start_command(self):
236 super(LinuxUdpTest, self).upload_start_command()
238 if self.get("s") == True:
239 # We want to make sure the server is running
240 # before the client starts.
241 # Run the command as a bash script in background,
242 # in the host ( but wait until the command has
243 # finished to continue )
244 self._run_in_background()
247 if self.get("s") == True:
248 # Server is already running
249 if self.state == ResourceState.READY:
250 command = self.get("command")
251 self.info("Starting command '%s'" % command)
255 msg = " Failed to execute command '%s'" % command
256 self.error(msg, out, err)
257 raise RuntimeError(err)
259 super(LinuxUdpTest, self).do_start()
262 def _start_command(self):
264 if self.get("continuous") == True:
265 args.append("while true; do ")
267 if self.get("printTimestamp") == True:
268 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
270 if self.get("s") == True:
271 args.append("udpserver")
273 args.append("udptest")
276 args.append("-p %d" % self.get("p"))
277 if self.get("a") == True:
280 args.append("-A %d" % self.get("A"))
282 args.append("-b %d" % self.get("b"))
284 args.append("-B %d" % self.get("B"))
285 if self.get("c") == True:
288 args.append("-d %d" % self.get("d"))
289 if self.get("e") == True:
291 if self.get("g") == True:
293 if self.get("target"):
294 args.append("-h %s" % self.get("target"))
295 if self.get("i") == True:
298 args.append("-l %d" % self.get("l"))
300 args.append("-m %d" % self.get("m"))
302 args.append("-o %d" % self.get("o"))
304 args.append("-P %d" % self.get("P"))
306 args.append("-q %s" % self.get("q"))
308 args.append("-r %d" % self.get("r"))
310 args.append("-t %d" % self.get("t"))
312 args.append("-T %d" % self.get("T"))
314 if self.get("continuous") == True:
315 args.append("; done ")
317 command = " ".join(args)
323 return "http://hpcbench.sourceforge.net/udp.tar.gz"
331 sources = self.get("sources").split(" ")[0]
332 sources = os.path.basename(sources)
335 # Evaluate if ccnx binaries are already installed
337 " test -f ${BIN}/udptest && "
338 " echo 'binaries found, nothing to do' "
340 # If not, untar and build
342 " mkdir -p ${SRC}/udptest && "
343 " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/udptest "
345 "cd ${SRC}/udptest && "
346 # Just execute and silence warnings...
348 " )") % ({ 'sources': sources,
354 # Evaluate if ccnx binaries are already installed
356 " test -f ${BIN}/udptest && "
357 " echo 'binaries found, nothing to do' "
360 " mv ${SRC}/udptest ${BIN} "
364 def _environment(self):
365 return "PATH=$PATH:${BIN}/udptest"
367 def valid_connection(self, guid):