def generate_mirroring_port_utilization_compact_bar_plot(results_repository):
    width               = 0.25
    ind                 = np.arange(11)
    fig, ax             = plt.subplots()
    solution_labels     = SOLUTION_LABELS
    colors              = cfg.BAR_PLOT_COLORS
    hatch               = cfg.BAR_PLOT_TEXTURES
    bar_locations       = [w for w in np.arange((width/2), len(solution_labels)*width, width)]

    # mean_utils :: solution_type -> switch_id -> util_list
    trial_name = "sub-trial-4"
    mean_utils = defaultdict(lambda: defaultdict(list))
    for run_name in ["run-%d" % run_idx for run_idx in range(3)]:
        for solution_name in solution_labels:
            topo, flows, switches, solutions, link_utilization_data = read_results(
                    results_repository, run_name, solution_name, trial_name)
            link_ids = [(s, d) for s, t in link_utilization_data[0].items() for d in t.keys()]
            collector_switch_dpid   = topo_mapper.get_collector_switch_dpid()
            id_to_dpid              = topo_mapper.get_and_validate_onos_topo(topo)
            dpid_to_id              = {v: k for k, v in id_to_dpid.items()}
            for s, d in [(s, d) for s, d in link_ids if d == collector_switch_dpid]:
                link_utils_over_time = []
                for time_idx, net_snapshot in enumerate(link_utilization_data):
                    try:
                        link_utils_over_time.append(net_snapshot[s][d])
                    except KeyError:
                        print("net_snapshot at time %d did not contain link %s -> %s" % 
                                (time_idx, s, d))

                source_switch_id = dpid_to_id[s]
                mean_utils[solution_name][source_switch_id].append(
                        util.bytes_per_second_to_mbps(mean(link_utils_over_time[1:])))
    
    for bar_idx, solution_name_to_switch_id in enumerate(mean_utils.items()):
        solution_name, switch_id_to_util_list = solution_name_to_switch_id
        data_tuples = sorted([(switch_id, mean(util_list))
            for switch_id, util_list in switch_id_to_util_list.items()],
            key=lambda kvp: kvp[0])
        std_dev_tuples = sorted([(switch_id, np.std(util_list))
            for switch_id, util_list in switch_id_to_util_list.items()],
            key=lambda kvp: kvp[0])

        ys = [d_i[1] for d_i in data_tuples]
        y_err = [s_i[1] for s_i in std_dev_tuples]

        ax.bar(ind+bar_locations[bar_idx], ys, width, color=colors[bar_idx], hatch=hatch[bar_idx],
                label=solution_labels[solution_name], align="center",
                ecolor="black", yerr=y_err)


    plt.rc('text', usetex=True)
    plt.rc('font', **cfg.FONT)
    plt.xlabel("Switch ID", **cfg.AXIS_LABELS)
    plt.ylabel("Switch load (Mbps)", **cfg.AXIS_LABELS)
    plt.xticks(ind+(width*len(solution_labels))/2, (ind+1))
    plt.grid()
    plt.xlim(0, max(ind) + (width*len(solution_labels)))
    # plt.legend(ncol=len(solution_labels), **cfg.LEGEND)

    helpers.save_figure("sfm-plotthree.pdf", len(solution_labels))
def compute_theoretical_and_actual_utilization( results_repository
                                              , run_count
                                              , solution_names
                                              , trial_count):
    utilization_data = defaultdict(lambda: defaultdict(list))
    theoretical_data = defaultdict(lambda: defaultdict(list))

    for run in ["run-%d" % run_idx for run_idx in range(run_count)]:
        for solution_name in solution_name:
            for trial_name in ["sub-trial-%d" % trial_idx for trial_idx in range(trial_count)]:
                topo, flows, switches, solutions, net_utilization = read_results(
                        results_repository, run, solution_name, trial_name)

                most_used_mirroring_port = compute_most_used_mirroring_port(flows, solutions)

                id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
                mirror_port_dpid = id_to_dpid[most_used_mirroring_port]
                collector_switch_dpid = topo_mapper.get_collector_switch_dpid()

                mirror_port_utils = []
                for util_at_time_t in net_utilization:
                    try:
                        mirror_port_utils.append(
                                util_at_time_t[mirror_port_dpid][collector_switch_dpid])
                    except KeyError as ke:
                        print("KEY ERROR KE %s" % ke)

                theoretical_util = compute_most_used_mirroring_port_rate(switches, solutions)
                utilization_data[solution_name][len(flows)].extend(mirror_port_utils)
                theoretical_data[solution_name][len(flows)].append(theoretical_util)

    return utilization_data, theoretical_data
def add_flow_mirroring_flows(topology, flows, switches, solutions):
    flow_ids_to_add = flows.keys()
    id_to_dpid = topo_mapper.get_and_validate_onos_topo(topology)
    flow_tokens = {}
    for flow_id in flow_ids_to_add:
        flow_tokens[flow_id] = request_flow_mirroring(flows[flow_id], switches, 
                solutions[flow_id], id_to_dpid, flow_id)
    return flow_tokens
Exemplo n.º 4
0
def generate_port_mirroring_port_utilization_cdf(results_repository):
    labels = ["rnd", "det", "df", "greedy", "optimal"]
    legend_labels = ["$\\epsilon$-LPR", "LPR", "DuFi", "Greedy", "Optimal"]
    markers = ["^", "*", "^", "o", "x"]
    colors = ["red", "green", "blue", "orange", "purple"]
    trial_name = "sub-trial-4"
    run_name = "run-0"
    for solution_idx, solution_name in enumerate(labels):
        topo, flows, switches, solutions, link_utilization_data, ports = read_results(
            results_repository, run_name, solution_name, trial_name)
        link_ids = [(s, d) for s, t in link_utilization_data[0].items()
                    for d in t.keys()]
        mean_utils = []
        labels = []
        errors = []
        collector_switch_dpid = topo_mapper.get_collector_switch_dpid()
        id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
        dpid_to_id = {v: k for k, v in id_to_dpid.items()}
        for s, d in [(s, d) for s, d in link_ids
                     if d == collector_switch_dpid]:
            link_utils_over_time = []
            for time_idx, net_snapshot in enumerate(link_utilization_data):
                try:
                    link_utils_over_time.append(net_snapshot[s][d])
                except KeyError:
                    print(
                        "net_snapshot at time %d did not contain link %s -> %s"
                        % (time_idx, s, d))
            mean_utils.append(
                util.bytes_per_second_to_mbps(mean(link_utils_over_time)))
            errors.append(
                util.bytes_per_second_to_mbps(np.std(link_utils_over_time)))
            labels.append(dpid_to_id[s])

        cdf_data = sorted(mean_utils)
        xs = [0.0]
        ys = [0.0]
        for idx, d in enumerate(cdf_data):
            xs.append(d)
            ys.append((1 + idx) / len(cdf_data))

        plt.plot(xs,
                 ys,
                 label=legend_labels[solution_idx],
                 marker=markers[solution_idx],
                 color=colors[solution_idx])
        plt.legend(loc="upper center",
                   bbox_to_anchor=(0.5, cfg.LEGEND_HEIGHT),
                   shadow=True,
                   ncol=len(labels))
        plt.rc('text', usetex=True)
        plt.rc('font', **cfg.FONT)
        plt.grid()
        plt.xlabel("Mirroring Port Rate $\\frac{Mb}{s}$")
        plt.ylabel("$\\mathbb{P}\\{x < \\mathcal{X}\\}$")

    helpers.save_figure("pm-plot-three-cdf.pdf")
def generate_mirroring_port_utilization_bar_plot(results_repository):
    topo, flows, switches, solutions, link_utilization_data = read_results(results_repository, "approx", "sub-trial-4")
    link_ids = [(s, d) for s, t in link_utilization_data[0].items() for d in t.keys()]
    mean_utils  = []
    labels      = []
    errors      = []
    collector_switch_dpid = topo_mapper.get_collector_switch_dpid()
    id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
    dpid_to_id = {v: k for k, v in id_to_dpid.items()}
    for s, d in [(s, d) for s, d in link_ids if d == collector_switch_dpid]:
        link_utils_over_time = []
        for time_idx, net_snapshot in enumerate(link_utilization_data):
            try:
                link_utils_over_time.append(net_snapshot[s][d])
            except KeyError:
                print("net_snapshot at time %d did not contain link %s -> %s" % (time_idx, s, d))
        mean_utils.append(util.bytes_per_second_to_mbps(mean(link_utils_over_time)))
        errors.append(util.bytes_per_second_to_mbps(np.std(link_utils_over_time)))
        labels.append(dpid_to_id[s])

    ind = np.arange(1, 12)
    width = 0.35
    fig, ax = plt.subplots()

    ys = [mu for mu, l in sorted(zip(mean_utils, labels), key=lambda t: t[1])]
    xs = labels
    errors = [e for e, l in sorted(zip(errors, labels), key=lambda t: t[1])]
    ax.set_xticks(ind+(width/2))
    ax.set_xticklabels(range(1, 12))
    ax.bar(ind-(width/2), ys, width, label="Measured", color="skyblue", hatch=".",
            yerr=errors, ecolor="black")

    mirroring_utils = defaultdict(float)
    for flow in flows.values():
        mirroring_switch_for_flow = solutions[flow.flow_id].mirror_switch_id
        mirroring_utils[mirroring_switch_for_flow] += flow.traffic_rate

    ys = []
    xs = []
    for switch_id in range(1, 12):
        aggregate_rate = mirroring_utils[switch_id]
        xs.append(switch_id)
        ys.append(aggregate_rate * 100)
    
    ax.bar(ind+(width/2), ys, width, color="green", hatch="\\", label="Expected") 
    plt.legend(loc="upper center", bbox_to_anchor=(0.5, cfg.LEGEND_HEIGHT), shadow=True, ncol=2)
    plt.rc('text', usetex=True)
    plt.rc('font', **cfg.FONT)
    plt.xlabel("Switch ID")
    plt.ylabel("Mean Mirroring Port Rate ($\\frac{Mb}{s}$)")
    helpers.save_figure("plot-three.pdf")
    plt.clf()
def add_port_mirroring_flows(topology, flows, switches, solutions, mirroring_ports):
    flow_ids_to_add = flows.keys()
    id_to_dpid = topo_mapper.get_and_validate_onos_topo(topology)
    port_ids_to_port_numbers = map_port_ids_to_nw_ports(mirroring_ports, id_to_dpid)
    flow_tokens = {}

    verify_that_all_flows_are_mirrored(flows, switches, solutions, port_ids_to_port_numbers,
            id_to_dpid)

    for flow_id in flow_ids_to_add:
        flow_tokens[flow_id] = request_port_mirroring(flows[flow_id], switches, solutions,
                id_to_dpid, flow_id, port_ids_to_port_numbers)
    return flow_tokens
Exemplo n.º 7
0
    def map_to_physical_network(trial):
        id_to_dpid = topo_mapper.get_and_validate_onos_topo(trial.topology)
        port_ids_to_port_numbers = onos_rest_helpers.map_port_ids_to_nw_ports(
            trial.mirroring_ports, id_to_dpid)

        new_flows = {}
        for flow_id, flow in trial.flows.items():
            new_path = [id_to_dpid[node] for node in flow.path]
            new_ports = [
                port_ids_to_port_numbers[switch_id][port]
                for switch_id, port in zip(flow.path[:-1], flow.ports[:-1])
            ]
            zipped_path = list(zip(new_path, new_ports))

            last_hop_switch_dpid = id_to_dpid[flow.path[-1]]
            last_hop_egress_port = topo_mapper.get_host_port(
                last_hop_switch_dpid)
            zipped_path.append((last_hop_switch_dpid, last_hop_egress_port))
            new_flow = PortMirroringFlow(flow_id, flow.traffic_rate,
                                         zipped_path)
            new_flows[flow_id] = new_flow

        new_solutions = defaultdict(list)
        for switch_id, solution_list in trial.solutions.items():
            for solution in solution_list:
                new_mirror_switch_id = id_to_dpid[solution.mirror_switch_id]
                new_mirror_switch_port = port_ids_to_port_numbers[
                    solution.mirror_switch_id][solution.mirror_switch_port]
                new_solution = PortMirroringSolution(new_mirror_switch_id,
                                                     new_mirror_switch_port,
                                                     solution.objective_value)
                new_solutions[switch_id].append(new_solution)

        solutions = {}
        solutions[trial.solution_type] = new_solutions
        det_solutions = solutions.get("det", None)
        df_solutions = solutions.get("df", None)
        greedy_solutions = solutions.get("greedy", None)
        optimal_solutions = solutions.get("optimal", None)
        rnd_solutions = solutions.get("rnd", None)
        new_trial = PortMirroringTrial(trial.topology, new_flows,
                                       trial.switches, det_solutions,
                                       df_solutions, greedy_solutions,
                                       optimal_solutions, rnd_solutions,
                                       trial.duration, trial.name,
                                       trial.mirroring_ports)
        print("solution_type %s" % trial.solution_type)
        pp.pprint(solutions)
        new_trial.set_solution_type(trial.solution_type)
        return new_trial
Exemplo n.º 8
0
def compute_theoretical_and_actual_utilization_by_run(results_repository):
    utilization_data = {}
    theoretical_data = {}

    for run in ["run-%d" % run_idx for run_idx in range(3)]:
        solution_results = {}
        theoretical_solution_results = {}
        for solution_name in ["rnd", "det", "df", "greedy", "optimal"]:
            trial_results = {}
            theoretical_trial_results = {}
            for trial_name in [
                    "sub-trial-%d" % trial_idx for trial_idx in range(5)
            ]:
                topo, flows, switches, solutions, net_utilization, ports = read_results(
                    results_repository, run, solution_name, trial_name)

                most_used_mirroring_port = compute_most_used_mirroring_port(
                    switches, solutions)

                id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
                mirror_port_dpid = id_to_dpid[most_used_mirroring_port]
                collector_switch_dpid = topo_mapper.get_collector_switch_dpid()

                mirror_port_utils = []
                for util_at_time_t in net_utilization:
                    try:
                        mirror_port_utils.append(
                            util_at_time_t[mirror_port_dpid]
                            [collector_switch_dpid])
                    except KeyError as ke:
                        print("KEY ERROR KE %s" % ke)

                theoretical_util = compute_most_used_mirroring_port_rate(
                    switches, solutions)
                trial_results[len(flows)] = mirror_port_utils
                theoretical_trial_results[len(flows)] = theoretical_util

            solution_results[solution_name] = trial_results
            theoretical_solution_results[
                solution_name] = theoretical_trial_results

        utilization_data[run] = solution_results
        theoretical_data[run] = theoretical_solution_results

    return utilization_data, theoretical_data
def compute_theoretical_and_actual_error(results_repository):
    utilization_data = defaultdict(list)

    for provider_name in ["optimal", "approx"]:
        for trial_idx in range(5):
            trial_name = "sub-trial-%d" % trial_idx
            topo, flows, switches, solutions, net_utilization = read_results(results_repository,
                    provider_name, trial_name)

            most_used_mirroring_port = compute_most_used_mirroring_port(flows, solutions)
            id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
            mirror_port_dpid = id_to_dpid[most_used_mirroring_port]
            collector_switch_dpid = topo_mapper.get_collector_switch_dpid()

            utilization = [util_at_time_t[mirror_port_dpid][collector_switch_dpid]
                    for util_at_time_t in net_utilization]
            utilization_data[provider_name].append((len(flows), utilization))

    return utilization_data
def generate_mirroring_port_utilization_box_plot(results_repository):
    width               = 0.25
    ind                 = np.arange(11)
    fig, ax             = plt.subplots()
    solution_labels     = SOLUTION_LABELS
    colors              = cfg.BAR_PLOT_COLORS
    hatch               = cfg.BAR_PLOT_TEXTURES
    bar_locations       = [w for w in np.arange((width/2), len(solution_labels)*width, width)]

    # mean_util_lists :: solution_type -> switch_id -> util_list
    trial_name = "sub-trial-4"
    mean_util_lists = defaultdict(lambda: defaultdict(list))
    for run_name in ["run-%d" % run_idx for run_idx in range(3)]:
        for solution_name in solution_labels:
            topo, flows, switches, solutions, link_utilization_data = read_results(
                    results_repository, run_name, solution_name, trial_name)
            link_ids = [(s, d) for s, t in link_utilization_data[0].items() for d in t.keys()]
            collector_switch_dpid   = topo_mapper.get_collector_switch_dpid()
            id_to_dpid              = topo_mapper.get_and_validate_onos_topo(topo)
            dpid_to_id              = {v: k for k, v in id_to_dpid.items()}
            for s, d in [(s, d) for s, d in link_ids if d == collector_switch_dpid]:
                link_utils_over_time = []
                for time_idx, net_snapshot in enumerate(link_utilization_data):
                    try:
                        link_utils_over_time.append(net_snapshot[s][d])
                    except KeyError:
                        print("net_snapshot at time %d did not contain link %s -> %s" % 
                                (time_idx, s, d))

                source_switch_id = dpid_to_id[s]
                most_used_id = compute_most_used_mirroring_port(flows, solutions)
                mean_link_utilization_for_run = util.bytes_per_second_to_mbps(mean(
                    link_utils_over_time[1:]))
                if source_switch_id == most_used_id:
                    print(solution_name, mean_link_utilization_for_run)
                mean_util_lists[solution_name][source_switch_id].append(
                        mean_link_utilization_for_run)

    pp.pprint(mean_util_lists) 
    mean_utils = defaultdict(dict)
    box_plot_lists = {}
    for solution_type, switch_id_to_util_list in mean_util_lists.items():
        list_for_solution_type = []
        for switch_id, util_list in switch_id_to_util_list.items():
            # pp.pprint(util_list)
            mean_value = mean(util_list)
            list_for_solution_type.append(mean_value)
            mean_utils[solution_type][switch_id] = mean_value
        box_plot_lists[solution_type] = list_for_solution_type

    box = plt.boxplot([box_plot_lists[solution_name] for solution_name in SOLUTION_NAMES],
            labels=[solution_labels[solution_name] for solution_name in SOLUTION_NAMES],
            patch_artist=True,
            widths=[0.5]*len(SOLUTION_NAMES))
    for element in ["boxes", "whiskers", "fliers", "means", "medians", "caps"]:
        plt.setp(box[element], color="black")

    for idx, patch in enumerate(box["boxes"]):
        patch.set(facecolor=cfg.BAR_PLOT_COLORS[idx], hatch=cfg.BAR_PLOT_TEXTURES[idx])

    plt.rc('text', usetex=True)
    plt.rc('font', **cfg.FONT)
    plt.xlabel("Algorithm", **cfg.AXIS_LABELS)
    plt.ylabel("Switch load (Mbps)", **cfg.AXIS_LABELS)
    plt.grid(**cfg.GRID)

    helpers.save_figure("sfm-boxplot.pdf")
Exemplo n.º 11
0
def generate_mirroring_port_utilization_bar_plot(results_repository):
    labels = ["rnd", "det", "df", "greedy", "optimal"]
    legend_labels = ["\\epsilon-LPR", "LPR", "DuFi", "Greedy", "Optimal"]
    trial_name = "sub-trial-4"
    run_name = "run-0"
    for solution_name in labels:
        topo, flows, switches, solutions, link_utilization_data, ports = read_results(
            results_repository, run_name, solution_name, trial_name)
        link_ids = [(s, d) for s, t in link_utilization_data[0].items()
                    for d in t.keys()]
        mean_utils = []
        labels = []
        errors = []
        collector_switch_dpid = topo_mapper.get_collector_switch_dpid()
        id_to_dpid = topo_mapper.get_and_validate_onos_topo(topo)
        dpid_to_id = {v: k for k, v in id_to_dpid.items()}
        for s, d in [(s, d) for s, d in link_ids
                     if d == collector_switch_dpid]:
            link_utils_over_time = []
            for time_idx, net_snapshot in enumerate(link_utilization_data):
                try:
                    link_utils_over_time.append(net_snapshot[s][d])
                except KeyError:
                    print(
                        "net_snapshot at time %d did not contain link %s -> %s"
                        % (time_idx, s, d))
            mean_utils.append(
                util.bytes_per_second_to_mbps(mean(link_utils_over_time)))
            errors.append(
                util.bytes_per_second_to_mbps(np.std(link_utils_over_time)))
            labels.append(dpid_to_id[s])

        ind = np.arange(1, 12)
        width = 0.35

        fig, ax = plt.subplots()
        ys = [
            mu for mu, l in sorted(zip(mean_utils, labels), key=lambda t: t[1])
        ]
        xs = labels
        errors = [
            e for e, l in sorted(zip(errors, labels), key=lambda t: t[1])
        ]
        ax.set_xticks(ind + (width / 2))
        ax.set_xticklabels(range(1, 12))
        ax.bar(ind - (width / 2),
               ys,
               width,
               label="Measured",
               color="skyblue",
               hatch=".",
               yerr=errors,
               ecolor="black")

        mirroring_utils = compute_theoretical_mirroring_rates_for_switches(
            switches, solutions)
        ys = []
        xs = []
        for switch_id in switches.keys():
            aggregate_rate = mirroring_utils[switch_id]
            xs.append(switch_id)
            ys.append(aggregate_rate * pm_cfg.rate_factor)
        ax.bar(ind + (width / 2),
               ys,
               width,
               color="green",
               hatch="\\",
               label="Expected")

        plt.legend(loc="upper center",
                   bbox_to_anchor=(0.5, cfg.LEGEND_HEIGHT),
                   shadow=True,
                   ncol=2)
        plt.rc('text', usetex=True)
        plt.rc('font', **cfg.FONT)
        plt.xlabel("Switch ID")
        plt.ylabel("Mean Mirroring Port Rate ($\\frac{Mb}{s}$)")
        plt.grid()
        helpers.save_figure("plot-three-%s.pdf" % solution_name)
        plt.clf()