-
Notifications
You must be signed in to change notification settings - Fork 579
/
Copy pathtest_buffer_dynamic.py
936 lines (744 loc) · 49.1 KB
/
test_buffer_dynamic.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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
import time
import pytest
import re
import buffer_model
from dvslib.dvs_common import PollingConfig
@pytest.fixture
def dynamic_buffer(dvs):
buffer_model.enable_dynamic_buffer(dvs.get_config_db(), dvs.runcmd)
yield
buffer_model.disable_dynamic_buffer(dvs.get_config_db(), dvs.runcmd)
@pytest.mark.usefixtures("dynamic_buffer")
class TestBufferMgrDyn(object):
DEFAULT_POLLING_CONFIG = PollingConfig(polling_interval=0.01, timeout=60, strict=True)
def setup_db(self, dvs):
self.initialized = False
self.cableLenTest1 = "15m"
self.cableLenTest2 = "25m"
self.speedToTest1 = "50000"
self.speedToTest2 = "10000"
self.app_db = dvs.get_app_db()
self.asic_db = dvs.get_asic_db()
self.config_db = dvs.get_config_db()
self.state_db = dvs.get_state_db()
fvs = self.config_db.wait_for_entry("PORT", "Ethernet0")
self.originalSpeed = fvs["speed"]
if self.originalSpeed == self.speedToTest1:
self.speedToTest1 = "100000"
elif self.originalSpeed == self.speedToTest2:
self.speedToTest2 = "100000"
elif self.originalSpeed == "":
self.originalSpeed = "100000"
# Check whether cable length has been configured
fvs = self.config_db.wait_for_entry("CABLE_LENGTH", "AZURE")
self.originalCableLen = fvs["Ethernet0"]
self.cableLenBeforeTest = self.originalCableLen
if self.originalCableLen == self.cableLenTest1:
self.cableLenTest1 = "20m"
elif self.originalCableLen == self.cableLenTest2:
self.cableLenTest2 = "20m"
elif self.originalCableLen == "0m":
fvs["Ethernet0"] = "5m"
self.originalCableLen = "5m"
self.config_db.update_entry("CABLE_LENGTH", "AZURE", fvs)
fvs = {"mmu_size": "12766208"}
self.state_db.create_entry("BUFFER_MAX_PARAM_TABLE", "global", fvs)
self.bufferMaxParameter = self.state_db.wait_for_entry("BUFFER_MAX_PARAM_TABLE", "Ethernet0")
# The default lossless priority group will be removed ahead of staring test
# By doing so all the dynamically generated profiles will be removed and
# it's easy to identify the SAI OID of the new profile once it's created by
# comparing the new set of ASIC_STATE:BUFFER_PROFILE table against the initial one
pgs = self.config_db.get_keys('BUFFER_PG')
for key in pgs:
pg = self.config_db.get_entry('BUFFER_PG', key)
if pg['profile'] == 'NULL':
self.config_db.delete_entry('BUFFER_PG', key)
# wait 5 seconds to make sure all the lossless PGs and profiles have been removed
seconds_delayed = 0
lossless_profile_name_pattern = 'pg_lossless_([1-9][0-9]*000)_([1-9][0-9]*m)_profile'
max_delay_seconds = 10
while seconds_delayed <= max_delay_seconds:
time.sleep(2)
seconds_delayed += 2
lossless_profile = None
profiles = self.app_db.get_keys('BUFFER_PROFILE_TABLE')
for key in profiles:
if re.search(lossless_profile_name_pattern, key):
lossless_profile = key
break
if not lossless_profile:
break
assert not lossless_profile, \
"There is still lossless profile ({}) {} seconds after all lossless PGs have been removed".format(lossless_profile, seconds_delayed)
time.sleep(10)
self.setup_asic_db(dvs)
self.initialized = True
def cleanup_db(self, dvs):
# Clean up: restore the origin cable length
fvs = self.config_db.wait_for_entry("CABLE_LENGTH", "AZURE")
fvs["Ethernet0"] = self.cableLenBeforeTest
self.config_db.update_entry("CABLE_LENGTH", "AZURE", fvs)
def setup_asic_db(self, dvs):
buffer_pool_set = set(self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL"))
self.initProfileSet = set(self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE"))
self.initPGSet = set(self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP"))
ingress_lossless_pool = self.app_db.get_entry("BUFFER_POOL_TABLE", "ingress_lossless_pool")
self.ingress_lossless_pool_asic = None
for key in buffer_pool_set:
bufferpool = self.asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL", key)
if bufferpool["SAI_BUFFER_POOL_ATTR_TYPE"] == "SAI_BUFFER_POOL_TYPE_INGRESS":
if ingress_lossless_pool["size"] == bufferpool["SAI_BUFFER_POOL_ATTR_SIZE"]:
self.ingress_lossless_pool_asic = bufferpool
self.ingress_lossless_pool_oid = key
def check_new_profile_in_asic_db(self, dvs, profile):
retry_count = 0
self.newProfileInAsicDb = None
while retry_count < 5:
retry_count += 1
diff = set(self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE")) - self.initProfileSet
if len(diff) == 1:
self.newProfileInAsicDb = diff.pop()
break
else:
time.sleep(1)
assert self.newProfileInAsicDb, "Can't get SAI OID for newly created profile {} after retry {} times".format(profile, retry_count)
# in case diff is empty, we just treat the newProfileInAsicDb cached the latest one
fvs = self.app_db.get_entry("BUFFER_PROFILE_TABLE", profile)
if fvs.get('dynamic_th'):
sai_threshold_value = fvs['dynamic_th']
sai_threshold_mode = 'SAI_BUFFER_PROFILE_THRESHOLD_MODE_DYNAMIC'
sai_threshold_name = 'SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH'
else:
sai_threshold_value = fvs['static_th']
sai_threshold_mode = 'SAI_BUFFER_PROFILE_THRESHOLD_MODE_STATIC'
sai_threshold_name = 'SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH'
self.asic_db.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE", self.newProfileInAsicDb,
{'SAI_BUFFER_PROFILE_ATTR_XON_TH': fvs['xon'],
'SAI_BUFFER_PROFILE_ATTR_XOFF_TH': fvs['xoff'],
'SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE': fvs['size'],
'SAI_BUFFER_PROFILE_ATTR_POOL_ID': self.ingress_lossless_pool_oid,
'SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE': sai_threshold_mode,
sai_threshold_name: sai_threshold_value},
self.DEFAULT_POLLING_CONFIG)
def make_lossless_profile_name(self, speed, cable_length, mtu = None, dynamic_th = None):
extra = ""
if mtu:
extra += "_mtu" + mtu
if dynamic_th:
extra += "_th" + dynamic_th
return "pg_lossless_" + speed + "_" + cable_length + extra + "_profile"
def change_cable_length(self, cable_length):
cable_lengths = self.config_db.get_entry('CABLE_LENGTH', 'AZURE')
cable_lengths['Ethernet0'] = cable_length
self.config_db.update_entry('CABLE_LENGTH', 'AZURE', cable_lengths)
def check_queues_after_port_startup(self, dvs):
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "{}:0-2".format("Ethernet0"), {"profile": "egress_lossy_profile"})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "{}:3-4".format("Ethernet0"), {"profile": "egress_lossless_profile"})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "{}:5-6".format("Ethernet0"), {"profile": "egress_lossy_profile"})
def test_changeSpeed(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
self.check_queues_after_port_startup(dvs)
# Configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
# Change speed to speed1 and verify whether the profile has been updated
dvs.port_field_set("Ethernet0", "speed", self.speedToTest1)
expectedProfile = self.make_lossless_profile_name(self.speedToTest1, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# Check whether buffer pg align
bufferPg = self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Remove lossless PG
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
# Change speed to speed2 and verify
dvs.port_field_set("Ethernet0", "speed", self.speedToTest2)
expectedProfile = self.make_lossless_profile_name(self.speedToTest2, self.originalCableLen)
# Re-add another lossless PG
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'NULL'})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Remove the lossless PG 6
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6")
# Remove the lossless PG 3-4 and revert speed
dvs.port_field_set("Ethernet0", "speed", self.originalSpeed)
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Remove lossless PG 3-4 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
@pytest.mark.skip(reason="Failing. Under investigation")
def test_changeCableLen(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# Configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
# Change to new cable length
self.change_cable_length(self.cableLenTest1)
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.cableLenTest1)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Remove the lossless PGs
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
# Change to another cable length
self.change_cable_length(self.cableLenTest2)
# Check whether the old profile has been removed
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile)
# Re-add lossless PGs
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.cableLenTest2)
# Check the BUFFER_PROFILE_TABLE and BUFFER_PG_TABLE
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Revert the cable length
self.change_cable_length(self.originalCableLen)
# Check the BUFFER_PROFILE_TABLE and BUFFER_PG_TABLE
# we are not able to check whether the SAI OID is removed from ASIC DB here
# because sometimes the SAI OID in ASIC DB can be reused for the newly created profile
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile)
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Remove lossless PG 3-4 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_MultipleLosslessPg(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# Configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
# Add another lossless PG
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'NULL'})
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Change speed and check
dvs.port_field_set("Ethernet0", "speed", self.speedToTest1)
expectedProfile = self.make_lossless_profile_name(self.speedToTest1, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Change cable length and check
self.change_cable_length(self.cableLenTest1)
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile)
expectedProfile = self.make_lossless_profile_name(self.speedToTest1, self.cableLenTest1)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Revert the speed and cable length and check
self.change_cable_length(self.originalCableLen)
dvs.port_field_set("Ethernet0", "speed", self.originalSpeed)
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.asic_db.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE", self.newProfileInAsicDb)
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Remove lossless PG 3-4 and 6 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_headroomOverride(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# Configure static profile
self.config_db.update_entry('BUFFER_PROFILE', 'test',
{'xon': '18432',
'xoff': '16384',
'size': '34816',
'dynamic_th': '0',
'pool': 'ingress_lossless_pool'})
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", "test")
self.app_db.wait_for_exact_match("BUFFER_PROFILE_TABLE", "test",
{ "pool" : "ingress_lossless_pool",
"xon" : "18432",
"xoff" : "16384",
"size" : "34816",
"dynamic_th" : "0"
})
self.check_new_profile_in_asic_db(dvs, "test")
# configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
self.change_cable_length(self.cableLenTest1)
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.cableLenTest1)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# configure lossless PG 3-4 with headroom override
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'test'})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": "test"})
# configure lossless PG 6 with headroom override
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'test'})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": "test"})
# update the profile
self.config_db.update_entry('BUFFER_PROFILE', 'test',
{'xon': '18432',
'xoff': '18432',
'size': '36864',
'dynamic_th': '0',
'pool': 'ingress_lossless_pool'})
self.app_db.wait_for_exact_match("BUFFER_PROFILE_TABLE", "test",
{ "pool" : "ingress_lossless_pool",
"xon" : "18432",
"xoff" : "18432",
"size" : "36864",
"dynamic_th" : "0"
})
self.check_new_profile_in_asic_db(dvs, "test")
# remove all lossless PGs
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6")
# readd lossless PG with dynamic profile
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# remove the headroom override profile
self.config_db.delete_entry('BUFFER_PROFILE', 'test')
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", "test")
self.asic_db.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE", self.newProfileInAsicDb)
self.change_cable_length(self.originalCableLen)
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile)
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# remove lossless PG 3-4 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_mtuUpdate(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
test_mtu = '1500'
default_mtu = '9100'
expectedProfileMtu = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen, mtu = test_mtu)
expectedProfileNormal = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
# update the mtu on the interface
dvs.port_field_set("Ethernet0", "mtu", test_mtu)
# configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
self.app_db.wait_for_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfileMtu)
self.check_new_profile_in_asic_db(dvs, expectedProfileMtu)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfileMtu})
dvs.port_field_set("Ethernet0", "mtu", default_mtu)
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfileMtu)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfileNormal)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfileNormal})
# clear configuration
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_nonDefaultAlpha(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
test_dynamic_th_1 = '1'
expectedProfile_th1 = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen, dynamic_th = test_dynamic_th_1)
test_dynamic_th_2 = '2'
expectedProfile_th2 = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen, dynamic_th = test_dynamic_th_2)
# add a profile with non-default dynamic_th
self.config_db.update_entry('BUFFER_PROFILE', 'non-default-dynamic',
{'dynamic_th': test_dynamic_th_1,
'headroom_type': 'dynamic',
'pool': 'ingress_lossless_pool'})
# configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'non-default-dynamic'})
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile_th1)
self.check_new_profile_in_asic_db(dvs, expectedProfile_th1)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile_th1})
# modify the profile to another dynamic_th
self.config_db.update_entry('BUFFER_PROFILE', 'non-default-dynamic',
{'dynamic_th': test_dynamic_th_2,
'headroom_type': 'dynamic',
'pool': 'ingress_lossless_pool'})
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE_TABLE", expectedProfile_th1)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile_th2)
self.check_new_profile_in_asic_db(dvs, expectedProfile_th2)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile_th2})
# clear configuration
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.config_db.delete_entry('BUFFER_PROFILE', 'non-default-dynamic')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_sharedHeadroomPool(self, dvs, testlog):
self.setup_db(dvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# configure lossless PG 3-4 on interface and start up the interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.check_new_profile_in_asic_db(dvs, expectedProfile)
profileInApplDb = self.app_db.get_entry('BUFFER_PROFILE_TABLE', expectedProfile)
# enable shared headroom pool by configuring over subscribe ratio
default_lossless_buffer_parameter = self.config_db.get_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE')
over_subscribe_ratio = default_lossless_buffer_parameter.get('over_subscribe_ratio')
assert not over_subscribe_ratio or over_subscribe_ratio == '0', "Over subscribe ratio isn't 0"
# config over subscribe ratio to 2
default_lossless_buffer_parameter['over_subscribe_ratio'] = '2'
self.config_db.update_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE', default_lossless_buffer_parameter)
# check buffer profile: xoff should be removed from size
profileInApplDb['size'] = profileInApplDb['xon']
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', expectedProfile, profileInApplDb)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# Check ingress_lossless_pool between appldb and asicdb
# There are only two lossless PGs configured on one port.
# Hence the shared headroom pool size should be (pg xoff * 2 - private headroom) / over subscribe ratio (2) = xoff - private_headroom / 2.
ingress_lossless_pool_in_appldb = self.app_db.get_entry('BUFFER_POOL_TABLE', 'ingress_lossless_pool')
private_headroom = 10 * 1024
shp_size = str(int(profileInApplDb['xoff']) - int(private_headroom / 2))
ingress_lossless_pool_in_appldb['xoff'] = shp_size
# toggle shared headroom pool, it requires some time to update pools
time.sleep(20)
self.app_db.wait_for_field_match('BUFFER_POOL_TABLE', 'ingress_lossless_pool', ingress_lossless_pool_in_appldb)
ingress_lossless_pool_in_asicdb = self.asic_db.get_entry('ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE', self.ingress_lossless_pool_oid)
ingress_lossless_pool_in_asicdb['SAI_BUFFER_POOL_ATTR_XOFF_SIZE'] = shp_size
self.asic_db.wait_for_field_match('ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL', self.ingress_lossless_pool_oid, ingress_lossless_pool_in_asicdb)
# config shared headroom pool size
shp_size = '204800'
ingress_lossless_pool_in_configdb = self.config_db.get_entry('BUFFER_POOL', 'ingress_lossless_pool')
ingress_lossless_pool_in_configdb['xoff'] = shp_size
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', ingress_lossless_pool_in_configdb)
# make sure the size is still equal to xon in the profile
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', expectedProfile, profileInApplDb)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# config over subscribe ratio to 4
default_lossless_buffer_parameter['over_subscribe_ratio'] = '4'
self.config_db.update_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE', default_lossless_buffer_parameter)
# shp size wins in case both size and over subscribe ratio is configured
ingress_lossless_pool_in_appldb['xoff'] = shp_size
self.app_db.wait_for_field_match('BUFFER_POOL_TABLE', 'ingress_lossless_pool', ingress_lossless_pool_in_appldb)
ingress_lossless_pool_in_asicdb['SAI_BUFFER_POOL_ATTR_XOFF_SIZE'] = shp_size
self.asic_db.wait_for_field_match('ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL', self.ingress_lossless_pool_oid, ingress_lossless_pool_in_asicdb)
# make sure the size is still equal to xon in the profile
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', expectedProfile, profileInApplDb)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# remove size configuration, new over subscribe ratio takes effect
ingress_lossless_pool_in_configdb['xoff'] = '0'
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', ingress_lossless_pool_in_configdb)
# shp size: (pg xoff * 2 - private headroom) / over subscribe ratio (4)
shp_size = str(int((2 * int(profileInApplDb['xoff']) - private_headroom) / 4))
time.sleep(30)
ingress_lossless_pool_in_appldb['xoff'] = shp_size
self.app_db.wait_for_field_match('BUFFER_POOL_TABLE', 'ingress_lossless_pool', ingress_lossless_pool_in_appldb)
ingress_lossless_pool_in_asicdb['SAI_BUFFER_POOL_ATTR_XOFF_SIZE'] = shp_size
self.asic_db.wait_for_field_match('ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL', self.ingress_lossless_pool_oid, ingress_lossless_pool_in_asicdb)
# make sure the size is still equal to xon in the profile
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', expectedProfile, profileInApplDb)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# remove over subscribe ratio configuration
default_lossless_buffer_parameter['over_subscribe_ratio'] = '0'
self.config_db.update_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE', default_lossless_buffer_parameter)
# check whether shp size has been removed from both asic db and appl db
ingress_lossless_pool_in_appldb['xoff'] = '0'
self.app_db.wait_for_field_match('BUFFER_POOL_TABLE', 'ingress_lossless_pool', ingress_lossless_pool_in_appldb)
ingress_lossless_pool_in_asicdb['SAI_BUFFER_POOL_ATTR_XOFF_SIZE'] = '0'
self.asic_db.wait_for_field_match('ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL', self.ingress_lossless_pool_oid, ingress_lossless_pool_in_asicdb)
# make sure the size is equal to xon + xoff in the profile
profileInApplDb['size'] = str(int(profileInApplDb['xon']) + int(profileInApplDb['xoff']))
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', expectedProfile, profileInApplDb)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
# remove lossless PG 3-4 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
dvs.port_admin_set('Ethernet0', 'down')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_shutdownPort(self, dvs, testlog):
self.setup_db(dvs)
lossy_pg_reference_config_db = 'ingress_lossy_profile'
lossy_pg_reference_appl_db = 'ingress_lossy_profile'
lossy_queue_reference_config_db = 'egress_lossy_profile'
lossy_queue_reference_appl_db = 'egress_lossy_profile'
lossless_queue_reference_appl_db = 'egress_lossless_profile'
lossy_pg_zero_reference = 'ingress_lossy_pg_zero_profile'
lossy_queue_zero_reference = 'egress_lossy_zero_profile'
lossless_queue_zero_reference = 'egress_lossless_zero_profile'
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# Configure lossless PG 3-4 on interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Shutdown port and check whether zero profiles have been applied on queues and the PG 0
maximumQueues = int(self.bufferMaxParameter['max_queues']) - 1
dvs.port_admin_set('Ethernet0', 'down')
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:5-6", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:7-{}".format(maximumQueues), {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE", expectedProfile)
# Add extra lossy and lossless PGs when a port is administratively down
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|1', {'profile': lossy_pg_reference_config_db})
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'NULL'})
# Add extra queue when a port is administratively down
self.config_db.update_entry('BUFFER_QUEUE', 'Ethernet0|8', {"profile": lossy_queue_reference_config_db})
# For queues, the slice in supported but not configured list should be '7-19'.
# After queue '8' is added, '7-19' should be removed and '7', '8', and '9-19' will be added
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:7-{}".format(maximumQueues))
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:7", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:8", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:9-{}".format(maximumQueues), {"profile": lossy_queue_zero_reference})
# Make sure they have not been added to APPL_DB
time.sleep(30)
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:1")
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6")
# Startup port and check whether all the PGs have been added
dvs.port_admin_set('Ethernet0', 'up')
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:1", {"profile": lossy_pg_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:5-6", {"profile": lossy_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:8", {"profile": lossy_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_reference_appl_db})
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:7")
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:9-{}".format(maximumQueues))
# Shutdown the port again to verify flow to remove buffer objects from an admin down port
dvs.port_admin_set('Ethernet0', 'down')
# First, check whether the objects have been correctly handled
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:5-6", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:7", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:8", {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:9-{}".format(maximumQueues), {"profile": lossy_queue_zero_reference})
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:1")
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6")
self.app_db.wait_for_deleted_entry("BUFFER_PROFILE", expectedProfile)
# Remove buffer objects from an admon down port
self.config_db.delete_entry('BUFFER_QUEUE', 'Ethernet0|8')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|1')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
# Checking
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:7")
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:8")
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:9-{}".format(maximumQueues))
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:7-{}".format(maximumQueues), {"profile": lossy_queue_zero_reference})
# Startup again
dvs.port_admin_set('Ethernet0', 'up')
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:0-2", {"profile": lossy_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:3-4", {"profile": lossless_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_QUEUE_TABLE", "Ethernet0:5-6", {"profile": lossy_queue_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": lossy_pg_reference_appl_db})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_deleted_entry("BUFFER_QUEUE_TABLE", "Ethernet0:7-{}".format(maximumQueues))
# Remove lossless PG 3-4 on interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_autoNegPort(self, dvs, testlog):
self.setup_db(dvs)
advertised_speeds = '10000,25000,50000'
maximum_advertised_speed = '50000'
if maximum_advertised_speed == self.originalSpeed:
# Let's make sure the configured speed isn't equal to maximum advertised speed
advertised_speeds = '10000,25000'
maximum_advertised_speed = '25000'
# Startup interfaces
dvs.port_admin_set('Ethernet0', 'up')
# Configure lossless PG 3-4 on the interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
# Enable port auto negotiation
dvs.port_field_set('Ethernet0','autoneg', 'on')
dvs.port_field_set('Ethernet0','adv_speeds', advertised_speeds)
# Check the buffer profile. The maximum_advertised_speed should be used
expectedProfile = self.make_lossless_profile_name(maximum_advertised_speed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PG_TABLE", "Ethernet0:3-4")
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
# Configure another lossless PG on the interface
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'NULL'})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Disable port auto negotiation
dvs.port_field_set('Ethernet0','autoneg', 'off')
# Check the buffer profile. The configured speed should be used
expectedProfile = self.make_lossless_profile_name(self.originalSpeed, self.originalCableLen)
self.app_db.wait_for_entry("BUFFER_PROFILE_TABLE", expectedProfile)
self.check_new_profile_in_asic_db(dvs, expectedProfile)
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": expectedProfile})
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:6", {"profile": expectedProfile})
# Remove lossless PGs on the interface
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
# Shutdown interface
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
@pytest.mark.skip(reason="Failing. Under investigation")
def test_removeBufferPool(self, dvs, testlog):
self.setup_db(dvs)
# Initialize additional databases that are used by this test only
self.counter_db = dvs.get_counters_db()
self.flex_db = dvs.get_flex_db()
try:
# Create a new pool
self.config_db.update_entry('BUFFER_POOL', 'ingress_test_pool', {'size': '0', 'mode': 'static', 'type': 'ingress'})
# Whether counterpoll is enabled? Enable it if not.
flex_counter = self.config_db.get_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK")
counter_poll_disabled = (not flex_counter or flex_counter["FLEX_COUNTER_STATUS"] != 'enable')
if counter_poll_disabled:
self.config_db.update_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK", {"FLEX_COUNTER_STATUS": "enable"})
# Check whether counter poll has been enabled
time.sleep(1)
poolmap = self.counter_db.wait_for_entry("COUNTERS_BUFFER_POOL_NAME_MAP", "")
assert poolmap["ingress_test_pool"]
self.flex_db.wait_for_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK_STAT_COUNTER:{}".format(poolmap["ingress_test_pool"]))
self.config_db.delete_entry('BUFFER_POOL', 'ingress_test_pool')
oid_to_remove = poolmap.pop('ingress_test_pool')
self.counter_db.wait_for_field_match("COUNTERS_BUFFER_POOL_NAME_MAP", "", poolmap)
self.flex_db.wait_for_deleted_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK_STAT_COUNTER:{}".format(oid_to_remove))
finally:
# Clean up: disable counterpoll if it was disabled
if counter_poll_disabled:
self.config_db.delete_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK")
self.cleanup_db(dvs)
def test_bufferPortMaxParameter(self, dvs, testlog):
self.setup_db(dvs)
# Update log level so that we can analyze the log in case the test failed
logfvs = self.config_db.wait_for_entry("LOGGER", "buffermgrd")
old_log_level = logfvs.get("LOGLEVEL")
logfvs["LOGLEVEL"] = "INFO"
self.config_db.update_entry("LOGGER", "buffermgrd", logfvs)
# Check whether port's maximum parameter has been exposed to STATE_DB
fvs = self.state_db.wait_for_entry("BUFFER_MAX_PARAM_TABLE", "Ethernet0")
assert int(fvs["max_queues"]) and int(fvs["max_priority_groups"])
_, oa_pid = dvs.runcmd("pgrep orchagent")
try:
fvs["max_headroom_size"] = "122880"
self.state_db.update_entry("BUFFER_MAX_PARAM_TABLE", "Ethernet0", fvs)
# Startup interface
dvs.port_admin_set('Ethernet0', 'up')
# Wait for the lossy profile to be handled
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:0", {"profile": "ingress_lossy_profile"})
# Stop orchagent to simulate the scenario that the system is during initialization
dvs.runcmd("kill -s SIGSTOP {}".format(oa_pid))
# Create a lossless profile
profile_fvs = {'xon': '19456',
'xoff': '10240',
'size': '29696',
'dynamic_th': '0',
'pool': 'ingress_lossless_pool'}
self.config_db.update_entry('BUFFER_PROFILE', 'test', profile_fvs)
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'test'})
# Make sure the entry has been handled by buffermgrd and is pending on orchagent's queue
self.app_db.wait_for_field_match("_BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": "test"})
# Should not be added due to the maximum headroom exceeded
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|1', {'profile': 'ingress_lossy_profile'})
# Should not be added due to the maximum headroom exceeded
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|6', {'profile': 'test'})
# Resume orchagent
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))
# Check whether BUFFER_PG_TABLE is updated as expected
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": "test"})
keys = self.app_db.get_keys('BUFFER_PG_TABLE')
assert 'Ethernet0:1' not in keys
assert 'Ethernet0:6' not in keys
# Update the profile
profile_fvs['size'] = '28672'
profile_fvs['xoff'] = '9216'
self.config_db.update_entry('BUFFER_PROFILE', 'test', profile_fvs)
self.app_db.wait_for_field_match('BUFFER_PROFILE_TABLE', 'test', profile_fvs)
# Verify a pending remove PG is not counted into the accumulative headroom
dvs.runcmd("kill -s SIGSTOP {}".format(oa_pid))
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
# Should be added because PG 3-4 has been removed and there are sufficient headroom
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|1', {'profile': 'ingress_lossy_profile'})
# Resume orchagent
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))
# Check whether BUFFER_PG_TABLE is updated as expected
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:1", {"profile": "ingress_lossy_profile"})
finally:
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|3-4')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|1')
self.config_db.delete_entry('BUFFER_PG', 'Ethernet0|6')
self.config_db.delete_entry('BUFFER_PROFILE', 'test')
fvs.pop("max_headroom_size")
self.state_db.delete_entry("BUFFER_MAX_PARAM_TABLE", "Ethernet0")
self.state_db.update_entry("BUFFER_MAX_PARAM_TABLE", "Ethernet0", fvs)
if old_log_level:
logfvs["LOGLEVEL"] = old_log_level
self.config_db.update_entry("LOGGER", "buffermgrd", logfvs)
dvs.port_admin_set('Ethernet0', 'down')
self.cleanup_db(dvs)
def test_bufferPoolInitWithSHP(self, dvs, testlog):
self.setup_db(dvs)
try:
# 1. Enable the shared headroom pool
default_lossless_buffer_parameter = self.config_db.get_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE')
default_lossless_buffer_parameter['over_subscribe_ratio'] = '2'
self.config_db.update_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE', default_lossless_buffer_parameter)
# 2. Stop the orchagent
_, oa_pid = dvs.runcmd("pgrep orchagent")
dvs.runcmd("kill -s SIGSTOP {}".format(oa_pid))
# 3. Remove the size from CONFIG_DB|BUFFER_POOL.ingress_lossless_pool
original_ingress_lossless_pool = self.config_db.get_entry('BUFFER_POOL', 'ingress_lossless_pool')
try:
self.config_db.delete_field('BUFFER_POOL', 'ingress_lossless_pool', 'size')
self.config_db.delete_field('BUFFER_POOL', 'ingress_lossless_pool', 'xoff')
except Exception as e:
pass
# 4. Remove the ingress_lossless_pool from the APPL_DB
self.app_db.delete_entry('BUFFER_POOL_TABLE', 'ingress_lossless_pool')
# 5. Mock it by adding a "TABLE_SET" entry to trigger the fallback logic
self.app_db.update_entry("BUFFER_PG_TABLE_SET", "", {"NULL": "NULL"})
# 6. Invoke the lua plugin
_, output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
assert "ingress_lossless_pool:2048:1024" in output
finally:
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', original_ingress_lossless_pool)
self.config_db.delete_entry('DEFAULT_LOSSLESS_BUFFER_PARAMETER', 'AZURE')
self.app_db.delete_entry("BUFFER_PG_TABLE_SET", "")
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))
def test_bufferPoolPercentage(self, dvs, testlog):
self.setup_db(dvs)
try:
self.config_db.delete_field('BUFFER_POOL', 'ingress_lossless_pool', 'size')
except Exception as e:
pass
try:
percentage = 75
margin = 1
re_pool_size = "ingress_lossless_pool:([0-9]+)"
_, original_output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
original_size = int(re.match(re_pool_size, original_output).group(1))
original_ingress_lossless_pool = self.config_db.get_entry('BUFFER_POOL', 'ingress_lossless_pool')
ingress_lossless_pool = original_ingress_lossless_pool
ingress_lossless_pool['percentage'] = str(percentage)
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', ingress_lossless_pool)
_, percentage_output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
percentage_size = int(re.match(re_pool_size, percentage_output).group(1))
real_percentage = percentage_size * 100 / original_size
assert abs(percentage - real_percentage) < margin
finally:
self.config_db.delete_entry('BUFFER_POOL', 'ingress_lossless_pool')
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', original_ingress_lossless_pool)