def set_sock_recv_buf(new_default, new_max): buf_default = check_output('sysctl net.core.rmem_default', shell=True) buf_default = int(buf_default.split('=')[-1]) buf_max = check_output('sysctl net.core.rmem_max', shell=True) buf_max = int(buf_max.split('=')[-1]) if buf_default != new_default: check_call('sudo sysctl -w net.core.rmem_default=%s' % new_default, shell=True) sys.stderr.write('Changed rmem_default from %s to %s\n' % (buf_default, new_default)) if buf_max != new_max: check_call('sudo sysctl -w net.core.rmem_max=%s' % new_max, shell=True) sys.stderr.write('Changed rmem_max from %s to %s\n' % (buf_max, new_max))
def set_qdisc(qdisc): curr_qdisc = check_output('sysctl net.core.default_qdisc', shell=True) curr_qdisc = curr_qdisc.split('=')[-1].strip() if curr_qdisc != qdisc: check_call('sudo sysctl -w net.core.default_qdisc=%s' % qdisc, shell=True) sys.stderr.write('Changed default_qdisc from %s to %s\n' % (curr_qdisc, qdisc))
def get_sys_info(): sys_info = '' sys_info += check_output(['uname', '-sr']) sys_info += check_output(['sysctl', 'net.core.default_qdisc']) sys_info += check_output(['sysctl', 'net.core.rmem_default']) sys_info += check_output(['sysctl', 'net.core.rmem_max']) sys_info += check_output(['sysctl', 'net.core.wmem_default']) sys_info += check_output(['sysctl', 'net.core.wmem_max']) sys_info += check_output(['sysctl', 'net.ipv4.tcp_rmem']) sys_info += check_output(['sysctl', 'net.ipv4.tcp_wmem']) return sys_info
def set_congestion_control(cc): curr_cc = check_output('sysctl net.ipv4.tcp_congestion_control', shell=True) curr_cc = curr_cc.split('=')[-1].strip() if curr_cc != cc: check_call('sudo sysctl -w net.ipv4.tcp_congestion_control=%s' % cc, shell=True) sys.stderr.write('Changed system wide cc from %s to %s\n' % (curr_cc, cc))
def enable_congestion_control(cc): cc_list = check_output('sysctl net.ipv4.tcp_allowed_congestion_control', shell=True) cc_list = cc_list.split('=')[-1].split() # return if cc is already in the allowed congestion control list if cc in cc_list: return cc_list.append(cc) check_call('sudo sysctl -w net.ipv4.tcp_allowed_congestion_control="%s"' % ' '.join(cc_list), shell=True)
def get_git_summary(mode='local', remote_path=None): git_summary_src = path.join(context.src_dir, 'experiments', 'git_summary.sh') local_git_summary = check_output(git_summary_src, cwd=context.base_dir) if mode == 'remote': r = parse_remote_path(remote_path) git_summary_src = path.join(r['src_dir'], 'experiments', 'git_summary.sh') ssh_cmd = 'cd %s; %s' % (r['base_dir'], git_summary_src) ssh_cmd = ' '.join(r['ssh_cmd']) + ' "%s"' % ssh_cmd remote_git_summary = check_output(ssh_cmd, shell=True) if local_git_summary != remote_git_summary: sys.stderr.write('--- local git summary ---\n%s\n' % local_git_summary) sys.stderr.write('--- remote git summary ---\n%s\n' % remote_git_summary) sys.exit('Repository differed between local and remote sides') return local_git_summary
def who_runs_first(cc): cc_src = path.join(context.src_dir, 'wrappers', cc + '.py') cmd = [cc_src, 'run_first'] run_first = check_output(cmd).strip() if run_first == 'receiver': run_second = 'sender' elif run_first == 'sender': run_second = 'receiver' else: sys.exit('Must specify "receiver" or "sender" runs first') return run_first, run_second
def get_git_summary(mode='local', remote_path=None): git_summary_src = path.join(context.src_dir, 'experiments', 'git_summary.sh') local_git_summary = check_output(git_summary_src, cwd=context.base_dir) if mode == 'remote': r = parse_remote_path(remote_path) git_summary_src = path.join( r['src_dir'], 'experiments', 'git_summary.sh') ssh_cmd = 'cd %s; %s' % (r['base_dir'], git_summary_src) ssh_cmd = ' '.join(r['ssh_cmd']) + ' "%s"' % ssh_cmd remote_git_summary = check_output(ssh_cmd, shell=True) if local_git_summary != remote_git_summary: sys.stderr.write( '--- local git summary ---\n%s\n' % local_git_summary) sys.stderr.write( '--- remote git summary ---\n%s\n' % remote_git_summary) sys.exit('Repository differed between local and remote sides') return local_git_summary
def query_clock_offset(ntp_addr, ssh_cmd): local_clock_offset = None remote_clock_offset = None ntp_cmds = {} ntpdate_cmd = ['ntpdate', '-t', '5', '-quv', ntp_addr] ntp_cmds['local'] = ntpdate_cmd ntp_cmds['remote'] = ssh_cmd + ntpdate_cmd for side in ['local', 'remote']: cmd = ntp_cmds[side] fail = True for _ in xrange(3): try: offset = check_output(cmd) sys.stderr.write(offset) offset = offset.rsplit(' ', 2)[-2] offset = str(float(offset) * 1000) except subprocess.CalledProcessError: sys.stderr.write('Failed to get clock offset\n') except ValueError: sys.stderr.write('Cannot convert clock offset to float\n') else: if side == 'local': local_clock_offset = offset else: remote_clock_offset = offset fail = False break if fail: sys.stderr.write('Failed after 3 queries to NTP server\n') return local_clock_offset, remote_clock_offset
def check_qdisc(qdisc): curr_qdisc = check_output('sysctl net.core.default_qdisc', shell=True) curr_qdisc = curr_qdisc.split('=')[-1].strip() if qdisc != curr_qdisc: sys.exit('Error: current qdisc %s is not %s' % (curr_qdisc, qdisc))
def get_congestion_control(): curr_cc = check_output('sysctl net.ipv4.tcp_congestion_control', shell=True) curr_cc = curr_cc.split('=')[-1].strip() return curr_cc