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.execution.resource import clsinit_copy
24 from nepi.resources.linux.application import LinuxApplication
25 from nepi.util.timefuncs import tnow
30 class LinuxUdpTest(LinuxApplication):
31 """ Uses the hpcbench udptest tool to gather UDP measurements.
32 Measurements require two ends, a server and a client RM.
34 http://hpcbench.sourceforge.net/
36 _rtype = "LinuxUdpTest"
39 def _register_attributes(cls):
41 "Runs in server mode. ",
44 flags = Flags.ExecReadOnly)
47 "Port to listen to in server mode, or to connect to in client mode. "
50 flags = Flags.ExecReadOnly)
53 "Client option. Perform UDP Round Trip Time (latency) ",
55 flags = Flags.ExecReadOnly)
59 "Message size for UDP RTT test. "
60 "UDP RTT (latency) test with specified message size.",
62 flags = Flags.ExecReadOnly)
66 "Client UDP buffer size in bytes. Using system default "
67 "value if not defined.",
69 flags = Flags.ExecReadOnly)
73 "Server UDP buffer size in bytes. The same as cleint's by default.",
75 flags = Flags.ExecReadOnly)
79 "CPU log option. Tracing system info during the test. "
80 "Only available when output is defined. ",
82 flags = Flags.ExecReadOnly)
86 "Data size of each read/write in bytes. The same as packet size "
89 flags = Flags.ExecReadOnly)
93 "Exponential test (data size of each sending increasing from 1 "
94 "byte to packet size). ",
96 flags = Flags.ExecReadOnly)
100 "UDP traffic generator (Keep sending data to a host). "
101 "Work without server's support.",
103 flags = Flags.ExecReadOnly)
105 target = Attribute("target",
107 "Hostname or IP address of UDP server. Must be specified.",
108 flags = Flags.ExecReadOnly)
112 "Bidirectional UDP throuhgput test. Default is unidirection "
115 flags = Flags.ExecReadOnly)
119 "UDP datagram (packet) size in bytes ( < udp-buffer-szie ). "
121 type = Types.Integer,
122 flags = Flags.ExecReadOnly)
126 "Total message size in bytes. 1048576 by default.",
127 type = Types.Integer,
128 flags = Flags.ExecReadOnly)
132 "Output file name. ",
133 flags = Flags.ExecReadOnly)
137 "Write the plot file for gnuplot. Only enable when the output "
140 flags = Flags.ExecReadOnly)
144 "Define the TOS field of IP packets. "
145 "Six values can be used for this setting:\n"
146 " 1:(IPTOS)-Minimize delay\n"
147 " 2:(IPTOS)-Maximize throughput\n"
148 " 3:(DiffServ)-Class1 with low drop probability\n"
149 " 4:(DiffServ)-class1 with high drop probability\n"
150 " 5:(DiffServ)-Class4 with low drop probabiltiy\n"
151 " 6:(DiffServ)-Class4 with high drop probabiltiy\n"
152 "Write the plot file for gnuplot. Only enable when the output "
154 type = Types.Enumerate,
155 allowed = ["1", "2", "3", "4", "5", "6"],
156 flags = Flags.ExecReadOnly)
160 "Repetition of tests. 10 by default. ",
161 type = Types.Integer,
162 flags = Flags.ExecReadOnly)
166 "Test time constraint in seconds. 5 by default. ",
167 type = Types.Integer,
168 flags = Flags.ExecReadOnly)
172 "Throughput constraint for UDP generator or throughput "
173 "test. Unlimited by default. ",
174 type = Types.Integer,
175 flags = Flags.ExecReadOnly)
177 continuous = Attribute("continuous",
178 "Run nping in a while loop",
181 flags = Flags.ExecReadOnly)
183 print_timestamp = Attribute("printTimestamp",
184 "Print timestamp before running nping",
187 flags = Flags.ExecReadOnly)
189 cls._register_attribute(s)
190 cls._register_attribute(p)
191 cls._register_attribute(a)
192 cls._register_attribute(A)
193 cls._register_attribute(b)
194 cls._register_attribute(B)
195 cls._register_attribute(c)
196 cls._register_attribute(d)
197 cls._register_attribute(e)
198 cls._register_attribute(g)
199 cls._register_attribute(target)
200 cls._register_attribute(g)
201 cls._register_attribute(i)
202 cls._register_attribute(l)
203 cls._register_attribute(m)
204 cls._register_attribute(o)
205 cls._register_attribute(P)
206 cls._register_attribute(q)
207 cls._register_attribute(r)
208 cls._register_attribute(t)
209 cls._register_attribute(T)
210 cls._register_attribute(continuous)
211 cls._register_attribute(print_timestamp)
213 def __init__(self, ec, guid):
214 super(LinuxUdpTest, self).__init__(ec, guid)
215 self._home = "udptest-%s" % self.guid
218 if not self.get("command"):
219 self.set("command", self._start_command)
221 if not self.get("sources"):
222 self.set("sources", self._sources)
224 if not self.get("install"):
225 self.set("install", self._install)
227 if not self.get("build"):
228 self.set("build", self._build)
230 if not self.get("env"):
231 self.set("env", self._environment)
233 if not self.get("depends"):
234 self.set("depends", self._depends)
236 super(LinuxUdpTest, self).deploy()
238 def upload_start_command(self):
240 super(LinuxUdpTest, self).upload_start_command()
242 if self.get("s") == True:
243 # We want to make sure the server is running
244 # before the client starts.
245 # Run the command as a bash script in background,
246 # in the host ( but wait until the command has
247 # finished to continue )
248 self._run_in_background()
251 if self.get("s") == True:
252 # Server is already running
253 if self.state == ResourceState.READY:
254 command = self.get("command")
255 self.info("Starting command '%s'" % command)
259 msg = " Failed to execute command '%s'" % command
260 self.error(msg, out, err)
262 raise RuntimeError, msg
264 super(LinuxUdpTest, self).start()
267 def _start_command(self):
269 if self.get("continuous") == True:
270 args.append("while true; do ")
272 if self.get("printTimestamp") == True:
273 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
275 if self.get("s") == True:
276 args.append("udpserver")
278 args.append("udptest")
281 args.append("-p %d" % self.get("p"))
282 if self.get("a") == True:
285 args.append("-A %d" % self.get("A"))
287 args.append("-b %d" % self.get("b"))
289 args.append("-B %d" % self.get("B"))
290 if self.get("c") == True:
293 args.append("-d %d" % self.get("d"))
294 if self.get("e") == True:
296 if self.get("g") == True:
298 if self.get("target"):
299 args.append("-h %s" % self.get("target"))
300 if self.get("i") == True:
303 args.append("-l %d" % self.get("l"))
305 args.append("-m %d" % self.get("m"))
307 args.append("-o %d" % self.get("o"))
309 args.append("-P %d" % self.get("P"))
311 args.append("-q %s" % self.get("q"))
313 args.append("-r %d" % self.get("r"))
315 args.append("-t %d" % self.get("t"))
317 args.append("-T %d" % self.get("T"))
319 if self.get("continuous") == True:
320 args.append("; done ")
322 command = " ".join(args)
328 return "http://hpcbench.sourceforge.net/udp.tar.gz"
336 sources = self.get("sources").split(" ")[0]
337 sources = os.path.basename(sources)
340 # Evaluate if ccnx binaries are already installed
342 " test -f ${BIN}/udptest && "
343 " echo 'binaries found, nothing to do' "
345 # If not, untar and build
347 " mkdir -p ${SRC}/udptest && "
348 " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/udptest "
350 "cd ${SRC}/udptest && "
351 # Just execute and silence warnings...
353 " )") % ({ 'sources': sources,
359 # Evaluate if ccnx binaries are already installed
361 " test -f ${BIN}/udptest && "
362 " echo 'binaries found, nothing to do' "
365 " mv ${SRC}/udptest ${BIN} "
369 def _environment(self):
370 return "PATH=$PATH:${BIN}/udptest"
372 def valid_connection(self, guid):