3
3
from flow_counter_util .route import exit_if_route_flow_counter_not_support
4
4
from swsscommon .swsscommon import ConfigDBConnector
5
5
from tabulate import tabulate
6
+ from sonic_py_common import device_info
6
7
7
8
BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK"
8
9
PORT_BUFFER_DROP = "PORT_BUFFER_DROP"
9
10
PG_DROP = "PG_DROP"
10
11
ACL = "ACL"
12
+ ENI = "ENI"
11
13
DISABLE = "disable"
12
14
ENABLE = "enable"
13
15
DEFLT_60_SEC = "default (60000)"
14
16
DEFLT_10_SEC = "default (10000)"
15
17
DEFLT_1_SEC = "default (1000)"
16
18
19
+
20
+ def is_dpu (db ):
21
+ """ Check if the device is DPU """
22
+ platform_info = device_info .get_platform_info (db )
23
+ if platform_info .get ('switch_type' ) == 'dpu' :
24
+ return True
25
+ else :
26
+ return False
27
+
28
+
17
29
@click .group ()
18
30
def cli ():
19
31
""" SONiC Static Counter Poll configurations """
@@ -126,6 +138,7 @@ def disable():
126
138
port_info ['FLEX_COUNTER_STATUS' ] = DISABLE
127
139
configdb .mod_entry ("FLEX_COUNTER_TABLE" , PORT_BUFFER_DROP , port_info )
128
140
141
+
129
142
# Ingress PG drop packet stat
130
143
@cli .group ()
131
144
@click .pass_context
@@ -382,6 +395,47 @@ def disable(ctx):
382
395
fc_info ['FLEX_COUNTER_STATUS' ] = 'disable'
383
396
ctx .obj .mod_entry ("FLEX_COUNTER_TABLE" , "FLOW_CNT_ROUTE" , fc_info )
384
397
398
+
399
+ # ENI counter commands
400
+ @cli .group ()
401
+ @click .pass_context
402
+ def eni (ctx ):
403
+ """ ENI counter commands """
404
+ ctx .obj = ConfigDBConnector ()
405
+ ctx .obj .connect ()
406
+ if not is_dpu (ctx .obj ):
407
+ click .echo ("ENI counters are not supported on non DPU platforms" )
408
+ exit (1 )
409
+
410
+
411
+ @eni .command (name = 'interval' )
412
+ @click .argument ('poll_interval' , type = click .IntRange (1000 , 30000 ))
413
+ @click .pass_context
414
+ def eni_interval (ctx , poll_interval ):
415
+ """ Set eni counter query interval """
416
+ eni_info = {}
417
+ eni_info ['POLL_INTERVAL' ] = poll_interval
418
+ ctx .obj .mod_entry ("FLEX_COUNTER_TABLE" , ENI , eni_info )
419
+
420
+
421
+ @eni .command (name = 'enable' )
422
+ @click .pass_context
423
+ def eni_enable (ctx ):
424
+ """ Enable eni counter query """
425
+ eni_info = {}
426
+ eni_info ['FLEX_COUNTER_STATUS' ] = 'enable'
427
+ ctx .obj .mod_entry ("FLEX_COUNTER_TABLE" , ENI , eni_info )
428
+
429
+
430
+ @eni .command (name = 'disable' )
431
+ @click .pass_context
432
+ def eni_disable (ctx ):
433
+ """ Disable eni counter query """
434
+ eni_info = {}
435
+ eni_info ['FLEX_COUNTER_STATUS' ] = 'disable'
436
+ ctx .obj .mod_entry ("FLEX_COUNTER_TABLE" , ENI , eni_info )
437
+
438
+
385
439
@cli .command ()
386
440
def show ():
387
441
""" Show the counter configuration """
@@ -399,6 +453,7 @@ def show():
399
453
tunnel_info = configdb .get_entry ('FLEX_COUNTER_TABLE' , 'TUNNEL' )
400
454
trap_info = configdb .get_entry ('FLEX_COUNTER_TABLE' , 'FLOW_CNT_TRAP' )
401
455
route_info = configdb .get_entry ('FLEX_COUNTER_TABLE' , 'FLOW_CNT_ROUTE' )
456
+ eni_info = configdb .get_entry ('FLEX_COUNTER_TABLE' , ENI )
402
457
403
458
header = ("Type" , "Interval (in ms)" , "Status" )
404
459
data = []
@@ -428,6 +483,10 @@ def show():
428
483
data .append (["FLOW_CNT_ROUTE_STAT" , route_info .get ("POLL_INTERVAL" , DEFLT_10_SEC ),
429
484
route_info .get ("FLEX_COUNTER_STATUS" , DISABLE )])
430
485
486
+ if is_dpu (config_db ) and eni_info :
487
+ data .append (["ENI_STAT" , eni_info .get ("POLL_INTERVAL" , DEFLT_10_SEC ),
488
+ eni_info .get ("FLEX_COUNTER_STATUS" , DISABLE )])
489
+
431
490
click .echo (tabulate (data , headers = header , tablefmt = "simple" , missingval = "" ))
432
491
433
492
def _update_config_db_flex_counter_table (status , filename ):
0 commit comments