def main(): """Plot all figures.""" debug_print_verbose('Generating Plots') if not os.path.exists('figures'): os.makedirs('figures') make_figure_8_plot('data/figure8.csv') make_experiment1_figure('data/experiment1.csv') make_experiment2_figure('data/experiment2.csv') make_experiment3_figure('data/experiment3.csv') make_experiment4_figure('data/experiment4.csv')
def make_experiment4_figure(logfile): """Generate high quality plot of data to reproduce figure 8. The logfile is a CSV of the format [congestion_control, loss_rate, goodput, rtt, capacity, specified_bw] """ results = {} cubic = {"loss": [], "goodput": []} bbr = {"loss": [], "goodput": []} # For available options on plot() method, see: https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot # We prefer to use explicit keyword syntax to help code readability. # Create a figure. fig_width = 8 fig_height = 5 fig, axes = plt.subplots(figsize=(fig_width, fig_height)) results = parse_results_csv(logfile) xmark_ticks = get_loss_percent_xmark_ticks(results) cubic = results['cubic'] bbr = results['bbr'] debug_print_verbose("CUBIC: %s" % cubic) debug_print_verbose("BBR: %s" % bbr) matplotlib.rcParams.update({'figure.autolayout': True}) plt.plot(cubic['loss'], cubic['goodput'], color='blue', linestyle='solid', marker='o', markersize=7, label='CUBIC') plt.plot(bbr['loss'], bbr['goodput'], color='red', linestyle='solid', marker='x', markersize=7, label='BBR') plt.xscale('log') apply_axes_formatting(axes, deduplicate_xmark_ticks(xmark_ticks)) plot_titles(plt, xaxis="Loss Rate (%) - Log Scale", yaxis="Goodput (Mbps)") plot_legend(plt, axes) save_figure(plt, name="figures/experiment4.png")
def _handle_connection(self, conn): num_msg = 0 start_time = time.time() conn.setblocking(0) # set to non-blocking timeout_in_seconds = 1.0 last_log_time_secs = time.time() log_interval_secs = 5 while not self.e.is_set(): time_now_secs = time.time() delta_secs = time_now_secs - last_log_time_secs if (delta_secs > log_interval_secs): debug_print_verbose("Server Heartbeat. e.is_set()? %s" % self.e.is_set()) last_log_time_secs = time_now_secs ready = select.select([conn], [], [], timeout_in_seconds) if ready[0]: # Only read the data if there is data to receive. conn.recv(self.size) num_msg += 1 # Once the event is set, break out elapsed_time = time.time() - start_time debug_print_verbose("Num msg: " + str(num_msg)) debug_print_verbose("Size: " + str(self.size) + " bytes") debug_print_verbose("Time: " + str(elapsed_time)) goodput = (num_msg * self.size * 8) / elapsed_time / 1e6 # Send the Goodput back to the master self.outQ.put(("Estimated goodput: " + str(goodput), None))
def run_client(cong_control, size=1024, address=(os.environ.get("MAHIMAHI_BASE") or "127.0.0.1"), port=5050): """Run the client.""" TCP_CONGESTION = 13 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.IPPROTO_TCP, TCP_CONGESTION, cong_control) s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 6553600) debug_print("Client Connecting to: " + str(address) + ":" + str(port)) try: s.connect((address, port)) except socket.error as msg: debug_print_error("Cannot Connect: " + str(msg)) return debug_print("Connection Established.") # Generate a random message of SIZE a single time. Send this over and over. msg = ''.join(random.choice(string.ascii_lowercase) for _ in range(size)) debug_print_verbose(msg) msg_count = 1 # It can take different amount of time to send message depending on network # configurations. Thus, log progress based on time intervals. last_log_time_secs = time.time() log_interval_secs = 5 debug_print("Client Starting Sending Messages...") while True: time_now_secs = time.time() delta_secs = time_now_secs - last_log_time_secs if (delta_secs > log_interval_secs): debug_print("Sending Message #%d" % msg_count) last_log_time_secs = time_now_secs try: s.send(msg) except Exception as e: debug_print_error("Socket Send Exception: " + str(e)) return msg_count += 1
def make_experiment3_figure(logfile): """Generate high quality plot of data for Experiment 3. Experiment 3 is looking at effects of various RTTs values between CUBIC and BBR. The logfile is a CSV of the format [congestion_control, loss_rate, goodput, rtt, capacity, specified_bw] """ results = {} plt.figure() # For available options on plot() method, see: https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot # We prefer to use explicit keyword syntax to help code readability. # TODO(jmuindi): Check that this graph generation works. # Create a figure. fig_width = 8 fig_height = 5 fig, axes = plt.subplots(figsize=(fig_width, fig_height)) results = parse_results_csv(logfile) xmark_ticks = get_loss_percent_xmark_ticks(results) cubic = results['cubic'] debug_print_verbose("--- Generating figures for experiment 3") rtt_filter_list = sorted(list(set(cubic['rtt']))) debug_print_verbose("RTT list: %s" % rtt_filter_list) matplotlib.rcParams.update({'figure.autolayout': True}) # See: https://matplotlib.org/examples/color/named_colors.html for available colors. # Need 5 colors since we look at 5 RTT values (ms): [2 10 100 1000 10000] cubic_rtt_colors = ['#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#084594'] bbr_rtt_colors = ['#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#99000d'] for index, rtt_filter in enumerate(rtt_filter_list): def include_predicate_fn(congestion_control, loss, goodput, rtt, capacity, specified_bw): return is_same_float(rtt, rtt_filter) filtered_result = parse_results_csv(logfile, include_predicate_fn) filtered_cubic = filtered_result['cubic'] filtered_bbr = filtered_result['bbr'] debug_print_verbose("Filtered Results : %s" % filtered_result) debug_print_verbose("Filter CUBIC: %s" % filtered_cubic) debug_print_verbose("Filter BBR: %s" % filtered_bbr) cubic_color = cubic_rtt_colors[index] bbr_color = bbr_rtt_colors[index] plt.plot(filtered_cubic['loss'], filtered_cubic['goodput'], color=cubic_color, linestyle='solid', marker='o', markersize=7, label='CUBIC (%s ms RTT)' % rtt_filter) plt.plot(filtered_bbr['loss'], filtered_bbr['goodput'], color=bbr_color, linestyle='solid', marker='x', markersize=7, label='BBR (%s ms RTT)' % rtt_filter) plot_titles(plt, xaxis="Loss Rate (%) - Log Scale", yaxis="Goodput (Mbps)") plt.xscale('log') apply_axes_formatting(axes, deduplicate_xmark_ticks(xmark_ticks)) # Sort the labels. # NOTE: Not using the helper function because we need to specifically # handle the fact that the strings aren't in perfect alphabetical order. handles, labels = axes.get_legend_handles_labels() labels, handles = zip( *sorted(zip(labels, handles), key=lambda t: t[0].split(' ', 1)[0])) # Plot Graph legend plt.legend(handles, labels, bbox_to_anchor=(0., 1.02, 1., .102), ncol=2, mode="expand", loc=3, fontsize=10, borderaxespad=0.) plt.tight_layout() save_figure(plt, name="figures/experiment3.png")
def make_experiment2_figure(logfile): """Generate high quality plot of data to reproduce figure for experiment 2. Looking at performance of different congestion control algorithms. The logfile is a CSV of the format [congestion_control, loss_rate, goodput, rtt, capacity, specified_bw] """ results = {} plt.figure() # For available options on plot() method, see: https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot # We prefer to use explicit keyword syntax to help code readability. # Create a figure. fig_width = 8 fig_height = 5 fig, axes = plt.subplots(figsize=(fig_width, fig_height)) results = parse_results_csv(logfile) xmark_ticks = get_loss_percent_xmark_ticks(results) # We gather results for the following congestion control algoirhtms: # cubic bbr bic vegas westwood reno cubic = results['cubic'] bbr = results['bbr'] bic = results['bic'] vegas = results['vegas'] westwood = results['westwood'] reno = results['reno'] debug_print_verbose("CUBIC: %s" % cubic) debug_print_verbose("BBR: %s" % bbr) debug_print_verbose("BIC: %s" % bic) debug_print_verbose("VEGAS: %s" % vegas) debug_print_verbose("WESTWOOD: %s" % westwood) debug_print_verbose("RENO: %s" % reno) matplotlib.rcParams.update({'figure.autolayout': True}) # Plot the results of the different congestion control algorithms plt.plot(cubic['loss'], cubic['goodput'], color='blue', linestyle='solid', marker='o', markersize=7, label='CUBIC') plt.plot(bbr['loss'], bbr['goodput'], color='red', linestyle='solid', marker='x', markersize=7, label='BBR') plt.plot(bic['loss'], bic['goodput'], color='#addd8e', linestyle='solid', marker='.', markersize=7, label='BIC') plt.plot(vegas['loss'], vegas['goodput'], color='#78c679', linestyle='solid', marker='.', markersize=7, label='VEGAS') plt.plot(westwood['loss'], westwood['goodput'], color='#31a354', linestyle='solid', marker='.', markersize=7, label='WESTWOOD') plt.plot(reno['loss'], reno['goodput'], color='#006837', linestyle='solid', marker='.', markersize=7, label='RENO') plt.xscale('log') plot_titles(plt, xaxis="Loss Rate (%) - Log Scale", yaxis="Goodput (Mbps)") apply_axes_formatting(axes, deduplicate_xmark_ticks(xmark_ticks)) plot_legend(plt, axes, ncol=3, fontsize=10) save_figure(plt, name="figures/experiment2.png")
def make_experiment1_figure(logfile): """Generate high quality plot of data for Experiment 1. Experiment 1 is looking at effects of various bandwithd between CUBIC and BBR. The logfile is a CSV of the format [congestion_control, loss_rate, goodput, rtt, capacity, specified_bw] """ results = {} plt.figure() # For available options on plot() method, see: https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot # We prefer to use explicit keyword syntax to help code readability. # Create a figure. fig_width = 8 fig_height = 5 fig, axes = plt.subplots(figsize=(fig_width, fig_height)) results = parse_results_csv(logfile) debug_print_verbose('Parsed Results: %s' % results) xmark_ticks = get_loss_percent_xmark_ticks(results) cubic = results['cubic'] debug_print_verbose("--- Generating figures for experiment 1") bandwidth_filter_list = sorted(list(set(cubic['specified_bw']))) debug_print_verbose("Bandwidth list: %s" % bandwidth_filter_list) matplotlib.rcParams.update({'figure.autolayout': True}) plt.xscale('log') # Tool for easily visualing color schemes: # http://colorbrewer2.org/#type=sequential&scheme=Reds&n=8 cubic_bandwidth_colors = [ '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#084594' ] bbr_bandwidth_colors = [ '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#99000d' ] for index, bandwidth_filter in enumerate(bandwidth_filter_list): def include_predicate_fn(congestion_control, loss, goodput, rtt, capacity, specified_bw): return is_same_float(specified_bw, bandwidth_filter) filtered_result = parse_results_csv(logfile, include_predicate_fn) debug_print_verbose("Filtered Results %s : %s" % (bandwidth_filter, filtered_result)) filtered_cubic = filtered_result['cubic'] filtered_bbr = filtered_result['bbr'] debug_print_verbose("Filter CUBIC: %s" % filtered_cubic) debug_print_verbose("Filter BBR: %s" % filtered_bbr) cubic_color = cubic_bandwidth_colors[index] bbr_color = bbr_bandwidth_colors[index] plt.plot(filtered_cubic['loss'], filtered_cubic['normalized_goodput'], color=cubic_color, linestyle='solid', marker='o', markersize=7, label='CUBIC (%s Mbps)' % bandwidth_filter) plt.plot(filtered_bbr['loss'], filtered_bbr['normalized_goodput'], color=bbr_color, linestyle='solid', marker='x', markersize=7, label='BBR (%s Mbps)' % bandwidth_filter) plot_titles(plt, xaxis="Loss Rate (%) - Log Scale", yaxis="Normalized Goodput") apply_axes_formatting(axes, deduplicate_xmark_ticks(xmark_ticks)) plot_legend(plt, axes, fontsize=10) save_figure(plt, name="figures/experiment1.png")