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
22 from nepi.resources.linux.application import LinuxApplication
23 from nepi.util.timefuncs import tnow
28 class LinuxUdpTest(LinuxApplication):
29 """ Uses the hpcbench udptest tool to gather UDP measurements.
30 Measurements require two ends, a server and a client RM.
32 http://hpcbench.sourceforge.net/
34 _rtype = "linux::UdpTest"
37 def _register_attributes(cls):
39 "Runs in server mode. ",
45 "Port to listen to in server mode, or to connect to in client mode. "
51 "Client option. Perform UDP Round Trip Time (latency) ",
57 "Message size for UDP RTT test. "
58 "UDP RTT (latency) test with specified message size.",
64 "Client UDP buffer size in bytes. Using system default "
65 "value if not defined.",
71 "Server UDP buffer size in bytes. The same as cleint's by default.",
77 "CPU log option. Tracing system info during the test. "
78 "Only available when output is defined. ",
84 "Data size of each read/write in bytes. The same as packet size "
91 "Exponential test (data size of each sending increasing from 1 "
92 "byte to packet size). ",
98 "UDP traffic generator (Keep sending data to a host). "
99 "Work without server's support.",
101 flags = Flags.Design)
103 target = Attribute("target",
105 "Hostname or IP address of UDP server. Must be specified.",
106 flags = Flags.Design)
110 "Bidirectional UDP throuhgput test. Default is unidirection "
113 flags = Flags.Design)
117 "UDP datagram (packet) size in bytes ( < udp-buffer-szie ). "
119 type = Types.Integer,
120 flags = Flags.Design)
124 "Total message size in bytes. 1048576 by default.",
125 type = Types.Integer,
126 flags = Flags.Design)
130 "Output file name. ",
131 flags = Flags.Design)
135 "Write the plot file for gnuplot. Only enable when the output "
138 flags = Flags.Design)
142 "Define the TOS field of IP packets. "
143 "Six values can be used for this setting:\n"
144 " 1:(IPTOS)-Minimize delay\n"
145 " 2:(IPTOS)-Maximize throughput\n"
146 " 3:(DiffServ)-Class1 with low drop probability\n"
147 " 4:(DiffServ)-class1 with high drop probability\n"
148 " 5:(DiffServ)-Class4 with low drop probabiltiy\n"
149 " 6:(DiffServ)-Class4 with high drop probabiltiy\n"
150 "Write the plot file for gnuplot. Only enable when the output "
152 type = Types.Enumerate,
153 allowed = ["1", "2", "3", "4", "5", "6"],
154 flags = Flags.Design)
158 "Repetition of tests. 10 by default. ",
159 type = Types.Integer,
160 flags = Flags.Design)
164 "Test time constraint in seconds. 5 by default. ",
165 type = Types.Integer,
166 flags = Flags.Design)
170 "Throughput constraint for UDP generator or throughput "
171 "test. Unlimited by default. ",
172 type = Types.Integer,
173 flags = Flags.Design)
175 continuous = Attribute("continuous",
176 "Run nping in a while loop",
179 flags = Flags.Design)
181 print_timestamp = Attribute("printTimestamp",
182 "Print timestamp before running nping",
185 flags = Flags.Design)
187 cls._register_attribute(s)
188 cls._register_attribute(p)
189 cls._register_attribute(a)
190 cls._register_attribute(A)
191 cls._register_attribute(b)
192 cls._register_attribute(B)
193 cls._register_attribute(c)
194 cls._register_attribute(d)
195 cls._register_attribute(e)
196 cls._register_attribute(g)
197 cls._register_attribute(target)
198 cls._register_attribute(g)
199 cls._register_attribute(i)
200 cls._register_attribute(l)
201 cls._register_attribute(m)
202 cls._register_attribute(o)
203 cls._register_attribute(P)
204 cls._register_attribute(q)
205 cls._register_attribute(r)
206 cls._register_attribute(t)
207 cls._register_attribute(T)
208 cls._register_attribute(continuous)
209 cls._register_attribute(print_timestamp)
211 def __init__(self, ec, guid):
212 super(LinuxUdpTest, self).__init__(ec, guid)
213 self._home = "udptest-%s" % self.guid
216 if not self.get("command"):
217 self.set("command", self._start_command)
219 if not self.get("sources"):
220 self.set("sources", self._sources)
222 if not self.get("install"):
223 self.set("install", self._install)
225 if not self.get("build"):
226 self.set("build", self._build)
228 if not self.get("env"):
229 self.set("env", self._environment)
231 if not self.get("depends"):
232 self.set("depends", self._depends)
234 super(LinuxUdpTest, self).do_deploy()
236 def upload_start_command(self):
237 super(LinuxUdpTest, self).upload_start_command()
239 if self.get("s") == True:
240 # We want to make sure the server is running
241 # before the client starts.
242 # Run the command as a bash script in background,
243 # in the host ( but wait until the command has
244 # finished to continue )
245 self._run_in_background()
248 if self.get("s") == True:
249 # Server is already running
250 if self.state == ResourceState.READY:
251 command = self.get("command")
252 self.info("Starting command '%s'" % command)
256 msg = " Failed to execute command '%s'" % command
257 self.error(msg, out, err)
258 raise RuntimeError, err
260 super(LinuxUdpTest, self).do_start()
263 def _start_command(self):
265 if self.get("continuous") == True:
266 args.append("while true; do ")
268 if self.get("printTimestamp") == True:
269 args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
271 if self.get("s") == True:
272 args.append("udpserver")
274 args.append("udptest")
277 args.append("-p %d" % self.get("p"))
278 if self.get("a") == True:
281 args.append("-A %d" % self.get("A"))
283 args.append("-b %d" % self.get("b"))
285 args.append("-B %d" % self.get("B"))
286 if self.get("c") == True:
289 args.append("-d %d" % self.get("d"))
290 if self.get("e") == True:
292 if self.get("g") == True:
294 if self.get("target"):
295 args.append("-h %s" % self.get("target"))
296 if self.get("i") == True:
299 args.append("-l %d" % self.get("l"))
301 args.append("-m %d" % self.get("m"))
303 args.append("-o %d" % self.get("o"))
305 args.append("-P %d" % self.get("P"))
307 args.append("-q %s" % self.get("q"))
309 args.append("-r %d" % self.get("r"))
311 args.append("-t %d" % self.get("t"))
313 args.append("-T %d" % self.get("T"))
315 if self.get("continuous") == True:
316 args.append("; done ")
318 command = " ".join(args)
324 return "http://hpcbench.sourceforge.net/udp.tar.gz"
332 sources = self.get("sources").split(" ")[0]
333 sources = os.path.basename(sources)
336 # Evaluate if ccnx binaries are already installed
338 " test -f ${BIN}/udptest && "
339 " echo 'binaries found, nothing to do' "
341 # If not, untar and build
343 " mkdir -p ${SRC}/udptest && "
344 " tar xf ${SRC}/%(sources)s --strip-components=1 -C ${SRC}/udptest "
346 "cd ${SRC}/udptest && "
347 # Just execute and silence warnings...
349 " )") % ({ 'sources': sources,
355 # Evaluate if ccnx binaries are already installed
357 " test -f ${BIN}/udptest && "
358 " echo 'binaries found, nothing to do' "
361 " mv ${SRC}/udptest ${BIN} "
365 def _environment(self):
366 return "PATH=$PATH:${BIN}/udptest"
368 def valid_connection(self, guid):