1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
|
3
|
|
|
# module under test |
4
|
|
|
from tests.integration.metadata_settings import MetadataSettings |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestResultsMetadata(MetadataSettings): |
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 bandwidth_list_builder(self, bandwidths, result): |
167
|
|
|
"""Method to set up bandwidth metadata""" |
168
|
|
|
for path in result[0]["paths"]: |
169
|
|
|
for i in range(1, len(path)): |
170
|
|
|
endpoint_a = path[i - 1] |
171
|
|
|
endpoint_b = path[i] |
172
|
|
|
meta_data = self.graph.get_link_metadata( |
173
|
|
|
endpoint_a, endpoint_b) |
174
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
175
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
176
|
|
|
|
177
|
|
|
def test_path_constrained_bandwidth_detailed(self): |
178
|
|
|
"""Tests to see if the edges used in the paths |
179
|
|
|
from User 1 to User 2 have at least 20 bandwidth. |
180
|
|
|
""" |
181
|
|
|
bandwidths = [] |
182
|
|
|
requirements = {"bandwidth": 20} |
183
|
|
|
|
184
|
|
|
self.initializer() |
185
|
|
|
|
186
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
187
|
|
|
|
188
|
|
|
if result: |
189
|
|
|
self.bandwidth_list_builder(bandwidths, result) |
190
|
|
|
|
191
|
|
|
valid = True |
192
|
|
|
for bandwidth in bandwidths: |
193
|
|
|
if bandwidth < requirements["bandwidth"]: |
194
|
|
|
valid = False |
195
|
|
|
break |
196
|
|
|
|
197
|
|
|
self.assertEqual(valid, True) |
198
|
|
|
|
199
|
|
|
def test_path_constrained_bandwidth_detailed_t2(self): |
200
|
|
|
"""Tests to see if the edges used in the paths |
201
|
|
|
from User 1 to User 2 have at least 20 bandwidth. |
202
|
|
|
""" |
203
|
|
|
bandwidths = [] |
204
|
|
|
requirements = {"bandwidth": 20} |
205
|
|
|
|
206
|
|
|
self.initializer(val=2) |
207
|
|
|
|
208
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
209
|
|
|
|
210
|
|
|
if result: |
211
|
|
|
self.bandwidth_list_builder(bandwidths, result) |
212
|
|
|
|
213
|
|
|
for bandwidth in bandwidths: |
214
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
215
|
|
|
|
216
|
|
|
def test_path_constrained_bandwidth_delay(self): |
217
|
|
|
"""Tests to see if the edges used in the paths from User 1 |
218
|
|
|
to User 2 have at least 20 bandwidth and under 30 delay. |
219
|
|
|
""" |
220
|
|
|
bandwidths = [] |
221
|
|
|
delays = [] |
222
|
|
|
requirements = {"bandwidth": 20, "delay": 29} |
223
|
|
|
|
224
|
|
|
self.initializer() |
225
|
|
|
|
226
|
|
|
result = self.get_path_constrained("User1", "User2", base=requirements) |
227
|
|
|
|
228
|
|
|
if result: |
229
|
|
|
for path in result[0]["paths"]: |
230
|
|
|
for i in range(1, len(path)): |
231
|
|
|
endpoint_a = path[i - 1] |
232
|
|
|
endpoint_b = path[i] |
233
|
|
|
meta_data = self.graph.get_link_metadata( |
234
|
|
|
endpoint_a, endpoint_b) |
235
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
236
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
237
|
|
|
elif meta_data and "delay" in meta_data.keys(): |
238
|
|
|
delays.append(meta_data["delay"]) |
239
|
|
|
|
240
|
|
|
for bandwidth in bandwidths: |
241
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
242
|
|
|
|
243
|
|
|
for delay in delays: |
244
|
|
|
self.assertEqual(delay > requirements["delay"], False) |
245
|
|
|
|
246
|
|
|
# @staticmethod |
247
|
|
|
# def generate_topology(): |
248
|
|
|
# """Generates a predetermined topology.""" |
249
|
|
|
# switches = {} |
250
|
|
|
# interfaces = {} |
251
|
|
|
# links = {} |
252
|
|
|
# |
253
|
|
|
# TestResultsMetadata.setting_switches_interfaces(interfaces, switches) |
254
|
|
|
# |
255
|
|
|
# TestResultsMetadata.setting_links(interfaces, links) |
256
|
|
|
# |
257
|
|
|
# TestResultsMetadata.adding_metadata(links) |
258
|
|
|
# |
259
|
|
|
# return switches, links |
260
|
|
|
|
261
|
|
|
# @staticmethod |
262
|
|
|
# def setting_switches_interfaces(interfaces, switches): |
263
|
|
|
# """Generates the switches in a a predetermined topology.""" |
264
|
|
|
# TestResults.create_switch("User1", switches) |
265
|
|
|
# TestResults.add_interfaces(3, switches["User1"], interfaces) |
266
|
|
|
# |
267
|
|
|
# TestResults.create_switch("S2", switches) |
268
|
|
|
# TestResults.add_interfaces(2, switches["S2"], interfaces) |
269
|
|
|
# |
270
|
|
|
# TestResults.create_switch("User2", switches) |
271
|
|
|
# TestResults.add_interfaces(3, switches["User2"], interfaces) |
272
|
|
|
# |
273
|
|
|
# TestResults.create_switch("S4", switches) |
274
|
|
|
# TestResults.add_interfaces(4, switches["S4"], interfaces) |
275
|
|
|
# |
276
|
|
|
# TestResults.create_switch("S5", switches) |
277
|
|
|
# TestResults.add_interfaces(2, switches["S5"], interfaces) |
278
|
|
|
# |
279
|
|
|
# @staticmethod |
280
|
|
|
# def setting_links(interfaces, links): |
281
|
|
|
# """Generates the links in a a predetermined topology.""" |
282
|
|
|
# TestResults.create_link("User1:1", "S2:1", interfaces, links) |
283
|
|
|
# |
284
|
|
|
# TestResults.create_link("User1:2", "S5:1", interfaces, links) |
285
|
|
|
# |
286
|
|
|
# TestResults.create_link("User1:3", "S4:1", interfaces, links) |
287
|
|
|
# |
288
|
|
|
# TestResults.create_link("S2:2", "User2:1", interfaces, links) |
289
|
|
|
# |
290
|
|
|
# TestResults.create_link("User2:2", "S4:2", interfaces, links) |
291
|
|
|
# |
292
|
|
|
# TestResults.create_link("S5:2", "S4:3", interfaces, links) |
293
|
|
|
# |
294
|
|
|
# TestResults.create_link("User2:3", "S4:4", interfaces, links) |
295
|
|
|
# |
296
|
|
|
# @staticmethod |
297
|
|
|
# def adding_metadata(links): |
298
|
|
|
# """Add the links' metadata in a a predetermined topology.""" |
299
|
|
|
# TestResults.add_metadata_to_link( |
300
|
|
|
# "User1:1", "S2:1", { |
301
|
|
|
# "reliability": 3, "ownership": "B", "delay": 30, |
302
|
|
|
# "bandwidth": 20}, links) |
303
|
|
|
# |
304
|
|
|
# TestResults.add_metadata_to_link( |
305
|
|
|
# "User1:2", "S5:1", { |
306
|
|
|
# "reliability": 1, "ownership": "A", "delay": 5, |
307
|
|
|
# "bandwidth": 50}, links) |
308
|
|
|
# |
309
|
|
|
# TestResults.add_metadata_to_link( |
310
|
|
|
# "User1:3", "S4:1", { |
311
|
|
|
# "reliability": 3, "ownership": "A", "delay": 60, |
312
|
|
|
# "bandwidth": 10}, links) |
313
|
|
|
# |
314
|
|
|
# TestResults.add_metadata_to_link( |
315
|
|
|
# "S2:2", "User2:1", { |
316
|
|
|
# "reliability": 3, "ownership": "B", "delay": 30, |
317
|
|
|
# "bandwidth": 20}, links) |
318
|
|
|
# |
319
|
|
|
# TestResults.add_metadata_to_link( |
320
|
|
|
# "User2:2", "S4:2", { |
321
|
|
|
# "reliability": 3, "ownership": "B", "delay": 30, |
322
|
|
|
# "bandwidth": 10}, links) |
323
|
|
|
# |
324
|
|
|
# TestResults.add_metadata_to_link( |
325
|
|
|
# "S5:2", "S4:3", { |
326
|
|
|
# "reliability": 1, "ownership": "A", "delay": 10, |
327
|
|
|
# "bandwidth": 50}, links) |
328
|
|
|
# |
329
|
|
|
# TestResults.add_metadata_to_link( |
330
|
|
|
# "User2:3", "S4:4", { |
331
|
|
|
# "reliability": 3, "ownership": "A", "delay": 29, |
332
|
|
|
# "bandwidth": 20}, links) |
333
|
|
|
# |
334
|
|
|
# @staticmethod |
335
|
|
|
# def generate_topology_1(): |
336
|
|
|
# """Generates a predetermined topology |
337
|
|
|
# - 2nd Variant.""" |
338
|
|
|
# switches = {} |
339
|
|
|
# interfaces = {} |
340
|
|
|
# links = {} |
341
|
|
|
# |
342
|
|
|
# TestResultsMetadata.setting_switches_interfaces_1(interfaces, switches) |
343
|
|
|
# |
344
|
|
|
# TestResultsMetadata.setting_links_1(interfaces, links) |
345
|
|
|
# |
346
|
|
|
# TestResultsMetadata.adding_metadata_1(links) |
347
|
|
|
# |
348
|
|
|
# return switches, links |
349
|
|
|
# |
350
|
|
|
# @staticmethod |
351
|
|
|
# def setting_switches_interfaces_1(interfaces, switches): |
352
|
|
|
# """Generates the switches in a a predetermined topology |
353
|
|
|
# - 2nd variant.""" |
354
|
|
|
# TestResults.create_switch("User1", switches) |
355
|
|
|
# TestResults.add_interfaces(2, switches["User1"], interfaces) |
356
|
|
|
# |
357
|
|
|
# TestResults.create_switch("User2", switches) |
358
|
|
|
# TestResults.add_interfaces(2, switches["User2"], interfaces) |
359
|
|
|
# |
360
|
|
|
# TestResults.create_switch("User3", switches) |
361
|
|
|
# TestResults.add_interfaces(2, switches["User3"], interfaces) |
362
|
|
|
# |
363
|
|
|
# TestResults.create_switch("S1", switches) |
364
|
|
|
# TestResults.add_interfaces(1, switches["S1"], interfaces) |
365
|
|
|
# |
366
|
|
|
# TestResults.create_switch("S2", switches) |
367
|
|
|
# TestResults.add_interfaces(1, switches["S2"], interfaces) |
368
|
|
|
# |
369
|
|
|
# TestResults.create_switch("S3", switches) |
370
|
|
|
# TestResults.add_interfaces(2, switches["S3"], interfaces) |
371
|
|
|
# |
372
|
|
|
# @staticmethod |
373
|
|
|
# def setting_links_1(interfaces, links): |
374
|
|
|
# """Generates the links in a a predetermined topology |
375
|
|
|
# - 2nd Variant.""" |
376
|
|
|
# TestResults.create_link("User1:1", "S1:1", interfaces, links) |
377
|
|
|
# |
378
|
|
|
# TestResults.create_link("User1:2", "S3:1", interfaces, links) |
379
|
|
|
# |
380
|
|
|
# TestResults.create_link("User2:1", "S2:1", interfaces, links) |
381
|
|
|
# |
382
|
|
|
# TestResults.create_link("User3:1", "S3:2", interfaces, links) |
383
|
|
|
# |
384
|
|
|
# @staticmethod |
385
|
|
|
# def adding_metadata_1(links): |
386
|
|
|
# """Add the links' metadata in a a predetermined topology |
387
|
|
|
# - 2nd Variant.""" |
388
|
|
|
# TestResults.add_metadata_to_link( |
389
|
|
|
# "User1:1", "S1:1", { |
390
|
|
|
# "reliability": 3, "ownership": "B", "delay": 30, |
391
|
|
|
# "bandwidth": 20}, links) |
392
|
|
|
# |
393
|
|
|
# TestResults.add_metadata_to_link( |
394
|
|
|
# "User1:2", "S3:1", { |
395
|
|
|
# "reliability": 1, "ownership": "A", "delay": 5, |
396
|
|
|
# "bandwidth": 50}, links) |
397
|
|
|
# |
398
|
|
|
# TestResults.add_metadata_to_link( |
399
|
|
|
# "User2:1", "S2:1", { |
400
|
|
|
# "reliability": 3, "ownership": "A", "delay": 60, |
401
|
|
|
# "bandwidth": 10}, links) |
402
|
|
|
# |
403
|
|
|
# TestResults.add_metadata_to_link( |
404
|
|
|
# "User3:1", "S3:2", { |
405
|
|
|
# "reliability": 3, "ownership": "B", "delay": 30, |
406
|
|
|
# "bandwidth": 20}, links) |
407
|
|
|
# |
408
|
|
|
# @staticmethod |
409
|
|
|
# def generate_topology_2(): |
410
|
|
|
# """Generates a predetermined topology |
411
|
|
|
# - 3rd Variant.""" |
412
|
|
|
# switches = {} |
413
|
|
|
# interfaces = {} |
414
|
|
|
# links = {} |
415
|
|
|
# |
416
|
|
|
# TestResultsMetadata.setting_switches_interfaces(interfaces, switches) |
417
|
|
|
# |
418
|
|
|
# TestResultsMetadata.setting_links(interfaces, links) |
419
|
|
|
# |
420
|
|
|
# TestResultsMetadata.adding_metadata_2(links) |
421
|
|
|
# |
422
|
|
|
# return switches, links |
423
|
|
|
# |
424
|
|
|
# @staticmethod |
425
|
|
|
# def adding_metadata_2(links): |
426
|
|
|
# """Add the links' metadata in a a predetermined topology |
427
|
|
|
# - 3rd Variant.""" |
428
|
|
|
# TestResults.add_metadata_to_link( |
429
|
|
|
# "User1:1", "S2:1", { |
430
|
|
|
# "reliability": 3, "ownership": "B", |
431
|
|
|
# "bandwidth": 20}, links) |
432
|
|
|
# |
433
|
|
|
# TestResults.add_metadata_to_link( |
434
|
|
|
# "User1:2", "S5:1", { |
435
|
|
|
# "reliability": 1, "delay": 5, |
436
|
|
|
# "bandwidth": 50}, links) |
437
|
|
|
# |
438
|
|
|
# TestResults.add_metadata_to_link( |
439
|
|
|
# "User1:3", "S4:1", { |
440
|
|
|
# "ownership": "A", "delay": 60, |
441
|
|
|
# "bandwidth": 10}, links) |
442
|
|
|
# |
443
|
|
|
# TestResults.add_metadata_to_link( |
444
|
|
|
# "S2:2", "User2:1", { |
445
|
|
|
# "reliability": 3, |
446
|
|
|
# "bandwidth": 20}, links) |
447
|
|
|
# |
448
|
|
|
# TestResults.add_metadata_to_link( |
449
|
|
|
# "User2:2", "S4:2", { |
450
|
|
|
# "ownership": "B", |
451
|
|
|
# "bandwidth": 10}, links) |
452
|
|
|
# |
453
|
|
|
# TestResults.add_metadata_to_link( |
454
|
|
|
# "S5:2", "S4:3", { |
455
|
|
|
# "delay": 10, |
456
|
|
|
# "bandwidth": 50}, links) |
457
|
|
|
# |
458
|
|
|
# TestResults.add_metadata_to_link( |
459
|
|
|
# "User2:3", "S4:4", { |
460
|
|
|
# "bandwidth": 20}, links) |
461
|
|
|
|