def main(): config = utils.parse_vantage_points() servers = [] for server_type in config: servers += config[server_type].keys() parser = argparse.ArgumentParser() parser.add_argument('server', choices=servers) args = parser.parse_args() call(['ssh', utils.get_host_addr(args.server)])
def download_tunnel_logs(self, tun_id): assert(self.mode == 'remote') # download logs from remote side cmd = 'scp -C %s:' % self.r['host_addr'] cmd += '%(remote_log)s %(local_log)s' # function to get a corresponding local path from a remote path f = lambda p: path.join(utils.tmp_dir, path.basename(p)) if self.sender_side == 'remote': local_log = f(self.datalink_egress_logs[tun_id]) call(cmd % {'remote_log': self.datalink_egress_logs[tun_id], 'local_log': local_log}, shell=True) self.datalink_egress_logs[tun_id] = local_log local_log = f(self.acklink_ingress_logs[tun_id]) call(cmd % {'remote_log': self.acklink_ingress_logs[tun_id], 'local_log': local_log}, shell=True) self.acklink_ingress_logs[tun_id] = local_log else: local_log = f(self.datalink_ingress_logs[tun_id]) call(cmd % {'remote_log': self.datalink_ingress_logs[tun_id], 'local_log': local_log}, shell=True) self.datalink_ingress_logs[tun_id] = local_log local_log = f(self.acklink_egress_logs[tun_id]) call(cmd % {'remote_log': self.acklink_egress_logs[tun_id], 'local_log': local_log}, shell=True) self.acklink_egress_logs[tun_id] = local_log
def download_tunnel_logs(self, tun_id): assert(self.mode == 'remote') # download logs from remote side cmd = 'scp -C %s:' % self.r['host_addr'] cmd += '%(remote_log)s %(local_log)s' # function to get a corresponding local path from a remote path f = lambda p: path.join(utils.tmp_dir, path.basename(p)) if self.sender_side == 'remote': local_log = f(self.datalink_egress_logs[tun_id]) call(cmd % {'remote_log': self.datalink_egress_logs[tun_id], 'local_log': local_log}, shell=True) self.datalink_egress_logs[tun_id] = local_log local_log = f(self.acklink_ingress_logs[tun_id]) call(cmd % {'remote_log': self.acklink_ingress_logs[tun_id], 'local_log': local_log}, shell=True) self.acklink_ingress_logs[tun_id] = local_log else: local_log = f(self.datalink_ingress_logs[tun_id]) call(cmd % {'remote_log': self.datalink_ingress_logs[tun_id], 'local_log': local_log}, shell=True) self.datalink_ingress_logs[tun_id] = local_log local_log = f(self.acklink_egress_logs[tun_id]) call(cmd % {'remote_log': self.acklink_egress_logs[tun_id], 'local_log': local_log}, shell=True) self.acklink_egress_logs[tun_id] = local_log
def pkill(args): sys.stderr.write('Cleaning up using pkill...' '(enabled by --pkill-cleanup)\n') if args.mode == 'remote': r = utils.parse_remote_path(args.remote_path) remote_pkill_src = path.join(r['base_dir'], 'tools', 'pkill.py') cmd = r['ssh_cmd'] + ['python', remote_pkill_src, '--kill-dir', r['base_dir']] call(cmd) pkill_src = path.join(context.base_dir, 'tools', 'pkill.py') cmd = ['python', pkill_src, '--kill-dir', context.src_dir] call(cmd)
def pkill(args): sys.stderr.write('Cleaning up using pkill...' '(enabled by --pkill-cleanup)\n') if args.mode == 'remote': r = utils.parse_remote_path(args.remote_path) remote_pkill_src = path.join(r['base_dir'], 'tools', 'pkill.py') cmd = r['ssh_cmd'] + ['python', remote_pkill_src, '--kill-dir', r['base_dir']] call(cmd) pkill_src = path.join(context.base_dir, 'tools', 'pkill.py') cmd = ['python', pkill_src, '--kill-dir', context.src_dir] call(cmd)
def setup(args): # update submodules utils.update_submodules() # setup specified schemes cc_schemes = None if args.all: cc_schemes = utils.parse_config()['schemes'].keys() elif args.schemes is not None: cc_schemes = args.schemes.split() if cc_schemes is None: return for cc in cc_schemes: cc_src = path.join(context.src_dir, 'wrappers', cc + '.py') # install dependencies if args.install_deps: install_deps(cc_src) else: # persistent setup across reboots if args.setup: check_call([cc_src, 'setup']) # setup required every time after reboot if call([cc_src, 'setup_after_reboot']) != 0: sys.stderr.write('Warning: "%s.py setup_after_reboot"' ' failed but continuing\n' % cc)
def install_deps(cc_src): deps = check_output([cc_src, 'deps']).strip() if deps: if call('sudo apt-get -y install ' + str(deps), shell=True) != 0: sys.stderr.write('Some dependencies failed to install ' 'but assuming things okay.\n')
def setup(args): # update submodules utils.update_submodules() # setup specified schemes cc_schemes = None if args.all: cc_schemes = utils.parse_config()['schemes'].keys() elif args.schemes is not None: cc_schemes = args.schemes.split() if cc_schemes is None: return for cc in cc_schemes: cc_src = path.join(context.src_dir, 'wrappers', cc + '.py') # install dependencies if args.install_deps: install_deps(cc_src) else: # persistent setup across reboots if args.setup: check_call([cc_src, 'setup']) # setup required every time after reboot if call([cc_src, 'setup_after_reboot']) != 0: sys.stderr.write('Warning: "%s.py setup_after_reboot"' ' failed but continuing\n' % cc)
def install_deps(cc_src): deps = check_output([cc_src, 'deps']).strip() if deps: if call('sudo apt-get -y install ' + deps, shell=True) != 0: sys.stderr.write('Some dependencies failed to install ' 'but assuming things okay.\n')
def main(): signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) parser = argparse.ArgumentParser() parser.add_argument( '--kill-dir', metavar='DIR', help='kill all scripts in the directory') args = parser.parse_args() # kill mahimahi shells and iperf pkill = 'pkill -f ' pkill_cmds = [pkill + 'mm-delay', pkill + 'mm-link', pkill + 'mm-loss', pkill + 'mm-tunnelclient', pkill + 'mm-tunnelserver', pkill + '-SIGKILL iperf'] if args.kill_dir: pkill_cmds.append(pkill + args.kill_dir) for cmd in pkill_cmds: call(cmd, shell=True)
def main(): signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) parser = argparse.ArgumentParser() parser.add_argument('--kill-dir', metavar='DIR', help='kill all scripts in the directory') args = parser.parse_args() # kill mahimahi shells and iperf pkill = 'pkill -f ' pkill_cmds = [ pkill + 'mm-delay', pkill + 'mm-link', pkill + 'mm-loss', pkill + 'mm-tunnelclient', pkill + 'mm-tunnelserver', pkill + '-SIGKILL iperf' ] if args.kill_dir: pkill_cmds.append(pkill + args.kill_dir) for cmd in pkill_cmds: call(cmd, shell=True)
def process_tunnel_logs(self): datalink_tun_logs = [] acklink_tun_logs = [] apply_ofst = False if self.mode == 'remote': if self.remote_ofst is not None and self.local_ofst is not None: apply_ofst = True if self.sender_side == 'remote': data_e_ofst = self.remote_ofst ack_i_ofst = self.remote_ofst data_i_ofst = self.local_ofst ack_e_ofst = self.local_ofst else: data_i_ofst = self.remote_ofst ack_e_ofst = self.remote_ofst data_e_ofst = self.local_ofst ack_i_ofst = self.local_ofst merge_tunnel_logs = path.join(context.src_dir, 'experiments', 'merge_tunnel_logs.py') for tun_id in xrange(1, self.flows + 1): if self.mode == 'remote': self.download_tunnel_logs(tun_id) uid = uuid.uuid4() datalink_tun_log = path.join( utils.tmp_dir, '%s_flow%s_uid%s.log.merged' % (self.datalink_name, tun_id, uid)) acklink_tun_log = path.join( utils.tmp_dir, '%s_flow%s_uid%s.log.merged' % (self.acklink_name, tun_id, uid)) cmd = [ merge_tunnel_logs, 'single', '-i', self.datalink_ingress_logs[tun_id], '-e', self.datalink_egress_logs[tun_id], '-o', datalink_tun_log ] if apply_ofst: cmd += [ '-i-clock-offset', data_i_ofst, '-e-clock-offset', data_e_ofst ] call(cmd) cmd = [ merge_tunnel_logs, 'single', '-i', self.acklink_ingress_logs[tun_id], '-e', self.acklink_egress_logs[tun_id], '-o', acklink_tun_log ] if apply_ofst: cmd += [ '-i-clock-offset', ack_i_ofst, '-e-clock-offset', ack_e_ofst ] call(cmd) datalink_tun_logs.append(datalink_tun_log) acklink_tun_logs.append(acklink_tun_log) cmd = [merge_tunnel_logs, 'multiple', '-o', self.datalink_log] if self.mode == 'local': cmd += ['--link-log', self.mm_datalink_log] cmd += datalink_tun_logs call(cmd) cmd = [merge_tunnel_logs, 'multiple', '-o', self.acklink_log] if self.mode == 'local': cmd += ['--link-log', self.mm_acklink_log] cmd += acklink_tun_logs call(cmd)
def apply_patch(patch_name, repo_dir): patch = path.join(context.src_dir, 'wrappers', 'patches', patch_name) if call(['git', 'apply', patch], cwd=repo_dir) != 0: sys.stderr.write('patch apply failed but assuming things okay ' '(patch applied previously?)\n')
def load_kernel_module(module): if call('sudo modprobe ' + module, shell=True) != 0: sys.exit('%s kernel module is not available' % module)
def cleanup(): cleanup_src = path.join(context.base_dir, 'tools', 'pkill.py') cmd = [cleanup_src, '--kill-dir', context.base_dir] call(cmd)
def process_tunnel_logs(self): datalink_tun_logs = [] acklink_tun_logs = [] apply_ofst = False if self.mode == 'remote': if self.remote_ofst is not None and self.local_ofst is not None: apply_ofst = True if self.sender_side == 'remote': data_e_ofst = self.remote_ofst ack_i_ofst = self.remote_ofst data_i_ofst = self.local_ofst ack_e_ofst = self.local_ofst else: data_i_ofst = self.remote_ofst ack_e_ofst = self.remote_ofst data_e_ofst = self.local_ofst ack_i_ofst = self.local_ofst merge_tunnel_logs = path.join(context.src_dir, 'experiments', 'merge_tunnel_logs.py') for tun_id in xrange(1, self.flows + 1): if self.mode == 'remote': self.download_tunnel_logs(tun_id) uid = uuid.uuid4() datalink_tun_log = path.join( utils.tmp_dir, '%s_flow%s_uid%s.log.merged' % (self.datalink_name, tun_id, uid)) acklink_tun_log = path.join( utils.tmp_dir, '%s_flow%s_uid%s.log.merged' % (self.acklink_name, tun_id, uid)) cmd = [merge_tunnel_logs, 'single', '-i', self.datalink_ingress_logs[tun_id], '-e', self.datalink_egress_logs[tun_id], '-o', datalink_tun_log] if apply_ofst: cmd += ['-i-clock-offset', data_i_ofst, '-e-clock-offset', data_e_ofst] call(cmd) cmd = [merge_tunnel_logs, 'single', '-i', self.acklink_ingress_logs[tun_id], '-e', self.acklink_egress_logs[tun_id], '-o', acklink_tun_log] if apply_ofst: cmd += ['-i-clock-offset', ack_i_ofst, '-e-clock-offset', ack_e_ofst] call(cmd) datalink_tun_logs.append(datalink_tun_log) acklink_tun_logs.append(acklink_tun_log) cmd = [merge_tunnel_logs, 'multiple', '-o', self.datalink_log] if self.mode == 'local': cmd += ['--link-log', self.mm_datalink_log] cmd += datalink_tun_logs call(cmd) cmd = [merge_tunnel_logs, 'multiple', '-o', self.acklink_log] if self.mode == 'local': cmd += ['--link-log', self.mm_acklink_log] cmd += acklink_tun_logs call(cmd)