1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
|
3
|
|
|
# module under test |
4
|
|
|
from tests.integration.test_results import TestResults |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestResultsMetadata(TestResults): |
8
|
|
|
"""Tests for the graph class. |
9
|
|
|
|
10
|
|
|
Tests if the metadata in search result edges have passing values. |
11
|
|
|
""" |
12
|
|
|
|
13
|
|
|
def test_path_constrained_user_user(self): |
14
|
|
|
"""Test to see if there is a constrained |
15
|
|
|
path between User - User.""" |
16
|
|
|
self.initializer() |
17
|
|
|
result = self.get_path_constrained("User1", "User2") |
18
|
|
|
self.assertNotEqual(result, [], True) |
19
|
|
|
|
20
|
|
|
def test_path_constrained_user_switch(self): |
21
|
|
|
"""Test to see if there is a constrained |
22
|
|
|
path between User - Switch.""" |
23
|
|
|
self.initializer() |
24
|
|
|
result = self.get_path_constrained("User1", "S4") |
25
|
|
|
self.assertNotEqual(result, [], True) |
26
|
|
|
|
27
|
|
|
def test_path_constrained_switch_switch(self): |
28
|
|
|
"""Test to see if there is a constrained |
29
|
|
|
path between Switch - Switch.""" |
30
|
|
|
self.initializer() |
31
|
|
|
result = self.get_path_constrained("S2", "S4") |
32
|
|
|
self.assertNotEqual(result, [], True) |
33
|
|
|
|
34
|
|
|
def test_no_path_constrained_user_user(self): |
35
|
|
|
"""Test to see if there is NOT a constrained |
36
|
|
|
path between User - User.""" |
37
|
|
|
self.initializer() |
38
|
|
|
result = self.get_path_constrained("User1", "User3") |
39
|
|
|
self.assertEqual(result, [], True) |
40
|
|
|
|
41
|
|
|
def test_path_constrained_user_user_t1(self): |
42
|
|
|
"""Test to see if there is a constrained path between |
43
|
|
|
User - User using the 2nd topology variant.""" |
44
|
|
|
self.initializer(val=1) |
45
|
|
|
result = self.get_path_constrained("User1", "User3") |
46
|
|
|
self.assertNotEqual(result, [], True) |
47
|
|
|
|
48
|
|
|
def test_no_path_constrained_user_user_t1(self): |
49
|
|
|
"""Test to see if there is NOT a constrained path between |
50
|
|
|
User - User using the 2nd topology variant.""" |
51
|
|
|
self.initializer(val=1) |
52
|
|
|
result = self.get_path_constrained("User1", "User2") |
53
|
|
|
self.assertEqual(result, [], True) |
54
|
|
|
|
55
|
|
|
def test_no_path_constrained_switch_switch_t1(self): |
56
|
|
|
"""Test to see if there is NOT a constrained path between |
57
|
|
|
Switch - Switch using the 2nd topology variant.""" |
58
|
|
|
self.initializer(val=1) |
59
|
|
|
result = self.get_path_constrained("S1", "S2") |
60
|
|
|
self.assertEqual(result, [], True) |
61
|
|
|
|
62
|
|
|
def test_path_constrained_user_user_t2(self): |
63
|
|
|
"""Test to see if there is a constrained path between |
64
|
|
|
User - User using the 3rd topology variant.""" |
65
|
|
|
self.initializer(val=2) |
66
|
|
|
result = self.get_path_constrained("User1", "User2") |
67
|
|
|
self.assertNotEqual(result, [], True) |
68
|
|
|
|
69
|
|
|
def test_path_constrained_user_switch_t2(self): |
70
|
|
|
"""Test to see if there is a constrained path between |
71
|
|
|
User - Switch using the 3rd topology variant.""" |
72
|
|
|
self.initializer(val=2) |
73
|
|
|
result = self.get_path_constrained("User1", "S4") |
74
|
|
|
self.assertNotEqual(result, [], True) |
75
|
|
|
|
76
|
|
|
def test_path_constrained_switch_switch_t2(self): |
77
|
|
|
"""Test to see if there is a constrained path between |
78
|
|
|
two switches using the 3rd topology variant.""" |
79
|
|
|
self.initializer(val=2) |
80
|
|
|
result = self.get_path_constrained("S2", "S4") |
81
|
|
|
self.assertNotEqual(result, [], True) |
82
|
|
|
|
83
|
|
|
def test_path_constrained_reliability(self): |
84
|
|
|
"""Tests to see if the edges used in the paths |
85
|
|
|
of the result set do not have poor reliability |
86
|
|
|
""" |
87
|
|
|
requirements = {"reliability": 3} |
88
|
|
|
|
89
|
|
|
self.initializer() |
90
|
|
|
|
91
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
92
|
|
|
|
93
|
|
|
self.assertNotEqual(result, []) |
94
|
|
|
|
95
|
|
|
def test_no_path_constrained_reliability(self): |
96
|
|
|
"""Tests to see if the edges used in the paths |
97
|
|
|
of the result set do not have poor reliability |
98
|
|
|
""" |
99
|
|
|
requirements = {"reliability": 3} |
100
|
|
|
|
101
|
|
|
self.initializer() |
102
|
|
|
|
103
|
|
|
result = self.get_path_constrained("User1", "User3", base=requirements) |
104
|
|
|
|
105
|
|
|
self.assertEqual(result, []) |
106
|
|
|
|
107
|
|
|
def test_path_constrained_reliability_detailed(self): |
108
|
|
|
"""Tests to see if the edges used in the paths |
109
|
|
|
of the result set do not have poor reliability |
110
|
|
|
""" |
111
|
|
|
reliabilities = [] |
112
|
|
|
requirements = {"reliability": 3} |
113
|
|
|
poor_reliability = 1 |
114
|
|
|
|
115
|
|
|
self.initializer() |
116
|
|
|
|
117
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
118
|
|
|
|
119
|
|
|
if result: |
120
|
|
|
for path in result[0]["paths"]: |
121
|
|
|
for i in range(1, len(path)): |
122
|
|
|
endpoint_a = path[i - 1] |
123
|
|
|
endpoint_b = path[i] |
124
|
|
|
meta_data = self.graph.get_link_metadata( |
125
|
|
|
endpoint_a, endpoint_b) |
126
|
|
|
if meta_data and "reliability" in meta_data.keys(): |
127
|
|
|
reliabilities.append(meta_data["reliability"]) |
128
|
|
|
|
129
|
|
|
self.assertNotIn(poor_reliability, reliabilities) |
130
|
|
|
|
131
|
|
|
else: |
132
|
|
|
self.assertNotEqual(result, []) |
133
|
|
|
|
134
|
|
|
def test_path_constrained_delay(self): |
135
|
|
|
"""Tests to see if the edges used in the paths |
136
|
|
|
from User 1 to User 2 have less than 30 delay. |
137
|
|
|
""" |
138
|
|
|
delays = [] |
139
|
|
|
requirements = {"delay": 29} |
140
|
|
|
|
141
|
|
|
self.initializer() |
142
|
|
|
|
143
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
144
|
|
|
|
145
|
|
|
if result: |
146
|
|
|
for path in result[0]["paths"]: |
147
|
|
|
for i in range(1, len(path)): |
148
|
|
|
endpoint_a = path[i - 1] |
149
|
|
|
endpoint_b = path[i] |
150
|
|
|
meta_data = self.graph.get_link_metadata( |
151
|
|
|
endpoint_a, endpoint_b) |
152
|
|
|
if meta_data and "delay" in meta_data.keys(): |
153
|
|
|
delays.append(meta_data["delay"]) |
154
|
|
|
|
155
|
|
|
if not delays: |
156
|
|
|
self.assertNotEqual(delays, []) |
157
|
|
|
|
158
|
|
|
valid = True |
159
|
|
|
for delay in delays: |
160
|
|
|
if delay > requirements["delay"]: |
161
|
|
|
valid = False |
162
|
|
|
break |
163
|
|
|
|
164
|
|
|
self.assertEqual(valid, True) |
165
|
|
|
|
166
|
|
|
def test_path_constrained_bandwidth_detailed(self): |
167
|
|
|
"""Tests to see if the edges used in the paths |
168
|
|
|
from User 1 to User 2 have at least 20 bandwidth. |
169
|
|
|
""" |
170
|
|
|
bandwidths = [] |
171
|
|
|
requirements = {"bandwidth": 20} |
172
|
|
|
|
173
|
|
|
self.initializer() |
174
|
|
|
|
175
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
176
|
|
|
|
177
|
|
|
if result: |
178
|
|
|
self.bandwidth_list_builder(bandwidths, result) |
179
|
|
|
|
180
|
|
|
# for bandwidth in bandwidths: |
181
|
|
|
# self.assertEqual(bandwidth < requirements["bandwidth"], False) |
182
|
|
|
valid = True |
183
|
|
|
for bandwidth in bandwidths: |
184
|
|
|
if bandwidth < requirements["bandwidth"]: |
185
|
|
|
valid = False |
186
|
|
|
break |
187
|
|
|
|
188
|
|
|
self.assertEqual(valid, True) |
189
|
|
|
|
190
|
|
|
def bandwidth_list_builder(self, bandwidths, result): |
191
|
|
|
for path in result[0]["paths"]: |
192
|
|
|
for i in range(1, len(path)): |
193
|
|
|
endpoint_a = path[i - 1] |
194
|
|
|
endpoint_b = path[i] |
195
|
|
|
meta_data = self.graph.get_link_metadata( |
196
|
|
|
endpoint_a, endpoint_b) |
197
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
198
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
199
|
|
|
|
200
|
|
|
def test_path_constrained_bandwidth_detailed_t2(self): |
201
|
|
|
"""Tests to see if the edges used in the paths |
202
|
|
|
from User 1 to User 2 have at least 20 bandwidth. |
203
|
|
|
""" |
204
|
|
|
bandwidths = [] |
205
|
|
|
requirements = {"bandwidth": 20} |
206
|
|
|
|
207
|
|
|
self.initializer(val=2) |
208
|
|
|
|
209
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
210
|
|
|
|
211
|
|
|
if result: |
212
|
|
|
self.bandwidth_list_builder(bandwidths, result) |
213
|
|
|
|
214
|
|
|
for bandwidth in bandwidths: |
215
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
216
|
|
|
|
217
|
|
|
def test_path_constrained_bandwidth_delay(self): |
218
|
|
|
"""Tests to see if the edges used in the paths from User 1 |
219
|
|
|
to User 2 have at least 20 bandwidth and under 30 delay. |
220
|
|
|
""" |
221
|
|
|
bandwidths = [] |
222
|
|
|
delays = [] |
223
|
|
|
requirements = {"bandwidth": 20, "delay": 29} |
224
|
|
|
|
225
|
|
|
self.initializer() |
226
|
|
|
|
227
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
228
|
|
|
|
229
|
|
|
if result: |
230
|
|
|
for path in result[0]["paths"]: |
231
|
|
|
for i in range(1, len(path)): |
232
|
|
|
endpoint_a = path[i - 1] |
233
|
|
|
endpoint_b = path[i] |
234
|
|
|
meta_data = self.graph.get_link_metadata( |
235
|
|
|
endpoint_a, endpoint_b) |
236
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
237
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
238
|
|
|
elif meta_data and "delay" in meta_data.keys(): |
239
|
|
|
delays.append(meta_data["delay"]) |
240
|
|
|
|
241
|
|
|
for bandwidth in bandwidths: |
242
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
243
|
|
|
|
244
|
|
|
for delay in delays: |
245
|
|
|
self.assertEqual(delay > requirements["delay"], False) |
246
|
|
|
|
247
|
|
|
@staticmethod |
248
|
|
|
def generate_topology(): |
249
|
|
|
"""Generates a predetermined topology.""" |
250
|
|
|
switches = {} |
251
|
|
|
interfaces = {} |
252
|
|
|
links = {} |
253
|
|
|
|
254
|
|
|
TestResultsMetadata.setting_switches_interfaces(interfaces, switches) |
255
|
|
|
|
256
|
|
|
TestResultsMetadata.setting_links(interfaces, links) |
257
|
|
|
|
258
|
|
|
TestResultsMetadata.adding_metadata(links) |
259
|
|
|
|
260
|
|
|
return switches, links |
261
|
|
|
|
262
|
|
|
@staticmethod |
263
|
|
|
def setting_switches_interfaces(interfaces, switches): |
264
|
|
|
"""Generates the switches in a a predetermined topology.""" |
265
|
|
|
TestResults.create_switch("User1", switches) |
266
|
|
|
TestResults.add_interfaces(3, switches["User1"], interfaces) |
267
|
|
|
|
268
|
|
|
TestResults.create_switch("S2", switches) |
269
|
|
|
TestResults.add_interfaces(2, switches["S2"], interfaces) |
270
|
|
|
|
271
|
|
|
TestResults.create_switch("User2", switches) |
272
|
|
|
TestResults.add_interfaces(3, switches["User2"], interfaces) |
273
|
|
|
|
274
|
|
|
TestResults.create_switch("S4", switches) |
275
|
|
|
TestResults.add_interfaces(4, switches["S4"], interfaces) |
276
|
|
|
|
277
|
|
|
TestResults.create_switch("S5", switches) |
278
|
|
|
TestResults.add_interfaces(2, switches["S5"], interfaces) |
279
|
|
|
|
280
|
|
|
@staticmethod |
281
|
|
|
def setting_links(interfaces, links): |
282
|
|
|
"""Generates the links in a a predetermined topology.""" |
283
|
|
|
TestResults.create_link("User1:1", "S2:1", interfaces, links) |
284
|
|
|
|
285
|
|
|
TestResults.create_link("User1:2", "S5:1", interfaces, links) |
286
|
|
|
|
287
|
|
|
TestResults.create_link("User1:3", "S4:1", interfaces, links) |
288
|
|
|
|
289
|
|
|
TestResults.create_link("S2:2", "User2:1", interfaces, links) |
290
|
|
|
|
291
|
|
|
TestResults.create_link("User2:2", "S4:2", interfaces, links) |
292
|
|
|
|
293
|
|
|
TestResults.create_link("S5:2", "S4:3", interfaces, links) |
294
|
|
|
|
295
|
|
|
TestResults.create_link("User2:3", "S4:4", interfaces, links) |
296
|
|
|
|
297
|
|
|
@staticmethod |
298
|
|
|
def adding_metadata(links): |
299
|
|
|
"""Add the links' metadata in a a predetermined topology.""" |
300
|
|
|
TestResults.add_metadata_to_link( |
301
|
|
|
"User1:1", "S2:1", { |
302
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
303
|
|
|
"bandwidth": 20}, links) |
304
|
|
|
|
305
|
|
|
TestResults.add_metadata_to_link( |
306
|
|
|
"User1:2", "S5:1", { |
307
|
|
|
"reliability": 1, "ownership": "A", "delay": 5, |
308
|
|
|
"bandwidth": 50}, links) |
309
|
|
|
|
310
|
|
|
TestResults.add_metadata_to_link( |
311
|
|
|
"User1:3", "S4:1", { |
312
|
|
|
"reliability": 3, "ownership": "A", "delay": 60, |
313
|
|
|
"bandwidth": 10}, links) |
314
|
|
|
|
315
|
|
|
TestResults.add_metadata_to_link( |
316
|
|
|
"S2:2", "User2:1", { |
317
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
318
|
|
|
"bandwidth": 20}, links) |
319
|
|
|
|
320
|
|
|
TestResults.add_metadata_to_link( |
321
|
|
|
"User2:2", "S4:2", { |
322
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
323
|
|
|
"bandwidth": 10}, links) |
324
|
|
|
|
325
|
|
|
TestResults.add_metadata_to_link( |
326
|
|
|
"S5:2", "S4:3", { |
327
|
|
|
"reliability": 1, "ownership": "A", "delay": 10, |
328
|
|
|
"bandwidth": 50}, links) |
329
|
|
|
|
330
|
|
|
TestResults.add_metadata_to_link( |
331
|
|
|
"User2:3", "S4:4", { |
332
|
|
|
"reliability": 3, "ownership": "A", "delay": 29, |
333
|
|
|
"bandwidth": 20}, links) |
334
|
|
|
|
335
|
|
|
@staticmethod |
336
|
|
|
def generate_topology_1(): |
337
|
|
|
"""Generates a predetermined topology |
338
|
|
|
- 2nd Variant.""" |
339
|
|
|
switches = {} |
340
|
|
|
interfaces = {} |
341
|
|
|
links = {} |
342
|
|
|
|
343
|
|
|
TestResultsMetadata.setting_switches_interfaces_1(interfaces, switches) |
344
|
|
|
|
345
|
|
|
TestResultsMetadata.setting_links_1(interfaces, links) |
346
|
|
|
|
347
|
|
|
TestResultsMetadata.adding_metadata_1(links) |
348
|
|
|
|
349
|
|
|
return switches, links |
350
|
|
|
|
351
|
|
|
@staticmethod |
352
|
|
|
def setting_switches_interfaces_1(interfaces, switches): |
353
|
|
|
"""Generates the switches in a a predetermined topology |
354
|
|
|
- 2nd variant.""" |
355
|
|
|
TestResults.create_switch("User1", switches) |
356
|
|
|
TestResults.add_interfaces(2, switches["User1"], interfaces) |
357
|
|
|
|
358
|
|
|
TestResults.create_switch("User2", switches) |
359
|
|
|
TestResults.add_interfaces(2, switches["User2"], interfaces) |
360
|
|
|
|
361
|
|
|
TestResults.create_switch("User3", switches) |
362
|
|
|
TestResults.add_interfaces(2, switches["User3"], interfaces) |
363
|
|
|
|
364
|
|
|
TestResults.create_switch("S1", switches) |
365
|
|
|
TestResults.add_interfaces(1, switches["S1"], interfaces) |
366
|
|
|
|
367
|
|
|
TestResults.create_switch("S2", switches) |
368
|
|
|
TestResults.add_interfaces(1, switches["S2"], interfaces) |
369
|
|
|
|
370
|
|
|
TestResults.create_switch("S3", switches) |
371
|
|
|
TestResults.add_interfaces(2, switches["S3"], interfaces) |
372
|
|
|
|
373
|
|
|
@staticmethod |
374
|
|
|
def setting_links_1(interfaces, links): |
375
|
|
|
"""Generates the links in a a predetermined topology |
376
|
|
|
- 2nd Variant.""" |
377
|
|
|
TestResults.create_link("User1:1", "S1:1", interfaces, links) |
378
|
|
|
|
379
|
|
|
TestResults.create_link("User1:2", "S3:1", interfaces, links) |
380
|
|
|
|
381
|
|
|
TestResults.create_link("User2:1", "S2:1", interfaces, links) |
382
|
|
|
|
383
|
|
|
TestResults.create_link("User3:1", "S3:2", interfaces, links) |
384
|
|
|
|
385
|
|
|
@staticmethod |
386
|
|
|
def adding_metadata_1(links): |
387
|
|
|
"""Add the links' metadata in a a predetermined topology |
388
|
|
|
- 2nd Variant.""" |
389
|
|
|
TestResults.add_metadata_to_link( |
390
|
|
|
"User1:1", "S1:1", { |
391
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
392
|
|
|
"bandwidth": 20}, links) |
393
|
|
|
|
394
|
|
|
TestResults.add_metadata_to_link( |
395
|
|
|
"User1:2", "S3:1", { |
396
|
|
|
"reliability": 1, "ownership": "A", "delay": 5, |
397
|
|
|
"bandwidth": 50}, links) |
398
|
|
|
|
399
|
|
|
TestResults.add_metadata_to_link( |
400
|
|
|
"User2:1", "S2:1", { |
401
|
|
|
"reliability": 3, "ownership": "A", "delay": 60, |
402
|
|
|
"bandwidth": 10}, links) |
403
|
|
|
|
404
|
|
|
TestResults.add_metadata_to_link( |
405
|
|
|
"User3:1", "S3:2", { |
406
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
407
|
|
|
"bandwidth": 20}, links) |
408
|
|
|
|
409
|
|
|
@staticmethod |
410
|
|
|
def generate_topology_2(): |
411
|
|
|
"""Generates a predetermined topology |
412
|
|
|
- 3rd Variant.""" |
413
|
|
|
switches = {} |
414
|
|
|
interfaces = {} |
415
|
|
|
links = {} |
416
|
|
|
|
417
|
|
|
TestResultsMetadata.setting_switches_interfaces(interfaces, switches) |
418
|
|
|
|
419
|
|
|
TestResultsMetadata.setting_links(interfaces, links) |
420
|
|
|
|
421
|
|
|
TestResultsMetadata.adding_metadata_2(links) |
422
|
|
|
|
423
|
|
|
return switches, links |
424
|
|
|
|
425
|
|
|
@staticmethod |
426
|
|
|
def adding_metadata_2(links): |
427
|
|
|
"""Add the links' metadata in a a predetermined topology |
428
|
|
|
- 3rd Variant.""" |
429
|
|
|
TestResults.add_metadata_to_link( |
430
|
|
|
"User1:1", "S2:1", { |
431
|
|
|
"reliability": 3, "ownership": "B", |
432
|
|
|
"bandwidth": 20}, links) |
433
|
|
|
|
434
|
|
|
TestResults.add_metadata_to_link( |
435
|
|
|
"User1:2", "S5:1", { |
436
|
|
|
"reliability": 1, "delay": 5, |
437
|
|
|
"bandwidth": 50}, links) |
438
|
|
|
|
439
|
|
|
TestResults.add_metadata_to_link( |
440
|
|
|
"User1:3", "S4:1", { |
441
|
|
|
"ownership": "A", "delay": 60, |
442
|
|
|
"bandwidth": 10}, links) |
443
|
|
|
|
444
|
|
|
TestResults.add_metadata_to_link( |
445
|
|
|
"S2:2", "User2:1", { |
446
|
|
|
"reliability": 3, |
447
|
|
|
"bandwidth": 20}, links) |
448
|
|
|
|
449
|
|
|
TestResults.add_metadata_to_link( |
450
|
|
|
"User2:2", "S4:2", { |
451
|
|
|
"ownership": "B", |
452
|
|
|
"bandwidth": 10}, links) |
453
|
|
|
|
454
|
|
|
TestResults.add_metadata_to_link( |
455
|
|
|
"S5:2", "S4:3", { |
456
|
|
|
"delay": 10, |
457
|
|
|
"bandwidth": 50}, links) |
458
|
|
|
|
459
|
|
|
TestResults.add_metadata_to_link( |
460
|
|
|
"User2:3", "S4:4", { |
461
|
|
|
"bandwidth": 20}, links) |
462
|
|
|
|