示例#1
0
def main(delta_conf):
    args = arg_parser.receiver_first(http_reversed=True)

    cc_repo = path.join(context.third_party_dir, 'genericCC')
    recv_src = path.join(cc_repo, 'receiver')
    send_src = path.join(cc_repo, 'sender')

    if args.option == 'deps':
        print(
            'makepp libboost-dev libprotobuf-dev protobuf-c-compiler '
            'protobuf-compiler libjemalloc-dev libboost-python-dev')
        return

    if args.option == 'setup':
        check_call(['makepp'], cwd=cc_repo)
        return

    if args.option == 'receiver':
        cmd = [recv_src, args.port]
        check_call(cmd)
        return

    if args.option == 'sender':
        sh_cmd = (
            'export MIN_RTT=1000000 && %s serverip=%s serverport=%s '
            'offduration=1 onduration=1000000 traffic_params=deterministic,'
            'num_cycles=1 cctype=markovian delta_conf=%s' %
            (send_src, args.ip, args.port, delta_conf))

        with open(os.devnull, 'w') as devnull:
            # suppress debugging output to stdout
            check_call(sh_cmd, shell=True, stdout=devnull)
        return

    if args.option == 'http_server':
        sys.path.append(cc_repo)
        import pygenericcc
        sender = pygenericcc.COPASender('do_ss:auto:0.1', args.ip,
                                        int(args.port), 0)
        with open(os.path.join(cc_repo, 'index.html'), 'r') as f:
            line = f.read()
            # pay attention to the type conversions between python and c++
            sender.send(line, len(line), 1)

    if args.option == 'http_client':
        sys.path.append(cc_repo)
        import pygenericcc

        receiver = pygenericcc.Receiver(int(args.port))
        filename = os.path.join(utils.tmp_dir, 'copa_index.html')
        try:
            p = Process(target=recvfrom, args=(receiver, filename))
            p.start()
            p.join()
        except:
            print traceback.format_exc()
            utils.kill_proc_group(p, signal.SIGTERM)
示例#2
0
def test_schemes(args):
    wrappers_dir = path.join(context.src_dir, 'wrappers')

    if args.all:
        schemes = utils.parse_config()['schemes'].keys()
    elif args.schemes is not None:
        schemes = args.schemes.split()

    for scheme in schemes:
        sys.stderr.write('Testing %s...\n' % scheme)
        src = path.join(wrappers_dir, scheme + '.py')

        run_first = check_output([src, 'run_first']).strip()
        run_second = 'receiver' if run_first == 'sender' else 'sender'

        port = utils.get_open_port()

        # run first to run
        cmd = [src, run_first, port]
        first_proc = Popen(cmd, preexec_fn=os.setsid)

        # wait for 'run_first' to be ready
        time.sleep(3)

        # run second to run
        cmd = [src, run_second, '127.0.0.1', port]
        second_proc = Popen(cmd, preexec_fn=os.setsid)

        # test lasts for 3 seconds
        signal.signal(signal.SIGALRM, utils.timeout_handler)
        signal.alarm(3)

        try:
            for proc in [first_proc, second_proc]:
                proc.wait()
                if proc.returncode != 0:
                    sys.exit('%s failed in tests' % scheme)
        except utils.TimeoutError:
            pass
        except Exception as exception:
            sys.exit('test_schemes.py: %s\n' % exception)
        else:
            signal.alarm(0)
            sys.exit('test exited before time limit')
        finally:
            # cleanup
            utils.kill_proc_group(first_proc)
            utils.kill_proc_group(second_proc)
示例#3
0
文件: test.py 项目: JerryLX/pantheon
 def run_congestion_control(self):
     if self.flows > 0:
         try:
             return self.run_with_tunnel()
         finally:
             utils.kill_proc_group(self.ts_manager)
             utils.kill_proc_group(self.tc_manager)
     else:
         # test without pantheon tunnel when self.flows = 0
         try:
             return self.run_without_tunnel()
         finally:
             utils.kill_proc_group(self.proc_first)
             utils.kill_proc_group(self.proc_second)
示例#4
0
 def run_congestion_control(self):
     if self.flows > 0:
         try:
             return self.run_with_tunnel()
         finally:
             utils.kill_proc_group(self.ts_manager)
             utils.kill_proc_group(self.tc_manager)
     else:
         # test without pantheon tunnel when self.flows = 0
         try:
             return self.run_without_tunnel()
         finally:
             utils.kill_proc_group(self.proc_first)
             utils.kill_proc_group(self.proc_second)
示例#5
0
    def stop_signal_handler(signum, frame):
        for tun_id in procs:
            utils.kill_proc_group(procs[tun_id])

        sys.exit('tunnel_manager: caught signal %s and cleaned up\n' % signum)
示例#6
0
def main():
    prompt = ''
    procs = {}

    # register SIGINT and SIGTERM events to clean up gracefully before quit
    def stop_signal_handler(signum, frame):
        for tun_id in procs:
            utils.kill_proc_group(procs[tun_id])

        sys.exit('tunnel_manager: caught signal %s and cleaned up\n' % signum)

    signal.signal(signal.SIGINT, stop_signal_handler)
    signal.signal(signal.SIGTERM, stop_signal_handler)

    sys.stdout.write('tunnel manager is running\n')
    sys.stdout.flush()

    while True:
        input_cmd = sys.stdin.readline().strip()

        if not input_cmd:
            # This may only happen if the parent process has died.
            sys.stderr.write('tunnel manager\'s parent process must have died '
                             '=> halting\n')
            input_cmd = 'halt'

        # print all the commands fed into tunnel manager
        if prompt:
            sys.stderr.write(prompt + ' ')
        sys.stderr.write(input_cmd + '\n')
        cmd = input_cmd.split()

        # manage I/O of multiple tunnels
        if cmd[0] == 'tunnel':
            if len(cmd) < 3:
                sys.stderr.write('error: usage: tunnel ID CMD...\n')
                continue

            try:
                tun_id = int(cmd[1])
            except ValueError:
                sys.stderr.write('error: usage: tunnel ID CMD...\n')
                continue

            cmd_to_run = ' '.join(cmd[2:])

            if cmd[2] == 'mm-tunnelclient' or cmd[2] == 'mm-tunnelserver':
                # expand env variables (e.g., MAHIMAHI_BASE)
                cmd_to_run = path.expandvars(cmd_to_run).split()

                # expand home directory
                for i in xrange(len(cmd_to_run)):
                    if ('--ingress-log' in cmd_to_run[i] or
                        '--egress-log' in cmd_to_run[i]):
                        t = cmd_to_run[i].split('=')
                        cmd_to_run[i] = t[0] + '=' + path.expanduser(t[1])

                procs[tun_id] = Popen(cmd_to_run, stdin=PIPE,
                                      stdout=PIPE, preexec_fn=os.setsid)
            elif cmd[2] == 'python':  # run python scripts inside tunnel
                if tun_id not in procs:
                    sys.stderr.write(
                        'error: run tunnel client or server first\n')

                procs[tun_id].stdin.write(cmd_to_run + '\n')
                procs[tun_id].stdin.flush()
            elif cmd[2] == 'readline':  # readline from stdout of tunnel
                if len(cmd) != 3:
                    sys.stderr.write('error: usage: tunnel ID readline\n')
                    continue

                if tun_id not in procs:
                    sys.stderr.write(
                        'error: run tunnel client or server first\n')

                sys.stdout.write(procs[tun_id].stdout.readline())
                sys.stdout.flush()
            else:
                sys.stderr.write('unknown command after "tunnel ID": %s\n'
                                 % cmd_to_run)
                continue
        elif cmd[0] == 'prompt':  # set prompt in front of commands to print
            if len(cmd) != 2:
                sys.stderr.write('error: usage: prompt PROMPT\n')
                continue

            prompt = cmd[1].strip()
        elif cmd[0] == 'halt':  # terminate all tunnel processes and quit
            if len(cmd) != 1:
                sys.stderr.write('error: usage: halt\n')
                continue

            for tun_id in procs:
                utils.kill_proc_group(procs[tun_id])

            sys.exit(0)
        else:
            sys.stderr.write('unknown command: %s\n' % input_cmd)
            continue
示例#7
0
    def stop_signal_handler(signum, frame):
        for tun_id in procs:
            utils.kill_proc_group(procs[tun_id])

        sys.exit('tunnel_manager: caught signal %s and cleaned up\n' % signum)
示例#8
0
def main():
    prompt = ''
    procs = {}

    # register SIGINT and SIGTERM events to clean up gracefully before quit
    def stop_signal_handler(signum, frame):
        for tun_id in procs:
            utils.kill_proc_group(procs[tun_id])

        sys.exit('tunnel_manager: caught signal %s and cleaned up\n' % signum)

    signal.signal(signal.SIGINT, stop_signal_handler)
    signal.signal(signal.SIGTERM, stop_signal_handler)

    sys.stdout.write('tunnel manager is running\n')
    sys.stdout.flush()

    while True:
        input_cmd = sys.stdin.readline().strip()

        # print all the commands fed into tunnel manager
        if prompt:
            sys.stderr.write(prompt + ' ')
        sys.stderr.write(input_cmd + '\n')
        cmd = input_cmd.split()

        # manage I/O of multiple tunnels
        if cmd[0] == 'tunnel':
            if len(cmd) < 3:
                sys.stderr.write('error: usage: tunnel ID CMD...\n')
                continue

            try:
                tun_id = int(cmd[1])
            except ValueError:
                sys.stderr.write('error: usage: tunnel ID CMD...\n')
                continue

            cmd_to_run = ' '.join(cmd[2:])

            if cmd[2] == 'mm-tunnelclient' or cmd[2] == 'mm-tunnelserver':
                # expand env variables (e.g., MAHIMAHI_BASE)
                cmd_to_run = path.expandvars(cmd_to_run).split()

                # expand home directory
                for i in xrange(len(cmd_to_run)):
                    if ('--ingress-log' in cmd_to_run[i] or
                        '--egress-log' in cmd_to_run[i]):
                        t = cmd_to_run[i].split('=')
                        cmd_to_run[i] = t[0] + '=' + path.expanduser(t[1])

                procs[tun_id] = Popen(cmd_to_run, stdin=PIPE,
                                      stdout=PIPE, preexec_fn=os.setsid)
            elif cmd[2] == 'python':  # run python scripts inside tunnel
                if tun_id not in procs:
                    sys.stderr.write(
                        'error: run tunnel client or server first\n')

                procs[tun_id].stdin.write(cmd_to_run + '\n')
                procs[tun_id].stdin.flush()
            elif cmd[2] == 'readline':  # readline from stdout of tunnel
                if len(cmd) != 3:
                    sys.stderr.write('error: usage: tunnel ID readline\n')
                    continue

                if tun_id not in procs:
                    sys.stderr.write(
                        'error: run tunnel client or server first\n')

                sys.stdout.write(procs[tun_id].stdout.readline())
                sys.stdout.flush()
            else:
                sys.stderr.write('unknown command after "tunnel ID": %s\n'
                                 % cmd_to_run)
                continue
        elif cmd[0] == 'prompt':  # set prompt in front of commands to print
            if len(cmd) != 2:
                sys.stderr.write('error: usage: prompt PROMPT\n')
                continue

            prompt = cmd[1].strip()
        elif cmd[0] == 'halt':  # terminate all tunnel processes and quit
            if len(cmd) != 1:
                sys.stderr.write('error: usage: halt\n')
                continue

            for tun_id in procs:
                utils.kill_proc_group(procs[tun_id])

            sys.exit(0)
        else:
            sys.stderr.write('unknown command: %s\n' % input_cmd)
            continue