diff --git a/miniattack/gui.py b/miniattack/gui.py index 9e99495..1589b2b 100644 --- a/miniattack/gui.py +++ b/miniattack/gui.py @@ -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 @@ -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) @@ -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 @@ -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() diff --git a/miniattack/net.py b/miniattack/net.py index b96a59d..07fa7fe 100644 --- a/miniattack/net.py +++ b/miniattack/net.py @@ -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 @@ -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() @@ -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"""