def run_second_side(self, send_manager, recv_manager, second_cmds): time.sleep(self.run_first_setup_time) start_time = time.time() self.test_start_time = utc_time() # start each flow self.interval seconds after the previous one for i in xrange(len(second_cmds)): if i != 0: time.sleep(self.interval) second_cmd = second_cmds[i] if self.run_first == 'receiver': send_manager.stdin.write(second_cmd) send_manager.stdin.flush() else: recv_manager.stdin.write(second_cmd) recv_manager.stdin.flush() elapsed_time = time.time() - start_time if elapsed_time > self.runtime: sys.stderr.write('Interval time between flows is too long') return False time.sleep(self.runtime - elapsed_time) self.test_end_time = utc_time() return True
def run_without_tunnel(self): port = get_open_port() # run the side specified by self.run_first cmd = ['python', self.cc_src, self.run_first, port] sys.stderr.write('Running %s %s...\n' % (self.cc, self.run_first)) self.proc_first = Popen(cmd, preexec_fn=os.setsid) # sleep just in case the process isn't quite listening yet # the cleaner approach might be to try to verify the socket is open time.sleep(self.run_first_setup_time) self.test_start_time = utc_time() # run the other side specified by self.run_second sh_cmd = 'python %s %s $MAHIMAHI_BASE %s' % (self.cc_src, self.run_second, port) sh_cmd = ' '.join(self.mm_cmd) + " -- sh -c '%s'" % sh_cmd sys.stderr.write('Running %s %s...\n' % (self.cc, self.run_second)) self.proc_second = Popen(sh_cmd, shell=True, preexec_fn=os.setsid) signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(self.runtime) try: self.proc_first.wait() self.proc_second.wait() except TimeoutError: pass else: signal.alarm(0) sys.stderr.write('Warning: test exited before time limit\n') finally: self.test_end_time = utc_time() return True
def run_without_tunnel(self): port = get_open_port() # run the side specified by self.run_first cmd = ['python', self.cc_src, self.run_first, port] sys.stderr.write('Running %s %s...\n' % (self.cc, self.run_first)) self.proc_first = Popen(cmd, preexec_fn=os.setsid) # sleep just in case the process isn't quite listening yet # the cleaner approach might be to try to verify the socket is open time.sleep(self.run_first_setup_time) self.test_start_time = utc_time() # run the other side specified by self.run_second sh_cmd = 'python %s %s $MAHIMAHI_BASE %s' % ( self.cc_src, self.run_second, port) sh_cmd = ' '.join(self.mm_cmd) + " -- sh -c '%s'" % sh_cmd sys.stderr.write('Running %s %s...\n' % (self.cc, self.run_second)) self.proc_second = Popen(sh_cmd, shell=True, preexec_fn=os.setsid) signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(self.runtime) try: self.proc_first.wait() self.proc_second.wait() except TimeoutError: pass else: signal.alarm(0) sys.stderr.write('Warning: test exited before time limit\n') finally: self.test_end_time = utc_time() return True
def update_stats_log(self, cc, run_id, stats): stats_log_path = path.join(self.data_dir, '%s_stats_run%s.log' % (cc, run_id)) if not path.isfile(stats_log_path): sys.stderr.write('Warning: %s does not exist\n' % stats_log_path) return None saved_lines = '' # back up old stats logs with open(stats_log_path) as stats_log: for line in stats_log: if any([ x in line for x in ['Start at:', 'End at:', 'clock offset:'] ]): saved_lines += line else: continue # write to new stats log with open(stats_log_path, 'w') as stats_log: stats_log.write(saved_lines) if stats: stats_log.write('\n# Below is generated by %s at %s\n' % (path.basename(__file__), utc_time())) stats_log.write('# Datalink statistics\n') stats_log.write('%s' % stats)
def update_stats_log(self, cc, run_id, stats): stats_log_path = path.join( self.data_dir, '%s_stats_run%s.log' % (cc, run_id)) if not path.isfile(stats_log_path): sys.stderr.write('Warning: %s does not exist\n' % stats_log_path) return None saved_lines = '' # back up old stats logs with open(stats_log_path) as stats_log: for line in stats_log: if any([x in line for x in [ 'Start at:', 'End at:', 'clock offset:']]): saved_lines += line else: continue # write to new stats log with open(stats_log_path, 'w') as stats_log: stats_log.write(saved_lines) if stats: stats_log.write('\n# Below is generated by %s at %s\n' % (path.basename(__file__), utc_time())) stats_log.write('# Datalink statistics\n') stats_log.write('%s' % stats)
def describe_metadata(self): desc = '\\centerline{\\textbf{\\large{Pantheon Report}}}\n' desc += '\\vspace{20pt}\n\n' desc += 'Generated at %s (UTC).\n\n' % utc_time() meta = self.meta if meta['mode'] == 'local': mm_cmd = [] if 'prepend_mm_cmds' in meta: mm_cmd.append(meta['prepend_mm_cmds']) mm_cmd += ['mm-link', meta['uplink_trace'], meta['downlink_trace']] if 'extra_mm_link_args' in meta: mm_cmd.append(meta['extra_mm_link_args']) if 'append_mm_cmds' in meta: mm_cmd.append(meta['append_mm_cmds']) mm_cmd = ' '.join(mm_cmd).replace('_', '\\_') desc += 'Tested in mahimahi: \\texttt{%s}\n\n' % mm_cmd elif meta['mode'] == 'remote': txt = {} for side in ['local', 'remote']: txt[side] = [] if '%s_desc' % side in meta: txt[side].append(meta['%s_desc' % side]) if '%s_if' % side in meta: txt[side].append(meta['%s_if' % side]) else: txt[side].append('Ethernet') txt[side] = ' '.join(txt[side]).replace('_', '\\_') if meta['sender_side'] == 'remote': desc += ('Data path: %s (\\textit{remote}) \\textrightarrow ' '%s (\\textit{local}).\n\n') % ( txt['remote'], txt['local']) else: desc += ('Data path: %s (\\textit{local}) \\textrightarrow ' '%s (\\textit{remote}).\n\n') % ( txt['local'], txt['remote']) if meta['flows'] == 1: flows = '1 flow' else: flows = ('%s flows with %s-second interval between two flows' % (meta['flows'], meta['interval'])) if meta['runtime'] == 1: runtime = '1 second' else: runtime = '%s seconds' % meta['runtime'] run_times = meta['run_times'] if run_times == 1: times = 'once' elif run_times == 2: times = 'twice' else: times = '%s times' % run_times desc += ( 'Repeated the test of %d congestion control schemes %s.\n\n' 'Each test lasted for %s running %s.\n\n' % (len(self.cc_schemes), times, runtime, flows)) desc += ( 'Increased UDP receive buffer to 16 MB (default) and ' '32 MB (max).\n\n' 'Tested BBR with qdisc of Fair Queuing (\\texttt{fq}), and ' 'other schemes with the default Linux qdisc ' '(\\texttt{pfifo\_fast}).\n\n') if 'ntp_addr' in meta: desc += ('NTP offsets were measured against \\texttt{%s} and have ' 'been applied to correct the timestamps in logs.\n\n' % meta['ntp_addr']) desc += ( '\\begin{verbatim}\n' 'Git summary:\n' '%s' '\\end{verbatim}\n\n' % meta['git_summary']) desc += '\\newpage\n\n' return desc