forked from osrg/gobgp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvis.py
More file actions
101 lines (88 loc) · 3.32 KB
/
vis.py
File metadata and controls
101 lines (88 loc) · 3.32 KB
1
#!/usr/bin/env python3import jsonimport matplotlib.pyplot as pltimport numpy as npFILES = { "oBGP": "report_obgp.json", "BGP": "report_bgp.json"}MODE_COLORS = { "oBGP": "#f15bb5", "BGP": "#00f5d4",}def load_data(filename): with open(filename, "r") as f: return json.load(f)def aggregate_percentiles(data, field, steps=None): if steps is None: steps = list(range(10, 91, 5)) observers = data.get("observers", {}) max_len = max(len(obs["series"]) for obs in observers.values()) all_series = [] for obs in observers.values(): series = [s.get(field, 0) for s in obs["series"]] if len(series) < max_len: series += [0] * (max_len - len(series)) all_series.append(series) all_series = np.array(all_series) percentiles = {p: np.percentile(all_series, p, axis=0) for p in steps} return percentilesdef plot_density_gradient(ax, perc, color, title, ylabel): x = range(len(next(iter(perc.values())))) steps = sorted(perc.keys()) mid = len(steps) // 2 for i in range(mid): low = steps[i] high = steps[-(i+1)] alpha = 0.1 + 0.15 * (1 - i/mid) ax.fill_between(x, perc[low], perc[high], color=color, alpha=alpha) ax.set_title(title, fontsize=13, weight="bold") ax.set_xlabel("Sample index", fontsize=11) ax.set_ylabel(ylabel, fontsize=11) ax.grid(True, alpha=0.3)if __name__ == "__main__": fig, axes = plt.subplots(4, 2, figsize=(16, 16), sharex=True, sharey="row") data_obgp = load_data(FILES["oBGP"]) perc_paths_obgp = aggregate_percentiles(data_obgp, "num_paths") perc_dests_obgp = aggregate_percentiles(data_obgp, "num_destinations") perc_len_min_obgp = aggregate_percentiles(data_obgp, "path_len_min") perc_len_max_obgp = aggregate_percentiles(data_obgp, "path_len_max") data_bgp = load_data(FILES["BGP"]) perc_paths_bgp = aggregate_percentiles(data_bgp, "num_paths") perc_dests_bgp = aggregate_percentiles(data_bgp, "num_destinations") perc_len_min_bgp = aggregate_percentiles(data_bgp, "path_len_min") perc_len_max_bgp = aggregate_percentiles(data_bgp, "path_len_max") plot_density_gradient( axes[0, 0], perc_paths_obgp, MODE_COLORS["oBGP"], "oBGP – Routes", "Number of routes" ) plot_density_gradient( axes[0, 1], perc_paths_bgp, MODE_COLORS["BGP"], "BGP – Routes", "Number of routes" ) plot_density_gradient( axes[1, 0], perc_dests_obgp, MODE_COLORS["oBGP"], "oBGP – Destinations", "Number of destinations" ) plot_density_gradient( axes[1, 1], perc_dests_bgp, MODE_COLORS["BGP"], "BGP – Destinations", "Number of destinations" ) plot_density_gradient( axes[2, 0], perc_len_min_obgp, MODE_COLORS["oBGP"], "oBGP – Minimum path length", "Path length" ) plot_density_gradient( axes[2, 1], perc_len_min_bgp, MODE_COLORS["BGP"], "BGP – Minimum path length", "Path length" ) plot_density_gradient( axes[3, 0], perc_len_max_obgp, MODE_COLORS["oBGP"], "oBGP – Maximum path length", "Path length" ) plot_density_gradient( axes[3, 1], perc_len_max_bgp, MODE_COLORS["BGP"], "BGP – Maximum path length", "Path length" ) plt.tight_layout(rect=[0, 0, 1, 0.97]) plt.show()