| for csv in pcap_csv_list: | for csv in pcap_csv_list: | ||||
| print("\rProcessing {} out of {} CSVs.\t({}%)\t".format(counter, len(pcap_csv_list), math.floor(counter/len(pcap_csv_list)))) | print("\rProcessing {} out of {} CSVs.\t({}%)\t".format(counter, len(pcap_csv_list), math.floor(counter/len(pcap_csv_list)))) | ||||
| transmission_df = pd.read_csv( | |||||
| "{}{}".format(args.pcap_csv_folder, csv), | |||||
| dtype=dict(is_retranmission=bool, is_dup_ack=bool), | |||||
| ) | |||||
| transmission_df["datetime"] = pd.to_datetime(transmission_df["datetime"]) - pd.Timedelta(hours=1) | |||||
| transmission_df = transmission_df.set_index("datetime") | |||||
| transmission_df.index = pd.to_datetime(transmission_df.index) | |||||
| transmission_df = transmission_df.sort_index() | |||||
| # srtt to [s] | |||||
| transmission_df["srtt"] = transmission_df["srtt"].apply(lambda x: x / 10**6) | |||||
| # key for columns and level for index | |||||
| transmission_df["goodput"] = transmission_df["payload_size"].groupby(pd.Grouper(level="datetime", freq="{}s".format(args.interval))).transform("sum") | |||||
| transmission_df["goodput"] = transmission_df["goodput"].apply( | |||||
| lambda x: ((x * 8) / args.interval) / 10**6 | |||||
| ) | |||||
| transmission_df["goodput_rolling"] = transmission_df["payload_size"].rolling("{}s".format(args.interval)).sum() | |||||
| transmission_df["goodput_rolling"] = transmission_df["goodput_rolling"].apply( | |||||
| lambda x: ((x * 8) / args.interval) / 10 ** 6 | |||||
| ) | |||||
| # set meta values and remove all not needed columns | |||||
| cc_algo = transmission_df["congestion_control"].iloc[0] | |||||
| cc_algo = cc_algo.upper() | |||||
| transmission_direction = transmission_df["direction"].iloc[0] | |||||
| #transmission_df = transmission_df.filter(["goodput", "datetime", "ack_rtt", "goodput_rolling", "snd_cwnd"]) | |||||
| # read serial csv | |||||
| serial_df = pd.read_csv(args.serial_file) | |||||
| serial_df["datetime"] = pd.to_datetime(serial_df["datetime"]) - pd.Timedelta(hours=1) | |||||
| serial_df = serial_df.set_index("datetime") | |||||
| serial_df.index = pd.to_datetime(serial_df.index) | |||||
| serial_df.sort_index() | |||||
| transmission_df = pd.merge_asof( | |||||
| transmission_df, | |||||
| serial_df, | |||||
| tolerance=pd.Timedelta("1s"), | |||||
| right_index=True, | |||||
| left_index=True, | |||||
| ) | |||||
| # transmission timeline | |||||
| scaley = 1.5 | |||||
| scalex = 1.0 | |||||
| fig, ax = plt.subplots(figsize=[6.4 * scaley, 4.8 * scalex]) | |||||
| plt.title("{} with {}".format(transmission_direction, cc_algo)) | |||||
| fig.subplots_adjust(right=0.75) | |||||
| twin1 = ax.twinx() | |||||
| twin2 = ax.twinx() | |||||
| twin3 = ax.twinx() | |||||
| # Offset the right spine of twin2. The ticks and label have already been | |||||
| # placed on the right by twinx above. | |||||
| twin2.spines.right.set_position(("axes", 1.1)) | |||||
| twin3.spines.right.set_position(("axes", 1.2)) | |||||
| # create list fo color indices | |||||
| transmission_df["index"] = transmission_df.index | |||||
| color_dict = dict() | |||||
| color_list = list() | |||||
| i = 0 | |||||
| for cell_id in transmission_df["cellID"]: | |||||
| if cell_id not in color_dict: | |||||
| color_dict[cell_id] = i | |||||
| i += 1 | |||||
| color_list.append(color_dict[cell_id]) | |||||
| transmission_df["cell_color"] = color_list | |||||
| color_dict = None | |||||
| color_list = None | |||||
| cmap = matplotlib.cm.get_cmap("Set3") | |||||
| unique_cells = transmission_df["cell_color"].unique() | |||||
| color_list = cmap.colors * (round(len(unique_cells) / len(cmap.colors)) + 1) | |||||
| for c in transmission_df["cell_color"].unique(): | |||||
| bounds = transmission_df[["index", "cell_color"]].groupby("cell_color").agg(["min", "max"]).loc[c] | |||||
| ax.axvspan(bounds.min(), bounds.max(), alpha=0.3, color=color_list[c]) | |||||
| p4, = twin3.plot(transmission_df["snd_cwnd"].dropna(), color="lime", linestyle="dashed", label="cwnd") | |||||
| p3, = twin2.plot(transmission_df["srtt"].dropna(), color="red", linestyle="dashdot", label="sRTT") | |||||
| p1, = ax.plot(transmission_df["goodput_rolling"], color="blue", linestyle="solid", label="goodput") | |||||
| p2, = twin1.plot(transmission_df["downlink_cqi"].dropna(), color="magenta", linestyle="dotted", label="CQI") | |||||
| ax.set_xlim(transmission_df["index"].min(), transmission_df["index"].max()) | |||||
| ax.set_ylim(0, 500) | |||||
| twin1.set_ylim(0, 15) | |||||
| twin2.set_ylim(0, transmission_df["ack_rtt"].max()) | |||||
| twin3.set_ylim(0, transmission_df["snd_cwnd"].max() + 10) | |||||
| ax.set_xlabel("arrival time") | |||||
| ax.set_ylabel("Goodput [mbps]") | |||||
| twin1.set_ylabel("CQI") | |||||
| twin2.set_ylabel("sRTT [s]") | |||||
| twin3.set_ylabel("cwnd") | |||||
| ax.yaxis.label.set_color(p1.get_color()) | |||||
| twin1.yaxis.label.set_color(p2.get_color()) | |||||
| twin2.yaxis.label.set_color(p3.get_color()) | |||||
| twin3.yaxis.label.set_color(p4.get_color()) | |||||
| tkw = dict(size=4, width=1.5) | |||||
| ax.tick_params(axis='y', colors=p1.get_color(), **tkw) | |||||
| twin1.tick_params(axis='y', colors=p2.get_color(), **tkw) | |||||
| twin2.tick_params(axis='y', colors=p3.get_color(), **tkw) | |||||
| twin3.tick_params(axis='y', colors=p4.get_color(), **tkw) | |||||
| ax.tick_params(axis='x', **tkw) | |||||
| #ax.legend(handles=[p1, p2, p3]) | |||||
| if args.save: | |||||
| plt.savefig("{}{}_plot.pdf".format(args.save, csv.replace(".csv", ""))) | |||||
| try: | |||||
| transmission_df = pd.read_csv( | |||||
| "{}{}".format(args.pcap_csv_folder, csv), | |||||
| dtype=dict(is_retranmission=bool, is_dup_ack=bool), | |||||
| ) | |||||
| transmission_df["datetime"] = pd.to_datetime(transmission_df["datetime"]) - pd.Timedelta(hours=1) | |||||
| transmission_df = transmission_df.set_index("datetime") | |||||
| transmission_df.index = pd.to_datetime(transmission_df.index) | |||||
| transmission_df = transmission_df.sort_index() | |||||
| # srtt to [s] | |||||
| transmission_df["srtt"] = transmission_df["srtt"].apply(lambda x: x / 10**6) | |||||
| # key for columns and level for index | |||||
| transmission_df["goodput"] = transmission_df["payload_size"].groupby(pd.Grouper(level="datetime", freq="{}s".format(args.interval))).transform("sum") | |||||
| transmission_df["goodput"] = transmission_df["goodput"].apply( | |||||
| lambda x: ((x * 8) / args.interval) / 10**6 | |||||
| ) | |||||
| transmission_df["goodput_rolling"] = transmission_df["payload_size"].rolling("{}s".format(args.interval)).sum() | |||||
| transmission_df["goodput_rolling"] = transmission_df["goodput_rolling"].apply( | |||||
| lambda x: ((x * 8) / args.interval) / 10 ** 6 | |||||
| ) | |||||
| # set meta values and remove all not needed columns | |||||
| cc_algo = transmission_df["congestion_control"].iloc[0] | |||||
| cc_algo = cc_algo.upper() | |||||
| transmission_direction = transmission_df["direction"].iloc[0] | |||||
| #transmission_df = transmission_df.filter(["goodput", "datetime", "ack_rtt", "goodput_rolling", "snd_cwnd"]) | |||||
| # read serial csv | |||||
| serial_df = pd.read_csv(args.serial_file) | |||||
| serial_df["datetime"] = pd.to_datetime(serial_df["datetime"]) - pd.Timedelta(hours=1) | |||||
| serial_df = serial_df.set_index("datetime") | |||||
| serial_df.index = pd.to_datetime(serial_df.index) | |||||
| serial_df.sort_index() | |||||
| transmission_df = pd.merge_asof( | |||||
| transmission_df, | |||||
| serial_df, | |||||
| tolerance=pd.Timedelta("1s"), | |||||
| right_index=True, | |||||
| left_index=True, | |||||
| ) | |||||
| # transmission timeline | |||||
| scaley = 1.5 | |||||
| scalex = 1.0 | |||||
| fig, ax = plt.subplots(figsize=[6.4 * scaley, 4.8 * scalex]) | |||||
| plt.title("{} with {}".format(transmission_direction, cc_algo)) | |||||
| fig.subplots_adjust(right=0.75) | |||||
| twin1 = ax.twinx() | |||||
| twin2 = ax.twinx() | |||||
| twin3 = ax.twinx() | |||||
| # Offset the right spine of twin2. The ticks and label have already been | |||||
| # placed on the right by twinx above. | |||||
| twin2.spines.right.set_position(("axes", 1.1)) | |||||
| twin3.spines.right.set_position(("axes", 1.2)) | |||||
| # create list fo color indices | |||||
| transmission_df["index"] = transmission_df.index | |||||
| color_dict = dict() | |||||
| color_list = list() | |||||
| i = 0 | |||||
| for cell_id in transmission_df["cellID"]: | |||||
| if cell_id not in color_dict: | |||||
| color_dict[cell_id] = i | |||||
| i += 1 | |||||
| color_list.append(color_dict[cell_id]) | |||||
| transmission_df["cell_color"] = color_list | |||||
| color_dict = None | |||||
| color_list = None | |||||
| cmap = matplotlib.cm.get_cmap("Set3") | |||||
| unique_cells = transmission_df["cell_color"].unique() | |||||
| color_list = cmap.colors * (round(len(unique_cells) / len(cmap.colors)) + 1) | |||||
| for c in transmission_df["cell_color"].unique(): | |||||
| bounds = transmission_df[["index", "cell_color"]].groupby("cell_color").agg(["min", "max"]).loc[c] | |||||
| ax.axvspan(bounds.min(), bounds.max(), alpha=0.3, color=color_list[c]) | |||||
| p4, = twin3.plot(transmission_df["snd_cwnd"].dropna(), color="lime", linestyle="dashed", label="cwnd") | |||||
| p3, = twin2.plot(transmission_df["srtt"].dropna(), color="red", linestyle="dashdot", label="sRTT") | |||||
| p1, = ax.plot(transmission_df["goodput_rolling"], color="blue", linestyle="solid", label="goodput") | |||||
| p2, = twin1.plot(transmission_df["downlink_cqi"].dropna(), color="magenta", linestyle="dotted", label="CQI") | |||||
| ax.set_xlim(transmission_df["index"].min(), transmission_df["index"].max()) | |||||
| ax.set_ylim(0, 500) | |||||
| twin1.set_ylim(0, 15) | |||||
| twin2.set_ylim(0, transmission_df["ack_rtt"].max()) | |||||
| twin3.set_ylim(0, transmission_df["snd_cwnd"].max() + 10) | |||||
| ax.set_xlabel("arrival time") | |||||
| ax.set_ylabel("Goodput [mbps]") | |||||
| twin1.set_ylabel("CQI") | |||||
| twin2.set_ylabel("sRTT [s]") | |||||
| twin3.set_ylabel("cwnd") | |||||
| ax.yaxis.label.set_color(p1.get_color()) | |||||
| twin1.yaxis.label.set_color(p2.get_color()) | |||||
| twin2.yaxis.label.set_color(p3.get_color()) | |||||
| twin3.yaxis.label.set_color(p4.get_color()) | |||||
| tkw = dict(size=4, width=1.5) | |||||
| ax.tick_params(axis='y', colors=p1.get_color(), **tkw) | |||||
| twin1.tick_params(axis='y', colors=p2.get_color(), **tkw) | |||||
| twin2.tick_params(axis='y', colors=p3.get_color(), **tkw) | |||||
| twin3.tick_params(axis='y', colors=p4.get_color(), **tkw) | |||||
| ax.tick_params(axis='x', **tkw) | |||||
| #ax.legend(handles=[p1, p2, p3]) | |||||
| if args.save: | |||||
| plt.savefig("{}{}_plot.pdf".format(args.save, csv.replace(".csv", ""))) | |||||
| except Exception as e: | |||||
| print("Error processing file: {}".format(csv)) | |||||
| print(str(e)) | |||||
| counter += 1 | counter += 1 | ||||
| plt.clf() | plt.clf() |