-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflow_statistics.py
More file actions
221 lines (164 loc) · 7.16 KB
/
Copy pathflow_statistics.py
File metadata and controls
221 lines (164 loc) · 7.16 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
__author__ = 'venkat'
from header import *
from json_http_handler import *
class FlowWindow:
bottom_frame = 0
bottom_row = 0
class FlowTable:
def __init__(self):
self.dest_ip = None
self.dest_mask = None
self.dest_mac = None
self.dest_port = None
self.dest_node = None
return
def updateflowtable(self, destIp, destMask, destMac, destPort, destNode):
self.dest_ip = destIp
self.dest_mask = destMask
self.dest_mac = destMac
self.dest_port = destPort
self.dest_node = destNode
return
def displayflowtable(self):
print(self.dest_ip,
self.dest_mask,
self.dest_mac,
self.dest_port,
self.dest_node)
return
class FlowStatistics:
def __init__(self):
self.listbox = None
self.toplevel = None
self.no_of_flows = 0
def CurSelet(self):
print("Hello")
switch = str((self.mylistbox.get(self.mylistbox.curselection())))
print(switch)
def fillListWithNodesInfo(self):
'''
Create an object of Http JSON Handler Class to receive
resp from respective Rest URL's
'''
http_obj = HttpJsonHandler()
json_nodes = http_obj.getnodeinfo()
for node in json_nodes['nodeProperties']:
self.listbox.insert(END, node['node']['id'])
def displayFlowTableTitle(self, bottom_frame, bottom_row):
for column in range(5):
if column == 0:
label = Label(bottom_frame, text="Destination IP", borderwidth=0, width=15, fg="red")
elif column == 1:
label = Label(bottom_frame, text="Destination Mask", borderwidth=0, width=15, fg="red")
elif column == 2:
label = Label(bottom_frame, text="Output Mac", borderwidth=0, width=15, fg="red")
elif column == 3:
label = Label(bottom_frame, text="Output Port", borderwidth=0, width=15, fg="red")
elif column == 4:
label = Label(bottom_frame, text="Output Node", borderwidth=0, width=25, fg="red")
label.configure(bg="white")
label.grid(row=bottom_row, column=column, sticky="nsew", padx=1, pady=1)
return
def displayFlowTableContent(self, flow_list, flow_window_obj):
bottom_frame = flow_window_obj.bottom_frame
bottom_row = flow_window_obj.bottom_row
#for row in range(4):
for row in flow_list:
current_row = []
for column in range(5):
if column == 0:
label = Label(bottom_frame, text="%s" % row.dest_ip, borderwidth=0, width=15)
elif column == 1:
label = Label(bottom_frame, text="%s" % row.dest_mask, borderwidth=0, width=15)
elif column == 2:
label = Label(bottom_frame, text="%s" % row.dest_mac, borderwidth=0, width=15)
elif column == 3:
label = Label(bottom_frame, text="%s" % row.dest_port, borderwidth=0, width=15)
elif column == 4:
label = Label(bottom_frame, text="%s" % row.dest_node, borderwidth=0, width=25)
label.configure(bg="white")
label.grid(row=bottom_row, column=column, sticky="nsew", padx=1, pady=1)
current_row.append(label)
bottom_row += 1
for column in range(5):
bottom_frame.grid_columnconfigure(column, weight=1)
return
def CurListSelet(self, evt, flow_window_obj):
#mylistbox = evt.widget
switch=str((self.listbox.get(self.listbox.curselection())))
print(switch)
'''
Create an object of Http JSON Handler Class to receive
resp from respective Rest URL's
'''
http_obj = HttpJsonHandler()
json_flows = http_obj.getflowinfo(switch)
no_of_flows = 0
flow_list = []
for flowCount in json_flows['flowStatistic']:
destIp = json_flows['flowStatistic'][no_of_flows]['flow']['match']['matchField'][0]['value']
destMask = json_flows['flowStatistic'][no_of_flows]['flow']['match']['matchField'][0]['mask']
destPort = 0
destnode = '00:00:00:00:00:00:00:00'
try:
destMac = json_flows['flowStatistic'][no_of_flows]['flow']['actions'][0]['address']
try:
destPort = json_flows['flowStatistic'][no_of_flows]['flow']['actions'][1]['port']['id']
destnode = json_flows['flowStatistic'][no_of_flows]['flow']['actions'][1]['port']['node']['id']
except:
print('')
except KeyError:
destPort = json_flows['flowStatistic'][no_of_flows]['flow']['actions'][0]['port']['id']
destnode = json_flows['flowStatistic'][no_of_flows]['flow']['actions'][0]['port']['node']['id']
destMac = '000000000000'
# destIp, destMask, destMac, destPort, destNode
# Create an instance of FlowTable class
flow_table_entry = FlowTable()
flow_table_entry.updateflowtable(destIp, destMask, destMac, destPort, destnode)
flow_list.append(flow_table_entry)
no_of_flows += 1
flow_table_entry.displayflowtable()
# sort the list with switch_is as Key
flow_list.sort(key=lambda host:host.dest_ip)
self.displayFlowTableContent(flow_list, flow_window_obj)
def flowstatistics():
# Create an instance of FlowTable class
#flow_table_entry = FlowTable()
# Create an instance of FlowStatistics class
obj = FlowStatistics()
'''
scrollbar.config(command=obj.mylistbox.yview)
submit = Button(obj.toplevel, text="Submit", command=obj.CurSelet)
submit.pack()
'''
toplevel = Toplevel()
toplevel.title("Flow Monitoring")
toplevel.geometry("750x250")
top_row = 0
bottom_row = 0
top_frame = Frame(toplevel)
top_frame.pack(side=TOP)
top_label = Label(top_frame, text=" SELECT SWITCH TO GET FLOW ENTRIES", fg="red", borderwidth=0, width=40)
top_label.grid(row=top_row, rowspan=1)
top_row += 1
bottom_frame = Frame(toplevel)
bottom_frame.pack(side=TOP)
bottom_label = Label(bottom_frame, fg="green")
bottom_label.grid(row=bottom_row)
bottom_row += 1
scrollbar = Scrollbar(top_frame)
obj.listbox = Listbox(top_frame, yscrollcommand=scrollbar.set)
obj.listbox.config(height=4)
# Fills the list of nodes in the List Box
obj.fillListWithNodesInfo()
obj.listbox.grid(row=top_row, column=0, sticky="nsew", padx=1, pady=1)
scrollbar.grid(row=top_row, column=1, sticky="nsew", padx=1, pady=1)
scrollbar.config(command=obj.listbox.yview)
obj.displayFlowTableTitle(bottom_frame, bottom_row)
bottom_row += 1
flow_window_obj = FlowWindow()
flow_window_obj.bottom_row = bottom_row
flow_window_obj.bottom_frame = bottom_frame
# Below code to activate on selection of items in List Box
obj.listbox.bind('<<ListboxSelect>>', lambda event, arg=flow_window_obj: obj.CurListSelet(event, flow_window_obj))
return