-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_root_ctrl_MCTestScen_v5.py
387 lines (340 loc) · 17.5 KB
/
code_root_ctrl_MCTestScen_v5.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
#!/usr/bin/python
import logging
import unittest
from code_root_ctrl_test_base import BaseRootCtrlTest
class RootCtrlTest(BaseRootCtrlTest):
""" Multi-Controller Test Scenario V5 test
Test Scenarios:
Docs/MCTestScenarios/scen-v5.png
"""
# Overide inter-domain links list to reflect port changes
INTER_DOM_LINKS = [
{"a": ("c1", "s02", 4), "b": ("c2", "s04", 3), "capacity": 100000000},
{"a": ("c1", "s02", 5), "b": ("c2", "s06", 3), "capacity": 500000000},
{"a": ("c1", "s02", 6), "b": ("c4", "s10", 3), "capacity": 500000000},
{"a": ("c1", "s02", 7), "b": ("c5", "s13", 3), "capacity": 300000000},
{"a": ("c2", "s05", 4), "b": ("c3", "s08", 3), "capacity": 200000000},
{"a": ("c2", "s07", 2), "b": ("c3", "s09", 2), "capacity": 300000000},
{"a": ("c3", "s09", 3), "b": ("c5", "s15", 3)},
{"a": ("c4", "s12", 3), "b": ("c5", "s14", 3)}
]
# Overide default instructions to reflect port changes
DEFAULT_INSTRUCTIONS = {
"c1": {
("h1", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."}],
("h2", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."}],
("h8", "h1"): [
{"action": "add", "in": ("s02", 4), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s02", 5), "out": -1, "out_eth": "a::"}],
("h8", "h2"): [
{"action": "add", "in": ("s02", 4), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s02", 5), "out": -1, "out_eth": "a::"}]
}, "c2": {
("h1", "h8"): [
{"action": "add", "in": ("s04", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)}],
("h2", "h8"): [
{"action": "add", "in": ("s04", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)}],
("h8", "h1"): [
{"action": "add", "in": ("s05", 4), "out": ("s04", 3)},
{"action": "add", "in": ("s07", 2), "out": ("s06", 3)}],
("h8", "h2"): [
{"action": "add", "in": ("s05", 4), "out": ("s04", 3)},
{"action": "add", "in": ("s07", 2), "out": ("s06", 3)}],
}, "c3": {
("h1", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
("h2", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
("h8", "h1"): [
{"action": "add", "in": -1, "out": ("s08", 3), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s09", 2), "out_addr": "0."}],
("h8", "h2"): [
{"action": "add", "in": -1, "out": ("s08", 3), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s09", 2), "out_addr": "0."}],
}
}
def __init__(self, *args, **kwargs):
super(RootCtrlTest, self).__init__(*args, **kwargs)
def test_case_00(self, show_print=True):
""" Compute and validate inter-domain paths """
if show_print:
print("\nTesting inter-domain path computation")
self.ctrl._compute_inter_domain_paths()
self._check_computed_paths()
def test_case_01(self, show_print=True):
""" Scenario 1: h1 -> h8 50M, h2 -> h8 60M
Outcome:
c1 Should swap h1-h8 to s2-s6
"""
if show_print:
print("\nTesting scenario 1 (h1->h8 50M | h2-h8 60M)")
# Configure the initial state of the test by running through previous scenarios
self.test_case_00(show_print=False)
# Ingress and egress change modifications received from local controllers for local
# TE optimisation
c1_change = {"cid": "c1", "hkey": ("h1", "h8"), "new_paths": [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}]
}
c2_change = {"cid": "c2", "hkey": ("h1", "h8"), "new_paths": [
{"action": "add", "in": ("s06", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s04", 3), "out": ("s07", 2)}]
}
# Initial expected path instructions for state at start of scenario (default state)
exp_paths = {}
exp_inst = {"c1": {}}
# Perform egress change on C1
self.ctrl._path_info_changed(c1_change)
exp_inst["c1"][("h1", "h8")] = c1_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
# Perform the ingress and egress change at C2
self.ctrl._path_info_changed(c2_change)
exp_paths[("h1", "h8")] = {}
exp_paths[("h1", "h8")]["prim"] = ["h1", "c1", "s02", "s06", "c2", "s05", "s08", "c3", "h8"]
exp_paths[("h1", "h8")]["sec"] = ["h1", "c1", "s02", "s04", "c2", "s07", "s09", "c3", "h8"]
exp_inst["c2"] = {}
exp_inst["c2"][("h1", "h8")] = c2_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
def test_case_02(self, show_print=True):
""" Scenario 2: h1 -> h8 50M, h2 -> h8 110M
Outcome:
c1 should swap h2-h8 to s2-s6
"""
if show_print:
print("\nTesting scenario 2 (h1->h8 50M | h2-h8 110M)")
# Configure the initial state of the test by running through previous scenarios
self.test_case_01(show_print=False)
# Local controller ingress and egress notifications sent to root controller
c1_change = {"cid": "c1", "hkey": ("h2", "h8"), "new_paths": [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}]
}
c2_change = {"cid": "c2", "hkey": ("h2", "h8"), "new_paths": [
{"action": "add", "in": ("s06", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s04", 3), "out": ("s07", 2)}]
}
# Expected path and instructions
exp_paths = {
("h1", "h8"): {
"prim": ["h1", "c1", "s02", "s06", "c2", "s05", "s08", "c3", "h8"],
"sec": ["h1", "c1", "s02", "s04", "c2", "s07", "s09", "c3", "h8"]}
}
exp_inst = {
"c1": {
("h1", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}],
}, "c2": {
("h1", "h8"): [
{"action": "add", "in": ("s06", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s04", 3), "out": ("s07", 2)}],
}, "c3": {
("h1", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
}
}
# Perform the ingress and egress change at C1
self.ctrl._path_info_changed(c1_change)
exp_inst["c1"][("h2", "h8")] = c1_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
# Perform the ingress change at C2
self.ctrl._path_info_changed(c2_change)
exp_paths[("h2", "h8")] = {}
exp_paths[("h2", "h8")]["prim"] = ["h2", "c1", "s02", "s06", "c2", "s05", "s08", "c3", "h8"]
exp_paths[("h2", "h8")]["sec"] = ["h2", "c1", "s02", "s04", "c2", "s07", "s09", "c3", "h8"]
exp_inst["c2"][("h2", "h8")] = c2_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
def test_case_03(self, show_print=True):
""" Scenario 3: h1 -> h8 100M, h2 -> h8 110M
Outcome:
C2 should swap h1-h8 to s7-s9
"""
if show_print:
print("\nTesting scenario 3 (h1->h8 100M | h2-h8 110M)")
# Configure the initial state of the test by running through previous scenarios
self.test_case_02(show_print=False)
# Local controller ingress and egress notifications sent to root controller
c2_change = {"cid": "c2", "hkey": ("h1", "h8"), "new_paths": [
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)},
{"action": "add", "in": ("s04", 3), "out": ("s05", 4)}]
}
c3_change = {"cid": "c3", "hkey": ("h1", "h8"), "new_paths": [
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"}]
}
# Expected path and instructions
exp_paths = {
("h1", "h8"): {
"prim": ["h1", "c1", "s02", "s06", "c2", "s07", "s08", "c3", "h8"],
"sec": ["h1", "c1", "s02", "s04", "c2", "s05", "s09", "c3", "h8"]},
("h2", "h8"): {
"prim": ["h2", "c1", "s02", "s06", "c2", "s05", "s08", "c3", "h8"],
"sec": ["h2", "c1", "s02", "s04", "c2", "s07", "s09", "c3", "h8"]}
}
exp_inst = {
"c1": {
("h1", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}],
("h2", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}],
}, "c2": {
("h2", "h8"): [
{"action": "add", "in": ("s06", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s04", 3), "out": ("s07", 2)}],
}, "c3": {
("h1", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
("h2", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
},
}
# Perform the ingress and egress change at C2
self.ctrl._path_info_changed(c2_change)
exp_inst["c2"][("h1", "h8")] = c2_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
# Perform the ingress change at C3
self.ctrl._path_info_changed(c3_change)
exp_paths[("h1", "h8")] = {}
exp_paths[("h1", "h8")]["prim"] = ["h1", "c1", "s02", "s06", "c2", "s07", "s09", "c3", "h8"]
exp_paths[("h1", "h8")]["sec"] = ["h1", "c1", "s02", "s04", "c2", "s05", "s08", "c3", "h8"]
exp_inst["c3"][("h1", "h8")] = c3_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
def test_case_04(self, show_print=True):
""" Scenario 4: h1 -> h8 310M, h2 -> h8 110M
Outcome:
h1-h8 moved to c4 at c1
"""
if show_print:
print("\nTesting scenario 4 (h1->h8 310M | h2-h8 110M)")
# Configure the initial state of the experiment
self.test_case_03(show_print=False)
# Expected path and instructions
exp_paths = {
("h1", "h8"): {
"prim": ["h1", "c1", "s02", "s10", "c4", "s12", "s14", "c5", "s15", "s09", "c3", "h8"],
"sec": ["h1", "c1", "s02", "s06", "c2", "s07", "s09", "c3", "h8"]},
("h2", "h8"): {
"prim": ["h2", "c1", "s02", "s06", "c2", "s05", "s08", "c3", "h8"],
"sec": ["h2", "c1", "s02", "s04", "c2", "s07", "s09", "c3", "h8"]}
}
exp_inst = {
"c1": {
("h1", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 6), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."}],
("h2", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}],
}, "c2": {
("h1", "h8"): [
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)}],
("h2", "h8"): [
{"action": "add", "in": ("s06", 3), "out": ("s05", 4)},
{"action": "add", "in": ("s04", 3), "out": ("s07", 2)}],
}, "c3": {
("h1", "h8"): [
{"action": "add", "in": ("s09", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
("h2", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
}, "c4": {
("h1", "h8"): [
{"action": "add", "in": ("s10", 3), "out": ("s12", 3)}]
}, "c5": {
("h1", "h8"): [
{"action": "add", "in": ("s14", 3), "out": ("s15", 3)}]
}
}
# Initiate experiment
self.ctrl._action_inter_domain_link_traffic(
{"cid": "c1", "sw": "s02", "port": 4, "traff_bps": 0})
self.ctrl._action_inter_domain_link_traffic(
{"cid": "c1", "sw": "s02", "port": 5, "traff_bps": 420000000})
self.ctrl._action_inter_domain_link_traffic(
{"cid": "c1", "sw": "s02", "port": 7, "traff_bps": 0})
self.ctrl._action_inter_domain_link_traffic(
{"cid": "c2", "sw": "s05", "port": 4, "traff_bps": 110000000})
self.ctrl._action_inter_domain_link_traffic(
{"cid": "c2", "sw": "s07", "port": 2, "traff_bps": 300000000})
self.ctrl._action_inter_domain_link_congested(
{"cid": "c2", "sw": "s07", "port": 2, "traff_bps": 310000000,
"te_thresh": 0.90, "paths": [(("h1", "h8"), 310000000)]}
)
self._check_computed_paths(exp_paths, exp_inst)
def test_case_05(self, show_print=True):
""" Scenario 5: h1 -> h8 310M, h2 -> h8 210M
Outcome:
c2 should swap h2-h8 to s7-s9
"""
if show_print:
print("\nTesting scenario 5 (h1->h8 310M | h2-h8 210M)")
# Configure the initial state of the test by running through previous scenarios
self.test_case_04(show_print=False)
# Local controller ingress and egress notifications sent to root controller
c2_change = {"cid": "c2", "hkey": ("h2", "h8"), "new_paths": [
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)},
{"action": "add", "in": ("s04", 3), "out": ("s05", 4)}]
}
c3_change = {"cid": "c3", "hkey": ("h2", "h8"), "new_paths": [
{"action": "add", "in": ("s09", 2), "out": -1},
{"action": "add", "in": ("s08", 3), "out": -1}]
}
# Expected path and instructions
exp_paths = {
("h1", "h8"): {
"prim": ["h1", "c1", "s02", "s10", "c4", "s12", "s14", "c5", "s15", "s09", "c3", "h8"],
"sec": ["h1", "c1", "s02", "s06", "c2", "s07", "s09", "c3", "h8"]},
("h2", "h8"): {
"prim": ["h2", "c1", "s02", "s06", "c2", "s07", "s08", "c3", "h8"],
"sec": ["h2", "c1", "s02", "s04", "c2", "s05", "s09", "c3", "h8"]}
}
exp_inst = {
"c1": {
("h1", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 6), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."}],
("h2", "h8"): [
{"action": "add", "in": -1, "out": ("s02", 5), "out_addr": "0."},
{"action": "add", "in": -1, "out": ("s02", 4), "out_addr": "0."}],
}, "c2": {
("h1", "h8"): [
{"action": "add", "in": ("s06", 3), "out": ("s07", 2)}],
}, "c3": {
("h1", "h8"): [
{"action": "add", "in": ("s09", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
("h2", "h8"): [
{"action": "add", "in": ("s08", 3), "out": -1, "out_eth": "a::"},
{"action": "add", "in": ("s09", 2), "out": -1, "out_eth": "a::"}],
}, "c4": {
("h1", "h8"): [
{"action": "add", "in": ("s10", 3), "out": ("s12", 3)}]
}, "c5": {
("h1", "h8"): [
{"action": "add", "in": ("s14", 3), "out": ("s15", 3)}]
}
}
# Perform the ingress and egress change at C2
self.ctrl._path_info_changed(c2_change)
exp_inst["c2"][("h2", "h8")] = c2_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)
# Perform the ingress change at C3
self.ctrl._path_info_changed(c3_change)
exp_paths[("h2", "h8")]["prim"] = ["h2", "c1", "s02", "s06", "c2", "s07", "s09", "c3", "h8"]
exp_paths[("h2", "h8")]["sec"] = ["h2", "c1", "s02", "s04", "c2", "s05", "s08", "c3", "h8"]
exp_inst["c3"][("h2", "h8")] = c3_change["new_paths"]
self._check_computed_paths(exp_paths, exp_inst)