Skip to content

Commit

Permalink
Highlight attack range
Browse files Browse the repository at this point in the history
  • Loading branch information
geraked committed Jun 29, 2021
1 parent 8db8e84 commit 47ebcc9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 6 additions & 7 deletions miniattack/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def draw_figure(canvas, figure):
return figure_canvas_agg


def gui(data, itfs=[]):
def gui(data, attack_range, itfs=[]):
# Calculate dynamic size
if len(itfs) == 0 or len(itfs) >= 8:
cols = 4
Expand All @@ -40,7 +40,7 @@ def gui(data, itfs=[]):

plt.figure(1)

# Show topology image
# Show the topology image
imp = path.join(path.dirname(__file__), '..', 'docs', 'topo.jpg')
imp = path.abspath(imp)
img = mpimg.imread(imp)
Expand All @@ -54,11 +54,12 @@ def gui(data, itfs=[]):
if len(itfs) > 0 and k not in itfs:
continue
plt.subplot(rows, cols, i)
y = data[k]
x = [str(t) for t in range(len(y))]
y = data[k]['load']
x = data[k]['time']
plt.plot(x, y)
plt.title(k)
plt.ylabel('bits/s')
plt.axvspan(*attack_range, color='red', alpha=0.1)
plt.xticks([])
i += 1

Expand All @@ -74,17 +75,15 @@ def gui(data, itfs=[]):
pp.savefig()
pp.close()

# Confiure PySimpleGUI
layout = [
[sg.Column([[sg.Canvas(key='-C1-')]], key='-COL1-', scrollable=True)],
]

window = sg.Window(
'Mininet Attack Test',
layout, finalize=True, resizable=True, element_justification='center', font='Helvetica 18', keep_on_top=True, size=(800, 600)
)

draw_figure(window['-C1-'].TKCanvas, fig)
window['-COL1-'].expand(True, True)

event, values = window.read()
window.close()
16 changes: 11 additions & 5 deletions miniattack/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import csv
from subprocess import Popen
from time import sleep
from time import sleep, time
from mininet.log import setLogLevel, info
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
Expand All @@ -29,8 +29,10 @@ def run(self):
self.start_monitor()
sleep(self.idle_dur)
self.start_attack()
self.ast = time()
sleep(self.attack_dur)
self.stop_attack()
self.aet = time()
sleep(self.idle_dur)
self.stop_monitor()
self.fill_data()
Expand Down Expand Up @@ -99,17 +101,21 @@ def fill_data(self):
csvr = csv.reader(csvf, delimiter=',')
for row in csvr:
key = row[1]
value = float(row[4]) * 8
tme = float(row[0])
load = float(row[4]) * 8
if key in self.data:
self.data[key].append(value)
self.data[key]['time'].append(tme)
self.data[key]['load'].append(load)
else:
self.data[key] = []
self.data[key] = {}
self.data[key]['time'] = []
self.data[key]['load'] = []

def plot(self):
"""Pass the loaded output of bwm-ng to gui to plot"""
info('*** Plot\n')
self.itfs = [t for t in self.itfs if t in self.data]
gui(self.data, self.itfs)
gui(self.data, (self.ast, self.aet), self.itfs)

def remove_tmp(self):
"""Remove the output file of bwm-ng if already exists"""
Expand Down

0 comments on commit 47ebcc9

Please sign in to comment.