highest_median = np.median(performance)

        for i in range(len(app_performances)):
            app_performances[i] = np.array(
                app_performances[i]) / highest_median

        for performance in app_performances:
            value = np.median(performance)
            values.append(value)
            low_percentile, high_percentile = np.percentile(
                performance, [25, 75])
            errors_below.append(value - low_percentile)
            errors_above.append(high_percentile - value)

        print benchmark
        print plotted_rates
        plt.errorbar(plotted_rates,
                     values,
                     yerr=(errors_below, errors_above),
                     label=benchmark,
                     capsize=5)
    plt.ylabel('Normalized Performance')
    plt.xlabel('Bandwidth Limit (Mbps)')
    graph_utils.set_legend_below(ncol=4)
    graph_utils.set_ticks()
    graph_utils.set_non_negative_axes()
    plt.xlim([0, 10000])
    filename = 'bandwidth_vs_performance.eps'
    plt.savefig(filename)
    print "Done! File saved in: ", filename
Пример #2
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--window-size',
                        nargs=2,
                        action='append',
                        dest='window_size',
                        help="How long to average over.  In ps.",
                        required=True)
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument(
        '--server',
        dest='server_ip',
        required=True,
        help="IP of the machine that the card is directory connected to")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title')
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)

    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()
    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()

    for pcap_file, label in args.input_files:
        for window_size, label_suffix in args.window_size:
            if pcap_file.endswith('.csv'):
                incoming_x_values, incoming_bandwidths = \
                        process_csv.extract_bandwidths(pcap_file, window_size,
                                                       to_ip=args.server_ip, count=args.packets)
                outgoing_x_values, outgoing_bandwidths = \
                    process_csv.extract_bandwidths(pcap_file, window_size,
                                                   from_ip=args.server_ip, count=args.packets)

            for i in range(len(incoming_bandwidths)):
                incoming_bandwidths[i] = float(incoming_bandwidths[i])

            # Dump the percentiles into a file.
            percentiles = np.linspace(0.0, 1.0, 10000)
            sorted_bandwidths = [
                x for x in sorted(incoming_bandwidths) if x > 0.0
            ]
            sorted_out_bandwidths = [
                x for x in sorted(outgoing_bandwidths) if x > 0.0
            ]
            with open(pcap_file + label_suffix + '.in_percentiles',
                      'w') as in_file:
                with open(pcap_file + label_suffix + '.out_percentiles',
                          'w') as out_file:
                    contents_in = []
                    contents_out = []
                    count_in = len(sorted_bandwidths) - 1
                    count_out = len(sorted_out_bandwidths) - 1
                    for percentile in percentiles:
                        fraction_through_in = int(percentile * count_in)
                        fraction_through_out = int(percentile * count_out)

                        contents_in.append(
                            str(percentile) + ' ' + '{0:.15f}'.format(
                                sorted_bandwidths[fraction_through_in]) + '\n')
                        contents_out.append(
                            str(percentile) + ' ' + '{0:.15f}'.format(
                                sorted_out_bandwidths[fraction_through_out]) +
                            '\n')
                    in_file.writelines(contents_in)
                    out_file.writelines(contents_out)

            min_lim = min(incoming_bandwidths)
            max_lim = max(incoming_bandwidths)
            small_diff = (min_lim + max_lim) / 10000.0
            bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                             np.inf)
            print bins
            plt.figure(1)
            plt.hist(incoming_bandwidths,
                     cumulative=True,
                     bins=bins,
                     histtype='step',
                     normed=True,
                     label=label + ' ' + label_suffix)

            no_zero_incoming_bandwidths = graph_utils.no_zeroes(
                incoming_bandwidths)
            if len(no_zero_incoming_bandwidths) > 0:
                min_lim = min(no_zero_incoming_bandwidths)
                max_lim = max(no_zero_incoming_bandwidths)
                logspace_bins = graph_utils.get_logspace(min_lim, max_lim)
                plt.figure(2)
                plt.hist(no_zero_incoming_bandwidths,
                         cumulative=True,
                         bins=logspace_bins,
                         histtype='step',
                         normed=True,
                         label=label + ' ' + label_suffix)
            else:
                print "Error: No non-zero bandwidths found"

            for i in range(len(outgoing_bandwidths)):
                outgoing_bandwidths[i] = float(outgoing_bandwidths[i])
            min_lim = min(outgoing_bandwidths)
            max_lim = max(outgoing_bandwidths)
            small_diff = (min_lim + max_lim) / 10000.0
            bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                             np.inf)
            plt.figure(3)
            plt.hist(outgoing_bandwidths,
                     cumulative=True,
                     bins=bins,
                     histtype='step',
                     normed=True,
                     label=label + ' ' + label_suffix)

            no_zero_outgoing_bandwidths = graph_utils.no_zeroes(
                outgoing_bandwidths)
            if len(no_zero_outgoing_bandwidths) > 0:
                min_lim = min(no_zero_outgoing_bandwidths)
                max_lim = max(no_zero_outgoing_bandwidths)
                logspace_bins = graph_utils.get_logspace(min_lim, max_lim)
                plt.figure(4)
                plt.hist(no_zero_outgoing_bandwidths,
                         cumulative=True,
                         bins=logspace_bins,
                         histtype='step',
                         normed=True,
                         label=label + ' ' + label_suffix)
            else:
                print "Error: No non-zero bandwidths found!"

    if args.title:
        plt.figure(1)
        plt.title('Client Traffic: ' + args.title)
        plt.figure(2)
        plt.title('Client Traffic: ' + args.title)
        plt.figure(3)
        plt.title('Server Traffic: ' + args.title)
        plt.figure(4)
        plt.title('Server Traffic: ' + args.title)

    label_count = len(args.input_files) * len(args.window_size)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.xlabel("Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_incoming_bandwidth_cdf_window.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(2)
    plt.ylabel("CDF")
    plt.xlabel("Bandwidth (Mbps)")
    graph_utils.set_log_x()
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_incoming_bandwidth_cdf_window_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(3)
    plt.xlabel("Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_bandwidth_cdf_window.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(4)
    plt.xlabel("Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_bandwidth_cdf_window_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument('--server', dest='server_ip', required=True)
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title', required=False, default=None)
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)

    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()
    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()

    pcap_files = args.input_files
    output_label = args.output_name

    for (pcap_file, label) in pcap_files:
        if pcap_file.endswith('.csv'):
            incoming_ipg_gaps = \
                process_csv.extract_ipgs(pcap_file, to_ip=args.server_ip)
            outgoing_ipg_gaps = \
                process_csv.extract_ipgs(pcap_file, from_ip=args.server_ip)

        range = [min(incoming_ipg_gaps), max(incoming_ipg_gaps)]
        print "Dealing with incoming IPG gaps"
        print "Range is ", range
        print "Median is ", np.median(incoming_ipg_gaps)
        print "Deviation is ", np.std(incoming_ipg_gaps)

        # Before we plot these, they need to be converted to normal
        # floats.  To do this, multiply by 10**9
        for i in xrange(len(incoming_ipg_gaps)):
            incoming_ipg_gaps[i] = float(
                Decimal(1000000000.0) * incoming_ipg_gaps[i])
        for i in xrange(len(outgoing_ipg_gaps)):
            outgoing_ipg_gaps[i] = float(
                Decimal(1000000000.0) * outgoing_ipg_gaps[i])

        # Remove anything greater than the 99th percentile to stop
        # if affecting the bins.
        i = 0
        nintyninth_percentile = np.percentile(incoming_ipg_gaps, 99)
        while i < len(incoming_ipg_gaps):
            if incoming_ipg_gaps[i] > nintyninth_percentile:
                del incoming_ipg_gaps[i]
            else:
                i += 1

        print nintyninth_percentile

        # Avoid issues witht the CDF line decreasing to zero after the data is
        # plotted.
        min_lim = min(incoming_ipg_gaps)
        max_lim = max(incoming_ipg_gaps)
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.linspace(min_lim, max_lim + small_diff, 1000)
        bins = np.append(bins, np.inf)

        plt.figure(1)
        plt.hist(incoming_ipg_gaps,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Now plot a log space version, with all times included.
        incoming_ipg_gas_no_zeroes = graph_utils.no_zeroes(incoming_ipg_gaps)
        if len(incoming_ipg_gas_no_zeroes) > 0:
            lim_min = min(incoming_ipg_gas_no_zeroes)
            lim_max = max(incoming_ipg_gas_no_zeroes)

            bins = graph_utils.get_logspace(lim_min, lim_max)
            plt.figure(2)
            plt.hist(incoming_ipg_gas_no_zeroes,
                     bins=bins,
                     cumulative=True,
                     histtype='step',
                     normed=True,
                     label=label)
        else:
            print "Error:: found only zero times on the incoming IPG gaps"

        # Now do the outgoing.
        # Remove anything greater than the 99th percentile to stop
        # if affecting the bins.
        i = 0
        nintyninth_percentile = np.percentile(outgoing_ipg_gaps, 99)
        while i < len(outgoing_ipg_gaps):
            if outgoing_ipg_gaps[i] > nintyninth_percentile:
                del outgoing_ipg_gaps[i]
            else:
                i += 1

        print nintyninth_percentile

        # Avoid issues witht the CDF line decreasing to zero after the data
        # is plotted.
        min_lim = min(outgoing_ipg_gaps)
        max_lim = max(outgoing_ipg_gaps)
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.linspace(min_lim, max_lim + small_diff, 1000)
        bins = np.append(bins, np.inf)

        plt.figure(3)
        plt.hist(outgoing_ipg_gaps,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Now plot the logspace version.
        outgoing_ipg_gaps_no_zeroes = graph_utils.no_zeroes(outgoing_ipg_gaps)
        if len(outgoing_ipg_gaps_no_zeroes) > 0:
            min_lim = min(outgoing_ipg_gaps_no_zeroes)
            max_lim = max(outgoing_ipg_gaps_no_zeroes)

            bins = graph_utils.get_logspace(min_lim, max_lim)
            plt.figure(4)
            plt.hist(outgoing_ipg_gaps_no_zeroes,
                     bins=bins,
                     cumulative=True,
                     histtype='step',
                     normed=True,
                     label=label)
        else:
            print "Error: No non-zero IPGs found in outgoing data"

    if args.title:
        plt.figure(1)
        plt.title('Client Traffic: ' + args.title)
        plt.figure(2)
        plt.title('Client Traffic: ' + args.title)
        plt.figure(3)
        plt.title('Server Traffic: ' + args.title)
        plt.figure(4)
        plt.title('Server Traffic: ' + args.title)

    label_count = len(args.input_files)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.xlim([min(outgoing_ipg_gaps), nintyninth_percentile])
    plt.ylabel("CDF")
    plt.xlabel("Inter-Arrival Time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = output_label + '_ipg_gaps_clients.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(2)
    plt.ylabel("CDF")
    plt.xlabel("Inter-Arrival Time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = output_label + '_ipg_gaps_clients_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(3)
    plt.xlim([min(outgoing_ipg_gaps), nintyninth_percentile])
    plt.ylabel("CDF")
    plt.xlabel("Inter-Arrival Time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = output_label + '_ipg_gaps_server.eps'
    plt.savefig(filename)

    print "Done! File is in ", filename

    plt.figure(4)
    plt.ylabel("CDF")
    plt.xlabel("Inter-Arrival Time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = output_label + '_ipg_gaps_server_log.eps'
    plt.savefig(filename)

    print "Done! File is in ", filename
Пример #4
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title')
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)
    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()

    for pcap_file, label in args.input_files:
        if pcap_file.endswith('.csv'):
            flow_lengths = \
                process_csv.extract_flow_lengths(pcap_file)

        if len(flow_lengths) == 0:
            print "There were no TCP connections detected in ", pcap_file
            continue

        for i in range(len(flow_lengths)):
            flow_lengths[i] = float(flow_lengths[i])
        min_lim = min(flow_lengths)
        max_lim = max(flow_lengths)
        small_diff = (min_lim + max_lim) / 1000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         np.inf)
        plt.figure(1)
        plt.hist(flow_lengths,
                 cumulative=True,
                 bins=bins,
                 histtype='step',
                 normed=True,
                 label=label)

        no_zero_values = graph_utils.no_zeroes(flow_lengths)
        if len(no_zero_values) > 0:
            min_lim = min(no_zero_values)
            max_lim = max(no_zero_values)
            logspace_bins = graph_utils.get_logspace(min_lim, max_lim)

            plt.figure(2)
            plt.hist(no_zero_values,
                     cumulative=True,
                     bins=logspace_bins,
                     histtype='step',
                     normed=True,
                     label=label)
        else:
            print "Hard Warning!: Found no non-zero flow sizes"

    if args.title:
        plt.figure(1)
        plt.title(args.title)
        plt.figure(2)
        plt.title(args.title)

    label_count = len(args.input_files)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.xlabel("Flow Completion Time (s)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_flow_lengths.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(2)
    plt.xlabel("Flow Completion Time (s)")
    plt.ylabel("CDF")
    graph_utils.set_log_x()
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_flow_lengths_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--server',
                        dest='server_ip',
                        help="The IP address of the server",
                        required=False,
                        default=None)
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title', required=False, default=None)
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)
    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()
    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()

    for pcap_file, label in args.input_files:
        if pcap_file.endswith('.csv'):
            timestamp_deltas_incoming = \
                process_csv.extract_deltas(pcap_file, to_ip=args.server_ip)
            timestamp_deltas_outgoing = \
                process_csv.extract_deltas(pcap_file, from_ip=args.server_ip)

        # Convert to ns before starting:
        for i in xrange(len(timestamp_deltas_incoming)):
            timestamp_deltas_incoming[i] = float(
                Decimal(1000000000.0) * timestamp_deltas_incoming[i])
        for i in xrange(len(timestamp_deltas_outgoing)):
            timestamp_deltas_outgoing[i] = float(
                Decimal(1000000000.0) * timestamp_deltas_outgoing[i])

        # Do the outgoing packets.
        range = [
            min(timestamp_deltas_outgoing),
            max(timestamp_deltas_outgoing)
        ]
        print "Range is ", range
        print "Median is ", np.median(timestamp_deltas_outgoing)
        print "Deviation is ", np.std(timestamp_deltas_outgoing)
        timestamp_deltas_outgoing = \
            np.asarray(timestamp_deltas_outgoing, dtype='float')

        plt.figure(1)
        min_lim = range[0]
        max_lim = range[1]
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         np.inf)
        plt.hist(timestamp_deltas_outgoing,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        timestamp_deltas_outgoing_no_zero = graph_utils.no_zeroes(
            timestamp_deltas_outgoing)
        if len(timestamp_deltas_outgoing_no_zero) > 0:
            min_lim = min(timestamp_deltas_outgoing_no_zero)
            max_lim = max(timestamp_deltas_outgoing_no_zero)
            logspace_bins = graph_utils.get_logspace(min_lim, max_lim)
            plt.figure(2)
            plt.hist(timestamp_deltas_outgoing_no_zero,
                     bins=logspace_bins,
                     cumulative=True,
                     histtype='step',
                     normed=True,
                     label=label)

        # Do the incoming.
        range = [
            min(timestamp_deltas_incoming),
            max(timestamp_deltas_incoming)
        ]
        print "Incoming Range is ", range
        print "Incoming Median is ", np.median(timestamp_deltas_incoming)
        print "Incoming Deviation is ", np.std(timestamp_deltas_incoming)
        timestamp_deltas_incoming = \
            np.asarray(timestamp_deltas_incoming, dtype='float')

        min_lim = range[0]
        max_lim = range[1]
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         np.inf)

        plt.figure(3)
        plt.hist(timestamp_deltas_incoming,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        timestamp_deltas_incoming_no_zero = graph_utils.no_zeroes(
            timestamp_deltas_incoming)
        if len(timestamp_deltas_incoming_no_zero) > 0:
            min_lim = min(timestamp_deltas_incoming_no_zero)
            max_lim = max(timestamp_deltas_incoming_no_zero)

            plt.figure(4)
            plt.hist(timestamp_deltas_incoming,
                     bins=logspace_bins,
                     cumulative=True,
                     histtype='step',
                     normed=True,
                     label=label)
        else:
            print "Error: found no incoming timestamp deltas with nonzero inter-arrival times"

    if args.title:
        plt.figure(1)
        plt.title("Server Traffic: " + args.title)
        plt.figure(2)
        plt.title("Server Traffic: " + args.title)
        plt.figure(3)
        plt.title("Client Traffic: " + args.title)
        plt.figure(4)
        plt.title("Client Traffic: " + args.title)

    label_count = len(args.input_files)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.ylabel("CDF")
    plt.xlabel("Inter-arrival time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_interarrival.eps'
    plt.savefig(filename)
    print "Done! File is in ", args.output_name + '_outgoing_interarrival'

    plt.figure(2)
    plt.ylabel("CDF")
    plt.xlabel("Inter-arrival time (ns)")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_interarrival_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", args.output_name + '_outgoing_interarrival'

    # Do the incoming packets.
    plt.figure(3)
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    plt.xlabel("Inter-arrival time (ns)")
    filename = args.output_name + '_incoming_interarrival.eps'
    plt.savefig(filename)
    print "Done! File is in ", args.output_name + '_incoming_interarrival'

    # Do the incoming packets.
    plt.figure(4)
    plt.ylabel("CDF")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    plt.xlabel("Inter-arrival time (ns)")
    filename = args.output_name + '_incoming_interarrival_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", args.output_name + '_incoming_interarrival'
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-file', dest='input_files', nargs=2, action='append', required=True, help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--window-size', nargs=2, dest='window_size', action='append', help="How long to average over.  In ps. (Also needs a label)", required=True)
    parser.add_argument('--keep-temps', dest='keep_temps', default=False, action='store_true', help="Keep temp files")
    parser.add_argument('--server', dest='server_ip', required=True, help="IP of the machine that the card is directory connected to")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title', required=False, default=None)
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets', type=int, required=False,
            default=None, dest='packets',
            help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)

    server_graph = plt.figure(1)
    plt.clf()
    client_graph = plt.figure(2)
    plt.clf()
    all_graph = plt.figure(3)
    plt.clf()

    for pcap_file, label in args.input_files:
        for (window, window_label) in args.window_size:
            if pcap_file.endswith('.csv'):
                server_windows, server_packet_sizes = \
                    process_csv.extract_sizes_by_window(pcap_file, window, from_ip=args.server_ip)
                client_windows, client_packet_sizes = \
                    process_csv.extract_sizes_by_window(pcap_file, window, to_ip=args.server_ip)
                all_windows, all_packet_sizes = \
                    process_csv.extract_sizes_by_window(pcap_file, window)

            # Print the server graph
            median_sizes = [np.median(x) for x in server_packet_sizes]
            server_windows = [x[0] for x in server_windows]
            # Recenter the values around zero.
            for i in range(1, len(server_windows)):
                server_windows[i] = server_windows[i] - server_windows[0]
            server_windows[0] = 0.0
            plt.figure(1)
            plt.plot(server_windows, median_sizes, label=label + ' ' + window_label)

            # Print the client graph
            median_sizes = [np.median(x) for x in client_packet_sizes]
            client_windows = [x[0] for x in client_windows]
            # Recenter the values around zero.
            for i in range(1, len(client_windows)):
                client_windows[i] = client_windows[i] - client_windows[0]
            client_windows[0] = 0.0
            plt.figure(2)
            plt.plot(client_windows, median_sizes, label=label + ' ' + window_label)

            # Print the graph of everything else.
            median_sizes = [np.median(x) for x in all_packet_sizes]
            all_windows = [x[0] for x in all_windows]
            # Recenter the values around zero.
            for i in range(1, len(all_windows)):
                all_windows[i] = all_windows[i] - all_windows[0]
            all_windows[0] = 0.0
            plt.figure(3)
            plt.plot(all_windows, median_sizes, label=label + ' ' + window_label)

    if args.title:
        plt.figure(1)
        plt.title("Traffic from server: " + args.title)
        plt.figure(2)
        plt.title("Traffic to server: " + args.title)
        plt.figure(3)
        plt.title(args.title)

    label_count = len(args.input_files) * len(args.window_size)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    # Output the server graph.
    plt.figure(1)
    plt.ylabel("Median Packet Size")
    plt.xlabel("Time (s)")
    plt.legend()
    graph_utils.set_ticks()
    graph_utils.set_non_negative_axes()
    plt.savefig(args.output_name + '_server_sizes_through_time.eps', format='eps')
    print "Done! File is in ", args.output_name + '_server_sizes_through_time.eps'

    # Output the client graph.
    plt.figure(2)
    plt.ylabel("Median Packet Size")
    plt.xlabel("Time (s)")
    plt.legend()
    graph_utils.set_ticks()
    graph_utils.set_non_negative_axes()
    graph_utils.set_integer_ticks()
    plt.savefig(args.output_name + '_client_sizes_through_time.eps', format='eps')
    print "Done! File is in ", args.output_name + '_client_sizes_through_time.eps'

    # Output the overall graph.
    plt.figure(3)
    plt.ylabel("Median Packet Size")
    plt.xlabel("Time (s)")
    plt.legend()
    graph_utils.set_ticks()
    graph_utils.set_non_negative_axes()
    graph_utils.set_integer_ticks()
    plt.savefig(args.output_name + '_all_times.eps', format='eps')
    print "Done! File is in ", args.output_name + '_all_times.eps'
Пример #7
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-file', dest='input_files', nargs=2, action='append', required=True, help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--window-size', nargs=2, dest='window_size', action='append', help="How long to average over.  In ps. (Also needs a label)", required=True)
    parser.add_argument('--keep-temps', dest='keep_temps', default=False, action='store_true', help="Keep temp files")
    parser.add_argument('--server', dest='server_ip', required=True, help="IP of the machine that the card is directory connected to")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title', required=False, default=None)
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets', type=int, required=False,
            default=None, dest='packets',
            help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)
    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()

    for (pcap_file, label) in args.input_files:
        for (window_size, label_suffix) in args.window_size:

            if pcap_file.endswith('.csv'):
                incoming_x_values, incoming_bandwidths = \
                        process_csv.extract_bandwidths(pcap_file, window_size,
                                                       to_ip=args.server_ip)
                outgoing_x_values, outgoing_bandwidths = \
                    process_csv.extract_bandwidths(pcap_file, window_size,
                                                   from_ip=args.server_ip)

            #  Handle the outgoing information first.
            # Recenter the xvalues around zero.
            zero_value = outgoing_x_values[0][0]
            for i in range(len(outgoing_x_values)):
                outgoing_x_values[i] = float(outgoing_x_values[i][0] - zero_value)

            #  Handle the incoming information next.
            # Recenter the xvalues around zero.
            zero_value = incoming_x_values[0][0]
            for i in range(len(incoming_x_values)):
                incoming_x_values[i] = float(incoming_x_values[i][0] - zero_value)

            if len(incoming_x_values) < 3000000:
                plt.figure(2)
                plt.plot(incoming_x_values, incoming_bandwidths, label=label + ' ' + label_suffix)
            else:
                print "Error: Skipping line ", label + ' ' + label_suffix, " because it has more than  3 million entries."

            if len(outgoing_x_values) < 3000000:
                plt.figure(1)
                plt.plot(outgoing_x_values, outgoing_bandwidths, label=label + ' ' + label_suffix)
            else:
                print "Error: Skipping line ", label + ' ' + label_suffix, " because it has more than  3 million entries."

    if args.title:
        plt.figure(1)
        plt.title('Server Traffic: ' + args.title)
        plt.figure(2)
        plt.title('Client Traffic: ' + args.title)

    label_count = len(args.input_files) * len(args.window_size)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(2)
    plt.xlabel("Time (s)")
    plt.ylabel("Bandwidth (Mbps)")
    graph_utils.set_ticks()
    graph_utils.set_non_negative_axes()
    graph_utils.set_legend_below()
    filename = args.output_name + '_incoming_bandwidth_windowed.eps'
    plt.savefig(filename, format='eps')
    print "Done! File is in ", filename

    plt.figure(1)
    plt.xlabel("Time (s)")
    plt.ylabel("Bandwidth (Mbps)")
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    graph_utils.set_legend_below()
    filename = args.output_name + '_outgoing_bandwidth_windowed.eps'

    plt.savefig(filename, format='eps')
    print "Done! File is in ", filename
Пример #8
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument(
        '--server',
        dest='server_ip',
        required=True,
        help="IP of the machine that the card is directory connected to")
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--title', dest='title', required=False, default=None)

    args = parser.parse_args(args)

    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()
    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()
    plt.figure(5)
    plt.clf()
    plt.figure(6)
    plt.clf()

    for (pcap_file, label) in args.input_files:
        if pcap_file.endswith('.csv'):
            outgoing_packet_sizes = process_csv.extract_sizes(
                pcap_file, from_ip=args.server_ip)
            incoming_packet_sizes = process_csv.extract_sizes(
                pcap_file, to_ip=args.server_ip)
            both_packet_sizes = process_csv.extract_sizes(pcap_file)

        # Plot the server packet sizes.
        range = [min(outgoing_packet_sizes), max(outgoing_packet_sizes)]
        print "From the server, "
        print "Range is ", range
        print "Median is ", np.median(outgoing_packet_sizes)
        print "Deviation is ", np.std(outgoing_packet_sizes)
        outgoing_packet_sizes = np.asarray(outgoing_packet_sizes)
        min_lim = min(outgoing_packet_sizes)
        max_lim = max(outgoing_packet_sizes)
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         [np.inf])
        plt.figure(1)
        plt.hist(outgoing_packet_sizes,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Plot the log version:
        log_bins = graph_utils.get_logspace(min_lim, max_lim)
        plt.figure(2)
        plt.hist(outgoing_packet_sizes,
                 bins=log_bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Plot the incoming packet sizes.
        range = [min(incoming_packet_sizes), max(incoming_packet_sizes)]
        print "Into the server, "
        print "Range is ", range
        print "Median is ", np.median(incoming_packet_sizes)
        print "Deviation is ", np.std(incoming_packet_sizes)
        incoming_packet_sizes = np.asarray(incoming_packet_sizes)
        min_lim = min(incoming_packet_sizes)
        max_lim = max(incoming_packet_sizes)
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         [np.inf])
        plt.figure(3)
        plt.hist(incoming_packet_sizes,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Plot the log versions.
        log_bins = graph_utils.get_logspace(min_lim, max_lim)
        plt.figure(4)
        plt.hist(incoming_packet_sizes,
                 bins=log_bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Plot both packet sizes.
        range = [min(both_packet_sizes), max(both_packet_sizes)]
        print "Overall,"
        print "Range is ", range
        print "Median is ", np.median(both_packet_sizes)
        print "Deviation is ", np.std(both_packet_sizes)
        both_packet_sizes = np.asarray(both_packet_sizes)
        min_lim = min(both_packet_sizes)
        max_lim = max(both_packet_sizes)
        small_diff = (min_lim + max_lim) / 10000.0
        bins = np.append(np.linspace(min_lim, max_lim + small_diff, 1000),
                         [np.inf])

        plt.figure(5)
        plt.hist(both_packet_sizes,
                 bins=bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

        # Plot the log versions.
        log_bins = graph_utils.get_logspace(min_lim, max_lim)
        plt.figure(6)
        plt.hist(both_packet_sizes,
                 bins=log_bins,
                 cumulative=True,
                 histtype='step',
                 normed=True,
                 label=label)

    if args.title:
        plt.figure(1)
        plt.title("From Server: " + args.title)
        plt.figure(2)
        plt.title("From Server: " + args.title)
        plt.figure(3)
        plt.title("From Clients: " + args.title)
        plt.figure(4)
        plt.title("From Clients: " + args.title)
        plt.figure(5)
        plt.title(args.title)
        plt.figure(6)
        plt.title(args.title)

    label_count = len(args.input_files)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_sizes.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(2)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_log_x()
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + '_outgoing_sizes_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(3)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_legend_below()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    graph_utils.set_integer_ticks()
    filename = args.output_name + '_incoming_sizes.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    plt.figure(4)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_log_x()
    graph_utils.set_legend_below()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = args.output_name + '_incoming_sizes_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    # Plot the packet sizes for both.
    plt.figure(5)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_legend_below()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    graph_utils.set_integer_ticks()
    filename = args.output_name + '_all_sizes.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename

    # Plot the packet sizes for both.
    plt.figure(6)
    plt.ylabel("CDF")
    plt.xlabel("Sizes (B)")
    graph_utils.set_legend_below()
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    graph_utils.set_integer_ticks()
    filename = args.output_name + '_all_sizes_log.eps'
    plt.savefig(filename)
    print "Done! File is in ", filename
Пример #9
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--input-file',
        dest='input_files',
        nargs=2,
        action='append',
        required=True,
        help="csv file to plot.  Needs a label as a second argument.")
    parser.add_argument(
        '--thresholds',
        dest='thresholds',
        help=
        "This should be a three-tuple.  The firs tiem should be how long between packets (ps) for sequential packets  to be counted in the same burst.  The second item should be how many packets must arrive before  a bursst starts.  The last item should be a label.",
        required=True,
        action='append',
        nargs=3)
    parser.add_argument('--keep-temps',
                        dest='keep_temps',
                        default=False,
                        action='store_true',
                        help="Keep temp files")
    parser.add_argument(
        '--server',
        dest='server_ip',
        required=False,
        default=None,
        help="IP of the machine that the card is directory connected to")
    parser.add_argument('--output-name', dest='output_name', required=True)
    parser.add_argument('--legend-cols',
                        dest='legend_cols',
                        required=false,
                        default=2,
                        help="Number of columns in the legend")
    parser.add_argument('--title', dest='title')
    # This is to avoid issues with tcpdump hanging.
    parser.add_argument('--packets',
                        type=int,
                        required=False,
                        default=None,
                        dest='packets',
                        help="Number of packets to process from a pcap file")

    args = parser.parse_args(args)
    plt.figure(1)
    plt.clf()
    plt.figure(2)
    plt.clf()
    plt.figure(3)
    plt.clf()
    plt.figure(4)
    plt.clf()
    plt.figure(5)
    plt.clf()
    plt.figure(6)
    plt.clf()
    plt.figure(7)
    plt.clf()
    plt.figure(8)
    plt.clf()

    for pcap_file, label in args.input_files:
        for allowed_ipg, burst_size, label_suffix in args.thresholds:
            ipg_threshold = Decimal(allowed_ipg) / Decimal(1000000000000.0)

            if pcap_file.endswith('.csv'):
                incoming_bursts = \
                        process_csv.find_bursts(pcap_file, ipg_threshold=ipg_threshold, packet_threshold=int(burst_size),
                                                       to_ip=args.server_ip)
                outgoing_bursts  = \
                    process_csv.find_bursts(pcap_file, ipg_threshold=ipg_threshold, packet_threshold=int(burst_size),
                                                   from_ip=args.server_ip)

            #  Handle the incoming information first.
            microburst_analyze(incoming_bursts,
                               str(ipg_threshold) + "_incoming", pcap_file,
                               label + ' ' + label_suffix, 0)
            microburst_analyze(outgoing_bursts,
                               str(ipg_threshold) + "_outgoing", pcap_file,
                               label + ' ' + label_suffix, 4)

    if args.title:
        plt.figure(1)
        plt.title('Client Traffic (Burst Lengths): ')
        plt.figure(2)
        plt.title('Client Traffic (Burst Lengths): ')
        plt.figure(3)
        plt.title('Client Traffic (Bandwidths): ')
        plt.figure(4)
        plt.title('Client Traffic (Bandwidths): ')
        plt.figure(5)
        plt.title('Server Traffic (Burst Lengths): ')
        plt.figure(6)
        plt.title('Server Traffic (Burst Lengths): ')
        plt.figure(7)
        plt.title('Server Traffic (Bandwidths): ')
        plt.figure(8)
        plt.title('Server Traffic (Bandwidths): ')

    global max_xlims_burst_lengths
    # Note that this only applies to the linear graphs.
    # You need a different check for log graphs.
    use_unified_length_max_linear = True
    # Get the max of the max limits.
    max_max_xlim = max(max_xlims_burst_lengths)
    for lim in max_xlims_burst_lengths:
        if float(lim) / float(max_max_xlim) < 0.3:
            # If the x limits are too far apart, it is not
            # worth using a unified x axis scale.
            use_unified_length_max_linear = False
    unified_length_max = max_max_xlim

    label_count = len(args.input_files) * len(args.thresholds)
    graph_utils.latexify(bottom_label_rows=label_count / 2)

    plt.figure(1)
    plt.xlabel("Burst Length (packets)")
    plt.ylabel("CDF")
    if use_unified_length_max_linear:
        plt.xlim([0, unified_length_max])
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_integer_ticks()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_length_cdf_incoming.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(2)
    plt.xlabel("Burst Length (packets)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_integer_ticks()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_length_cdf_incoming_log.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(3)
    plt.xlabel("Burst Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_bandwidth_cdf_incoming.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(4)
    plt.xlabel("Burst Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_bandwidth_cdf_incoming_log.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(5)
    plt.xlabel("Burst Length (packets)")
    plt.ylabel("CDF")
    if use_unified_length_max_linear:
        plt.xlim([0, unified_length_max])
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_integer_ticks()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_length_bandwidth_outgoing.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(6)
    plt.xlabel("Burst Length (packets)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_log_x()
    graph_utils.set_yax_max_one()
    graph_utils.set_non_negative_axes()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_length_bandwidth_outgoing_log.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(7)
    plt.xlabel("Burst Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_bandwidth_cdf_outgoing.eps"
    plt.savefig(filename)
    print "Output in ", filename

    plt.figure(8)
    plt.xlabel("Burst Bandwidth (Mbps)")
    plt.ylabel("CDF")
    graph_utils.set_legend_below(ncol=args.legend_cols)
    graph_utils.set_log_x()
    graph_utils.set_non_negative_axes()
    graph_utils.set_yax_max_one()
    graph_utils.set_ticks()
    filename = args.output_name + "_burst_bandwidth_cdf_outgoing_log.eps"
    plt.savefig(filename)
    print "Output in ", filename