Exemple #1
0
def plot_test():
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    st_proc = stp.StatsProcessor(hm, of_proc)
    grapher = stp.Grapher()

    trial_name = read_trial_name('./name_hints.txt')
    tx_file = './tx_stats.p'
    rx_file = './rx_stats.p'
    tx_stats = pickle.load(open(tx_file, 'rb'))
    rx_stats = pickle.load(open(rx_file, 'rb'))

    stats_list = st_proc.calc_link_util_per_t(tx_stats, cfg.pkt_size,
                                              cfg.time_slice,
                                              stp.Units.MegaBitsPerSecond)
    stats_avg = st_proc.calc_link_util(tx_stats, cfg.pkt_size, cfg.time_slice,
                                       stp.Units.MegaBitsPerSecond)
    stats_loss = st_proc.calc_loss_rates(read_trial_name('./name_hints.txt'))
    stats_uplink = st_proc.calc_ingress_util_per_t(rx_stats, cfg.pkt_size,
                                                   cfg.time_slice,
                                                   stp.Units.MegaBitsPerSecond)
    stats_tput = st_proc.calc_flow_rate(trial_name, cfg.pkt_size,
                                        cfg.sample_freq, cfg.trial_length)

    grapher.graph_util_over_time(stats_list, 'util_per_ts', show_plot=True)

    fig, ax = plt.subplots(1, 1)
    grapher.graph_loss_cdf(ax, stats_loss, 'loss_plot')
    fig.savefig('loss_plot.png')

    grapher.graph_util_over_time(stats_uplink, 'uplink_ports')
Exemple #2
0
def remove_all_tbl_100_flows():
    hm = mapper.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)
    sw_list = of_proc.get_switch_list()
    for sw in sw_list:
        of_proc.remove_table_flows(sw, 100)
Exemple #3
0
def test_pkt_loss_analysis():
    trial_name = '8_7_2018_1533690234'
    hm = mapper.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)
    st_proc = stp.StatsProcessor(hm, of_proc)
    st_proc.calc_loss_rates(trial_name)
Exemple #4
0
def main():
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)

    arg_parser = build_arg_parser()
    args = arg_parser.parse_args()
    print('args: ' + str(args))
    args.func(args, hm, of_proc)
Exemple #5
0
def new_of_api_test():
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    for dpid in of_proc.get_switch_list():
        desc = of_proc.get_switch_desc(dpid)
        print('%s -> %s' % (dpid, desc.get_sw_name()))

    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    p.pprint(
        mk_pretty_sw_dict(of_proc.get_topo_links().get_adj_mat(), hm,
                          lambda k: k, lambda n, k: n))
Exemple #6
0
def gen_lossplot(input_files):
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    st_proc = stp.StatsProcessor(hm, of_proc)
    grapher = stp.Grapher()

    fig, ax = plt.subplots(1, 1)
    stats_avg = []
    for i, f in enumerate(input_files):
        trial_name = f + '/name_hints.txt'
        loss_stats = st_proc.calc_loss_rates(read_trial_name(trial_name))
        grapher.graph_loss_cdf(ax, loss_stats, f)
    legend = ax.legend(loc='bottom right', shadow=True, fontsize='medium')
    plt.show()
Exemple #7
0
def calc_stats_list():
    trial_name = read_trial_name('./name_hints.txt')
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    tx_file = './tx_stats.p'
    rx_file = './rx_stats.p'
    stats = pickle.load(open(tx_file, 'rb'))
    rx_stats = pickle.load(open(rx_file, 'rb'))
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    st_proc = stp.StatsProcessor(hm, of_proc)
    st_dict = st_proc.calc_link_util_per_t(stats,
                                           cfg.pkt_size,
                                           cfg.sample_freq,
                                           units=stp.Units.MegaBitsPerSecond)
    p.pprint(st_dict)
def draw_topology():
    hm = mapper.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)
    builder = GraphVisualizer()
    adj_mat = ui.get_friendly_adj_mat(of_proc, hm)
    dpid_map = ui.get_dpid_map(of_proc, hm)
    sw_list = list(dpid_map.keys())
    g = builder.build_graph(adj_mat, sw_list, dpid_map)
    layout = nx.spectral_layout(g)
    nx.draw(g, layout, node_size=1000)
    labels = {}
    for sw in dpid_map.values():
        labels[sw] = '$%s$' % sw.split('_')[-1]
    nx.draw_networkx_labels(g, layout, labels, font_size=16)
    # plt.savefig('/home/ubuntu/test.png', transparent=True, dpi=512)
    plt.show()
Exemple #9
0
def ping_all():
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    mapper = hm.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    sw_list = of_proc.get_switch_list()
    print('switch list:')
    print(sw_list)
    hosts = {}
    for sw in sw_list:
        sw_num = int(mapper.map_dpid_to_sw_num(sw))
        hostname = mapper.map_sw_to_host(sw_num)
        hosts[sw_num] = mk_host_defaults(hostname)
        hosts[sw_num].connect()

    sw_ids = list(map(lambda dpid: mapper.map_dpid_to_sw_num(dpid), sw_list))
    pairs = [(src, dst) for src in sw_ids for dst in sw_ids if src != dst]

    for (src, dst) in pairs:
        hostname = mapper.map_sw_to_host(dst)
        rem_ip = mapper.resolve_hostname(hostname)
        fd1, fd2 = hosts[src].ping(rem_ip)
        for ln in fd1:
            print(ln)
Exemple #10
0
def gen_boxplot(input_files):
    of_proc = ofp.OFProcessor(cfg.of_controller_ip, cfg.of_controller_port)
    hm = mapper.HostMapper([cfg.dns_server_ip], cfg.of_controller_ip,
                           cfg.of_controller_port)
    st_proc = stp.StatsProcessor(hm, of_proc)
    grapher = stp.Grapher()

    fig, ax = plt.subplots(1, 1)
    stats_avg = []
    for i, f in enumerate(input_files):
        stat_path = f + '/tx_stats.p'
        tx_stats = pickle.load(open(stat_path, 'rb'))
        link_util = st_proc.calc_link_util(tx_stats, cfg.pkt_size,
                                           cfg.time_slice,
                                           stp.Units.MegaBitsPerSecond)
        flat = [util for v in link_util.values() for util in v.values()]
        stats_avg.append(flat)
    grapher.graph_timeframes(ax, stats_avg, input_files)
    plt.show()

    fig, ax = plt.subplots(1, 1)
    stats_avg = []
    for i, f in enumerate(input_files):
        stat_path = f + '/tx_stats.p'
        tx_stats = pickle.load(open(stat_path, 'rb'))
        trial_name = read_trial_name(f + '/name_hints.txt')
        flow_rate = st_proc.calc_flow_rate(trial_name, cfg.pkt_size,
                                           cfg.sample_freq, cfg.trial_length)
        flat = [
            rate for v in flow_rate.values() for u in v.values()
            for rate in u.values()
        ]
        stats_avg.append(flat)

    grapher.graph_timeframes(ax, stats_avg, input_files)
    plt.show()
Exemple #11
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)