-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_te_swap_efficiency_test.py
706 lines (593 loc) · 29 KB
/
code_te_swap_efficiency_test.py
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#!/usr/bin/env python
# -----------------------------------------------------------------
#
# Integration tests that checks that the controller TE optimisation
# mechanism behaves as expected. The tests implement the "TE Swap
# Efficiency Test" outlined in `Docs/TESwapEfficiencyTest.md`.
#
# Run using the command:
# python -m unittest code_te_swap_efficiency_test.py
#
# -----------------------------------------------------------------
import sys
import os
import unittest
import logging
from dummy_ctrl import DummyCtrl
class TEScenarioTest(unittest.TestCase):
""" Integrationt test class.
Arguments:
DEFAULT_PATHS (dict): Dictionary of expected path information to be generated
by the controller.
topo (dict): Topology description of the network
hosts (list of str): List of hosts in the topology
ctrl (DummyCtrl): Dummy controller object to test
"""
DEFAULT_PATHS = {
("h1", "h2"): {
"ingress": "s1", "in_port": 1,
"egress": "s1", "out_port": 2,
"groups": {}
}, ("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {"s1": [3, 4], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]}
}, ("h1", "h4"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 4,
"groups": {"s1": [3, 4], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]}
}, ("h2", "h1"): {
"ingress": "s1", "in_port": 2,
"egress": "s1", "out_port": 1,
"groups": {}
}, ("h2", "h3"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 3,
"groups": {"s1": [3, 4], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {"s1": [3, 4], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]}
}, ("h3", "h1"): {
"ingress": "s3", "in_port": 3,
"egress": "s1", "out_port": 1,
"groups": {"s3": [1, 2], "s2": [1, 2], "s1": [1], "s5": [1], "s4": [1]}
}, ("h3", "h2"): {
"ingress": "s3", "in_port": 3,
"egress": "s1", "out_port": 2,
"groups": {"s3": [1, 2], "s2": [1, 2], "s1": [2], "s5": [1], "s4": [1]}
}, ("h3", "h4"): {
"ingress": "s3", "in_port": 3,
"egress": "s3", "out_port": 4,
"groups": {}
}, ("h4", "h1"): {
"ingress": "s3", "in_port": 4,
"egress": "s1", "out_port": 1,
"groups": {"s3": [1, 2], "s2": [1, 2], "s1": [1], "s5": [1], "s4": [1]}
}, ("h4", "h2"): {
"ingress": "s3", "in_port": 4,
"egress": "s1", "out_port": 2,
"groups": {"s3": [1, 2], "s2": [1, 2], "s1": [2], "s5": [1], "s4": [1]}
}, ("h4", "h3"): {
"ingress": "s3", "in_port": 4,
"egress": "s3", "out_port": 3,
"groups": {}
}
}
def setUp(self):
""" Build the topology, initiate the controller and compute required paths """
self.topo = {
"h1": {-1: {"dest": "s1", "destPort": 1, "speed": 1000000000}},
"h2": {-1: {"dest": "s1", "destPort": 2, "speed": 1000000000}},
"s1": { 1: {"dest": "h1", "destPort": -1, "speed": 1000000000},
2: {"dest": "h2", "destPort": -1, "speed": 1000000000},
3: {"dest": "s2", "destPort": 1, "speed": 1000000000},
4: {"dest": "s4", "destPort": 1, "speed": 1000000000}},
"s4": { 1: {"dest": "s1", "destPort": 4, "speed": 1000000000},
2: {"dest": "s2", "destPort": 2, "speed": 1000000000}},
"s2": { 1: {"dest": "s1", "destPort": 3, "speed": 1000000000},
2: {"dest": "s4", "destPort": 2, "speed": 1000000000},
3: {"dest": "s3", "destPort": 1, "speed": 1000000000},
4: {"dest": "s5", "destPort": 1, "speed": 1000000000}},
"s5": { 1: {"dest": "s2", "destPort": 4, "speed": 1000000000},
2: {"dest": "s3", "destPort": 2, "speed": 1000000000}},
"s3": { 1: {"dest": "s2", "destPort": 3, "speed": 1000000000},
2: {"dest": "s5", "destPort": 2, "speed": 1000000000},
3: {"dest": "h3", "destPort": -1, "speed": 1000000000},
4: {"dest": "h4", "destPort": -1, "speed": 1000000000}},
"h3": {-1: {"dest": "s3", "destPort": 3, "speed": 1000000000}},
"h4": {-1: {"dest": "s3", "destPort": 4, "speed": 1000000000}}}
self.hosts = ["h1", "h2", "h3", "h4"]
# Supress any logging by setting to a level above critical
logging.basicConfig(level=100)
self.ctrl = DummyCtrl(topo=self.topo, hosts=self.hosts, logger=logging)
self.ctrl._install_protection()
self.ctrl.clear_traffic()
def test_case_00(self):
print("\nTesting default controller state")
self._check_info_dict(self.ctrl.paths)
self._check_congested_link([])
def test_case_01(self):
print("\nTesting scenario 1 (h1-h3 150M | h2-h4 120M)")
# Constraint the link between s1-s2 to 200Mbps and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=200000000)
self.ctrl.graph.update_port_info("s2", 1, speed=200000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [3, 4], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_02(self):
print("\nTesting scenario 2 (h1-h3 150M | h2-h4 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=200000000)
self.ctrl.graph.update_port_info("s2", 1, speed=200000000)
self.ctrl.graph.update_port_info("s2", 3, speed=200000000)
self.ctrl.graph.update_port_info("s3", 1, speed=200000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [3, 4], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_03(self):
print("\nTesting scenario 3 (h1-h3 150M | h2-h4 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=200000000)
self.ctrl.graph.update_port_info("s2", 1, speed=200000000)
self.ctrl.graph.update_port_info("s2", 3, speed=200000000)
self.ctrl.graph.update_port_info("s3", 1, speed=200000000)
self.ctrl.graph.update_port_info("s5", 2, speed=100000000)
self.ctrl.graph.update_port_info("s3", 2, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [3, 4], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([("s2", 3)])
# XXX TODO: While going through the steps of this test it seems that the controller
# TE swapover misbehaves, why dosen't it detect that swapping traffic at S1-S4 for
# both host pairs over-constrains the next effective link, S2-S3. This is strange.
# what is going on!!!!
def test_case_04(self):
print("\nTesting scenario 4 (h1-h3 150M | h2-h4 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=100000000)
self.ctrl.graph.update_port_info("s2", 1, speed=100000000)
self.ctrl.graph.update_port_info("s2", 3, speed=200000000)
self.ctrl.graph.update_port_info("s3", 1, speed=200000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation (step 1)
print("\tChecking for congested links (step 1)")
expected_congested = [("s1", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network (step 1)")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [4, 3], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications (step 1)")
self._check_info_dict(self.ctrl.paths, expected)
# Check for congested links and run optimisation (step 2)
print("\tChecking for congested links (step 2)")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
expected_congested = [("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network (step 2)")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [4, 3], "s2": [3, 4], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications (step 2)")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_05(self):
print("\nTesting scenario 5 (h1-h3 150M | h2-h4 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=200000000)
self.ctrl.graph.update_port_info("s2", 1, speed=200000000)
self.ctrl.graph.update_port_info("s2", 3, speed=100000000)
self.ctrl.graph.update_port_info("s3", 1, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [3, 4], "s2": [4, 3], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_06(self):
print("\nTesting scenario 6 (h1-h3 150M | h2-h4 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=100000000)
self.ctrl.graph.update_port_info("s2", 1, speed=100000000)
self.ctrl.graph.update_port_info("s2", 3, speed=100000000)
self.ctrl.graph.update_port_info("s3", 1, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_07(self):
print("\nTesting scenario 7 (h1-h3 150M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000}
self.ctrl.graph.update_port_info("s1", 3, speed=100000000)
self.ctrl.graph.update_port_info("s2", 1, speed=100000000)
self.ctrl.graph.update_port_info("s2", 3, speed=100000000)
self.ctrl.graph.update_port_info("s3", 1, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h2", "h4"): {
"ingress": "s1", "in_port": 2,
"egress": "s3", "out_port": 4,
"groups": {
"s1": [3, 4], "s2": [3, 4], "s3": [4], "s4": [2], "s5": [2]
}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_08(self):
print("\nTesting scenario 8 (h1-h3 150M | h4-h2 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h4", "h2"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=200000000)
self.ctrl.graph.update_port_info("s2", 1, speed=200000000)
self.ctrl.graph.update_port_info("s2", 3, speed=200000000)
self.ctrl.graph.update_port_info("s3", 1, speed=200000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = []
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
print("\tChecking paths were not modified")
self._check_info_dict(self.ctrl.paths)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_09(self):
print("\nTesting scenario 9 (h1-h3 150M | h4-h2 120M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h4", "h2"): 120000000}
self.ctrl.graph.update_port_info("s1", 3, speed=100000000)
self.ctrl.graph.update_port_info("s2", 1, speed=100000000)
self.ctrl.graph.update_port_info("s2", 3, speed=100000000)
self.ctrl.graph.update_port_info("s3", 1, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 3), ("s2", 3), ("s3", 1), ("s2", 1)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
expected = {
("h1", "h3"): {
"ingress": "s1", "in_port": 1,
"egress": "s3", "out_port": 3,
"groups": {
"s1": [4, 3], "s2": [4, 3], "s3": [3], "s4": [2], "s5": [2]
}
}, ("h4", "h2"): {
"ingress": "s3", "in_port": 4,
"egress": "s1", "out_port": 2,
"groups": {"s3": [2, 1], "s2": [2, 1], "s1": [2], "s5": [1], "s4": [1]}
}
}
print("\tChecking path modifications")
self._check_info_dict(self.ctrl.paths, expected)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([])
def test_case_10(self):
print("\nTesting scenario 10 (h1-h2 1G | h3-h4 1G)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h2"): 1000000000, ("h3", "h4"): 1000000000}
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s1", 2), ("s3", 4)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
print("\tChecking paths were not modified")
self._check_info_dict(self.ctrl.paths)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([], expected_congested)
def test_case_11(self):
print("\nTesting scenario 11 (h1-h3 150M | h2-h4 150M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h3"): 150000000, ("h2", "h4"): 150000000}
self.ctrl.graph.update_port_info("h1", -1, speed=100000000)
self.ctrl.graph.update_port_info("s1", 1, speed=100000000)
self.ctrl.graph.update_port_info("h2", -1, speed=100000000)
self.ctrl.graph.update_port_info("s1", 2, speed=100000000)
self.ctrl.graph.update_port_info("h3", -1, speed=100000000)
self.ctrl.graph.update_port_info("s3", 3, speed=100000000)
self.ctrl.graph.update_port_info("h4", -1, speed=100000000)
self.ctrl.graph.update_port_info("s3", 4, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s3", 3), ("s3", 4)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
print("\tChecking paths were not modified")
self._check_info_dict(self.ctrl.paths)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([], expected_congested)
def test_case_12(self):
print("\nTesting scenario 12 (h1-h4 150M | h2-h3 150M)")
# Constrain links and load traffic
print("\tConstraining topology links and loading traffic")
scenario_traffic = {("h1", "h4"): 150000000, ("h2", "h3"): 150000000}
self.ctrl.graph.update_port_info("h1", -1, speed=100000000)
self.ctrl.graph.update_port_info("s1", 1, speed=100000000)
self.ctrl.graph.update_port_info("h2", -1, speed=100000000)
self.ctrl.graph.update_port_info("s1", 2, speed=100000000)
self.ctrl.graph.update_port_info("h3", -1, speed=100000000)
self.ctrl.graph.update_port_info("s3", 3, speed=100000000)
self.ctrl.graph.update_port_info("h4", -1, speed=100000000)
self.ctrl.graph.update_port_info("s3", 4, speed=100000000)
self.ctrl.load_traffic(scenario_traffic)
# Check for congested links and run optimisation
print("\tChecking for congested links")
expected_congested = [("s3", 3), ("s3", 4)]
self._check_congested_link(expected_congested)
print("\tOptimising network")
self.ctrl.TE._optimise_TE()
print("\tChecking paths were not modified")
self._check_info_dict(self.ctrl.paths)
print("\tChecking final state of controller")
self.ctrl.clear_traffic()
self.ctrl.load_traffic(scenario_traffic)
self._check_congested_link([], expected_congested)
# ---------- HELPER METHODS ----------
def _check_info_dict(self, check, expected={}):
""" Asert if the information dictionary `check` contains the same state as `expected`.
Only the value of the fields in `expected` are compared. If the entries in `check`
contain extra fields, these will be ignored.
NOTE:
If `expected` dosen't contain a path host key, the default value is compared against
`expected`. Defaults are defined in `mod:attr:(DEFAULTS_PATHS)`.
"""
# Compare expected
for hkey,expect_d in expected.iteritems():
self.assertIn(hkey, check, msg="Host key %s-%s not in path info" % hkey)
for field,val in expect_d.iteritems():
target = self.ctrl.paths[hkey]
self.assertIn(field, target, msg="Field %s not in path info of %s-%s" %
(field, hkey[0], hkey[1]))
self.assertEqual(target[field], val, msg="Field (%s) %s != %s for path info of %s-%s" %
(field, target[field], val, hkey[0], hkey[1]))
# Compare default field values
for hkey,expect_d in self.DEFAULT_PATHS.iteritems():
if hkey in expected:
continue
self.assertIn(hkey, check, msg="(DEFAULT) Host key %s-%s not in path info" % hkey)
for field,val in expect_d.iteritems():
target = self.ctrl.paths[hkey]
self.assertIn(field, target, msg="(DEFAULT) Field %s not in path info of %s-%s" %
(field, hkey[0], hkey[1]))
self.assertEqual(target[field], val, msg="(DEFAULT) Field (%s) %s != %s for path info of %s-%s" %
(field, target[field], val, hkey[0], hkey[1]))
def _check_congested_link(self, congested, over_util_keys=None):
""" Assert that the controller is correctly detecting all links defined in `congested` as
congested. All other links also need to not be congested.
NOTE: `over_util_keys` specifies what keys we expect to be present in the TE module
over utilised dictionary at the end of the link congestion check. By default this value
is set to the list of congested ports `congested`.
"""
# Check that the congested links are being detected as congested
for lk in congested:
sw, pn = lk
pinfo = self.ctrl.graph.get_port_info(sw, pn)
self.assertIsNotNone(pinfo)
self.assertIn("poll_stats", pinfo)
self.assertIn("tx_bytes", pinfo["poll_stats"])
conv = 8.0 / self.ctrl.get_poll_rate()
tx = pinfo["poll_stats"]["tx_bytes"]
tx_rate = round(float(tx*conv)/float(pinfo["speed"]), 2)
self.assertTrue(self.ctrl.TE.check_link_congested(sw, pn, tx_rate),
msg="SW %s port %s is not congested (expected congestion)" % lk)
# Check that the other links are not congested
for sw,sw_d in self.ctrl.graph.topo.iteritems():
for pn,pn_d in sw_d.iteritems():
if (sw, pn) in congested:
continue
pinfo = self.ctrl.graph.get_port_info(sw, pn)
self.assertIn("poll_stats", pinfo)
self.assertIn("tx_bytes", pinfo["poll_stats"])
conv = 8.0 / self.ctrl.get_poll_rate()
tx = pinfo["poll_stats"]["tx_bytes"]
tx_rate = round(float(tx*conv)/float(pinfo["speed"]), 2)
self.assertFalse(self.ctrl.TE.check_link_congested(sw, pn, tx_rate),
msg="SW %s port %s is congested (expected not congestion)" % (sw, pn))
# Make sure the congested dict of the TE module is correct
if over_util_keys is None:
over_util_keys = sorted(congested)
keys = sorted(self.ctrl.TE.over_utilised.keys())
self.assertEqual(over_util_keys, keys, msg="TE over-util keys %s != %s" % (keys, over_util_keys))
# ----- Main method runner of unittest ----- #
if __name__ == "__main__":
unittest.main()