Skip to content

Commit

Permalink
refactor analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Peters committed Nov 26, 2024
1 parent d99af93 commit 6550e93
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 57 deletions.
67 changes: 20 additions & 47 deletions xray/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def __init__(self, csv_name):

class PcapData:
def __init__(self, pcap_name):
# pcaps
# for each packet, show it (with timestamps)
# 1. leaving original socket
# 2. arriving at wg interface
# 3. leaving wg interface
# 4. arriving at destination socket
# with this info
# - draw funnel diagram
# - Show different distribution graphs or maybe a graph with three data points showing the span and normal distribution of those data points (apparently called box plot)
# 1. time from og socket to wg
# 2. time from wg enter to wg exit (how do I know which packet entering is which packet exiting?)
# 3. time from wg to dst socket
pass

class Analyzer:
Expand All @@ -48,11 +60,13 @@ def __init__(self, csv_name, pcap_name, count):
pcap = [self.packet_latency]

fig, ax = plt.subplots(nrows=max(len(csv), len(pcap)), ncols=2)
fig.tight_layout(pad=5)

for i, fn in enumerate(csv):
fn(ax[i, 0])
for i, fn in enumerate(pcap):
fn(ax[i, 1])

fig.tight_layout()
plt.show()


Expand Down Expand Up @@ -84,8 +98,8 @@ def packet_ordering(self, ax):
y_axis.append(None)
x_axis.append(i + 1)
ax.set_title("Packet order")
# ax.xlabel("Received order")
# ax.ylabel("Packet index")
ax.set_xlabel("Received order")
ax.set_ylabel("Packet index")
ax.plot(x_axis, y_axis)

def packet_latency(self, ax):
Expand All @@ -96,35 +110,10 @@ def packet_latency(self, ax):
bucket_index = int((ts - self.csv_data.min_ts) / bucket_size)
buckets.append(self.csv_data.min_ts + (bucket_index * bucket_size))
ax.set_title("Latency")
# ax.xlabel("Latency (nanosecond)")
# ax.ylabel("Count")
ax.set_xlabel("Latency (nanosecond)")
ax.set_ylabel("Count")
ax.hist(buckets, color="blue", bins=num_buckets)


def analyze_csv(file_name, count):
# prepare data
indices = []
timestamps = []
min_timestamp = -1
max_timestamp = -1
with open(file_name, newline="") as csvfile:
reader = csv.reader(csvfile, delimiter=",", quotechar="|")
next(reader)
for row in reader:
indices.append(int(row[0]))
ts = int(row[2]) - int(row[1])
timestamps.append(ts)
if min_timestamp < 0 or ts < min_timestamp:
min_timestamp = ts
if max_timestamp < 0 or ts > max_timestamp:
max_timestamp = ts

plt.subplot(3, 1, 1)

plt.subplot(3, 1, 2)

plt.subplot(3, 1, 3)



# This counts in-order packets by looking at series of successive packets
# the length of the sequence could be considered a number of packest in order
Expand All @@ -147,19 +136,3 @@ def count_ordered(data):
prev = data[i]
ordered += range_len - (0 if range_good_start else 1)
return ordered


def analyze_pcap(file_name, count):
# pcaps
# for each packet, show it (with timestamps)
# 1. leaving original socket
# 2. arriving at wg interface
# 3. leaving wg interface
# 4. arriving at destination socket
# with this info
# - draw funnel diagram
# - Show different distribution graphs or maybe a graph with three data points showing the span and normal distribution of those data points (apparently called box plot)
# 1. time from og socket to wg
# 2. time from wg enter to wg exit (how do I know which packet entering is which packet exiting?)
# 3. time from wg to dst socket
pass
20 changes: 10 additions & 10 deletions xray/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ def main():
assert count > 0, f"Count must be at least one, but got {count}"
build_neptun = args.nobuild is None

# setup_wireguard(wg, build_neptun)
# tcpdump = start_tcpdump(get_pcap_name(wg.name, test_type))
setup_wireguard(wg, build_neptun)
tcpdump = start_tcpdump(get_pcap_name(wg.name, test_type))

# try:
# run_xray(wg.name, test_type, count)
# finally:
# stop_tcpdump(tcpdump)
# destroy_wireguard(wg)
try:
run_xray(wg.name, test_type, count)
finally:
stop_tcpdump(tcpdump)
destroy_wireguard(wg)

analyze(
get_csv_name(wg.name, test_type), get_pcap_name(wg.name, test_type), count
)
analyze(
get_csv_name(wg.name, test_type), get_pcap_name(wg.name, test_type), count
)


if __name__ == "__main__":
Expand Down

0 comments on commit 6550e93

Please sign in to comment.