コード例 #1
0
def remove_all_flows():
    switches = of.SwitchList(
        cfg.of_controller_ip,
        cfg.of_controller_port).get_response().get_sw_list()
    for sw in switches:
        print(sw)
        req = of.RemoveAllFlows(sw, cfg.of_controller_ip,
                                cfg.of_controller_port)
        req.get_response()
コード例 #2
0
def stat_mon_test():
    switches = of.SwitchList(
        cfg.of_controller_ip,
        cfg.of_controller_port).get_response().get_sw_list()
    monitor = mp.MPStatMonitor(cfg.of_controller_ip,
                               cfg.of_controller_port,
                               switches,
                               mon_period=5.0)
    monitor.start_monitor()
    t.sleep(30)
    monitor.stop_monitor()
    p.pprint(monitor.retrieve_results())
コード例 #3
0
def add_tbl_0_to_all_sws():
    switches = of.SwitchList(
        cfg.of_controller_ip,
        cfg.of_controller_port).get_response().get_sw_list()
    for sw in switches:
        print(sw)
        flow_mod = fm.Flowmod(sw)
        flow_mod.add_action(
            fm.Action(fm.ActionTypes.GotoTable, {'table_id': 100}))
        req = of.PushFlowmod(flow_mod, cfg.of_controller_ip,
                             cfg.of_controller_port)
        req.get_response()
コード例 #4
0
def print_all_flows():
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    req = of.SwitchList(cfg.of_controller_ip, cfg.of_controller_port)
    sws = req.get_response().get_sw_list()
    for sw in sws:
        print(
            '***************************************************************')
        print('sw_name: %s' % hm.map_dpid_to_sw(sw))
        print(
            '***************************************************************')

        flow_req = of.SwitchFlows(sw, cfg.of_controller_ip,
                                  cfg.of_controller_port)
        resp = flow_req.get_response()
        p.pprint(resp.get_flows())
コード例 #5
0
def test_traffic_transmission(route_adder, trial_length, mu, sigma):

    remove_all_count_files(route_adder)
    mapper = hm.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    # Start each trial in a known state
    sw_list = of_proc.get_switch_list()
    print('main -> switch list:')
    print(sw_list)
    for sw in sw_list:
        sw_num = int(mapper.map_dpid_to_sw_num(sw))
        print('switch: ' + str(sw) + 'maps to id: ' + str(sw_num))
    for sw in sw_list:
        of_proc.remove_table_flows(sw, 100)

    for sw in sw_list:
        of_proc.add_default_route(sw, 100)

    route_adder.install_routes()

    path_name = generate_fname()
    rx_path = '/home/ubuntu/packet_counts/rx/%s' % path_name
    tx_path = '/home/ubuntu/packet_counts/tx/%s' % path_name
    mkdir(rx_path)
    mkdir(tx_path)

    od_pairs = route_adder.get_src_dst_pairs()
    print('ODLen: %d' % len(od_pairs))
    host_ids = set([src
                    for (src, _) in od_pairs] + [dst for (_, dst) in od_pairs])
    print(host_ids)
    hosts = {}
    for host_id in host_ids:
        hostname = mapper.map_sw_to_host(host_id)
        hosts[host_id] = mk_host_defaults(hostname)
        hosts[host_id].connect()
        hosts[host_id].start_server(host_id)

    time.sleep(5)

    path_ratios = route_adder.get_path_ratios()
    pp.pprint(path_ratios)
    for (src_host, dst_host, path_split, (mu, sigma)) in path_ratios:
        print('main -> transmission: (mu,sigma): ' + str((mu, sigma)))
        dst_hostname = mapper.map_sw_to_host(dst_host)
        dst_ip = mapper.resolve_hostname(dst_hostname)
        hosts[src_host].configure_client(mu, sigma, cfg.traffic_model, dst_ip,
                                         cfg.dst_port, path_split, src_host,
                                         cfg.time_slice)

    for s in set([s for s, _ in od_pairs]):
        hosts[s].start_clients()

    sw_list = of.SwitchList(
        cfg.of_controller_ip,
        cfg.of_controller_port).get_response().get_sw_list()
    traffic_mon = mp.MPStatMonitor(cfg.of_controller_ip,
                                   cfg.of_controller_port, sw_list)
    traffic_mon.start_monitor()

    time.sleep(trial_length)

    traffic_mon.stop_monitor()

    for host_id in host_ids:
        hosts[host_id].stop_client()

    time.sleep(15)

    for host_id in host_ids:
        hosts[host_id].stop_server()

    time.sleep(15)

    for host_id in host_ids:
        hosts[host_id].retrieve_client_files(tx_path)
        hosts[host_id].retrieve_server_files(rx_path)

    time.sleep(15)

    for host_id in host_ids:
        hosts[host_id].remove_all_files('%stx' % mp.MPTestHost.COUNT_DIR,
                                        'txt')
        hosts[host_id].remove_all_files('%srx' % mp.MPTestHost.COUNT_DIR, 'p')

    route_adder.remove_routes()
    rx_res, tx_res = traffic_mon.retrieve_results()
    print('main')
    print('route dir: ' + str(route_adder._route_provider._route_dir))
    print('seed no: ' + str(route_adder._route_provider._seed_no))
    for (i, p_n) in rx_res:
        print('rx(dpid, port_no)=' + '(' + str(i) + ',' + str(p_n) + ')' +
              ', count=' + str(rx_res[(i, p_n)]))
    for (i, p_n) in tx_res:
        print('tx(dpid, port_no)=' + '(' + str(i) + ',' + str(p_n) + ')' +
              ', count=' + str(rx_res[(i, p_n)]))

    rx_file = './rx_stats.p'
    tx_file = './tx_stats.p'
    pickle.dump(rx_res, open(rx_file, 'wb'))
    pickle.dump(tx_res, open(tx_file, 'wb'))
    record_trial_name(path_name)
コード例 #6
0
def query_switch_list():
    req = of.SwitchList(cfg.of_controller_ip, cfg.of_controller_port)
    resp = req.get_response()
    print(resp.switches)
コード例 #7
0
def add_low_prio_to_all_sws():
    switches = of.SwitchList(
        cfg.of_controller_ip,
        cfg.of_controller_port).get_response().get_sw_list()
    for sw in switches:
        add_low_prio_flow_mod(sw)