def plot_accumulated_data_netflix(input_file, home_ip, website, platform, y_limit, show=False):
    data = generate_data(input_file, home_ip, website=website, protocols=['TCP'])
    all_stream_data = data['all_streams']
    # all_stream_data['time'] = filter(lambda x: x[0] < 50, all_stream_data['time'])
    if platform == 'android':
        first_stream_id, first_stream_data = sorted(data.items(), cmp=lambda x, y: x[1]['total'] - y[1]['total'], reverse=True)[1]
        second_stream_id, second_stream_data = sorted(data.items(), cmp=lambda x, y: x[1]['total'] - y[1]['total'], reverse=True)[2]
        third_stream_id, third_stream_data = sorted(data.items(), cmp=lambda x, y: x[1]['total'] - y[1]['total'], reverse=True)[3]

    fig, ax = plt.subplots()
    ax.set_ylabel('accumulated data')
    ax.set_xlabel('time, s')

    if y_limit is not None:
        fn, tix = make_storage_ticks(filter(lambda x: x < y_limit, map(lambda x: x[1], all_stream_data['time'])))
    else:
        fn, tix = make_storage_ticks(map(lambda x: x[1], all_stream_data['time']))
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    red_line = plt.plot(map(lambda x: x[1], all_stream_data['time']), color='red')
    if platform == 'android':
        blue_line = plt.plot(map(lambda x: x[1], first_stream_data['time']), color='blue')
        green_line = plt.plot(map(lambda x: x[1], second_stream_data['time']), color='green')
        orange_line = plt.plot(map(lambda x: x[1], third_stream_data['time']), color='orange')
        plt.legend([red_line[0], blue_line[0], green_line[0], orange_line[0]], map(pretty_name(website), ['{} combined traffic', '{} first stream', '{} second stream', '{} third stream']))
    else:
        plt.legend([red_line[0]], map(pretty_name(website), ['{} combined traffic']))
    if y_limit is not None:
        plt.ylim(0, y_limit)
    plt.savefig('{}_{}_accumulated_data{}.svg'.format(website, platform, '_limited' if y_limit is not None else ''))
    if show:
        plt.show()
Example #2
0
def flow_plot_both(android_file, android_ip, chrome_file, chrome_ip, website, is_incoming=True, show=False):
    android_y = generate_flow_plot_data(android_file, android_ip, website, is_incoming)
    chrome_y = generate_flow_plot_data(chrome_file, chrome_ip, website, is_incoming)
    fig, ax = plt.subplots()
    ax.set_ylabel("# of open connections")
    ax.set_xlabel("time, s")
    plt.tight_layout()
    android_line = plt.plot(android_y, color="blue")
    chrome_line = plt.plot(chrome_y, color="red")
    plt.legend([android_line[0], chrome_line[0]], map(pretty_name(website), ["{} Android", "{} Chrome"]))
    plt.savefig(pretty_name(website)("{}_android_chrome_flow_plot_over_time.svg"))
    if show:
        plt.show()
    plt.clf()
def plot_accumulated_data(input_file, home_ip, website, platform, show=False):
    data = generate_data(input_file, home_ip, website=website, protocols=["TCP"])
    all_stream_data = data["all_streams"]
    video_stream_id, video_stream_data = sorted(
        data.items(), cmp=lambda x, y: x[1]["total"] - y[1]["total"], reverse=True
    )[1]
    audio_stream_id, audio_stream_data = sorted(
        data.items(), cmp=lambda x, y: x[1]["total"] - y[1]["total"], reverse=True
    )[2]

    fig, ax = plt.subplots()
    ax.set_ylabel("accumulated data")
    ax.set_xlabel("time, s")

    fn, tix = make_storage_ticks(map(lambda x: x[1], all_stream_data["time"]))
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    red_line = plt.plot(map(lambda x: x[1], all_stream_data["time"]), color="red")
    blue_line = plt.plot(map(lambda x: x[1], video_stream_data["time"]), color="blue")
    green_line = plt.plot(map(lambda x: x[1], audio_stream_data["time"]), color="green")
    plt.legend(
        [red_line[0], blue_line[0], green_line[0]],
        map(pretty_name(website), ["{} combined traffic", "{} video traffic", "{} audio traffic"]),
        loc=4,
    )
    plt.savefig("{}_{}_accumulated_data.svg".format(website, platform))
    if show:
        plt.show()
Example #4
0
def top_flows_chart(chrome_file,
                    android_file,
                    chrome_ip,
                    android_ip,
                    website,
                    is_incoming,
                    chrome_color='red',
                    android_color='blue',
                    ax=None):
    """
    Draws a plot of how much traffic transferred per flow.
    :return:
    """
    chrome_data, chrome_shortened = generate_data(chrome_file, chrome_ip,
                                                  website, is_incoming)
    chrome_data = map(lambda x: x[1], chrome_data)
    android_data, android_shortened = generate_data(android_file, android_ip,
                                                    website, is_incoming)
    android_data = map(lambda x: x[1], android_data)
    # android_data = scale_data(android_data, sum(chrome_data), 1)
    num_values = max(len(chrome_data), len(android_data))
    shortened = chrome_shortened if len(chrome_data) > len(
        android_data) else android_shortened

    labels = ['Conn. {0}'.format(i + 1) for i in xrange(num_values)]
    if shortened:
        labels[-1] = 'Rest'
    ind = np.array(
        map(lambda x: x + 0.15,
            np.arange(num_values)))  # the x locations for the groups

    width = 0.35  # the width of the bars

    if ax is None:
        fig, ax = plt.subplots()
    print chrome_data
    chrome_bars = ax.bar(ind, chrome_data, width, color=chrome_color)
    print android_data
    android_bars = ax.bar(ind + width,
                          android_data,
                          width,
                          color=android_color)

    ax.legend((chrome_bars[0], android_bars[0]),
              map(pretty_name(website), ['{} Chrome', '{} Android']))

    # add some text for labels, title and axes ticks
    ax.set_ylabel('Data transferred')
    ax.set_xlabel('Connection')

    fn, tix = make_storage_ticks(chrome_data)
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    ax.set_xticks(ind + width)
    ax.set_xticklabels(labels)

    plt.tight_layout()
def plot_accumulated_data_netflix(input_file, home_ip, website, platform, y_limit, show=False):
    data = generate_data(input_file, home_ip, website=website, protocols=["TCP"])
    all_stream_data = data["all_streams"]
    # all_stream_data['time'] = filter(lambda x: x[0] < 50, all_stream_data['time'])
    if platform == "android":
        first_stream_id, first_stream_data = sorted(
            data.items(), cmp=lambda x, y: x[1]["total"] - y[1]["total"], reverse=True
        )[1]
        second_stream_id, second_stream_data = sorted(
            data.items(), cmp=lambda x, y: x[1]["total"] - y[1]["total"], reverse=True
        )[2]
        third_stream_id, third_stream_data = sorted(
            data.items(), cmp=lambda x, y: x[1]["total"] - y[1]["total"], reverse=True
        )[3]

    fig, ax = plt.subplots()
    ax.set_ylabel("accumulated data")
    ax.set_xlabel("time, s")

    if y_limit is not None:
        fn, tix = make_storage_ticks(filter(lambda x: x < y_limit, map(lambda x: x[1], all_stream_data["time"])))
    else:
        fn, tix = make_storage_ticks(map(lambda x: x[1], all_stream_data["time"]))
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    red_line = plt.plot(map(lambda x: x[1], all_stream_data["time"]), color="red")
    if platform == "android":
        blue_line = plt.plot(map(lambda x: x[1], first_stream_data["time"]), color="blue")
        green_line = plt.plot(map(lambda x: x[1], second_stream_data["time"]), color="green")
        orange_line = plt.plot(map(lambda x: x[1], third_stream_data["time"]), color="orange")
        plt.legend(
            [red_line[0], blue_line[0], green_line[0], orange_line[0]],
            map(
                pretty_name(website), ["{} combined traffic", "{} first stream", "{} second stream", "{} third stream"]
            ),
        )
    else:
        plt.legend([red_line[0]], map(pretty_name(website), ["{} combined traffic"]))
    if y_limit is not None:
        plt.ylim(0, y_limit)
    plt.savefig("{}_{}_accumulated_data{}.svg".format(website, platform, "_limited" if y_limit is not None else ""))
    if show:
        plt.show()
Example #6
0
def bitrate_cdf_plot(android_file, chrome_file, android_ip, chrome_ip, website, quic_file=None, show=False):
    with_quic = quic_file is not None

    # generate data
    chrome_byte_rate_list = generate_bitrate_plot_data(chrome_file, chrome_ip, website, is_incoming=True)
    android_byte_rate_list = generate_bitrate_plot_data(android_file, android_ip, website, is_incoming=True)
    if with_quic:
        quic_byte_rate_list = generate_bitrate_plot_data(quic_file, chrome_ip, website, is_incoming=True, protocols=['TCP', 'UDP'])

    chrome_x_values, chrome_y_values = get_x_y_values(chrome_byte_rate_list)
    ax, line1 = cdf_plot(chrome_x_values, chrome_y_values, color='red', is_log=False)

    if with_quic:
        quic_x_values, quic_y_values = get_x_y_values(quic_byte_rate_list)
        ax, line2 = cdf_plot(quic_x_values, quic_y_values, color='green', ax=ax, is_log=False)

    android_x_values, android_y_values = get_x_y_values(android_byte_rate_list)
    ax, line3 = cdf_plot(android_x_values, android_y_values, color='blue', ax=ax, is_log=False)

    if with_quic:
        plt.legend([line1[0], line2[0], line3[0]], map(pretty_name(website), ['{} Chrome (TCP)', '{} Chrome (QUIC)', '{} Android (TCP)']), loc=4)
    else:
        plt.legend([line1[0], line3[0]], map(pretty_name(website), ['{} Chrome (TCP)', '{} Android (TCP)']), loc=4)
    plt.savefig('{}_android_bitrate.svg'.format(website))
    if show:
        plt.show()
    plt.clf()

    ax, line1 = cdf_plot(chrome_x_values, chrome_y_values, color='red', is_log=True)
    if with_quic:
        ax, line2 = cdf_plot(quic_x_values, quic_y_values, color='green', ax=ax, is_log=True)
    ax, line3 = cdf_plot(android_x_values, android_y_values, color='blue', ax=ax, is_log=True)
    if with_quic:
        plt.legend([line1[0], line2[0], line3[0]], map(pretty_name(website), ['{} Chrome (TCP)', '{} Chrome (QUIC)', '{} Android (TCP)']), loc=4)
    else:
        plt.legend([line1[0], line3[0]], map(pretty_name(website), ['{} Chrome (TCP)', '{} Android (TCP)']), loc=4)
    plt.savefig('{}_android_bitrate_log.svg'.format(website))
    if show:
        plt.show()
    plt.clf()
Example #7
0
def cdf_plot_both(android_file,
                  android_ip,
                  chrome_file,
                  chrome_ip,
                  website,
                  is_incoming=True,
                  show=False):
    android_y_values = generate_flow_plot_data(android_file, android_ip,
                                               website, is_incoming)
    android_x_values = sorted(android_y_values)
    android_y_values = np.arange(len(android_x_values)) / float(
        len(android_x_values))

    chrome_y_values = generate_flow_plot_data(chrome_file, chrome_ip, website,
                                              is_incoming)
    chrome_x_values = sorted(chrome_y_values)
    chrome_y_values = np.arange(len(chrome_x_values)) / float(
        len(chrome_x_values))

    fig, ax = plt.subplots()
    ax.set_yticklabels(['{:3}%'.format(x * 100) for x in ax.get_yticks()])
    ax.set_ylabel('% Total')
    ax.set_xlabel('Number of connections')
    plt.tight_layout()

    android_line = plt.plot(android_x_values, android_y_values, color='blue')
    chrome_line = plt.plot(chrome_x_values, chrome_y_values, color='red')

    loc = 2 if website == 'youtube.com' else 4
    plt.legend([android_line[0], chrome_line[0]],
               map(pretty_name(website), ['{} Android', '{} Chrome']),
               loc=loc)
    plt.savefig(pretty_name(website)('{}_android_chrome_connections_cdf.svg'))
    if show:
        plt.show()
    plt.clf()
Example #8
0
def flow_plot_both(android_file,
                   android_ip,
                   chrome_file,
                   chrome_ip,
                   website,
                   is_incoming=True,
                   show=False):
    android_y = generate_flow_plot_data(android_file, android_ip, website,
                                        is_incoming)
    chrome_y = generate_flow_plot_data(chrome_file, chrome_ip, website,
                                       is_incoming)
    fig, ax = plt.subplots()
    ax.set_ylabel('# of open connections')
    ax.set_xlabel('time, s')
    plt.tight_layout()
    android_line = plt.plot(android_y, color='blue')
    chrome_line = plt.plot(chrome_y, color='red')
    plt.legend([android_line[0], chrome_line[0]],
               map(pretty_name(website), ['{} Android', '{} Chrome']))
    plt.savefig(
        pretty_name(website)('{}_android_chrome_flow_plot_over_time.svg'))
    if show:
        plt.show()
    plt.clf()
Example #9
0
def cdf_plot_both(android_file, android_ip, chrome_file, chrome_ip, website, is_incoming=True, show=False):
    android_y_values = generate_flow_plot_data(android_file, android_ip, website, is_incoming)
    android_x_values = sorted(android_y_values)
    android_y_values = np.arange(len(android_x_values)) / float(len(android_x_values))

    chrome_y_values = generate_flow_plot_data(chrome_file, chrome_ip, website, is_incoming)
    chrome_x_values = sorted(chrome_y_values)
    chrome_y_values = np.arange(len(chrome_x_values)) / float(len(chrome_x_values))

    fig, ax = plt.subplots()
    ax.set_yticklabels(["{:3}%".format(x * 100) for x in ax.get_yticks()])
    ax.set_ylabel("% Total")
    ax.set_xlabel("Number of connections")
    plt.tight_layout()

    android_line = plt.plot(android_x_values, android_y_values, color="blue")
    chrome_line = plt.plot(chrome_x_values, chrome_y_values, color="red")

    loc = 2 if website == "youtube.com" else 4
    plt.legend([android_line[0], chrome_line[0]], map(pretty_name(website), ["{} Android", "{} Chrome"]), loc=loc)
    plt.savefig(pretty_name(website)("{}_android_chrome_connections_cdf.svg"))
    if show:
        plt.show()
    plt.clf()
def in_out_android_chrome(android_file, android_ip, chrome_file, chrome_ip, website, tso, is_incoming, show):
    use_log = is_incoming and not tso
    data_points_android, _ = get_packet_length_data(android_file, android_ip, website, is_incoming=is_incoming, tso=tso, need_ids=False)
    print_things('data_points_android', data_points_android)
    data_points_android = filter(lambda x: x != 1500, data_points_android)
    ax = plot_packet_length(data_points_android, color='blue', use_log=use_log, storage_units=use_log)

    data_points_chrome, _ = get_packet_length_data(chrome_file, chrome_ip, website, is_incoming=is_incoming, tso=tso, need_ids=False)
    data_points_chrome = filter(lambda x: x != 1500 and x != 1480, data_points_chrome)
    plot_packet_length(data_points_chrome, color='red', ax=ax, use_log=use_log, storage_units=use_log)
    print_things('data_points_chrome', data_points_chrome)
    name = pretty_name(website)('{}')
    output_file = '{}_{}_packet_length_android_chrome{}.svg'.format(name, 'in' if is_incoming else 'out', '_tso' if tso else '')
    plt.savefig(output_file)
    if show:
        plt.show()
    plt.clf()
Example #11
0
def top_flows_chart(chrome_file, android_file, chrome_ip, android_ip, website, is_incoming,
                    chrome_color='red', android_color='blue', ax=None):
    """
    Draws a plot of how much traffic transferred per flow.
    :return:
    """
    chrome_data, chrome_shortened = generate_data(chrome_file, chrome_ip, website, is_incoming)
    chrome_data = map(lambda x: x[1], chrome_data)
    android_data, android_shortened = generate_data(android_file, android_ip, website, is_incoming)
    android_data = map(lambda x: x[1], android_data)
    # android_data = scale_data(android_data, sum(chrome_data), 1)
    num_values = max(len(chrome_data), len(android_data))
    shortened = chrome_shortened if len(chrome_data) > len(android_data) else android_shortened

    labels = ['Conn. {0}'.format(i + 1) for i in xrange(num_values)]
    if shortened:
        labels[-1] = 'Rest'
    ind = np.array(map(lambda x: x + 0.15, np.arange(num_values)))  # the x locations for the groups

    width = 0.35  # the width of the bars

    if ax is None:
        fig, ax = plt.subplots()
    print chrome_data
    chrome_bars = ax.bar(ind, chrome_data, width, color=chrome_color)
    print android_data
    android_bars = ax.bar(ind + width, android_data, width, color=android_color)

    ax.legend((chrome_bars[0], android_bars[0]), map(pretty_name(website),  ['{} Chrome', '{} Android']))

    # add some text for labels, title and axes ticks
    ax.set_ylabel('Data transferred')
    ax.set_xlabel('Connection')

    fn, tix = make_storage_ticks(chrome_data)
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    ax.set_xticks(ind + width)
    ax.set_xticklabels(labels)

    plt.tight_layout()
def plot_accumulated_data(input_file, home_ip, website, platform, show=False):
    data = generate_data(input_file, home_ip, website=website, protocols=['TCP'])
    all_stream_data = data['all_streams']
    video_stream_id, video_stream_data = sorted(data.items(), cmp=lambda x, y: x[1]['total'] - y[1]['total'], reverse=True)[1]
    audio_stream_id, audio_stream_data = sorted(data.items(), cmp=lambda x, y: x[1]['total'] - y[1]['total'], reverse=True)[2]

    fig, ax = plt.subplots()
    ax.set_ylabel('accumulated data')
    ax.set_xlabel('time, s')

    fn, tix = make_storage_ticks(map(lambda x: x[1], all_stream_data['time']))
    ax.yaxis.set_major_formatter(fn)
    plt.yticks(tix)

    red_line = plt.plot(map(lambda x: x[1], all_stream_data['time']), color='red')
    blue_line = plt.plot(map(lambda x: x[1], video_stream_data['time']), color='blue')
    green_line = plt.plot(map(lambda x: x[1], audio_stream_data['time']), color='green')
    plt.legend([red_line[0], blue_line[0], green_line[0]], map(pretty_name(website), ['{} combined traffic', '{} video traffic', '{} audio traffic']), loc=4)
    plt.savefig('{}_{}_accumulated_data.svg'.format(website, platform))
    if show:
        plt.show()
Example #13
0
def in_out_android_chrome(android_file, android_ip, chrome_file, chrome_ip,
                          website, tso, is_incoming, show):
    use_log = is_incoming and not tso
    data_points_android, _ = get_packet_length_data(android_file,
                                                    android_ip,
                                                    website,
                                                    is_incoming=is_incoming,
                                                    tso=tso,
                                                    need_ids=False)
    print_things('data_points_android', data_points_android)
    data_points_android = filter(lambda x: x != 1500, data_points_android)
    ax = plot_packet_length(data_points_android,
                            color='blue',
                            use_log=use_log,
                            storage_units=use_log)

    data_points_chrome, _ = get_packet_length_data(chrome_file,
                                                   chrome_ip,
                                                   website,
                                                   is_incoming=is_incoming,
                                                   tso=tso,
                                                   need_ids=False)
    data_points_chrome = filter(lambda x: x != 1500 and x != 1480,
                                data_points_chrome)
    plot_packet_length(data_points_chrome,
                       color='red',
                       ax=ax,
                       use_log=use_log,
                       storage_units=use_log)
    print_things('data_points_chrome', data_points_chrome)
    name = pretty_name(website)('{}')
    output_file = '{}_{}_packet_length_android_chrome{}.svg'.format(
        name, 'in' if is_incoming else 'out', '_tso' if tso else '')
    plt.savefig(output_file)
    if show:
        plt.show()
    plt.clf()
Example #14
0
def bitrate_cdf_plot(android_file,
                     chrome_file,
                     android_ip,
                     chrome_ip,
                     website,
                     quic_file=None,
                     show=False):
    with_quic = quic_file is not None

    # generate data
    chrome_byte_rate_list = generate_bitrate_plot_data(chrome_file,
                                                       chrome_ip,
                                                       website,
                                                       is_incoming=True)
    android_byte_rate_list = generate_bitrate_plot_data(android_file,
                                                        android_ip,
                                                        website,
                                                        is_incoming=True)
    if with_quic:
        quic_byte_rate_list = generate_bitrate_plot_data(
            quic_file,
            chrome_ip,
            website,
            is_incoming=True,
            protocols=['TCP', 'UDP'])

    chrome_x_values, chrome_y_values = get_x_y_values(chrome_byte_rate_list)
    ax, line1 = cdf_plot(chrome_x_values,
                         chrome_y_values,
                         color='red',
                         is_log=False)

    if with_quic:
        quic_x_values, quic_y_values = get_x_y_values(quic_byte_rate_list)
        ax, line2 = cdf_plot(quic_x_values,
                             quic_y_values,
                             color='green',
                             ax=ax,
                             is_log=False)

    android_x_values, android_y_values = get_x_y_values(android_byte_rate_list)
    ax, line3 = cdf_plot(android_x_values,
                         android_y_values,
                         color='blue',
                         ax=ax,
                         is_log=False)

    if with_quic:
        plt.legend(
            [line1[0], line2[0], line3[0]],
            map(pretty_name(website),
                ['{} Chrome (TCP)', '{} Chrome (QUIC)', '{} Android (TCP)']),
            loc=4)
    else:
        plt.legend([line1[0], line3[0]],
                   map(pretty_name(website),
                       ['{} Chrome (TCP)', '{} Android (TCP)']),
                   loc=4)
    plt.savefig('{}_android_bitrate.svg'.format(website))
    if show:
        plt.show()
    plt.clf()

    ax, line1 = cdf_plot(chrome_x_values,
                         chrome_y_values,
                         color='red',
                         is_log=True)
    if with_quic:
        ax, line2 = cdf_plot(quic_x_values,
                             quic_y_values,
                             color='green',
                             ax=ax,
                             is_log=True)
    ax, line3 = cdf_plot(android_x_values,
                         android_y_values,
                         color='blue',
                         ax=ax,
                         is_log=True)
    if with_quic:
        plt.legend(
            [line1[0], line2[0], line3[0]],
            map(pretty_name(website),
                ['{} Chrome (TCP)', '{} Chrome (QUIC)', '{} Android (TCP)']),
            loc=4)
    else:
        plt.legend([line1[0], line3[0]],
                   map(pretty_name(website),
                       ['{} Chrome (TCP)', '{} Android (TCP)']),
                   loc=4)
    plt.savefig('{}_android_bitrate_log.svg'.format(website))
    if show:
        plt.show()
    plt.clf()