forked from cbrenton/564NetworkVisualization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.py
More file actions
93 lines (68 loc) · 2.59 KB
/
filter.py
File metadata and controls
93 lines (68 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import networkx as nx
import matplotlib.pyplot as plt
from socket import socket as sock, AF_INET, SOCK_DGRAM
class Filter:
g = nx.Graph()
def __init__(self, host="", port=6969):
self.host = host
self.port = port
def addFlowToGraph(routerSrc, dst, nextHop):
if nextHop == "0.0.0.0":
flowGraph.add_edge(routerSrc, dst)
else:
flowGraph.add_edge(routerSrc, nextHop)
def updateNetworkGraph():
pos=nx.spring_layout(flowGraph)
nx.draw(flowGraph, pos, fontsize=10)
plt.axis('off')
plt.savefig("graph.png")
def updateMetrics(self, unique, record):
#Check if the flow record is already in the dictionary
if unique in self.data:
flowRecord = self.data[unique]
# Check if start times are the same
if flowRecord[START] == record[START]:
self.data[unique][L3_BYTES] += record[L3_BYTES]
self.data[unique][END] = record[END]
def __init__(self, host="", port=6969):
self.host = host
self.port = port
self.listener = sock(AF_INET, SOCK_DGRAM, 0)
self.listener.bind((host, port))
self.flowGraph = nx.Graph()
self.data = {}
self.nodeNames = ["---"]
self.nodeData = ["Select a node."]
self.avgByteGraph = []
self.avgLenGraph = []
self.numFlowsGraph = []
def updateNetworkGraph(self):
pos=nx.spring_layout(self.flowGraph)
nx.draw(self.flowGraph, pos, fontsize=10)
plt.axis('off')
plt.savefig("graph.png")
def addFlowToGraph(self, routerSrc, dst, nextHop):
if nextHop == "0.0.0.0":
self.flowGraph.add_edge(routerSrc, dst)
else:
self.flowGraph.add_edge(routerSrc, nextHop)
def getAvgBytes(self):
def getAvgFlowLength(self):
def getNumOfFlows(self):
return self.numFlowsGraph
def generateGraphs(self):
return [ self.getAvgBytes(), self.getAvgFlowLength(), self.getNumOfFlows() ]
def update(self, nodeIndex):
return [ self.generateGraphs(), self.getNewNodes(), self.nodeData[nodeIndex] ]
def start(self);
while True:
def updateMetrics(self, unique, record):
#Check if the flow record is already in the dictionary
if unique in self.data:
flowRecord = self.data[unique]
# Check if start times are the same
if flowRecord[START] == record[START]:
self.data[unique][L3_BYTES] += record[L3_BYTES]
self.data[unique][END] = record[END]
else:
self.data[unique] = record