Example #1
0
def start_network():
    if network_running():
        logging.getLogger(__name__).info('Some network components already running...')
        stop_network()

    logging.getLogger(__name__).info('Starting simulated network...')

    # Create fake NICs
    logging.getLogger(__name__).info('Creating network interfaces...')
    autogen_click_conf(get_topo_file('servers'), get_topo_file('clients'), get_topo_file('dns'))
    run_bg('%s %s' % (CLICK, CLICK_CONF))

    # Set up traffic shaping
    logging.getLogger(__name__).info('Enabling traffic shaping...')
    try:
        check_output('%s start' % TC_SETUP)
        install_filters(get_topo_file('bottlenecks'))
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Launch apache instances
    logging.getLogger(__name__).info('Configuring apache...')
    try:
        configure_apache(get_server_ip_list())
        restart_apache()
    except Exception as e:
        logging.getLogger(__name__).error(e)


    logging.getLogger(__name__).info('Network started.')
Example #2
0
def stop_network():
    logging.getLogger(__name__).info('Stopping simulated network...')

    # stop apache instances
    logging.getLogger(__name__).info('Stopping apache...')
    try:
        reset_apache(get_server_ip_list())
        restart_apache()
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Stop traffic shaping
    logging.getLogger(__name__).info('Disabling traffic shaping...')
    try:
        check_output('%s stop' % TC_SETUP)
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Destroy fake NICs
    logging.getLogger(__name__).info('Destroying network interfaces...')
    try:
        check_both('killall -9 click', shouldPrint=False)
        time.sleep(0.1)
    except:
        pass
    logging.getLogger(__name__).info('Network stopped.')
def stop_network():
    logging.getLogger(__name__).info('Stopping simulated network...')

    # stop apache instances
    logging.getLogger(__name__).info('Stopping apache...')
    try:
        reset_apache(get_server_ip_list())
        restart_apache()
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Stop traffic shaping
    logging.getLogger(__name__).info('Disabling traffic shaping...')
    try:
        check_output('%s stop' % TC_SETUP)
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Destroy fake NICs
    logging.getLogger(__name__).info('Destroying network interfaces...')
    try:
        check_both('killall -9 click', shouldPrint=False)
        time.sleep(0.1)
    except:
        pass
    logging.getLogger(__name__).info('Network stopped.')
def start_network():
    if network_running():
        logging.getLogger(__name__).info("Some network components already running...")
        stop_network()

    logging.getLogger(__name__).info("Starting simulated network...")

    # Create fake NICs
    logging.getLogger(__name__).info("Creating network interfaces...")
    autogen_click_conf(get_topo_file("servers"), get_topo_file("clients"), get_topo_file("dns"))
    if os.path.isfile(CLICK):
        run_bg("%s %s" % (CLICK, CLICK_CONF))
    else:
        run_bg("%s %s" % (CLICK_LOCAL, CLICK_CONF))

    # Set up traffic shaping
    logging.getLogger(__name__).info("Enabling traffic shaping...")
    try:
        check_output("%s start" % TC_SETUP)
        install_filters(get_topo_file("bottlenecks"))
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Launch apache instances
    logging.getLogger(__name__).info("Configuring apache...")
    try:
        configure_apache(get_server_ip_list())
        restart_apache()
    except Exception as e:
        logging.getLogger(__name__).error(e)

    logging.getLogger(__name__).info("Network started.")
def start_network():
    if network_running():
        logging.getLogger(__name__).info(
            'Some network components already running...')
        stop_network()

    logging.getLogger(__name__).info('Starting simulated network...')

    # Create fake NICs
    logging.getLogger(__name__).info('Creating network interfaces...')
    autogen_click_conf(get_topo_file('servers'), get_topo_file('clients'),
                       get_topo_file('dns'))
    if os.path.isfile(CLICK):
        run_bg('sudo {} {}'.format(CLICK, CLICK_CONF))
    else:
        run_bg('sudo %s %s' % (CLICK_LOCAL, CLICK_CONF))

    # Set up traffic shaping
    logging.getLogger(__name__).info('Enabling traffic shaping...')
    try:
        check_output('%s start' % TC_SETUP)
        install_filters(get_topo_file('bottlenecks'))
    except Exception as e:
        logging.getLogger(__name__).error(e)

    # Launch apache instances
    logging.getLogger(__name__).info('Configuring apache...')
    try:
        configure_apache(get_server_ip_list())
        restart_apache()
    except Exception as e:
        logging.getLogger(__name__).error(e)
        import traceback
        traceback.print_exc()

    logging.getLogger(__name__).info('Network started.')
Example #6
0
def start_servers():
    if servers_running():
        logging.getLogger(__name__).info('Some components already running...')
        stop_servers()

    logging.getLogger(__name__).info('Starting servers...')

    # Launch apache instances
    logging.getLogger(__name__).info('Configuring apache...')
    if args.topology == 'servers':
        with open(args.servers) as servers_file:
            for line in strip_comments(servers_file):
                servers.append('127.0.0.1:%d' % int(line))
                servers_port.append(int(line))
        servers_file.closed
        try:
            configure_apache(servers)
            restart_apache()
        except Exception as e:
            logging.getLogger(__name__).error(e)
    else:
        if args.topology == 'onelink':
            try:
                configure_apache(['127.0.0.1:8080'])
                restart_apache()
            except Exception as e:
                logging.getLogger(__name__).error(e)
        else:
            try:
                configure_apache(['127.0.0.1:8080', '127.0.0.1:8081'])
                restart_apache()
            except Exception as e:
                logging.getLogger(__name__).error(e)

        # Create click bandwidth shaper
        logging.getLogger(__name__).info('Creating bandwidth shaper...')
        autogen_click()
        run_bg('click %s.click' % args.topology)

    logging.getLogger(__name__).info('Network started.')
Example #7
0
def stop_servers():
    logging.getLogger(__name__).info('Stopping simulated network...')

    # stop apache instances
    logging.getLogger(__name__).info('Stopping apache...')
    if args.topology == 'servers':
        servers = []
        with open(args.servers) as servers_file:
            for line in strip_comments(servers_file):
                servers.append(int(line))
        servers_file.closed
        try:
            reset_apache(servers)
            restart_apache()
        except Exception as e:
            logging.getLogger(__name__).error(e)
    else:
        if args.topology == 'onelink':
            try:
                reset_apache(['127.0.0.1:8080'])
                restart_apache()
            except Exception as e:
                logging.getLogger(__name__).error(e)
        else:
            try:
                reset_apache(['127.0.0.1:8080', '127.0.0.1:8081'])
                restart_apache()
            except Exception as e:
                logging.getLogger(__name__).error(e)

        # Destroy fake NICs
        logging.getLogger(__name__).info('Destroying bandwidth shaper...')
        try:
            check_both('killall -9 click', shouldPrint=False)
            time.sleep(0.1)
        except:
            pass
    logging.getLogger(__name__).info('Network stopped.')