def wired_simulation_testbed(rates, delays, tot_runs):

    client_int = 'eth0'
    router_int = 'eth0'

    for rate in rates:
        for delay in delays:
            Q = Router('192.168.1.1', 'root', 'passw0rd')
            if rate != 0:
                Q.remoteCommand('sh ratelimit3.sh eth0 '+str(rate))
                Q.remoteCommand('sh ratelimit3.sh eth1 '+str(rate))
                Q.remoteCommand('tc qdisc del dev eth0 root')
                Q.remoteCommand('tc qdisc del dev eth1 root')
            Q.host.close()

            R = remove_tc_shaping(client_int, router_int)
            if delay != 0:
                subprocess.check_output('tc qdisc add dev '+client_int+' root netem delay ' +str(delay)+ 'ms', shell=True)
                R.remoteCommand('tc qdisc add dev '+router_int+' root netem delay ' +str(delay)+ 'ms')
            R.host.close()

            measurement_folder_name = 'wired_delay_'+str(int(2*delay))+'_access_'+str(rate)
            print "\n\t\t START " + measurement_folder_name + "\n"
            time.sleep(5)

            e = Experiment(measurement_folder_name)
            e.collect_calibrate = False

            for nruns in range(tot_runs):
                print "\n\t\t RUN : " + str(nruns) + " DELAY : " + str(delay) + " ACCESS LINK RATE : " + str(rate) + "\n"
                experiment_suit(e)
                time.sleep(1)

            # transfer all with no delay and no shaping
            R = remove_tc_shaping(client_int, router_int)
            R.host.close()
            Q = Router('192.168.1.1', 'root', 'passw0rd')
            Q.remoteCommand('tc qdisc del dev eth0 root')
            Q.remoteCommand('tc qdisc del dev eth1 root')
            Q.host.close()

            e.kill_all()
            e.clear_all()
            e.transfer_all_later()

            print "\n\t\t DONE " + measurement_folder_name + "\n"

    return e
    def __init__(self, measurement_name=None):
        self.A = Client(const.CLIENT_ADDRESS)
        self.R = Router(const.ROUTER_ADDRESS_LOCAL, const.ROUTER_USER,
                        const.ROUTER_PASS)
        self.S = Server(const.SERVER_ADDRESS)
        self.EXTRA_NODES = const.EXTRA_NODES
        if self.EXTRA_NODES:
            self.arrB = []
            for addr in const.EXTRA_NODE_ADDRESSES:
                self.arrB.append(Server(addr))
        self.check_connection()
        self.iface = self.get_default_interface()
        self.A.ip = self.get_ip_address(self.iface)
        self.device_list = [self.A, self.R, self.S]
        self.run_number = 0
        self.collect_calibrate = False
        self.experiment_counter = 0
        self.experiment_name = 'default'
        self.create_monitor_interface()
        self.set_unique_id(measurement_name)
        self.set_test_timeout(const.EXPERIMENT_TIMEOUT)

        self.kill_all(1)  #kill tcpdump, iperf, netperf, fping on all
        self.clear_all(
            0)  #clear /tmp/browserlab/* but don't close the connection to R

        self.set_config_options(const.METHOD)
        self.set_iperf_config_options()

        self.start_servers()

        self.probe_rate = defaultdict(int)
        self.set_udp_rate_mbit(const.INIT_ACCESS_RATE, const.INIT_HOME_RATE,
                               const.INIT_BLAST_RATE)
def remove_tc_shaping(client_int='eth0', router_int='eth0'):
    Q = Router('192.168.10.1', 'root', 'passw0rd')
    try:
        subprocess.check_output('tc qdisc del dev ' +client_int+ ' root', shell=True)
    except Exception:
        print subprocess.check_output('tc qdisc show dev ' +client_int, shell=True)
    try:
        Q.remoteCommand('tc qdisc del dev ' +router_int+ ' root')
    except Exception:
        Q.remoteCommand('tc qdisc show dev ' +router_int)
    return Q
Beispiel #4
0
def readFile():
    global topologyFile
    f = open(topologyFile, 'r')
    f = f.read()
    f = f.split("#")
    nodeList, routerList, routertableList = f[1].split('\n')[1:], f[2].split(
        '\n')[1:], f[3].split('\n')[1:]
    nodeAux, routerAux, routertableAux = [], [], []
    for elem in nodeList:
        node = elem.split(',')
        if len(node) == 5:
            node = Node(node[0], node[1], node[2], node[3], node[4])
            nodeAux.append(node)

    for elem in routerList:
        router = elem.split(',')
        if len(router) > 2:
            name = router[0]
            num_ports = router[1]
            router = router[2:]
            i = 0
            node_routers = []
            while i < len(router):
                nodeRouter = Node_router(router[i], router[i + 1],
                                         router[i + 2])
                node_routers.append(nodeRouter)
                i += 3
            router = Router(name, num_ports, node_routers)
            routerAux.append(router)

    for elem in routertableList:
        routertable = elem.split(',')
        if len(routertable) == 4:
            routertable = Routertable(routertable[0], routertable[1],
                                      routertable[2], routertable[3])
            routertableAux.append(routertable)

    return nodeAux, routerAux, routertableAux
Beispiel #5
0
def main(origin=None, destination=None):
    if os.environ.get('WIFIONLY'):
        return ''

    src = request.args if request.method == 'GET' else request.form

    _('Sorry, an error occured =(')
    _('select origin…')
    _('select destination…')
    _('Edit Settings')
    _('swap')
    _('close')
    _('share')
    _('create shortcut')
    _('wifi positioning is currently not (yet) available')
    _('determining your position…')

    ctx = {
        'location_select':
        sorted(graph.selectable_locations.values(),
               key=lambda l: (0 - l.priority, l.title)),
        'titles': {
            name: titles.get(get_locale(), name)
            for name, titles in graph.data['titles'].items()
        },
        'mobile_client':
        request.headers.get('User-Agent').startswith('c3navClient'),
        'fake_mobile_client':
        'fakemobile' in request.args,
        'graph':
        graph
    }

    # Select origins

    origin = graph.get_selectable_location(src.get('o', origin))
    destination = graph.get_selectable_location(src.get('d', destination))
    ctx.update({'origin': origin, 'destination': destination})
    if request.method == 'POST':
        if origin is None:
            return 'missing origin'

        if destination is None:
            return 'missing destination'

    # Load Settings
    settingscookie = request.cookies.get('settings')
    cookie_settings = {}
    if settingscookie is not None:
        try:
            cookie_settings = json.loads(settingscookie)
        except:
            pass
        else:
            ctx['had_settings_cookie'] = True

    setsettings = {}
    for name, default_value in Router.default_settings.items():
        if not isinstance(default_value, str) and isinstance(
                default_value, Iterable):
            value = src.getlist(name)
            cookie_value = cookie_settings.get(name)
            if value or ('force-' + name) in src:
                setsettings[name] = value
            elif isinstance(cookie_value, list):
                setsettings[name] = cookie_value
        elif name in src:
            setsettings[name] = src.get(name)
        elif name in cookie_settings:
            cookie_value = cookie_settings.get(name)
            if (isinstance(cookie_value, Iterable)
                    and isinstance(default_value, str)
                    or isinstance(cookie_value, int)
                    and isinstance(default_value, int)):
                setsettings[name] = cookie_value

    router = Router(graph, setsettings)
    ctx['settings'] = router.settings

    settings_flat = sum(
        [(sum([[(n, vv)]
               for vv in v], []) if isinstance(v, Iterable) else [(n, v)])
         for n, v in router.settings.items()], [])
    ctx['settings_fields'] = [(n, v) for n, v in settings_flat if n in src]

    # parse what is avoided
    avoid = []
    for ctype in ('steps', 'stairs', 'escalators', 'elevators'):
        s = router.settings[ctype]
        if s == 'yes':
            continue
        else:
            avoid.append(ctype + {'no': '↕', 'up': '↓', 'down': '↑'}[s])
    for e in router.settings['e']:
        avoid.append(graph.titles.get(e, {}).get('en', e))
    ctx['avoid'] = avoid

    if request.method == 'GET':
        resp = make_response(minify(render_template('main.html', **ctx)))
        if 'lang' in request.cookies or 'lang' in request.args:
            resp.set_cookie('lang',
                            g.locale,
                            expires=datetime.now() + timedelta(days=30))
        return resp
    """
    Now lets route!
    """
    messages, route = router.get_route(origin, destination)
    if route is not None:
        route_description, has_avoided_ctypes = route.describe()
        if has_avoided_ctypes:
            messages.append(
                ('warn',
                 _('This route contains way types that you wanted to avoid '
                   'because otherwise no route would be possible.')))
        total_duration = sum(rp['duration'] for rp in route_description)

        ctx.update({
            'routeparts':
            route_description,
            'origin_title':
            None
            if isinstance(route.points[0], Node) else route.points[0].title,
            'destination_title':
            None
            if isinstance(route.points[-1], Node) else route.points[-1].title,
            'total_distance':
            round(sum(rp['distance'] for rp in route_description) / 100, 1),
            'total_duration':
            (int(total_duration / 60), int(total_duration % 60)),
            'jsonfoo':
            json.dumps(route_description, indent=4)
        })

    ctx.update({
        'messages': messages,
        'isresult': True,
        'resultsonly': src.get('ajax') == '1'
    })

    resp = make_response(minify(render_template('main.html', **ctx)))
    if src.get('savesettings') == '1':
        resp.set_cookie('settings',
                        json.dumps(router.settings),
                        expires=datetime.now() + timedelta(days=30))
    if 'lang' in request.cookies or 'lang' in request.args:
        resp.set_cookie('lang',
                        g.locale,
                        expires=datetime.now() + timedelta(days=30))
    return resp
Beispiel #6
0
def main(origin=None, destination=None):
    if os.environ.get('WIFIONLY'):
        return ''

    src = request.args if request.method == 'GET' else request.form

    _('Sorry, an error occured =(')
    _('select origin…')
    _('select destination…')
    _('Edit Settings')
    _('swap')
    _('close')
    _('share')
    _('create shortcut')
    _('wifi positioning is currently not (yet) available')
    _('determining your position…')

    ctx = {
        'location_select': sorted(graph.selectable_locations.values(), key=lambda l: (0-l.priority, l.title)),
        'titles': {name: titles.get(get_locale(), name) for name, titles in graph.data['titles'].items()},
        'mobile_client': request.headers.get('User-Agent').startswith('c3navClient'),
        'fake_mobile_client': 'fakemobile' in request.args,
        'graph': graph
    }

    # Select origins

    origin = graph.get_selectable_location(src.get('o', origin))
    destination = graph.get_selectable_location(src.get('d', destination))
    ctx.update({'origin': origin, 'destination': destination})
    if request.method == 'POST':
        if origin is None:
            return 'missing origin'

        if destination is None:
            return 'missing destination'

    # Load Settings
    settingscookie = request.cookies.get('settings')
    cookie_settings = {}
    if settingscookie is not None:
        try:
            cookie_settings = json.loads(settingscookie)
        except:
            pass
        else:
            ctx['had_settings_cookie'] = True

    setsettings = {}
    for name, default_value in Router.default_settings.items():
        if not isinstance(default_value, str) and isinstance(default_value, Iterable):
            value = src.getlist(name)
            cookie_value = cookie_settings.get(name)
            if value or ('force-'+name) in src:
                setsettings[name] = value
            elif isinstance(cookie_value, list):
                setsettings[name] = cookie_value
        elif name in src:
            setsettings[name] = src.get(name)
        elif name in cookie_settings:
            cookie_value = cookie_settings.get(name)
            if (isinstance(cookie_value, Iterable) and isinstance(default_value, str) or
                    isinstance(cookie_value, int) and isinstance(default_value, int)):
                setsettings[name] = cookie_value

    router = Router(graph, setsettings)
    ctx['settings'] = router.settings

    settings_flat = sum([(sum([[(n, vv)] for vv in v], []) if isinstance(v, Iterable) else [(n, v)])
                         for n, v in router.settings.items()], [])
    ctx['settings_fields'] = [(n, v) for n, v in settings_flat if n in src]

    # parse what is avoided
    avoid = []
    for ctype in ('steps', 'stairs', 'escalators', 'elevators'):
        s = router.settings[ctype]
        if s == 'yes':
            continue
        else:
            avoid.append(ctype+{'no': '↕', 'up': '↓', 'down': '↑'}[s])
    for e in router.settings['e']:
        avoid.append(graph.titles.get(e, {}).get('en', e))
    ctx['avoid'] = avoid

    if request.method == 'GET':
        resp = make_response(minify(render_template('main.html', **ctx)))
        if 'lang' in request.cookies or 'lang' in request.args:
            resp.set_cookie('lang', g.locale, expires=datetime.now()+timedelta(days=30))
        return resp

    """
    Now lets route!
    """
    messages, route = router.get_route(origin, destination)
    if route is not None:
        route_description, has_avoided_ctypes = route.describe()
        if has_avoided_ctypes:
            messages.append(('warn', _('This route contains way types that you wanted to avoid '
                                       'because otherwise no route would be possible.')))
        total_duration = sum(rp['duration'] for rp in route_description)

        ctx.update({
            'routeparts': route_description,
            'origin_title': None if isinstance(route.points[0], Node) else route.points[0].title,
            'destination_title': None if isinstance(route.points[-1], Node) else route.points[-1].title,
            'total_distance': round(sum(rp['distance'] for rp in route_description)/100, 1),
            'total_duration': (int(total_duration/60), int(total_duration % 60)),
            'jsonfoo': json.dumps(route_description, indent=4)
        })

    ctx.update({
        'messages': messages,
        'isresult': True,
        'resultsonly': src.get('ajax') == '1'
    })

    resp = make_response(minify(render_template('main.html', **ctx)))
    if src.get('savesettings') == '1':
        resp.set_cookie('settings', json.dumps(router.settings),
                        expires=datetime.now()+timedelta(days=30))
    if 'lang' in request.cookies or 'lang' in request.args:
        resp.set_cookie('lang', g.locale, expires=datetime.now()+timedelta(days=30))
    return resp
def main_testbed_compare(rate=4):

    rate_bit = str(rate * 8)
    rate_byte = str(rate)

    Q = Router('192.168.1.1', 'root', 'passw0rd')
    Q.remoteCommand('tc qdisc del dev br-lan root;tc qdisc add dev br-lan root netem delay 40ms;tc qdisc show dev br-lan')

    if rate != 0 and rate_byte != '0':
        Q.remoteCommand('sh ratelimit3.sh eth0 '+rate_byte)
        Q.remoteCommand('sh ratelimit3.sh eth1 '+rate_byte)
    else:
        Q.remoteCommand('tc qdisc del dev eth0 root')
        Q.remoteCommand('tc qdisc del dev eth1 root')
        #Q.remoteCommand('tc qdisc del dev br-lan root')
    Q.host.close()


    print "START ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    starttime = time.time()

    e, all_folder_name_list = compare_all_techniques([1,2,3,4,5,6,7,8,9,10],[5])
    #e, all_folder_name_list = compare_all_techniques()

    print "DONE ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    endtime = time.time()

    print "\n Total time taken = ", endtime - starttime

    Q = Router('192.168.1.1', 'root', 'passw0rd')
    Q.remoteCommand('tc qdisc del dev br-lan root;tc qdisc del dev eth0 root;tc qdisc del dev eth1 root')
    subprocess.check_output('sudo ifconfig eth0 up', shell=True)

    transfer = 'y'
    #transfer = raw_input("start transfer... [y]")

    if transfer == 'y' or transfer == 'Y':
        transfer_all_folder_names(e, all_folder_name_list)

    endtime2 = time.time()
    print "\n Total transfer time = ", endtime2 - endtime

    subprocess.check_output('sudo ifconfig eth0 down', shell=True)
    return e
def test_measurements(tot_runs, rate, timeout, comment=''):

    rate_bit = str(rate * 8)
    timeout_sec = str(timeout)
    rate_byte = str(rate)
    Q = Router('192.168.1.1', 'root', 'passw0rd')

    if rate != 0 and rate_byte != '0':
        Q.remoteCommand('sh ratelimit3.sh eth0 '+rate_byte)
        Q.remoteCommand('sh ratelimit3.sh eth1 '+rate_byte)
        Q.remoteCommand('tc qdisc del dev br-lan root;tc qdisc add dev br-lan root netem delay 40ms;tc qdisc show dev br-lan')
    else:
        Q.remoteCommand('tc qdisc del dev eth0 root')
        Q.remoteCommand('tc qdisc del dev eth1 root')
        #Q.remoteCommand('tc qdisc del dev br-lan root')

    Q.host.close()

    if comment != '':
        e = Experiment('hnl1_access_'+rate_bit+'Mbps_timeout_'+timeout_sec+'_'+comment)
    else:
        e = Experiment('hnl1_access_'+rate_bit+'Mbps_timeout_'+timeout_sec)

    e.collect_calibrate = False
    e.set_udp_rate_mbit(rate * 8)
    e.set_test_timeout(timeout)
    e.set_test_timeout(timeout)

    for nruns in range(tot_runs):
        print "\n\t\t RUN : " + str(nruns) + " rate : " + rate_bit + "Mbps\n"
        experiment_suit_testbed_all(e)
        #experiment_suit_testbed_udp(e)
        time.sleep(1)

    Q = Router('192.168.1.1', 'root', 'passw0rd')
    Q.remoteCommand('tc qdisc del dev eth0 root')
    Q.remoteCommand('tc qdisc del dev eth1 root')
    Q.remoteCommand('tc qdisc del dev br-lan root')
    Q.host.close()

    e.transfer_all_later()

    e.kill_all()
    e.clear_all()

    return e
def bottleneck_vs_scenario():

    measurement_folder_name = raw_input('Enter measurement name: ')
    tot_runs = raw_input('how many runs? each run should last around 5-6 mins - I suggest at least 30 with laptop in the same location. ')

    try:
        tot_runs = int(tot_runs)
    except Exception:
        tot_runs = 1
        print "Error. Running "+str(tot_runs)+" measurement."

    e = Experiment()
    # set all to yes
    e.collect_calibrate = False
    e.use_iperf_timeout = 1
    e.USE_IPERF3 = 1
    e.USE_IPERF_REV = 1
    e.USE_UDP_PROBE = 1
    e.USE_NETPERF = 0
    e.tcp = 1
    e.udp = 1
    e.start_servers()
    e.WTF_enable = 1
    e.timeout = 5
    e.num_parallel_streams = 4

    print "START ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    starttime = time.time()

    all_folder_name_list = []

    for rate in range(16):

        rate_bit = str(rate * 8)
        rate_byte = str(rate)

        folder_name = measurement_folder_name + '_access_' + str(rate_bit)
        if not folder_name in all_folder_name_list:
            all_folder_name_list.append(folder_name)
        e.set_unique_id(folder_name)

        Q = Router('192.168.1.1', 'root', 'passw0rd')
        Q.remoteCommand('tc qdisc del dev br-lan root;tc qdisc add dev br-lan root netem delay 40ms;tc qdisc show dev br-lan')
        if rate != 0 and rate_byte != '0':
            Q.remoteCommand('sh ratelimit3.sh eth0 '+rate_byte)
            Q.remoteCommand('sh ratelimit3.sh eth1 '+rate_byte)
        else:
            Q.remoteCommand('tc qdisc del dev eth0 root')
            Q.remoteCommand('tc qdisc del dev eth1 root')
            #Q.remoteCommand('tc qdisc del dev br-lan root')
        Q.host.close()

        for runs in range(tot_runs):
            e.parallel = 1
            e.run_only_experiment(e.no_traffic, 'no_tra')
            #iperf3_tcp
            e.run_only_experiment(e.iperf3_tcp_up_AS, 'AS_tcp')
            e.run_only_experiment(e.iperf3_tcp_up_AR, 'AR_tcp')
            e.run_only_experiment(e.iperf3_tcp_up_RS, 'RS_tcp')
            e.run_only_experiment(e.iperf3_tcp_dw_SA, 'SA_tcp')
            e.run_only_experiment(e.iperf3_tcp_dw_RA, 'RA_tcp')
            e.run_only_experiment(e.iperf3_tcp_dw_SR, 'SR_tcp')
            #iperf_udp
            e.parallel = 0
            e.run_only_experiment(e.iperf_udp_up_AS, 'AS_udp')
            e.run_only_experiment(e.iperf_udp_dw_SA, 'SA_udp')
            #probe_udp
            #TODO problem in probe_udp - time insufficient
            #e.run_only_experiment(e.probe_udp_AR, 'AR_udp')
            #e.run_only_experiment(e.probe_udp_AS, 'AS_udp')
            #e.run_only_experiment(e.probe_udp_RS, 'RS_udp')

    print "DONE ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    endtime = time.time()

    print "\n Total time taken = ", endtime - starttime

    # Transfer to server
    Q = Router('192.168.1.1', 'root', 'passw0rd')
    Q.remoteCommand('tc qdisc del dev br-lan root;tc qdisc del dev eth0 root;tc qdisc del dev eth1 root')
    subprocess.check_output('sudo ifconfig eth0 up', shell=True)
    time.sleep(5)
    transfer = 'y'
    #transfer = raw_input("start transfer... [y]")
    if transfer == 'y' or transfer == 'Y':
        transfer_all_folder_names(e, all_folder_name_list)
    subprocess.check_output('sudo ifconfig eth0 down', shell=True)

    endtime2 = time.time()
    print "\n Total transfer time = ", endtime2 - endtime
    print "\n Total script time = ", endtime2 - starttime

    return e