1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
from itertools import combinations |
3
|
|
|
|
4
|
|
|
# Core modules to import |
5
|
|
|
from kytos.core.link import Link |
6
|
|
|
|
7
|
|
|
# module under test |
8
|
|
|
from tests.integration.test_results import TestResults |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class TestResultsEdges(TestResults): |
12
|
|
|
"""Tests for the graph class. |
13
|
|
|
|
14
|
|
|
Tests to see if reflexive searches and impossible searches |
15
|
|
|
show correct results. |
16
|
|
|
""" |
17
|
|
|
|
18
|
|
|
def test_path1(self): |
19
|
|
|
"""Tests paths between all users using unconstrained path algorithm.""" |
20
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
21
|
|
|
self.initializer() |
22
|
|
|
|
23
|
|
|
valid = True |
24
|
|
|
for point_a, point_b in combos: |
25
|
|
|
results = self.get_path(point_a, point_b) |
26
|
|
|
if not results: |
27
|
|
|
valid = False |
28
|
|
|
break |
29
|
|
|
|
30
|
|
|
self.assertNotEqual(valid, False) |
31
|
|
|
|
32
|
|
|
def test_path12(self): |
33
|
|
|
"""Tests paths between all users using unconstrained path algorithm.""" |
34
|
|
|
combos = combinations(["User1", "User2", "User3", "User4", "User5"], 2) |
35
|
|
|
self.initializer() |
36
|
|
|
|
37
|
|
|
valid = True |
38
|
|
|
for point_a, point_b in combos: |
39
|
|
|
results = self.get_path(point_a, point_b) |
40
|
|
|
if not results: |
41
|
|
|
valid = False |
42
|
|
|
break |
43
|
|
|
|
44
|
|
|
self.assertEqual(valid, False) |
45
|
|
|
|
46
|
|
|
def test_path2(self): |
47
|
|
|
"""Tests paths between all users using constrained path algorithm, |
48
|
|
|
with no constraints set. |
49
|
|
|
""" |
50
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
51
|
|
|
self.initializer() |
52
|
|
|
|
53
|
|
|
for point_a, point_b in combos: |
54
|
|
|
results = self.get_path_constrained(point_a, point_b) |
55
|
|
|
self.assertNotEqual(results, []) |
56
|
|
|
|
57
|
|
|
def paths_between_all_users(self, item, base): |
58
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
59
|
|
|
self.initializer() |
60
|
|
|
|
61
|
|
|
my_key, my_val = next(iter(base.items())) |
62
|
|
|
base = {my_key: my_val} |
63
|
|
|
|
64
|
|
|
valid = True |
65
|
|
|
for point_a, point_b in combos: |
66
|
|
|
results = self.get_path_constrained( |
67
|
|
|
point_a, point_b, base=base) |
68
|
|
|
for result in results: |
69
|
|
|
for path in result["paths"]: |
70
|
|
|
if item in path: |
71
|
|
|
valid = False |
72
|
|
|
|
73
|
|
|
return valid |
74
|
|
|
|
75
|
|
|
def test_path3_1(self): |
76
|
|
|
"""Tests paths between all users using constrained path algorithm, |
77
|
|
|
with the ownership constraint set to B. |
78
|
|
|
""" |
79
|
|
|
self.assertTrue(self.paths_between_all_users("S4:1", {'ownership': "B"})) |
80
|
|
|
|
81
|
|
|
def test_path3_2(self): |
82
|
|
|
"""Tests paths between all users using constrained path algorithm, |
83
|
|
|
with the ownership constraint set to B. |
84
|
|
|
""" |
85
|
|
|
self.assertTrue(self.paths_between_all_users("S5:2", {'ownership': "B"})) |
86
|
|
|
|
87
|
|
|
def test_path3_3(self): |
88
|
|
|
"""Tests paths between all users using constrained path algorithm, |
89
|
|
|
with the ownership constraint set to B. |
90
|
|
|
""" |
91
|
|
|
self.assertTrue(self.paths_between_all_users("S4:2", {'ownership': "B"})) |
92
|
|
|
|
93
|
|
|
def test_path3_4(self): |
94
|
|
|
"""Tests paths between all users using constrained path algorithm, |
95
|
|
|
with the ownership constraint set to B. |
96
|
|
|
""" |
97
|
|
|
self.assertTrue(self.paths_between_all_users("User1:2", {'ownership': "B"})) |
98
|
|
|
|
99
|
|
|
def test_path3_5(self): |
100
|
|
|
"""Tests paths between all users using constrained path algorithm, |
101
|
|
|
with the ownership constraint set to B. |
102
|
|
|
""" |
103
|
|
|
self.assertTrue(self.paths_between_all_users("S5:4", {'ownership': "B"})) |
104
|
|
|
|
105
|
|
|
def test_path3_6(self): |
106
|
|
|
"""Tests paths between all users using constrained path algorithm, |
107
|
|
|
with the ownership constraint set to B. |
108
|
|
|
""" |
109
|
|
|
self.assertTrue(self.paths_between_all_users("S6:2", {'ownership': "B"})) |
110
|
|
|
|
111
|
|
|
def test_path3_7(self): |
112
|
|
|
"""Tests paths between all users using constrained path algorithm, |
113
|
|
|
with the ownership constraint set to B. |
114
|
|
|
""" |
115
|
|
|
self.assertTrue(self.paths_between_all_users("S6:5", {'ownership': "B"})) |
116
|
|
|
|
117
|
|
|
def test_path3_8(self): |
118
|
|
|
"""Tests paths between all users using constrained path algorithm, |
119
|
|
|
with the ownership constraint set to B. |
120
|
|
|
""" |
121
|
|
|
self.assertTrue(self.paths_between_all_users("S10:1", {'ownership': "B"})) |
122
|
|
|
|
123
|
|
|
def test_path3_9(self): |
124
|
|
|
"""Tests paths between all users using constrained path algorithm, |
125
|
|
|
with the ownership constraint set to B. |
126
|
|
|
""" |
127
|
|
|
self.assertTrue(self.paths_between_all_users("S8:6", {'ownership': "B"})) |
128
|
|
|
|
129
|
|
|
def test_path3_1_0(self): |
130
|
|
|
"""Tests paths between all users using constrained path algorithm, |
131
|
|
|
with the ownership constraint set to B. |
132
|
|
|
""" |
133
|
|
|
self.assertTrue(self.paths_between_all_users("S10:2", {'ownership': "B"})) |
134
|
|
|
|
135
|
|
|
def test_path3_1_1(self): |
136
|
|
|
"""Tests paths between all users using constrained path algorithm, |
137
|
|
|
with the ownership constraint set to B. |
138
|
|
|
""" |
139
|
|
|
self.assertTrue(self.paths_between_all_users("S10:3", {'ownership': "B"})) |
140
|
|
|
|
141
|
|
|
def test_path3_1_2(self): |
142
|
|
|
"""Tests paths between all users using constrained path algorithm, |
143
|
|
|
with the ownership constraint set to B. |
144
|
|
|
""" |
145
|
|
|
self.assertTrue(self.paths_between_all_users("User2:1", {'ownership': "B"})) |
146
|
|
|
|
147
|
|
|
def test_path4_1(self): |
148
|
|
|
"""Tests paths between all users using constrained path algorithm, |
149
|
|
|
with the reliability constraint set to 3. |
150
|
|
|
""" |
151
|
|
|
self.assertTrue(self.paths_between_all_users("S4:1", {'reliability': 3})) |
152
|
|
|
|
153
|
|
|
def test_path4_2(self): |
154
|
|
|
"""Tests paths between all users using constrained path algorithm, |
155
|
|
|
with the reliability constraint set to 3. |
156
|
|
|
""" |
157
|
|
|
self.assertTrue(self.paths_between_all_users("S5:2", {'reliability': 3})) |
158
|
|
|
|
159
|
|
|
def test_path4_3(self): |
160
|
|
|
"""Tests paths between all users using constrained path algorithm, |
161
|
|
|
with the reliability constraint set to 3. |
162
|
|
|
""" |
163
|
|
|
self.assertTrue(self.paths_between_all_users("S5:3", {'reliability': 3})) |
164
|
|
|
|
165
|
|
|
def test_path4_4(self): |
166
|
|
|
"""Tests paths between all users using constrained path algorithm, |
167
|
|
|
with the reliability constraint set to 3. |
168
|
|
|
""" |
169
|
|
|
self.assertTrue(self.paths_between_all_users("S6:1", {'reliability': 3})) |
170
|
|
|
|
171
|
|
|
def test_path5_1(self): |
172
|
|
|
"""Tests paths between all users using constrained path algorithm, |
173
|
|
|
with the reliability constraint set to 3. |
174
|
|
|
""" |
175
|
|
|
self.assertTrue(self.paths_between_all_users("S3:1", {'bandwidth': 100})) |
176
|
|
|
|
177
|
|
|
def test_path5_2(self): |
178
|
|
|
"""Tests paths between all users using constrained path algorithm, |
179
|
|
|
with the reliability constraint set to 3. |
180
|
|
|
""" |
181
|
|
|
self.assertTrue(self.paths_between_all_users("S5:1", {'bandwidth': 100})) |
182
|
|
|
|
183
|
|
|
def test_path5_3(self): |
184
|
|
|
"""Tests paths between all users using constrained path algorithm, |
185
|
|
|
with the reliability constraint set to 3. |
186
|
|
|
""" |
187
|
|
|
self.assertTrue(self.paths_between_all_users("User1:4", {'bandwidth': 100})) |
188
|
|
|
|
189
|
|
|
def test_path5_4(self): |
190
|
|
|
"""Tests paths between all users using constrained path algorithm, |
191
|
|
|
with the reliability constraint set to 3. |
192
|
|
|
""" |
193
|
|
|
self.assertTrue(self.paths_between_all_users("User4:3", {'bandwidth': 100})) |
194
|
|
|
|
195
|
|
|
def test_path6_1(self): |
196
|
|
|
"""Tests paths between all users using constrained path algorithm, |
197
|
|
|
with the delay constraint set to 50. |
198
|
|
|
""" |
199
|
|
|
self.assertTrue(self.paths_between_all_users("S1:1", {'delay': 50})) |
200
|
|
|
|
201
|
|
|
def test_path6_2(self): |
202
|
|
|
"""Tests paths between all users using constrained path algorithm, |
203
|
|
|
with the delay constraint set to 50. |
204
|
|
|
""" |
205
|
|
|
self.assertTrue(self.paths_between_all_users("S2:1", {'delay': 50})) |
206
|
|
|
|
207
|
|
|
def test_path6_3(self): |
208
|
|
|
"""Tests paths between all users using constrained path algorithm, |
209
|
|
|
with the delay constraint set to 50. |
210
|
|
|
""" |
211
|
|
|
self.assertTrue(self.paths_between_all_users("S3:1", {'delay': 50})) |
212
|
|
|
|
213
|
|
|
def test_path6_4(self): |
214
|
|
|
"""Tests paths between all users using constrained path algorithm, |
215
|
|
|
with the delay constraint set to 50. |
216
|
|
|
""" |
217
|
|
|
self.assertTrue(self.paths_between_all_users("S5:1", {'delay': 50})) |
218
|
|
|
|
219
|
|
|
def test_path6_5(self): |
220
|
|
|
"""Tests paths between all users using constrained path algorithm, |
221
|
|
|
with the delay constraint set to 50. |
222
|
|
|
""" |
223
|
|
|
self.assertTrue(self.paths_between_all_users("S4:2", {'delay': 50})) |
224
|
|
|
|
225
|
|
|
def test_path6_6(self): |
226
|
|
|
"""Tests paths between all users using constrained path algorithm, |
227
|
|
|
with the delay constraint set to 50. |
228
|
|
|
""" |
229
|
|
|
self.assertTrue(self.paths_between_all_users("User1:2", {'delay': 50})) |
230
|
|
|
|
231
|
|
|
def test_path6_7(self): |
232
|
|
|
"""Tests paths between all users using constrained path algorithm, |
233
|
|
|
with the delay constraint set to 50. |
234
|
|
|
""" |
235
|
|
|
self.assertTrue(self.paths_between_all_users("S5:5", {'delay': 50})) |
236
|
|
|
|
237
|
|
|
def test_path6_8(self): |
238
|
|
|
"""Tests paths between all users using constrained path algorithm, |
239
|
|
|
with the delay constraint set to 50. |
240
|
|
|
""" |
241
|
|
|
self.assertTrue(self.paths_between_all_users("S8:2", {'delay': 50})) |
242
|
|
|
|
243
|
|
|
def test_path6_9(self): |
244
|
|
|
"""Tests paths between all users using constrained path algorithm, |
245
|
|
|
with the delay constraint set to 50. |
246
|
|
|
""" |
247
|
|
|
self.assertTrue(self.paths_between_all_users("S5:6", {'delay': 50})) |
248
|
|
|
|
249
|
|
|
def test_path6_1_0(self): |
250
|
|
|
"""Tests paths between all users using constrained path algorithm, |
251
|
|
|
with the delay constraint set to 50. |
252
|
|
|
""" |
253
|
|
|
self.assertTrue(self.paths_between_all_users("User1:3", {'delay': 50})) |
254
|
|
|
|
255
|
|
|
def test_path6_1_1(self): |
256
|
|
|
"""Tests paths between all users using constrained path algorithm, |
257
|
|
|
with the delay constraint set to 50. |
258
|
|
|
""" |
259
|
|
|
self.assertTrue(self.paths_between_all_users("S6:3", {'delay': 50})) |
260
|
|
|
|
261
|
|
|
def test_path6_1_2(self): |
262
|
|
|
"""Tests paths between all users using constrained path algorithm, |
263
|
|
|
with the delay constraint set to 50. |
264
|
|
|
""" |
265
|
|
|
self.assertTrue(self.paths_between_all_users("S9:1", {'delay': 50})) |
266
|
|
|
|
267
|
|
|
def test_path6_1_3(self): |
268
|
|
|
"""Tests paths between all users using constrained path algorithm, |
269
|
|
|
with the delay constraint set to 50. |
270
|
|
|
""" |
271
|
|
|
self.assertTrue(self.paths_between_all_users("S6:4", {'delay': 50})) |
272
|
|
|
|
273
|
|
|
def test_path6_1_4(self): |
274
|
|
|
"""Tests paths between all users using constrained path algorithm, |
275
|
|
|
with the delay constraint set to 50. |
276
|
|
|
""" |
277
|
|
|
self.assertTrue(self.paths_between_all_users("S9:2", {'delay': 50})) |
278
|
|
|
|
279
|
|
|
def test_path6_1_5(self): |
280
|
|
|
"""Tests paths between all users using constrained path algorithm, |
281
|
|
|
with the delay constraint set to 50. |
282
|
|
|
""" |
283
|
|
|
self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50})) |
284
|
|
|
|
285
|
|
|
def test_path6_1_6(self): |
286
|
|
|
"""Tests paths between all users using constrained path algorithm, |
287
|
|
|
with the delay constraint set to 50. |
288
|
|
|
""" |
289
|
|
|
self.assertTrue(self.paths_between_all_users("S6:5", {'delay': 50})) |
290
|
|
|
|
291
|
|
|
def test_path6_1_7(self): |
292
|
|
|
"""Tests paths between all users using constrained path algorithm, |
293
|
|
|
with the delay constraint set to 50. |
294
|
|
|
""" |
295
|
|
|
self.assertTrue(self.paths_between_all_users("S10:1", {'delay': 50})) |
296
|
|
|
|
297
|
|
|
def test_path6_1_8(self): |
298
|
|
|
"""Tests paths between all users using constrained path algorithm, |
299
|
|
|
with the delay constraint set to 50. |
300
|
|
|
""" |
301
|
|
|
self.assertTrue(self.paths_between_all_users("S8:5", {'delay': 50})) |
302
|
|
|
|
303
|
|
|
def test_path6_1_9(self): |
304
|
|
|
"""Tests paths between all users using constrained path algorithm, |
305
|
|
|
with the delay constraint set to 50. |
306
|
|
|
""" |
307
|
|
|
self.assertTrue(self.paths_between_all_users("S9:4", {'delay': 50})) |
308
|
|
|
|
309
|
|
|
def test_path6_2_0(self): |
310
|
|
|
"""Tests paths between all users using constrained path algorithm, |
311
|
|
|
with the delay constraint set to 50. |
312
|
|
|
""" |
313
|
|
|
self.assertTrue(self.paths_between_all_users("User1:4", {'delay': 50})) |
314
|
|
|
|
315
|
|
|
def test_path6_2_1(self): |
316
|
|
|
"""Tests paths between all users using constrained path algorithm, |
317
|
|
|
with the delay constraint set to 50. |
318
|
|
|
""" |
319
|
|
|
self.assertTrue(self.paths_between_all_users("User4:3", {'delay': 50})) |
320
|
|
|
|
321
|
|
|
def test_path7(self): |
322
|
|
|
"""Tests paths between all users using constrained path algorithm, |
323
|
|
|
with the delay constraint set to 50, the bandwidth constraint set |
324
|
|
|
to 100, the reliability constraint set to 3, and the ownership |
325
|
|
|
constraint set to 'B' |
326
|
|
|
""" |
327
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
328
|
|
|
self.initializer() |
329
|
|
|
|
330
|
|
|
for point_a, point_b in combos: |
331
|
|
|
results = self.get_path_constrained( |
332
|
|
|
point_a, point_b, base=dict(delay=50, bandwidth=100, |
333
|
|
|
reliability=3, |
334
|
|
|
ownership="B")) |
335
|
|
|
for result in results: |
336
|
|
|
for path in result["paths"]: |
337
|
|
|
# delay = 50 checks |
338
|
|
|
self.assertNotIn("S1:1", path) |
339
|
|
|
self.assertNotIn("S2:1", path) |
340
|
|
|
self.assertNotIn("S3:1", path) |
341
|
|
|
self.assertNotIn("S5:1", path) |
342
|
|
|
self.assertNotIn("S4:2", path) |
343
|
|
|
self.assertNotIn("User1:2", path) |
344
|
|
|
self.assertNotIn("S5:5", path) |
345
|
|
|
self.assertNotIn("S8:2", path) |
346
|
|
|
self.assertNotIn("S5:6", path) |
347
|
|
|
self.assertNotIn("User1:3", path) |
348
|
|
|
self.assertNotIn("S6:3", path) |
349
|
|
|
self.assertNotIn("S9:1", path) |
350
|
|
|
self.assertNotIn("S6:4", path) |
351
|
|
|
self.assertNotIn("S9:2", path) |
352
|
|
|
self.assertNotIn("S6:5", path) |
353
|
|
|
self.assertNotIn("S10:1", path) |
354
|
|
|
self.assertNotIn("S8:5", path) |
355
|
|
|
self.assertNotIn("S9:4", path) |
356
|
|
|
self.assertNotIn("User1:4", path) |
357
|
|
|
self.assertNotIn("User4:3", path) |
358
|
|
|
|
359
|
|
|
# bandwidth = 100 checks |
360
|
|
|
|
361
|
|
|
self.assertNotIn("S3:1", path) |
362
|
|
|
self.assertNotIn("S5:1", path) |
363
|
|
|
self.assertNotIn("User1:4", path) |
364
|
|
|
self.assertNotIn("User4:3", path) |
365
|
|
|
|
366
|
|
|
# reliability = 3 checks |
367
|
|
|
|
368
|
|
|
self.assertNotIn("S4:1", path) |
369
|
|
|
self.assertNotIn("S5:2", path) |
370
|
|
|
self.assertNotIn("S5:3", path) |
371
|
|
|
self.assertNotIn("S6:1", path) |
372
|
|
|
|
373
|
|
|
# ownership = "B" checks |
374
|
|
|
|
375
|
|
|
self.assertNotIn("S4:1", path) |
376
|
|
|
self.assertNotIn("S5:2", path) |
377
|
|
|
self.assertNotIn("S4:2", path) |
378
|
|
|
self.assertNotIn("User1:2", path) |
379
|
|
|
self.assertNotIn("S5:4", path) |
380
|
|
|
self.assertNotIn("S6:2", path) |
381
|
|
|
self.assertNotIn("S6:5", path) |
382
|
|
|
self.assertNotIn("S10:1", path) |
383
|
|
|
self.assertNotIn("S8:6", path) |
384
|
|
|
self.assertNotIn("S10:2", path) |
385
|
|
|
self.assertNotIn("S10:3", path) |
386
|
|
|
self.assertNotIn("User2:1", path) |
387
|
|
|
|
388
|
|
|
def test_path8(self): |
389
|
|
|
"""Tests paths between all users using constrained path algorithm, |
390
|
|
|
with the delay constraint set to 50, the bandwidth constraint |
391
|
|
|
set to 100, the reliability constraint set to 3, and the ownership |
392
|
|
|
constraint set to 'B' |
393
|
|
|
|
394
|
|
|
Tests conducted with flexibility enabled |
395
|
|
|
""" |
396
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
397
|
|
|
self.initializer() |
398
|
|
|
|
399
|
|
|
for point_a, point_b in combos: |
400
|
|
|
results = self.get_path_constrained( |
401
|
|
|
point_a, point_b, flexible=dict(delay=50, bandwidth=100, |
402
|
|
|
reliability=3, |
403
|
|
|
ownership="B")) |
404
|
|
|
for result in results: |
405
|
|
|
# delay = 50 checks |
406
|
|
View Code Duplication |
if "delay" in result["metrics"]: |
|
|
|
|
407
|
|
|
for path in result["paths"]: |
408
|
|
|
self.assertNotIn("S1:1", path) |
409
|
|
|
self.assertNotIn("S2:1", path) |
410
|
|
|
self.assertNotIn("S3:1", path) |
411
|
|
|
self.assertNotIn("S5:1", path) |
412
|
|
|
self.assertNotIn("S4:2", path) |
413
|
|
|
self.assertNotIn("User1:2", path) |
414
|
|
|
self.assertNotIn("S5:5", path) |
415
|
|
|
self.assertNotIn("S8:2", path) |
416
|
|
|
self.assertNotIn("S5:6", path) |
417
|
|
|
self.assertNotIn("User1:3", path) |
418
|
|
|
self.assertNotIn("S6:3", path) |
419
|
|
|
self.assertNotIn("S9:1", path) |
420
|
|
|
self.assertNotIn("S6:4", path) |
421
|
|
|
self.assertNotIn("S9:2", path) |
422
|
|
|
self.assertNotIn("S6:5", path) |
423
|
|
|
self.assertNotIn("S10:1", path) |
424
|
|
|
self.assertNotIn("S8:5", path) |
425
|
|
|
self.assertNotIn("S9:4", path) |
426
|
|
|
self.assertNotIn("User1:4", path) |
427
|
|
|
self.assertNotIn("User4:3", path) |
428
|
|
|
|
429
|
|
|
# bandwidth = 100 checks |
430
|
|
|
if "bandwidth" in result["metrics"]: |
431
|
|
|
for path in result["paths"]: |
432
|
|
|
self.assertNotIn("S3:1", path) |
433
|
|
|
self.assertNotIn("S5:1", path) |
434
|
|
|
self.assertNotIn("User1:4", path) |
435
|
|
|
self.assertNotIn("User4:3", path) |
436
|
|
|
|
437
|
|
|
# reliability = 3 checks |
438
|
|
|
if "reliability" in result["metrics"]: |
439
|
|
|
for path in result["paths"]: |
440
|
|
|
self.assertNotIn("S4:1", path) |
441
|
|
|
self.assertNotIn("S5:2", path) |
442
|
|
|
self.assertNotIn("S5:3", path) |
443
|
|
|
self.assertNotIn("S6:1", path) |
444
|
|
|
|
445
|
|
|
# ownership = "B" checks |
446
|
|
|
if "ownership" in result["metrics"]: |
447
|
|
|
for path in result["paths"]: |
448
|
|
|
self.assertNotIn("S4:1", path) |
449
|
|
|
self.assertNotIn("S5:2", path) |
450
|
|
|
self.assertNotIn("S4:2", path) |
451
|
|
|
self.assertNotIn("User1:2", path) |
452
|
|
|
self.assertNotIn("S5:4", path) |
453
|
|
|
self.assertNotIn("S6:2", path) |
454
|
|
|
self.assertNotIn("S6:5", path) |
455
|
|
|
self.assertNotIn("S10:1", path) |
456
|
|
|
self.assertNotIn("S8:6", path) |
457
|
|
|
self.assertNotIn("S10:2", path) |
458
|
|
|
self.assertNotIn("S10:3", path) |
459
|
|
|
self.assertNotIn("User2:1", path) |
460
|
|
|
|
461
|
|
|
def test_path9(self): |
462
|
|
|
"""Tests paths between all users using constrained path algorithm, |
463
|
|
|
with the delay constraint set to 50, the bandwidth constraint |
464
|
|
|
set to 100, the reliability constraint set to 3, and the ownership |
465
|
|
|
constraint set to 'B' |
466
|
|
|
|
467
|
|
|
Tests conducted with all but ownership flexible |
468
|
|
|
""" |
469
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
470
|
|
|
self.initializer() |
471
|
|
|
|
472
|
|
|
for point_a, point_b in combos: |
473
|
|
|
results = self.get_path_constrained(point_a, point_b, |
474
|
|
|
base={"ownership": "B"}, |
475
|
|
|
flexible={"delay": 50, |
476
|
|
|
"bandwidth": 100, |
477
|
|
|
"reliability": 3}) |
478
|
|
|
for result in results: |
479
|
|
|
# delay = 50 checks |
480
|
|
View Code Duplication |
if "delay" in result["metrics"]: |
|
|
|
|
481
|
|
|
for path in result["paths"]: |
482
|
|
|
self.assertNotIn("S1:1", path) |
483
|
|
|
self.assertNotIn("S2:1", path) |
484
|
|
|
self.assertNotIn("S3:1", path) |
485
|
|
|
self.assertNotIn("S5:1", path) |
486
|
|
|
self.assertNotIn("S4:2", path) |
487
|
|
|
self.assertNotIn("User1:2", path) |
488
|
|
|
self.assertNotIn("S5:5", path) |
489
|
|
|
self.assertNotIn("S8:2", path) |
490
|
|
|
self.assertNotIn("S5:6", path) |
491
|
|
|
self.assertNotIn("User1:3", path) |
492
|
|
|
self.assertNotIn("S6:3", path) |
493
|
|
|
self.assertNotIn("S9:1", path) |
494
|
|
|
self.assertNotIn("S6:4", path) |
495
|
|
|
self.assertNotIn("S9:2", path) |
496
|
|
|
self.assertNotIn("S6:5", path) |
497
|
|
|
self.assertNotIn("S10:1", path) |
498
|
|
|
self.assertNotIn("S8:5", path) |
499
|
|
|
self.assertNotIn("S9:4", path) |
500
|
|
|
self.assertNotIn("User1:4", path) |
501
|
|
|
self.assertNotIn("User4:3", path) |
502
|
|
|
|
503
|
|
|
# bandwidth = 100 checks |
504
|
|
|
if "bandwidth" in result["metrics"]: |
505
|
|
|
for path in result["paths"]: |
506
|
|
|
self.assertNotIn("S3:1", path) |
507
|
|
|
self.assertNotIn("S5:1", path) |
508
|
|
|
self.assertNotIn("User1:4", path) |
509
|
|
|
self.assertNotIn("User4:3", path) |
510
|
|
|
|
511
|
|
|
# reliability = 3 checks |
512
|
|
|
if "reliability" in result["metrics"]: |
513
|
|
|
for path in result["paths"]: |
514
|
|
|
self.assertNotIn("S4:1", path) |
515
|
|
|
self.assertNotIn("S5:2", path) |
516
|
|
|
self.assertNotIn("S5:3", path) |
517
|
|
|
self.assertNotIn("S6:1", path) |
518
|
|
|
|
519
|
|
|
# ownership = "B" checks |
520
|
|
|
self.assertIn("ownership", result["metrics"]) |
521
|
|
|
for path in result["paths"]: |
522
|
|
|
self.assertNotIn("S4:1", path) |
523
|
|
|
self.assertNotIn("S5:2", path) |
524
|
|
|
self.assertNotIn("S4:2", path) |
525
|
|
|
self.assertNotIn("User1:2", path) |
526
|
|
|
self.assertNotIn("S5:4", path) |
527
|
|
|
self.assertNotIn("S6:2", path) |
528
|
|
|
self.assertNotIn("S6:5", path) |
529
|
|
|
self.assertNotIn("S10:1", path) |
530
|
|
|
self.assertNotIn("S8:6", path) |
531
|
|
|
self.assertNotIn("S10:2", path) |
532
|
|
|
self.assertNotIn("S10:3", path) |
533
|
|
|
self.assertNotIn("User2:1", path) |
534
|
|
|
|
535
|
|
|
def test_path10(self): |
536
|
|
|
"""Tests that TypeError is generated by get_path_constrained |
537
|
|
|
|
538
|
|
|
Tests with ownership using an int type rather than string |
539
|
|
|
""" |
540
|
|
|
self.initializer() |
541
|
|
|
|
542
|
|
|
with self.assertRaises(TypeError): |
543
|
|
|
self.get_path_constrained( |
544
|
|
|
"User1", "User2", base={"ownership": 1}) |
545
|
|
|
|
546
|
|
|
@staticmethod |
547
|
|
|
def generate_topology(): |
548
|
|
|
"""Generates a predetermined topology""" |
549
|
|
|
switches = {} |
550
|
|
|
interfaces = {} |
551
|
|
|
links = {} |
552
|
|
|
|
553
|
|
|
TestResults.create_switch("S1", switches) |
554
|
|
|
TestResults.add_interfaces(2, switches["S1"], interfaces) |
555
|
|
|
|
556
|
|
|
TestResults.create_switch("S2", switches) |
557
|
|
|
TestResults.add_interfaces(2, switches["S2"], interfaces) |
558
|
|
|
|
559
|
|
|
TestResults.create_switch("S3", switches) |
560
|
|
|
TestResults.add_interfaces(6, switches["S3"], interfaces) |
561
|
|
|
|
562
|
|
|
TestResults.create_switch("S4", switches) |
563
|
|
|
TestResults.add_interfaces(2, switches["S4"], interfaces) |
564
|
|
|
|
565
|
|
|
TestResults.create_switch("S5", switches) |
566
|
|
|
TestResults.add_interfaces(6, switches["S5"], interfaces) |
567
|
|
|
|
568
|
|
|
TestResults.create_switch("S6", switches) |
569
|
|
|
TestResults.add_interfaces(5, switches["S6"], interfaces) |
570
|
|
|
|
571
|
|
|
TestResults.create_switch("S7", switches) |
572
|
|
|
TestResults.add_interfaces(2, switches["S7"], interfaces) |
573
|
|
|
|
574
|
|
|
TestResults.create_switch("S8", switches) |
575
|
|
|
TestResults.add_interfaces(8, switches["S8"], interfaces) |
576
|
|
|
|
577
|
|
|
TestResults.create_switch("S9", switches) |
578
|
|
|
TestResults.add_interfaces(4, switches["S9"], interfaces) |
579
|
|
|
|
580
|
|
|
TestResults.create_switch("S10", switches) |
581
|
|
|
TestResults.add_interfaces(3, switches["S10"], interfaces) |
582
|
|
|
|
583
|
|
|
TestResults.create_switch("S11", switches) |
584
|
|
|
TestResults.add_interfaces(3, switches["S11"], interfaces) |
585
|
|
|
|
586
|
|
|
TestResults.create_switch("User1", switches) |
587
|
|
|
TestResults.add_interfaces(4, switches["User1"], interfaces) |
588
|
|
|
|
589
|
|
|
TestResults.create_switch("User2", switches) |
590
|
|
|
TestResults.add_interfaces(2, switches["User2"], interfaces) |
591
|
|
|
|
592
|
|
|
TestResults.create_switch("User3", switches) |
593
|
|
|
TestResults.add_interfaces(2, switches["User3"], interfaces) |
594
|
|
|
|
595
|
|
|
TestResults.create_switch("User4", switches) |
596
|
|
|
TestResults.add_interfaces(3, switches["User4"], interfaces) |
597
|
|
|
|
598
|
|
|
TestResultsEdges._fill_links(links, interfaces) |
599
|
|
|
|
600
|
|
|
TestResultsEdges._add_metadata_to_links(links) |
601
|
|
|
|
602
|
|
|
return switches, links |
603
|
|
|
|
604
|
|
|
@staticmethod |
605
|
|
|
def _add_metadata_to_links(links): |
606
|
|
|
links["S1:1<->S2:1"].extend_metadata( |
607
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 105}) |
608
|
|
|
|
609
|
|
|
links["S1:2<->User1:1"].extend_metadata( |
610
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
611
|
|
|
|
612
|
|
|
links["S2:2<->User4:1"].extend_metadata( |
613
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 10}) |
614
|
|
|
|
615
|
|
|
links["S3:1<->S5:1"].extend_metadata( |
616
|
|
|
{"reliability": 5, "bandwidth": 10, "delay": 112}) |
617
|
|
|
|
618
|
|
|
links["S3:2<->S7:1"].extend_metadata( |
619
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
620
|
|
|
|
621
|
|
|
links["S3:3<->S8:1"].extend_metadata( |
622
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
623
|
|
|
|
624
|
|
|
links["S3:4<->S11:1"].extend_metadata( |
625
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 6}) |
626
|
|
|
|
627
|
|
|
links["S3:5<->User3:1"].extend_metadata( |
628
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
629
|
|
|
|
630
|
|
|
links["S3:6<->User4:2"].extend_metadata( |
631
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 10}) |
632
|
|
|
|
633
|
|
|
links["S4:1<->S5:2"].extend_metadata( |
634
|
|
|
{"reliability": 1, "bandwidth": 100, "delay": 30, |
635
|
|
|
"ownership": "A"}) |
636
|
|
|
|
637
|
|
|
links["S4:2<->User1:2"].extend_metadata( |
638
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 110, |
639
|
|
|
"ownership": "A"}) |
640
|
|
|
|
641
|
|
|
links["S5:3<->S6:1"].extend_metadata( |
642
|
|
|
{"reliability": 1, "bandwidth": 100, "delay": 40}) |
643
|
|
|
|
644
|
|
|
links["S5:4<->S6:2"].extend_metadata( |
645
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 40, |
646
|
|
|
"ownership": "A"}) |
647
|
|
|
|
648
|
|
|
links["S5:5<->S8:2"].extend_metadata( |
649
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 112}) |
650
|
|
|
|
651
|
|
|
links["S5:6<->User1:3"].extend_metadata( |
652
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 60}) |
653
|
|
|
|
654
|
|
|
links["S6:3<->S9:1"].extend_metadata( |
655
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 60}) |
656
|
|
|
|
657
|
|
|
links["S6:4<->S9:2"].extend_metadata( |
658
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 62}) |
659
|
|
|
|
660
|
|
|
links["S6:5<->S10:1"].extend_metadata( |
661
|
|
|
{"bandwidth": 100, "delay": 108, "ownership": "A"}) |
662
|
|
|
|
663
|
|
|
links["S7:2<->S8:3"].extend_metadata( |
664
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
665
|
|
|
|
666
|
|
|
links["S8:4<->S9:3"].extend_metadata( |
667
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 32}) |
668
|
|
|
|
669
|
|
|
links["S8:5<->S9:4"].extend_metadata( |
670
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 110}) |
671
|
|
|
|
672
|
|
|
links["S8:6<->S10:2"].extend_metadata( |
673
|
|
|
{"reliability": 5, "bandwidth": 100, "ownership": "A"}) |
674
|
|
|
|
675
|
|
|
links["S8:7<->S11:2"].extend_metadata( |
676
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 7}) |
677
|
|
|
|
678
|
|
|
links["S8:8<->User3:2"].extend_metadata( |
679
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
680
|
|
|
|
681
|
|
|
links["S10:3<->User2:1"].extend_metadata( |
682
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 10, |
683
|
|
|
"ownership": "A"}) |
684
|
|
|
|
685
|
|
|
links["S11:3<->User2:2"].extend_metadata( |
686
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 6}) |
687
|
|
|
|
688
|
|
|
links["User1:4<->User4:3"].extend_metadata( |
689
|
|
|
{"reliability": 5, "bandwidth": 10, "delay": 105}) |
690
|
|
|
|
691
|
|
|
@staticmethod |
692
|
|
|
def _fill_links(links, interfaces): |
693
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
694
|
|
|
|
695
|
|
|
links["S1:2<->User1:1"] = Link(interfaces["S1:2"], interfaces["User1:1"]) |
696
|
|
|
|
697
|
|
|
links["S2:2<->User4:1"] = Link(interfaces["S2:2"], interfaces["User4:1"]) |
698
|
|
|
|
699
|
|
|
links["S3:1<->S5:1"] = Link(interfaces["S3:1"], interfaces["S5:1"]) |
700
|
|
|
|
701
|
|
|
links["S3:2<->S7:1"] = Link(interfaces["S3:2"], interfaces["S7:1"]) |
702
|
|
|
|
703
|
|
|
links["S3:3<->S8:1"] = Link(interfaces["S3:3"], interfaces["S8:1"]) |
704
|
|
|
|
705
|
|
|
links["S3:4<->S11:1"] = Link(interfaces["S3:4"], interfaces["S11:1"]) |
706
|
|
|
|
707
|
|
|
links["S3:5<->User3:1"] = Link(interfaces["S3:5"], interfaces["User3:1"]) |
708
|
|
|
|
709
|
|
|
links["S3:6<->User4:2"] = Link(interfaces["S3:6"], interfaces["User4:2"]) |
710
|
|
|
|
711
|
|
|
links["S4:1<->S5:2"] = Link(interfaces["S4:1"], interfaces["S5:2"]) |
712
|
|
|
|
713
|
|
|
links["S4:2<->User1:2"] = Link(interfaces["S4:2"], interfaces["User1:2"]) |
714
|
|
|
|
715
|
|
|
links["S5:3<->S6:1"] = Link(interfaces["S5:3"], interfaces["S6:1"]) |
716
|
|
|
|
717
|
|
|
links["S5:4<->S6:2"] = Link(interfaces["S5:4"], interfaces["S6:2"]) |
718
|
|
|
|
719
|
|
|
links["S5:5<->S8:2"] = Link(interfaces["S5:5"], interfaces["S8:2"]) |
720
|
|
|
|
721
|
|
|
links["S5:6<->User1:3"] = Link(interfaces["S5:6"], interfaces["User1:3"]) |
722
|
|
|
|
723
|
|
|
links["S6:3<->S9:1"] = Link(interfaces["S6:3"], interfaces["S9:1"]) |
724
|
|
|
|
725
|
|
|
links["S6:4<->S9:2"] = Link(interfaces["S6:4"], interfaces["S9:2"]) |
726
|
|
|
|
727
|
|
|
links["S6:5<->S10:1"] = Link(interfaces["S6:5"], interfaces["S10:1"]) |
728
|
|
|
|
729
|
|
|
links["S7:2<->S8:3"] = Link(interfaces["S7:2"], interfaces["S8:3"]) |
730
|
|
|
|
731
|
|
|
links["S8:4<->S9:3"] = Link(interfaces["S8:4"], interfaces["S9:3"]) |
732
|
|
|
|
733
|
|
|
links["S8:5<->S9:4"] = Link(interfaces["S8:5"], interfaces["S9:4"]) |
734
|
|
|
|
735
|
|
|
links["S8:6<->S10:2"] = Link(interfaces["S8:6"], interfaces["S10:2"]) |
736
|
|
|
|
737
|
|
|
links["S8:7<->S11:2"] = Link(interfaces["S8:7"], interfaces["S11:2"]) |
738
|
|
|
|
739
|
|
|
links["S8:8<->User3:2"] = Link(interfaces["S8:8"], interfaces["User3:2"]) |
740
|
|
|
|
741
|
|
|
links["S10:3<->User2:1"] = Link(interfaces["S10:3"], interfaces["User2:1"]) |
742
|
|
|
|
743
|
|
|
links["S11:3<->User2:2"] = Link(interfaces["S11:3"], interfaces["User2:2"]) |
744
|
|
|
|
745
|
|
|
links["User1:4<->User4:3"] = Link(interfaces["User1:4"], interfaces["User4:3"]) |
746
|
|
|
|