Skip to content

Commit

Permalink
Add show and clear commands for headroom pool watermark (#1144)
Browse files Browse the repository at this point in the history
Depends on sonic-net/sonic-swss#1453

- What I did
Added support to query and clear headroom pool watermark counters
Added unit test for the headroom pool watermark counters

- How I did it
Modified watermarkstat script to query/clear headroom pool watermark counters
Added show and clear commands

- How to verify it
Send traffic such that it treks into the headroom pool and check for the headroom pool usage using the show command below
Set polling interval to 30s and issue clear commands mentioned below and verify that counters are cleared

- New command output (if the output of a command-line utility has changed)
Show commands
admin@sonic:~$ show headroom-pool watermark 
Headroom pool maximum occupancy:
                 Pool    Bytes
---------------------  -------
ingress_lossless_pool    12480

admin@sonic:~$ show headroom-pool persistent-watermark 
Headroom pool maximum occupancy:
                 Pool    Bytes
---------------------  -------
ingress_lossless_pool    12480

Clear commands
admin@sonic:~$ sudo sonic-clear headroom-pool watermark 
admin@sonic:~$ sudo sonic-clear headroom-pool persistent-watermark 

Signed-off-by: Neetha John <nejo@microsoft.com>
  • Loading branch information
neethajohn authored Dec 9, 2020
1 parent d414970 commit 57a0b41
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 7 deletions.
24 changes: 24 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ def clear_pwm_q_multi():
command = 'watermarkstat -c -p -t q_shared_multi'
run_command(command)


@cli.group(name='headroom-pool')
def headroom_pool():
"""Clear headroom pool WM"""
pass

@headroom_pool.command('watermark')
def watermark():
"""Clear headroom pool user WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

command = 'watermarkstat -c -t headroom_pool'
run_command(command)

@headroom_pool.command('persistent-watermark')
def persistent_watermark():
"""Clear headroom pool persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

command = 'watermarkstat -c -p -t headroom_pool'
run_command(command)

#
# 'arp' command ####
#
Expand Down
14 changes: 10 additions & 4 deletions scripts/watermarkstat
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class Watermarkstat(object):
"header_prefix": "MC"},
"buffer_pool" : {"message": "Shared pool maximum occupancy:",
"wm_name": "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES",
"header" : headerBufferPool},
"headroom_pool" : {"message": "Headroom pool maximum occupancy:",
"wm_name": "SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES",
"header" : headerBufferPool}
}

Expand Down Expand Up @@ -226,12 +229,15 @@ class Watermarkstat(object):
def print_all_stat(self, table_prefix, key):
table = []
type = self.watermark_types[key]
if key == 'buffer_pool':
if key in ['buffer_pool', 'headroom_pool']:
self.header_list = type['header']
# Get stats for each buffer pool
for buf_pool, bp_oid in natsorted(self.buffer_pool_name_to_oid_map.items()):
key = table_prefix + bp_oid
data = self.counters_db.get(self.counters_db.COUNTERS_DB, key, type["wm_name"])
if key == 'headroom_pool' and 'ingress_lossless' not in buf_pool:
continue

db_key = table_prefix + bp_oid
data = self.counters_db.get(self.counters_db.COUNTERS_DB, db_key, type["wm_name"])
if data is None:
data = STATUS_NA
table.append((buf_pool, data))
Expand Down Expand Up @@ -275,7 +281,7 @@ Examples:
parser.add_argument('-c', '--clear', action='store_true', help='Clear watermarks request')
parser.add_argument('-p', '--persistent', action='store_true', help='Do the operations on the persistent watermark')
parser.add_argument('-t', '--type', required=True, action='store',
choices=['pg_headroom', 'pg_shared', 'q_shared_uni', 'q_shared_multi', 'buffer_pool'],
choices=['pg_headroom', 'pg_shared', 'q_shared_uni', 'q_shared_multi', 'buffer_pool', 'headroom_pool'],
help='The type of watermark')
parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')
args = parser.parse_args()
Expand Down
21 changes: 21 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,27 @@ def pwm_buffer_pool():
run_command(command)


#
# 'headroom-pool' group ("show headroom-pool ...")
#

@cli.group(name='headroom-pool', cls=clicommon.AliasedGroup)
def headroom_pool():
"""Show details of headroom pool"""

@headroom_pool.command('watermark')
def wm_headroom_pool():
"""Show user WM for headroom pool"""
command = 'watermarkstat -t headroom_pool'
run_command(command)

@headroom_pool.command('persistent-watermark')
def pwm_headroom_pool():
"""Show persistent WM for headroom pool"""
command = 'watermarkstat -p -t headroom_pool'
run_command(command)


#
# 'mac' command ("show mac ...")
#
Expand Down
6 changes: 4 additions & 2 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "2000"
},
"USER_WATERMARKS:oid:0x18000000000b66": {
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "3000"
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "3000",
"SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES": "432640"
},
"PERSISTENT_WATERMARKS:oid:0x18000000000b64": {
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "2000"
Expand All @@ -999,7 +1000,8 @@
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "3000"
},
"PERSISTENT_WATERMARKS:oid:0x18000000000b66": {
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "4000"
"SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "4000",
"SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES": "863616"
},
"CRM:ACL_STATS:INGRESS:VLAN":{
"crm_stats_acl_table_used":"0",
Expand Down
6 changes: 6 additions & 0 deletions tests/watermarkstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def test_show_queue_multicast_wm(self):
def test_show_buffer_pool_wm(self):
self.executor(testData['show_buffer_pool_wm'])

def test_show_headroom_pool_wm(self):
self.executor(testData['show_hdrm_pool_wm'])

def test_show_pg_shared_peristent_wm(self):
self.executor(testData['show_pg_pwm_shared'])

Expand All @@ -51,6 +54,9 @@ def test_show_queue_multicast_persistent_wm(self):
def test_show_buffer_pool_persistent_wm(self):
self.executor(testData['show_buffer_pool_pwm'])

def test_show_headroom_pool_persistent_wm(self):
self.executor(testData['show_hdrm_pool_pwm'])

def executor(self, testcase):
runner = CliRunner()

Expand Down
24 changes: 23 additions & 1 deletion tests/wm_input/wm_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@
ingress_lossless_pool 4000
"""

show_hdrm_pool_wm_output="""\
Headroom pool maximum occupancy:
Pool Bytes
--------------------- -------
ingress_lossless_pool 432640
"""

show_hdrm_pool_persistent_wm_output="""\
Headroom pool maximum occupancy:
Pool Bytes
--------------------- -------
ingress_lossless_pool 863616
"""

testData = {
'show_pg_wm_shared' : [ {'cmd' : ['priority-group', 'watermark', 'shared'],
'rc_output': show_pg_wm_shared_output
Expand Down Expand Up @@ -119,5 +133,13 @@
'show_buffer_pool_pwm' : [ {'cmd' : ['buffer_pool', 'persistent-watermark'],
'rc_output': show_buffer_pool_persistent_wm_output
}
]
],
'show_hdrm_pool_wm' : [ {'cmd' : ['headroom-pool', 'watermark'],
'rc_output': show_hdrm_pool_wm_output
}
],
'show_hdrm_pool_pwm' : [ {'cmd' : ['headroom-pool', 'persistent-watermark'],
'rc_output': show_hdrm_pool_persistent_wm_output
}
]
}

0 comments on commit 57a0b41

Please sign in to comment.