Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show and clear commands for headroom pool watermark #1144

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,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 @@ -169,6 +169,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 @@ -228,12 +231,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 @@ -278,7 +284,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')
args = parser.parse_args()
watermarkstat = Watermarkstat()
Expand Down
21 changes: 21 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,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
}
]
}