Skip to content

Commit

Permalink
Merge pull request #31 from YousefEZ/fixpcap
Browse files Browse the repository at this point in the history
🐛 Fix PCAP analysis
  • Loading branch information
YousefEZ authored Apr 12, 2024
2 parents 103df52 + e969ad2 commit c6b219a
Show file tree
Hide file tree
Showing 22 changed files with 588 additions and 431 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/bandwidth_alternate-baseline_udp-frr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pcap_analysis/plots/bandwidth_alternate-udp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/bandwidth_primary-baseline_udp-frr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pcap_analysis/plots/bandwidth_primary-no-udp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pcap_analysis/plots/bandwidth_primary-udp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/delay_all-baseline_no_udp-frr_no_udp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/delay_all-baseline_udp-frr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/delay_alternate-baseline_udp-frr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pcap_analysis/plots/delay_primary-baseline_udp-frr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 117 additions & 53 deletions pcap_analysis/process_pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from scapy.all import *
import matplotlib.pyplot as plt

import numpy as np

def read_pcap(filename):
packets = []
Expand Down Expand Up @@ -60,49 +60,108 @@ def flow_completion_time(packets):


# def save_plot(timestamp, completion_time, stream_direction):
# os.makedirs("/host/pcap_analysis/plots", exist_ok=True)
# os.makedirs("../pcap_analysis/plots", exist_ok=True)
# plt.plot(timestamp, completion_time, label=stream_direction, marker='o')
# plt.xlabel("time stamp of the sender of the packet")
# plt.ylabel("transfer completion time")
#
# plt.savefig("/host/pcap_analysis/plots/completion_time-timestamp.png")
# plt.savefig("../pcap_analysis/plots/completion_time-timestamp.png")

def get_avg_fc_time(source_directory):

seeds = os.listdir(source_directory)
fc_time = 0.0
for seed in seeds:
sd = f"{source_directory}/{seed}/-TrafficSender0-1.pcap"
result = flow_completion_time(read_pcap(sd))
assert result is not None, "Unable to read from directory"
fc_time += result
print(source_directory, fc_time / len(seeds))
return fc_time / len(seeds)

def record_result(source_directory, variable, queue_size, scenario, results):
fc_time = get_avg_fc_time(f"{source_directory}{variable}/{queue_size}/{scenario}")
results.append((scenario.replace("-", "_"), queue_size, fc_time, variable))


def generate_queue_size_dict():
return {"20": 0.0, "40": 0.0, "60": 0.0, "80": 0.0, "base": 0.0}

def generate_variable_dict(variables):
return {variable: generate_queue_size_dict() for variable in variables}

scenarios = ["baseline-no-udp", "baseline-udp", "frr-no-udp", "frr"]

cases = ["no-udp", "udp"]

def record_flow_completion_time(source_directory, result_directory, mode):
variables = os.listdir(source_directory)
results = []
results = {case: generate_variable_dict(variables) for case in cases}

for variable in variables:
if os.path.isdir(os.path.join(source_directory, variable)):
queue_sizes = os.listdir(source_directory + variable)
for queue_size in queue_sizes:
if os.path.isdir(os.path.join(source_directory + variable + "/" + queue_size)) and queue_size != '99':
senderPackets = read_pcap(
source_directory + variable + "/" + queue_size + "/" + "baseline-no-udp/-TrafficSender-1.pcap")
fc_time = flow_completion_time(senderPackets)
results.append(("baseline_no_udp", queue_size, fc_time, variable))

senderPackets = read_pcap(
source_directory + variable + "/" + queue_size + "/" + "baseline-udp/-TrafficSender-1.pcap")
fc_time = flow_completion_time(senderPackets)
results.append(("baseline_udp", queue_size, fc_time, variable))

senderPackets = read_pcap(
source_directory + variable + "/" + queue_size + "/" + "frr-no-udp/-TrafficSender-1.pcap")
fc_time = flow_completion_time(senderPackets)
results.append(("frr_no_udp", queue_size, fc_time, variable))

senderPackets = read_pcap(
source_directory + variable + "/" + queue_size + "/" + "frr/-TrafficSender-1.pcap")
fc_time = flow_completion_time(senderPackets)
results.append(("frr", queue_size, fc_time, variable))

for case in cases:
for queue_size in queue_sizes:
if os.path.isdir(os.path.join(source_directory + variable + "/" + queue_size)) and queue_size != '99':
if case == "udp":
results[case][variable][queue_size] = get_avg_fc_time(f"{source_directory}{variable}/{queue_size}/frr")
else:
results[case][variable][queue_size] = get_avg_fc_time(f"{source_directory}{variable}/{queue_size}/frr-{case}")
results[case][variable]['base'] = get_avg_fc_time(f"{source_directory}{variable}/20/baseline-{case}")

filepath = os.path.join(result_directory, f"{mode}.txt")
with open(filepath, 'w') as f:
for result in results:
f.write(str(result) + "\n")
for case, variables in results.items():
for variable, queue_sizes in variables.items():
for queue_size, result in queue_sizes.items():
f.write(f"{case} {variable} {queue_size} {result}\n")

return results

def get_scaling_results(results, case, queue_size):
output = {}
for variable, queue_sizes in results[case].items():
output[variable] = queue_sizes[queue_size]
return output

queue_sizes = ["20", "40", "60", "80", "base"]

def extract_integer(string):
for i in range(len(string)):
if not string[i].isdigit() and string[i] != ".":
return float(string[:i])
return None

def plot_flow_comp_time(results, case, mode):
plt.figure(figsize=(12, 6)) # Increase the width to 12 inches and height to 6 inches

for queue_size in queue_sizes:
output = get_scaling_results(results, case, queue_size)

best_fit = False

scaling_var = sorted(list(output.keys()))
scaling_results = [float(output[var]) for var in scaling_var]

if best_fit:
floats = list(map(extract_integer, scaling_var))
scaling_var_float = np.array(floats)

x, y = np.polyfit(scaling_var_float, np.array(scaling_results), 1)
plt.plot(scaling_var, x*scaling_var_float+y, label=queue_size)
else:
plt.plot(scaling_var, scaling_results, label=queue_size)
# plt.plot(scaling_var, scaling_results, label=queue_size)

plt.ylabel("flow completion time in seconds")
plt.xlabel(mode)
plt.legend()

plt.savefig(f"../pcap_analysis/plots/{mode}-{case}.png", dpi=300)
plt.clf()



def plot_flow_completion_time(results, mode, cases):
sorted_results = sorted(results,
Expand Down Expand Up @@ -175,39 +234,44 @@ def plot_flow_completion_time(results, mode, cases):
figure.subplots_adjust(left=0.2)
# figure.tight_layout()

figure.savefig(f"/host/pcap_analysis/plots/{mode}-{cases[0]}-{cases[1]}.png", dpi=300)
figure.savefig(f"../pcap_analysis/plots/{mode}-{cases[0]}-{cases[1]}.png", dpi=300)


if __name__ == '__main__':
os.makedirs("/host/pcap_analysis/results", exist_ok=True)
os.makedirs("/host/pcap_analysis/plots", exist_ok=True)
os.makedirs("../pcap_analysis/results", exist_ok=True)
os.makedirs("../pcap_analysis/plots", exist_ok=True)

bandwidth_primary_results = record_flow_completion_time("../traces/bandwidth_primary/",
"../pcap_analysis/results", "bandwidth_primary")
plot_flow_comp_time(bandwidth_primary_results, "udp", "bandwidth_primary")
plot_flow_comp_time(bandwidth_primary_results, "no-udp", "bandwidth_primary")

bandwidth_primary_results = record_flow_completion_time("/host/experiments/bandwidth-primary/",
"/host/pcap_analysis/results", "bandwidth_primary")
plot_flow_completion_time(bandwidth_primary_results, "bandwidth_primary", ['baseline_no_udp', 'frr_no_udp'])
#plot_flow_completion_time(bandwidth_primary_results, "bandwidth_primary", ['baseline_no_udp', 'frr_no_udp'])
# no udp
plot_flow_completion_time(bandwidth_primary_results, "bandwidth_primary", ['baseline_udp', 'frr'])
#plot_flow_completion_time(bandwidth_primary_results, "bandwidth_primary", ['baseline_udp', 'frr'])
# with udp

bandwidth_alternate_results = record_flow_completion_time("/host/experiments/bandwidth-alternate/",
"/host/pcap_analysis/results", "bandwidth_alternate")
plot_flow_completion_time(bandwidth_alternate_results, "bandwidth_alternate", ['baseline_no_udp', 'frr_no_udp'])
plot_flow_completion_time(bandwidth_alternate_results, "bandwidth_alternate", ['baseline_udp', 'frr'])
#bandwidth_alternate_results = record_flow_completion_time("../traces/bandwidth_alternate/",
# "../pcap_analysis/results", "bandwidth_alternate")
#plot_flow_comp_time(bandwidth_alternate_results, "udp", "bandwidth_alternate")
#plot_flow_comp_time(bandwidth_alternate_results, "no-udp", "bandwidth_alternate")
#plot_flow_completion_time(bandwidth_alternate_results, "bandwidth_alternate", ['baseline_no_udp', 'frr_no_udp'])
#plot_flow_completion_time(bandwidth_alternate_results, "bandwidth_alternate", ['baseline_udp', 'frr'])

delay_all_results = record_flow_completion_time("/host/experiments/delay-all/",
"/host/pcap_analysis/results", "delay_all")
plot_flow_completion_time(delay_all_results, "delay_all", ['baseline_no_udp', 'frr_no_udp'])
plot_flow_completion_time(delay_all_results, "delay_all", ['baseline_udp', 'frr'])
#delay_all_results = record_flow_completion_time("../traces/delay_all/",
# "../pcap_analysis/results", "delay_all")
#plot_flow_completion_time(delay_all_results, "delay_all", ['baseline_no_udp', 'frr_no_udp'])
#plot_flow_completion_time(delay_all_results, "delay_all", ['baseline_udp', 'frr'])

delay_primary_results = record_flow_completion_time("/host/experiments/delay-primary/",
"/host/pcap_analysis/results", "delay_primary")
plot_flow_completion_time(delay_primary_results, "delay_primary", ['baseline_no_udp', 'frr_no_udp'])
plot_flow_completion_time(delay_primary_results, "delay_primary", ['baseline_udp', 'frr'])
#delay_primary_results = record_flow_completion_time("../traces/delay_primary/",
# "../pcap_analysis/results", "delay_primary")
#plot_flow_completion_time(delay_primary_results, "delay_primary", ['baseline_no_udp', 'frr_no_udp'])
#plot_flow_completion_time(delay_primary_results, "delay_primary", ['baseline_udp', 'frr'])

delay_alternate_results = record_flow_completion_time("/host/experiments/delay-alternate/",
"/host/pcap_analysis/results", "delay_alternate")
plot_flow_completion_time(delay_alternate_results, "delay_alternate", ['baseline_no_udp', 'frr_no_udp'])
plot_flow_completion_time(delay_alternate_results, "delay_alternate", ['baseline_udp', 'frr'])
#delay_alternate_results = record_flow_completion_time("../traces/delay_alternate/",
# "../pcap_analysis/results", "delay_alternate")
#plot_flow_completion_time(delay_alternate_results, "delay_alternate", ['baseline_no_udp', 'frr_no_udp'])
#plot_flow_completion_time(delay_alternate_results, "delay_alternate", ['baseline_udp', 'frr'])

# results = []
#
Expand All @@ -224,8 +288,8 @@ def plot_flow_completion_time(results, mode, cases):
# results.append(result)
# # save_plot(timestamp, completion_time, stream_direction)
#
# os.makedirs("/host/pcap_analysis/results", exist_ok=True)
# os.makedirs("../pcap_analysis/results", exist_ok=True)
#
# with open("/host/pcap_analysis/results/results.txt", "w") as f:
# with open("../pcap_analysis/results/results.txt", "w") as f:
# for result in results:
# f.write(result)
170 changes: 90 additions & 80 deletions pcap_analysis/results/bandwidth_alternate.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,90 @@
('baseline_no_udp', '60', Decimal('6.390986'), '800Kbps')
('baseline_udp', '60', Decimal('8.900453'), '800Kbps')
('frr_no_udp', '60', Decimal('3.233893'), '800Kbps')
('frr', '60', Decimal('3.636093'), '800Kbps')
('baseline_no_udp', '20', Decimal('6.390986'), '800Kbps')
('baseline_udp', '20', Decimal('8.900453'), '800Kbps')
('frr_no_udp', '20', Decimal('2.946426'), '800Kbps')
('frr', '20', Decimal('3.501319'), '800Kbps')
('baseline_no_udp', '80', Decimal('6.390986'), '800Kbps')
('baseline_udp', '80', Decimal('8.900453'), '800Kbps')
('frr_no_udp', '80', Decimal('3.262639'), '800Kbps')
('frr', '80', Decimal('4.251466'), '800Kbps')
('baseline_no_udp', '40', Decimal('6.390986'), '800Kbps')
('baseline_udp', '40', Decimal('8.900453'), '800Kbps')
('frr_no_udp', '40', Decimal('3.018293'), '800Kbps')
('frr', '40', Decimal('3.306693'), '800Kbps')
('baseline_no_udp', '60', Decimal('6.390986'), '1000Kbps')
('baseline_udp', '60', Decimal('8.900453'), '1000Kbps')
('frr_no_udp', '60', Decimal('3.047039'), '1000Kbps')
('frr', '60', Decimal('4.745221'), '1000Kbps')
('baseline_no_udp', '20', Decimal('6.390986'), '1000Kbps')
('baseline_udp', '20', Decimal('8.900453'), '1000Kbps')
('frr_no_udp', '20', Decimal('2.817066'), '1000Kbps')
('frr', '20', Decimal('5.015125'), '1000Kbps')
('baseline_no_udp', '80', Decimal('6.390986'), '1000Kbps')
('baseline_udp', '80', Decimal('8.900453'), '1000Kbps')
('frr_no_udp', '80', Decimal('3.104533'), '1000Kbps')
('frr', '80', Decimal('5.043573'), '1000Kbps')
('baseline_no_udp', '40', Decimal('6.390986'), '1000Kbps')
('baseline_udp', '40', Decimal('8.900453'), '1000Kbps')
('frr_no_udp', '40', Decimal('2.903306'), '1000Kbps')
('frr', '40', Decimal('4.245994'), '1000Kbps')
('baseline_no_udp', '60', Decimal('6.390986'), '200Kbps')
('baseline_udp', '60', Decimal('8.900453'), '200Kbps')
('frr_no_udp', '60', Decimal('3.751333'), '200Kbps')
('frr', '60', Decimal('6.023146'), '200Kbps')
('baseline_no_udp', '20', Decimal('6.390986'), '200Kbps')
('baseline_udp', '20', Decimal('8.900453'), '200Kbps')
('frr_no_udp', '20', Decimal('3.666266'), '200Kbps')
('frr', '20', Decimal('5.896239'), '200Kbps')
('baseline_no_udp', '80', Decimal('6.390986'), '200Kbps')
('baseline_udp', '80', Decimal('8.900453'), '200Kbps')
('frr_no_udp', '80', Decimal('3.780079'), '200Kbps')
('frr', '80', Decimal('6.534879'), '200Kbps')
('baseline_no_udp', '40', Decimal('6.390986'), '200Kbps')
('baseline_udp', '40', Decimal('8.900453'), '200Kbps')
('frr_no_udp', '40', Decimal('6.108559'), '200Kbps')
('frr', '40', Decimal('7.952719'), '200Kbps')
('baseline_no_udp', '60', Decimal('6.390986'), '600Kbps')
('baseline_udp', '60', Decimal('8.900453'), '600Kbps')
('frr_no_udp', '60', Decimal('3.236239'), '600Kbps')
('frr', '60', Decimal('5.426933'), '600Kbps')
('baseline_no_udp', '20', Decimal('6.390986'), '600Kbps')
('baseline_udp', '20', Decimal('8.900453'), '600Kbps')
('frr_no_udp', '20', Decimal('2.948773'), '600Kbps')
('frr', '20', Decimal('3.091626'), '600Kbps')
('baseline_no_udp', '80', Decimal('6.390986'), '600Kbps')
('baseline_udp', '80', Decimal('8.900453'), '600Kbps')
('frr_no_udp', '80', Decimal('3.263813'), '600Kbps')
('frr', '80', Decimal('4.438213'), '600Kbps')
('baseline_no_udp', '40', Decimal('6.390986'), '600Kbps')
('baseline_udp', '40', Decimal('8.900453'), '600Kbps')
('frr_no_udp', '40', Decimal('3.022399'), '600Kbps')
('frr', '40', Decimal('4.931786'), '600Kbps')
('baseline_no_udp', '60', Decimal('6.390986'), '400Kbps')
('baseline_udp', '60', Decimal('8.900453'), '400Kbps')
('frr_no_udp', '60', Decimal('2.882919'), '400Kbps')
('frr', '60', Decimal('4.140639'), '400Kbps')
('baseline_no_udp', '20', Decimal('6.390986'), '400Kbps')
('baseline_udp', '20', Decimal('8.900453'), '400Kbps')
('frr_no_udp', '20', Decimal('3.076373'), '400Kbps')
('frr', '20', Decimal('4.464826'), '400Kbps')
('baseline_no_udp', '80', Decimal('6.390986'), '400Kbps')
('baseline_udp', '80', Decimal('8.900453'), '400Kbps')
('frr_no_udp', '80', Decimal('2.963146'), '400Kbps')
('frr', '80', Decimal('4.420373'), '400Kbps')
('baseline_no_udp', '40', Decimal('6.390986'), '400Kbps')
('baseline_udp', '40', Decimal('8.900453'), '400Kbps')
('frr_no_udp', '40', Decimal('3.075786'), '400Kbps')
('frr', '40', Decimal('5.853919'), '400Kbps')
no-udp 400Kbps 20 2.333640
no-udp 400Kbps 40 2.549240
no-udp 400Kbps 60 2.894200
no-udp 400Kbps 80 2.721720
no-udp 400Kbps base 4.521973
no-udp 325Kbps 20 2.333640
no-udp 325Kbps 40 2.441440
no-udp 325Kbps 60 2.829520
no-udp 325Kbps 80 2.700160
no-udp 325Kbps base 4.521973
no-udp 275Kbps 20 2.333640
no-udp 275Kbps 40 2.441440
no-udp 275Kbps 60 2.829520
no-udp 275Kbps 80 2.700160
no-udp 275Kbps base 4.521973
no-udp 200Kbps 20 2.376760
no-udp 200Kbps 40 2.398320
no-udp 200Kbps 60 2.549240
no-udp 200Kbps 80 2.721720
no-udp 200Kbps base 4.521973
no-udp 350Kbps 20 2.333640
no-udp 350Kbps 40 2.441440
no-udp 350Kbps 60 2.829520
no-udp 350Kbps 80 2.700160
no-udp 350Kbps base 4.521973
no-udp 225Kbps 20 2.376760
no-udp 225Kbps 40 2.398320
no-udp 225Kbps 60 2.549240
no-udp 225Kbps 80 2.721720
no-udp 225Kbps base 4.521973
no-udp 250Kbps 20 2.333640
no-udp 250Kbps 40 2.441440
no-udp 250Kbps 60 2.829520
no-udp 250Kbps 80 2.700160
no-udp 250Kbps base 4.521973
no-udp 300Kbps 20 2.333640
no-udp 300Kbps 40 2.441440
no-udp 300Kbps 60 2.829520
no-udp 300Kbps 80 2.700160
no-udp 300Kbps base 4.521973
no-udp 375Kbps 20 2.333640
no-udp 375Kbps 40 2.441440
no-udp 375Kbps 60 2.829520
no-udp 375Kbps 80 2.700160
no-udp 375Kbps base 4.521973
udp 400Kbps 20 2.333640
udp 400Kbps 40 2.549240
udp 400Kbps 60 3.897306
udp 400Kbps 80 2.721720
udp 400Kbps base 8.540880
udp 325Kbps 20 2.333640
udp 325Kbps 40 2.441440
udp 325Kbps 60 2.829520
udp 325Kbps 80 2.700160
udp 325Kbps base 8.540880
udp 275Kbps 20 2.333640
udp 275Kbps 40 2.441440
udp 275Kbps 60 2.829520
udp 275Kbps 80 2.700160
udp 275Kbps base 8.540880
udp 200Kbps 20 2.376760
udp 200Kbps 40 2.398320
udp 200Kbps 60 2.549240
udp 200Kbps 80 2.721720
udp 200Kbps base 8.540880
udp 350Kbps 20 2.333640
udp 350Kbps 40 2.441440
udp 350Kbps 60 2.829520
udp 350Kbps 80 2.700160
udp 350Kbps base 8.540880
udp 225Kbps 20 2.376760
udp 225Kbps 40 2.398320
udp 225Kbps 60 2.549240
udp 225Kbps 80 2.721720
udp 225Kbps base 8.540880
udp 250Kbps 20 2.333640
udp 250Kbps 40 2.441440
udp 250Kbps 60 2.829520
udp 250Kbps 80 2.700160
udp 250Kbps base 8.540880
udp 300Kbps 20 2.333640
udp 300Kbps 40 2.441440
udp 300Kbps 60 2.829520
udp 300Kbps 80 2.700160
udp 300Kbps base 8.540880
udp 375Kbps 20 2.333640
udp 375Kbps 40 2.441440
udp 375Kbps 60 2.829520
udp 375Kbps 80 2.700160
udp 375Kbps base 8.540880
Loading

0 comments on commit c6b219a

Please sign in to comment.