mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 1 | import os, time, re, logging |
mbligh | 67a72f9 | 2009-01-13 19:31:08 +0000 | [diff] [blame] | 2 | from autotest_lib.client.bin import test, utils |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 3 | from autotest_lib.client.bin.net import net_utils |
mbligh | 67a72f9 | 2009-01-13 19:31:08 +0000 | [diff] [blame] | 4 | from autotest_lib.client.common_lib import error |
mbligh | 9f85792 | 2008-06-05 16:19:07 +0000 | [diff] [blame] | 5 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 6 | MPSTAT_IX = 0 |
| 7 | NETPERF_IX = 1 |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 8 | |
| 9 | class netperf2(test.test): |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 10 | version = 3 |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 11 | |
lmr | 0570b97 | 2010-05-25 20:07:00 +0000 | [diff] [blame^] | 12 | # ftp://ftp.netperf.org/netperf/netperf-2.4.5.tar.bz2 |
| 13 | def setup(self, tarball = 'netperf-2.4.5.tar.bz2'): |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 14 | self.job.require_gcc() |
mbligh | 8b35285 | 2008-06-07 01:07:08 +0000 | [diff] [blame] | 15 | tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame] | 16 | utils.extract_tarball_to_dir(tarball, self.srcdir) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 17 | os.chdir(self.srcdir) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 18 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 19 | utils.system('patch -p0 < ../wait_before_data.patch') |
mbligh | ab88fbb | 2010-04-08 18:31:13 +0000 | [diff] [blame] | 20 | utils.configure() |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 21 | utils.system('make') |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 22 | utils.system('sync') |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 23 | |
| 24 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 25 | def initialize(self): |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 26 | self.server_prog = '%s&' % os.path.join(self.srcdir, 'src/netserver') |
| 27 | self.client_prog = '%s' % os.path.join(self.srcdir, 'src/netperf') |
| 28 | self.valid_tests = ['TCP_STREAM', 'TCP_MAERTS', 'TCP_RR', 'TCP_CRR', |
| 29 | 'TCP_SENDFILE', 'UDP_STREAM', 'UDP_RR'] |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 30 | self.results = [] |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 31 | self.actual_times = [] |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 32 | self.netif = '' |
| 33 | self.network = net_utils.network() |
| 34 | self.network_utils = net_utils.network_utils() |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 35 | |
mbligh | 6f5bbce | 2007-08-10 19:18:37 +0000 | [diff] [blame] | 36 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 37 | def run_once(self, server_ip, client_ip, role, test = 'TCP_STREAM', |
| 38 | test_time = 15, stream_list = [1], test_specific_args = '', |
| 39 | cpu_affinity = '', dev = '', bidi = False, wait_time = 5): |
| 40 | """ |
| 41 | server_ip: IP address of host running netserver |
| 42 | client_ip: IP address of host running netperf client(s) |
| 43 | role: 'client' or 'server' |
| 44 | test: one of TCP_STREAM, TCP_MEARTS, TCP_RR, TCP_CRR, TCP_SENDFILE, |
| 45 | UDP_STREAM or UDP_RR |
| 46 | test_time: time to run the test for in seconds |
| 47 | stream_list: list of number of netperf streams to launch |
| 48 | test_specific_args: Optional test specific args. For example to set |
| 49 | the request,response size for RR tests to 200,100, set it |
| 50 | to: '-- -r 200,100'. Or, to set the send buffer size of STREAM |
| 51 | tests to 200, set it to: '-- -m 200' |
| 52 | cpu_affinity: netperf/netserver processes will get taskset to the |
| 53 | cpu_affinity. cpu_affinity is specified as a bitmask in hex |
| 54 | without the leading 0x. For example, to run on CPUs 0 & 5, |
| 55 | cpu_affinity needs to be '21' |
| 56 | dev: device on which to run traffic on. For example, to run on |
| 57 | inteface eth1, set it to 'eth1'. |
| 58 | bidi: bi-directional traffic. This is supported for TCP_STREAM |
| 59 | test only. The RR & CRR tests are bi-directional by nature. |
| 60 | wait_time: Time to wait after establishing data/control connections |
| 61 | but before sending data traffic. |
| 62 | """ |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 63 | if test not in self.valid_tests: |
| 64 | raise error.TestError('invalid test specified') |
| 65 | self.role = role |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 66 | self.test = test |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 67 | self.test_time = test_time |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 68 | self.wait_time = wait_time |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 69 | self.stream_list = stream_list |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 70 | self.bidi = bidi |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 71 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 72 | server_tag = server_ip + '#netperf-server' |
| 73 | client_tag = client_ip + '#netperf-client' |
| 74 | all = [server_tag, client_tag] |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 75 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 76 | # If a specific device has been requested, configure it. |
| 77 | if dev: |
| 78 | timeout = 60 |
| 79 | if role == 'server': |
| 80 | self.configure_interface(dev, server_ip) |
| 81 | self.ping(client_ip, timeout) |
| 82 | else: |
| 83 | self.configure_interface(dev, client_ip) |
| 84 | self.ping(server_ip, timeout) |
| 85 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 86 | for num_streams in stream_list: |
| 87 | if role == 'server': |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 88 | self.server_start(cpu_affinity) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 89 | try: |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 90 | # Wait up to ten minutes for the client to reach this |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 91 | # point. |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 92 | self.job.barrier(server_tag, 'start_%d' % num_streams, |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 93 | 600).rendezvous(*all) |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 94 | # Wait up to test_time + 5 minutes for the test to |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 95 | # complete |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 96 | self.job.barrier(server_tag, 'stop_%d' % num_streams, |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 97 | test_time+300).rendezvous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 98 | finally: |
| 99 | self.server_stop() |
| 100 | |
| 101 | elif role == 'client': |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 102 | # Wait up to ten minutes for the server to start |
| 103 | self.job.barrier(client_tag, 'start_%d' % num_streams, |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 104 | 600).rendezvous(*all) |
| 105 | self.client(server_ip, test, test_time, num_streams, |
| 106 | test_specific_args, cpu_affinity) |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 107 | # Wait up to 5 minutes for the server to also reach this point |
| 108 | self.job.barrier(client_tag, 'stop_%d' % num_streams, |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 109 | 300).rendezvous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 110 | else: |
| 111 | raise error.TestError('invalid role specified') |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 112 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 113 | self.restore_interface() |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 114 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 115 | |
| 116 | def configure_interface(self, dev, ip_addr): |
| 117 | self.netif = net_utils.netif(dev) |
| 118 | self.netif.up() |
| 119 | if self.netif.get_ipaddr() != ip_addr: |
| 120 | self.netif.set_ipaddr(ip_addr) |
| 121 | |
| 122 | |
| 123 | def restore_interface(self): |
| 124 | if self.netif: |
| 125 | self.netif.restore() |
| 126 | |
| 127 | |
| 128 | def server_start(self, cpu_affinity): |
mbligh | 78be24a | 2008-06-13 21:40:08 +0000 | [diff] [blame] | 129 | utils.system('killall netserver', ignore_status=True) |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 130 | cmd = self.server_prog |
| 131 | if cpu_affinity: |
| 132 | cmd = 'taskset %s %s' % (cpu_affinity, cmd) |
| 133 | |
| 134 | self.results.append(utils.system_output(cmd, retain_output=True)) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 135 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 136 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 137 | def server_stop(self): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 138 | utils.system('killall netserver', ignore_status=True) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 139 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 140 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 141 | def client(self, server_ip, test, test_time, num_streams, |
| 142 | test_specific_args, cpu_affinity): |
| 143 | args = '-H %s -t %s -l %d' % (server_ip, test, test_time) |
| 144 | if self.wait_time: |
| 145 | args += ' -s %d ' % self.wait_time |
| 146 | |
| 147 | # Append the test specific arguments. |
| 148 | if test_specific_args: |
| 149 | args += ' ' + test_specific_args |
| 150 | |
| 151 | cmd = '%s %s' % (self.client_prog, args) |
| 152 | |
| 153 | if cpu_affinity: |
| 154 | cmd = 'taskset %s %s' % (cpu_affinity, cmd) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 155 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 156 | try: |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 157 | cmds = [] |
| 158 | |
| 159 | # Get 5 mpstat samples. Since tests with large number of streams |
| 160 | # take a long time to start up all the streams, we'll toss out the |
| 161 | # first and last sample when recording results |
| 162 | interval = max(1, test_time / 5) |
| 163 | cmds.append('sleep %d && mpstat -P ALL %s 5' % (self.wait_time, |
| 164 | interval)) |
| 165 | |
| 166 | # Add the netperf commands |
| 167 | for i in xrange(num_streams): |
| 168 | cmds.append(cmd) |
| 169 | if self.bidi and test == 'TCP_STREAM': |
| 170 | cmds.append(cmd.replace('TCP_STREAM', 'TCP_MAERTS')) |
| 171 | |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 172 | t0 = time.time() |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 173 | # Launch all commands in parallel |
| 174 | out = utils.run_parallel(cmds, timeout=test_time + 500, |
| 175 | ignore_status=True) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 176 | t1 = time.time() |
| 177 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 178 | self.results.append(out) |
| 179 | self.actual_times.append(t1 - t0 - self.wait_time) |
| 180 | # Log test output |
| 181 | logging.info(out) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 182 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 183 | except error.CmdError, e: |
| 184 | """ Catch errors due to timeout, but raise others |
| 185 | The actual error string is: |
| 186 | "Command did not complete within %d seconds" |
| 187 | called in function join_bg_job in the file common_lib/utils.py |
mbligh | e8fa3af | 2006-09-28 23:14:56 +0000 | [diff] [blame] | 188 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 189 | Looking for 'within' is probably not the best way to do this but |
| 190 | works for now""" |
| 191 | |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 192 | if ('within' in e.additional_text |
| 193 | or 'non-zero' in e.additional_text): |
lmr | 4c607f2 | 2009-06-02 11:50:38 +0000 | [diff] [blame] | 194 | logging.debug(e.additional_text) |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 195 | self.results.append(None) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 196 | self.actual_times.append(1) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 197 | else: |
| 198 | raise |
| 199 | |
| 200 | |
| 201 | def postprocess(self): |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 202 | if self.role == 'client': |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 203 | # if profilers are enabled, the test gets runs twice |
| 204 | if (len(self.stream_list) != len(self.results) and |
| 205 | 2*len(self.stream_list) != len(self.results)): |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 206 | raise error.TestError('Mismatched number of results') |
| 207 | |
| 208 | function = None |
| 209 | keys = None |
| 210 | |
| 211 | # Each of the functions return tuples in which the keys define |
| 212 | # what that item in the tuple represents |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 213 | if self.test in ['TCP_STREAM', 'TCP_MAERTS', 'TCP_SENDFILE']: |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 214 | function = self.process_tcp_stream |
| 215 | keys = ('Throughput',) |
| 216 | elif self.test == 'UDP_STREAM': |
| 217 | function = self.process_udp_stream |
| 218 | keys = ('Throughput', 'Errors') |
| 219 | elif self.test in ['TCP_RR', 'TCP_CRR', 'UDP_RR']: |
| 220 | function = self.process_request_response |
| 221 | keys = ('Transfer_Rate',) |
| 222 | else: |
| 223 | raise error.TestError('Unhandled test') |
| 224 | |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 225 | for i, streams in enumerate(self.stream_list): |
| 226 | attr = {'stream_count':streams} |
| 227 | keyval = {} |
| 228 | temp_vals = [] |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 229 | |
| 230 | # Short circuit to handle errors due to client timeouts |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 231 | if not self.results[i]: |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 232 | self.write_iteration_keyval(attr, keyval) |
| 233 | continue |
| 234 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 235 | # Collect output of netperf sessions |
| 236 | failed_streams_count = 0 |
| 237 | for result in self.results[i][NETPERF_IX:]: |
| 238 | if result.exit_status: |
| 239 | failed_streams_count += 1 |
| 240 | else: |
| 241 | temp_vals.append(function(result.stdout)) |
| 242 | |
| 243 | keyval['Failed_streams_count'] = failed_streams_count |
| 244 | |
| 245 | # Process mpstat output |
| 246 | mpstat_out = self.results[i][MPSTAT_IX].stdout |
| 247 | cpu_stats = self.network_utils.process_mpstat(mpstat_out, 5) |
| 248 | keyval['CPU_C'] = 100 - cpu_stats['idle'] |
| 249 | keyval['CPU_C_SYS'] = cpu_stats['sys'] |
| 250 | keyval['CPU_C_HI'] = cpu_stats['irq'] |
| 251 | keyval['CPU_C_SI'] = cpu_stats['soft'] |
| 252 | keyval['INTRS_C'] = cpu_stats['intr/s'] |
| 253 | |
| 254 | actual_time = self.actual_times[i] |
| 255 | keyval['actual_time'] = actual_time |
| 256 | logging.info('actual_time: %f', actual_time) |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 257 | |
mbligh | 6d858fa | 2008-09-19 21:19:03 +0000 | [diff] [blame] | 258 | # Compute the sum of elements returned from function which |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 259 | # represent the string contained in keys |
| 260 | for j, key in enumerate(keys): |
| 261 | vals = [x[j] for x in temp_vals] |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 262 | # scale result by the actual time taken |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 263 | keyval[key] = sum(vals) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame] | 264 | |
| 265 | # record 'Efficiency' as perf/CPU |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 266 | if keyval['CPU_C'] != 0: |
| 267 | keyval['Efficieny_C'] = keyval[keys[0]]/keyval['CPU_C'] |
| 268 | else: |
| 269 | keyval['Efficieny_C'] = keyval[keys[0]] |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 270 | |
| 271 | self.write_iteration_keyval(attr, keyval) |
| 272 | |
| 273 | |
| 274 | def process_tcp_stream(self, output): |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 275 | """Parses the following (works for both TCP_STREAM, TCP_MAERTS and |
| 276 | TCP_SENDFILE) and returns a singleton containing throughput. |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 277 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 278 | TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to foo.bar.com \ |
| 279 | (10.10.10.3) port 0 AF_INET |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 280 | Recv Send Send |
| 281 | Socket Socket Message Elapsed |
| 282 | Size Size Size Time Throughput |
| 283 | bytes bytes bytes secs. 10^6bits/sec |
| 284 | |
| 285 | 87380 16384 16384 2.00 941.28 |
| 286 | """ |
| 287 | |
| 288 | return float(output.splitlines()[6].split()[4]), |
| 289 | |
| 290 | |
| 291 | def process_udp_stream(self, output): |
| 292 | """Parses the following and returns a touple containing throughput |
| 293 | and the number of errors. |
| 294 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 295 | UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET \ |
| 296 | to foo.bar.com (10.10.10.3) port 0 AF_INET |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 297 | Socket Message Elapsed Messages |
| 298 | Size Size Time Okay Errors Throughput |
| 299 | bytes bytes secs # # 10^6bits/sec |
| 300 | |
| 301 | 129024 65507 2.00 3673 0 961.87 |
| 302 | 131072 2.00 3673 961.87 |
| 303 | """ |
| 304 | |
| 305 | line_tokens = output.splitlines()[5].split() |
| 306 | return float(line_tokens[5]), int(line_tokens[4]) |
| 307 | |
| 308 | |
| 309 | def process_request_response(self, output): |
| 310 | """Parses the following which works for both rr (TCP and UDP) and crr |
| 311 | tests and returns a singleton containing transfer rate. |
| 312 | |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 313 | TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET \ |
| 314 | to foo.bar.com (10.10.10.3) port 0 AF_INET |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 315 | Local /Remote |
| 316 | Socket Size Request Resp. Elapsed Trans. |
| 317 | Send Recv Size Size Time Rate |
| 318 | bytes Bytes bytes bytes secs. per sec |
| 319 | |
| 320 | 16384 87380 1 1 2.00 14118.53 |
| 321 | 16384 87380 |
| 322 | """ |
| 323 | |
| 324 | return float(output.splitlines()[6].split()[5]), |
mbligh | 4439424 | 2009-06-15 21:31:32 +0000 | [diff] [blame] | 325 | |
| 326 | |
| 327 | def ping(self, ip, timeout): |
| 328 | curr_time = time.time() |
| 329 | end_time = curr_time + timeout |
| 330 | while curr_time < end_time: |
| 331 | if not os.system('ping -c 1 ' + ip): |
| 332 | # Ping succeeded |
| 333 | return |
| 334 | # Ping failed. Lets sleep a bit and try again. |
| 335 | time.sleep(5) |
| 336 | curr_time = time.time() |
| 337 | |
| 338 | return |