-
Notifications
You must be signed in to change notification settings - Fork 529
/
test_qos_map.py
627 lines (497 loc) · 22.1 KB
/
test_qos_map.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
import json
import time
from swsscommon import swsscommon
CFG_TC_TO_DSCP_MAP_TABLE_NAME = "TC_TO_DSCP_MAP"
CFG_TC_TO_DSCP_MAP_KEY = "AZURE"
TC_TO_DSCP_MAP = {
"0": "20",
"1": "16",
"2": "5",
"3": "43",
"4": "34",
"5": "52",
"6": "61",
"7": "17",
}
CFG_TC_TO_DOT1P_MAP_TABLE_NAME = "TC_TO_DOT1P_MAP"
CFG_TC_TO_DOT1P_MAP_KEY = "AZURE"
TC_TO_DOT1P_MAP = {
"0": "0",
"1": "6",
"2": "5",
"3": "3",
"4": "4",
"5": "2",
"6": "1",
"7": "7",
}
CFG_DOT1P_TO_TC_MAP_TABLE_NAME = "DOT1P_TO_TC_MAP"
CFG_DOT1P_TO_TC_MAP_KEY = "AZURE"
DOT1P_TO_TC_MAP = {
"0": "0",
"1": "6",
"2": "5",
"3": "3",
"4": "4",
"5": "2",
"6": "1",
"7": "7",
}
CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME = "MPLS_TC_TO_TC_MAP"
CFG_MPLS_TC_TO_TC_MAP_KEY = "AZURE_MPLS_TC"
MPLS_TC_TO_TC_MAP = {
"0": "0",
"1": "4",
"2": "1",
"3": "3",
"4": "5",
"5": "2",
"6": "7",
"7": "6",
}
CFG_PORT_QOS_MAP_TABLE_NAME = "PORT_QOS_MAP"
CFG_PORT_QOS_DOT1P_MAP_FIELD = "dot1p_to_tc_map"
CFG_PORT_QOS_MPLS_TC_MAP_FIELD = "mpls_tc_to_tc_map"
CFG_PORT_QOS_TC_DOT1P_MAP_FIELD = "tc_to_dot1p_map"
CFG_PORT_QOS_TC_DSCP_MAP_FIELD = "tc_to_dscp_map"
CFG_PORT_TABLE_NAME = "PORT"
#Tests for TC-to-DSCP qos map configuration
class TestTcDscp(object):
def connect_dbs(self, dvs):
self.asic_db = swsscommon.DBConnector(1, dvs.redis_sock, 0)
self.config_db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
def create_tc_dscp_profile(self):
tbl = swsscommon.Table(self.config_db, CFG_TC_TO_DSCP_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs(list(TC_TO_DSCP_MAP.items()))
tbl.set(CFG_TC_TO_DSCP_MAP_KEY, fvs)
time.sleep(1)
def find_tc_dscp_profile(self):
found = False
tc_dscp_map_raw = None
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST":
tc_dscp_map_raw = fv[1]
elif fv[0] == "SAI_QOS_MAP_ATTR_TYPE" and fv[1] == "SAI_QOS_MAP_TYPE_TC_AND_COLOR_TO_DSCP":
found = True
if found:
break
assert found == True
return (key, tc_dscp_map_raw)
def apply_tc_dscp_profile_on_all_ports(self):
tbl = swsscommon.Table(self.config_db, CFG_PORT_QOS_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs([(CFG_PORT_QOS_TC_DSCP_MAP_FIELD, CFG_TC_TO_DSCP_MAP_KEY)])
ports = swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys()
for port in ports:
tbl.set(port, fvs)
time.sleep(1)
def test_tc_dscp_cfg(self, dvs):
self.connect_dbs(dvs)
self.create_tc_dscp_profile()
_, tc_dscp_map_raw = self.find_tc_dscp_profile()
tc_dscp_map = json.loads(tc_dscp_map_raw)
for tc2dscp in tc_dscp_map['list']:
tc_val = str(tc2dscp['key']['tc'])
dscp_val = str(tc2dscp['value']['dscp'])
assert dscp_val == TC_TO_DSCP_MAP[tc_val]
def test_port_tc_dscp(self, dvs):
self.connect_dbs(dvs)
self.create_tc_dscp_profile()
oid, _ = self.find_tc_dscp_profile()
self.apply_tc_dscp_profile_on_all_ports()
cnt = 0
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP":
cnt += 1
assert fv[1] == oid
port_cnt = len(swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys())
assert port_cnt == cnt
#Tests for TC-to-Dot1p qos map configuration
class TestTcDot1p(object):
def connect_dbs(self, dvs):
self.asic_db = swsscommon.DBConnector(1, dvs.redis_sock, 0)
self.config_db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
def create_tc_dot1p_profile(self):
tbl = swsscommon.Table(self.config_db, CFG_TC_TO_DOT1P_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs(list(TC_TO_DOT1P_MAP.items()))
tbl.set(CFG_TC_TO_DOT1P_MAP_KEY, fvs)
time.sleep(1)
def find_tc_dot1p_profile(self):
found = False
tc_dot1p_map_raw = None
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST":
tc_dot1p_map_raw = fv[1]
elif fv[0] == "SAI_QOS_MAP_ATTR_TYPE" and fv[1] == "SAI_QOS_MAP_TYPE_TC_AND_COLOR_TO_DOT1P":
found = True
if found:
break
assert found == True
return (key, tc_dot1p_map_raw)
def apply_tc_dot1p_profile_on_all_ports(self):
tbl = swsscommon.Table(self.config_db, CFG_PORT_QOS_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs([(CFG_PORT_QOS_TC_DOT1P_MAP_FIELD, CFG_TC_TO_DOT1P_MAP_KEY)])
ports = swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys()
for port in ports:
tbl.set(port, fvs)
time.sleep(1)
def test_tc_dot1p_cfg(self, dvs):
self.connect_dbs(dvs)
self.create_tc_dot1p_profile()
_, tc_dot1p_map_raw = self.find_tc_dot1p_profile()
tc_dot1p_map = json.loads(tc_dot1p_map_raw)
for tc2dot1p in tc_dot1p_map['list']:
tc_val = str(tc2dot1p['key']['tc'])
dot1p_val = str(tc2dot1p['value']['dot1p'])
assert dot1p_val == TC_TO_DOT1P_MAP[tc_val]
def test_port_tc_dot1p(self, dvs):
self.connect_dbs(dvs)
self.create_tc_dot1p_profile()
oid, _ = self.find_tc_dot1p_profile()
self.apply_tc_dot1p_profile_on_all_ports()
cnt = 0
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP":
cnt += 1
assert fv[1] == oid
port_cnt = len(swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys())
assert port_cnt == cnt
#Tests for Dot1p-to-TC qos map configuration
class TestDot1p(object):
def connect_dbs(self, dvs):
self.asic_db = swsscommon.DBConnector(1, dvs.redis_sock, 0)
self.config_db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
def create_dot1p_profile(self):
tbl = swsscommon.Table(self.config_db, CFG_DOT1P_TO_TC_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs(list(DOT1P_TO_TC_MAP.items()))
tbl.set(CFG_DOT1P_TO_TC_MAP_KEY, fvs)
time.sleep(1)
def find_dot1p_profile(self):
found = False
dot1p_tc_map_raw = None
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST":
dot1p_tc_map_raw = fv[1]
elif fv[0] == "SAI_QOS_MAP_ATTR_TYPE" and fv[1] == "SAI_QOS_MAP_TYPE_DOT1P_TO_TC":
found = True
if found:
break
assert found == True
return (key, dot1p_tc_map_raw)
def apply_dot1p_profile_on_all_ports(self):
tbl = swsscommon.Table(self.config_db, CFG_PORT_QOS_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs([(CFG_PORT_QOS_DOT1P_MAP_FIELD, CFG_DOT1P_TO_TC_MAP_KEY)])
ports = swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys()
for port in ports:
tbl.set(port, fvs)
time.sleep(1)
def test_dot1p_cfg(self, dvs):
self.connect_dbs(dvs)
self.create_dot1p_profile()
_, dot1p_tc_map_raw = self.find_dot1p_profile()
dot1p_tc_map = json.loads(dot1p_tc_map_raw)
for dot1p2tc in dot1p_tc_map['list']:
dot1p = str(dot1p2tc['key']['dot1p'])
tc = str(dot1p2tc['value']['tc'])
assert tc == DOT1P_TO_TC_MAP[dot1p]
def test_port_dot1p(self, dvs):
self.connect_dbs(dvs)
self.create_dot1p_profile()
oid, _ = self.find_dot1p_profile()
self.apply_dot1p_profile_on_all_ports()
cnt = 0
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP":
cnt += 1
assert fv[1] == oid
port_cnt = len(swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys())
assert port_cnt == cnt
class TestCbf(object):
ASIC_QOS_MAP_STR = "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP"
ASIC_PORT_STR = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
def init_test(self, dvs):
self.dvs = dvs
self.asic_db = dvs.get_asic_db()
self.config_db = dvs.get_config_db()
self.asic_qos_map_ids = self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)
self.asic_qos_map_count = len(self.asic_qos_map_ids)
self.dscp_ps = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_DSCP_TO_FC_MAP_TABLE_NAME)
self.exp_ps = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_EXP_TO_FC_MAP_TABLE_NAME)
# Set switch FC capability to 63
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_MAX_NUMBER_OF_FORWARDING_CLASSES', '63')
def get_qos_id(self):
diff = set(self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)) - set(self.asic_qos_map_ids)
assert len(diff) <= 1
return None if len(diff) == 0 else diff.pop()
def test_dscp_to_fc(self, dvs):
self.init_test(dvs)
# Create a DSCP_TO_FC map
dscp_map = [(str(i), str(i)) for i in range(0, 63)]
self.dscp_ps.set("AZURE", swsscommon.FieldValuePairs(dscp_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)
# Get the DSCP map ID
dscp_map_id = self.get_qos_id()
assert(dscp_map_id is not None)
# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, dscp_map_id)
assert(fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_DSCP_TO_FORWARDING_CLASS")
# Modify the map
dscp_map = [(str(i), '0') for i in range(0, 63)]
self.dscp_ps.set("AZURE", swsscommon.FieldValuePairs(dscp_map))
time.sleep(1)
# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, dscp_map_id)
sai_dscp_map = json.loads(fvs.get("SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST"))
for dscp2fc in sai_dscp_map['list']:
fc = str(dscp2fc['value']['fc'])
assert fc == '0'
# Delete the map
self.dscp_ps._del("AZURE")
self.asic_db.wait_for_deleted_entry(self.ASIC_QOS_MAP_STR, dscp_map_id)
# Test validation
maps = [
('-1', '0'), # negative DSCP
('64', '0'), # DSCP greater than max value
('0', '-1'), # negative FC
('0', '63'), # FC greater than max value
('a', '0'), # non-integer DSCP
('0', 'a'), # non-integet FC
]
for fvs in maps:
self.dscp_ps.set('AZURE', swsscommon.FieldValuePairs([fvs]))
time.sleep(1)
assert(self.asic_qos_map_count == len(self.asic_db.get_keys('ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP')))
self.dscp_ps._del("AZURE")
# Delete a map that does not exist. Nothing should happen
self.dscp_ps._del("AZURE")
time.sleep(1)
assert(len(self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)) == self.asic_qos_map_count)
def test_exp_to_fc(self, dvs):
self.init_test(dvs)
# Create a EXP_TO_FC map
exp_map = [(str(i), str(i)) for i in range(0, 8)]
self.exp_ps.set("AZURE", swsscommon.FieldValuePairs(exp_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)
# Get the EXP map ID
exp_map_id = self.get_qos_id()
# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, exp_map_id)
assert(fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_MPLS_EXP_TO_FORWARDING_CLASS")
# Modify the map
exp_map = [(str(i), '0') for i in range(0, 8)]
self.exp_ps.set("AZURE", swsscommon.FieldValuePairs(exp_map))
time.sleep(1)
# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, exp_map_id)
sai_exp_map = json.loads(fvs.get("SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST"))
for exp2fc in sai_exp_map['list']:
fc = str(exp2fc['value']['fc'])
assert fc == '0'
# Delete the map
self.exp_ps._del("AZURE")
self.asic_db.wait_for_deleted_entry(self.ASIC_QOS_MAP_STR, exp_map_id)
# Test validation
maps = [
('-1', '0'), # negative EXP
('8', '0'), # EXP greater than max value
('0', '-1'), # negative FC
('0', '63'), # FC greater than max value
('a', '0'), # non-integer EXP
('0', 'a'), # non-integet FC
]
for fvs in maps:
self.exp_ps.set('AZURE', swsscommon.FieldValuePairs([fvs]))
time.sleep(1)
assert(self.asic_qos_map_count == len(self.asic_db.get_keys('ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP')))
self.exp_ps._del("AZURE")
# Update the map with valid values
exp_map = [(str(i), str(i + 10)) for i in range(0, 8)]
self.exp_ps.set('AZURE', swsscommon.FieldValuePairs(exp_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)
# Delete the map
exp_map_id = self.get_qos_id()
self.exp_ps._del("AZURE")
self.asic_db.wait_for_deleted_entry(self.ASIC_QOS_MAP_STR, exp_map_id)
# Delete a map that does not exist. Nothing should happen
self.exp_ps._del("AZURE")
time.sleep(1)
assert(len(self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)) == self.asic_qos_map_count)
def test_per_port_cbf_binding(self, dvs):
self.init_test(dvs)
# Create a DSCP_TO_FC map
dscp_map = [(str(i), str(i)) for i in range(0, 63)]
self.dscp_ps.set("AZURE", swsscommon.FieldValuePairs(dscp_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)
dscp_map_id = self.get_qos_id()
self.asic_qos_map_ids = self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)
# Create a EXP_TO_FC map
exp_map = [(str(i), str(i)) for i in range(0, 8)]
self.exp_ps.set("AZURE", swsscommon.FieldValuePairs(exp_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 2)
exp_map_id = self.get_qos_id()
tbl = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_PORT_QOS_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs([('dscp_to_fc_map', "AZURE"),
('exp_to_fc_map', "AZURE")])
keys = self.config_db.get_keys(swsscommon.CFG_PORT_TABLE_NAME)
for key in keys:
tbl.set(key, fvs)
time.sleep(1)
dscp_cnt = 0
exp_cnt = 0
for key in self.asic_db.get_keys(self.ASIC_PORT_STR):
fvs = self.asic_db.get_entry(self.ASIC_PORT_STR, key)
if 'SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP' in fvs:
assert fvs['SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP'] == dscp_map_id
dscp_cnt += 1
if 'SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP' in fvs:
assert fvs['SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP'] == exp_map_id
exp_cnt += 1
assert dscp_cnt == exp_cnt == len(keys)
class TestMplsTc(object):
def connect_dbs(self, dvs):
self.asic_db = swsscommon.DBConnector(1, dvs.redis_sock, 0)
self.config_db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
def create_mpls_tc_profile(self):
tbl = swsscommon.Table(self.config_db, CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs(list(MPLS_TC_TO_TC_MAP.items()))
tbl.set(CFG_MPLS_TC_TO_TC_MAP_KEY, fvs)
time.sleep(1)
def find_mpls_tc_profile(self):
found = False
mpls_tc_tc_map_raw = None
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST":
mpls_tc_tc_map_raw = fv[1]
elif fv[0] == "SAI_QOS_MAP_ATTR_TYPE" and fv[1] == "SAI_QOS_MAP_TYPE_MPLS_EXP_TO_TC":
found = True
if found:
break
assert found == True
return (key, mpls_tc_tc_map_raw)
def apply_mpls_tc_profile_on_all_ports(self):
tbl = swsscommon.Table(self.config_db, CFG_PORT_QOS_MAP_TABLE_NAME)
fvs = swsscommon.FieldValuePairs([(CFG_PORT_QOS_MPLS_TC_MAP_FIELD, CFG_MPLS_TC_TO_TC_MAP_KEY)])
ports = swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys()
for port in ports:
tbl.set(port, fvs)
time.sleep(1)
def test_mpls_tc_cfg(self, dvs):
self.connect_dbs(dvs)
self.create_mpls_tc_profile()
_, mpls_tc_tc_map_raw = self.find_mpls_tc_profile()
mpls_tc_tc_map = json.loads(mpls_tc_tc_map_raw)
for mplstc2tc in mpls_tc_tc_map['list']:
mpls_tc = str(mplstc2tc['key']['mpls_exp'])
tc = str(mplstc2tc['value']['tc'])
assert tc == MPLS_TC_TO_TC_MAP[mpls_tc]
def test_port_mpls_tc(self, dvs):
self.connect_dbs(dvs)
self.create_mpls_tc_profile()
oid, _ = self.find_mpls_tc_profile()
self.apply_mpls_tc_profile_on_all_ports()
cnt = 0
tbl = swsscommon.Table(self.asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
keys = tbl.getKeys()
for key in keys:
(status, fvs) = tbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP":
cnt += 1
assert fv[1] == oid
port_cnt = len(swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys())
assert port_cnt == cnt
class TestDscpToTcMap(object):
ASIC_QOS_MAP_STR = "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP"
ASIC_PORT_STR = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
ASIC_SWITCH_STR = "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH"
def init_test(self, dvs):
dvs.setup_db()
self.asic_db = dvs.get_asic_db()
self.config_db = dvs.get_config_db()
self.asic_qos_map_ids = self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)
self.asic_qos_map_count = len(self.asic_qos_map_ids)
self.dscp_to_tc_table = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_DSCP_TO_TC_MAP_TABLE_NAME)
self.port_qos_table = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_PORT_QOS_MAP_TABLE_NAME)
def get_qos_id(self):
diff = set(self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)) - set(self.asic_qos_map_ids)
assert len(diff) <= 1
return None if len(diff) == 0 else diff.pop()
def test_dscp_to_tc_map_applied_to_switch(self, dvs):
self.init_test(dvs)
dscp_to_tc_map_id = None
created_new_map = False
try:
existing_map = self.dscp_to_tc_table.getKeys()
if "AZURE" not in existing_map:
# Create a DSCP_TO_TC map
dscp_to_tc_map = [(str(i), str(i)) for i in range(0, 63)]
self.dscp_to_tc_table.set("AZURE", swsscommon.FieldValuePairs(dscp_to_tc_map))
self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)
# Get the DSCP_TO_TC map ID
dscp_to_tc_map_id = self.get_qos_id()
assert(dscp_to_tc_map_id is not None)
# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, dscp_to_tc_map_id)
assert(fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_DSCP_TO_TC")
created_new_map = True
else:
for id in self.asic_qos_map_ids:
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, id)
if fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_DSCP_TO_TC":
dscp_to_tc_map_id = id
break
switch_oid = dvs.getSwitchOid()
# Insert switch level map entry
self.port_qos_table.set("global", [("dscp_to_tc_map", "AZURE")])
time.sleep(1)
# Check the switch level DSCP_TO_TC_MAP is applied
fvs = self.asic_db.get_entry(self.ASIC_SWITCH_STR, switch_oid)
assert(fvs.get("SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP") == dscp_to_tc_map_id)
# Remove the global level DSCP_TO_TC_MAP
self.port_qos_table._del("global")
time.sleep(1)
# Check the global level DSCP_TO_TC_MAP is set to SAI_
fvs = self.asic_db.get_entry(self.ASIC_SWITCH_STR, switch_oid)
assert(fvs.get("SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP") == "oid:0x0")
finally:
if created_new_map:
self.dscp_to_tc_table._del("AZURE")
# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
def test_nonflaky_dummy():
pass