Skip to content

Commit

Permalink
Save output text and post it as comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-grz committed Dec 19, 2024
1 parent d853f5c commit 42387d4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,31 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- name: Install wg
- name: Setup
working-directory: xray
run: |
sudo apt-get update
sudo apt-get install -y wireguard
- name: Setup pipenv
working-directory: xray
run: |
sudo apt install -y wireguard-go
python -m pip install --upgrade pip
pip install pipenv
pipenv install
- name: Execute xray
working-directory: xray
run: pipenv run python run.py --wg native --ascii --save-chart
- name: Upload results
run: |
pipenv run python run.py --wg native --ascii --save-output
pipenv run python run.py --wg wggo --ascii --save-output
pipenv run python run.py --wg neptun --ascii --save-output
- name: Upload graph results
uses: actions/upload-artifact@v4
with:
name: xray-results
path: xray/results/*.png
- name: Results
working-directory: xray/results
run: |
for file in *.txt; do
echo "----- $file -----"
cat "$file"
echo ""
done
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

**/*.csv
**/*.pcap
**/*.png
**/*.sk
**/*.pk
**/__pycache__
2 changes: 1 addition & 1 deletion xray/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!xray_setup.png
results/
20 changes: 11 additions & 9 deletions xray/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import mpl_ascii


def analyze(csv_path, pcap_path, count, test_type, png_path, ascii):
Analyzer(csv_path, pcap_path, count, test_type, png_path, ascii)
def analyze(csv_path, test_path, count, test_type, ascii, save_output):
Analyzer(csv_path, test_path, count, test_type, ascii, save_output)


class CsvData:
Expand Down Expand Up @@ -63,10 +63,10 @@ def __init__(self, pcap_path, test_type):


class Analyzer:
def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
def __init__(self, csv_name, test_path, count, test_type, ascii, save_output):
self.count = count
self.csv_data = CsvData(csv_name)
self.pcap_data = PcapData(pcap_name, test_type)
self.pcap_data = PcapData(test_path + ".pcap", test_type)

graphs = [
self.ordering_pie_chart,
Expand All @@ -86,12 +86,12 @@ def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
fn(ax[i, 1])

plt.show()
if png_path:
plt.savefig(png_path)
if save_output:
plt.savefig(test_path + ".png")

if ascii:
mpl_ascii.AXES_WIDTH=100
mpl_ascii.AXES_HEIGHT=40
mpl_ascii.AXES_WIDTH = 70
mpl_ascii.AXES_HEIGHT = 25
mpl.use("module://mpl_ascii")
graphs = [
self.packet_ordering,
Expand All @@ -102,12 +102,14 @@ def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
rows = len(graphs)

fig, ax = plt.subplots(nrows=rows)
# fig.tight_layout(pad=)
fig.tight_layout()

for i, fn in enumerate(graphs):
fn(ax[i])

plt.show()
if save_output:
plt.savefig(test_path + ".txt")

def ordering_pie_chart(self, ax):
in_order = count_ordered(self.csv_data.indices, self.count)
Expand Down
26 changes: 11 additions & 15 deletions xray/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ def get_csv_name(wg, test_type, count):
return f"results/xray_metrics_{wg.lower()}_{test_type}_{count}.csv"


def get_pcap_name(wg, test_type, count):
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}.pcap"


def get_png_name(wg, test_type, count):
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}.png"
def get_test_path(wg, test_type, count):
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}"


class Wireguard(Enum):
Expand All @@ -53,7 +49,7 @@ def setup_wireguard(wg, build_neptun):
run_command(f"sudo ip link add dev {WG_IFC_NAME} type wireguard")
elif wg == Wireguard.WgGo:
wggo = (
run_command("which wireguard", capture_output=True)[0]
run_command("which wireguard-go", capture_output=True)[0]
.strip()
.decode("utf-8")
)
Expand Down Expand Up @@ -108,7 +104,7 @@ def main():
parser.add_argument("--count")
parser.add_argument("--nobuild-neptun", action="store_true")
parser.add_argument("--nobuild-xray", action="store_true")
parser.add_argument("--save-chart", action="store_true")
parser.add_argument("--save-output", action="store_true")
parser.add_argument("--ascii", action="store_true")
args = parser.parse_args()

Expand All @@ -122,18 +118,18 @@ def main():
assert count > 0, f"Count must be at least one, but got {count}"
build_neptun = args.nobuild_neptun is False
build_xray = args.nobuild_xray is False
png_path = get_png_name(wg.name, test_type, count) if args.save_chart else None

Path("results/").mkdir(parents=True, exist_ok=True)
try:
os.remove(get_csv_name(wg.name, test_type, count))
os.remove(get_pcap_name(wg.name, test_type, count))
os.remove(get_png_name(wg.name, test_type, count))
os.remove(get_test_path(wg.name, test_type, count) + ".pcap")
os.remove(get_test_path(wg.name, test_type, count) + ".png")
os.remove(get_test_path(wg.name, test_type, count) + ".txt")
except: # noqa: E722
pass

setup_wireguard(wg, build_neptun)
tcpdump = start_tcpdump(get_pcap_name(wg.name, test_type, count))
tcpdump = start_tcpdump(get_test_path(wg.name, test_type, count) + ".pcap")

succeeded = True
try:
Expand All @@ -148,11 +144,11 @@ def main():
if succeeded:
analyze(
get_csv_name(wg.name, test_type, count),
get_pcap_name(wg.name, test_type, count),
get_test_path(wg.name, test_type, count),
count,
test_type,
png_path,
args.ascii
args.ascii,
args.save_output
)


Expand Down

0 comments on commit 42387d4

Please sign in to comment.