Skip to content

Commit b1156be

Browse files
wendanilguohan
authored andcommitted
Add mmuconfig (sonic-net#344)
* Dump buffer pool and profile config Signed-off-by: Wenda <[email protected]> * Add logic to set dynamic alpha Signed-off-by: Wenda <[email protected]> * Add show mmu Signed-off-by: Wenda <[email protected]> * Add command line description Signed-off-by: Wenda <[email protected]> * Check alpha value range; exit with error message if field to set is not supported Signed-off-by: Wenda <[email protected]>
1 parent 6d00d14 commit b1156be

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

scripts/mmuconfig

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/python
2+
"""
3+
mmuconfig is the utility to show and change mmu configuration
4+
5+
usage: mmuconfig [-h] [-v] [-l] [-p PROFILE] [-a ALPHA] [-vv]
6+
7+
optional arguments:
8+
-h --help show this help message and exit
9+
-v --version show program's version number and exit
10+
-vv --verbose verbose output
11+
-l --list show mmu configuration
12+
-p --profile specify buffer profile name
13+
-a --alpha set n for dyanmic threshold alpha 2^(n)
14+
15+
"""
16+
17+
from __future__ import print_function
18+
19+
import os
20+
import sys
21+
import argparse
22+
import swsssdk
23+
import tabulate
24+
25+
BUFFER_POOL_TABLE_NAME = "BUFFER_POOL"
26+
BUFFER_PROFILE_TABLE_NAME = "BUFFER_PROFILE"
27+
28+
DYNAMIC_THRESHOLD = "dynamic_th"
29+
BUFFER_PROFILE_FIELDS = {
30+
"alpha": DYNAMIC_THRESHOLD
31+
}
32+
33+
34+
class MmuConfig(object):
35+
def __init__(self, verbose):
36+
self.verbose = verbose
37+
38+
# Set up db connections
39+
self.db = swsssdk.ConfigDBConnector()
40+
self.db.connect()
41+
42+
def list(self):
43+
buf_pools = self.db.get_table(BUFFER_POOL_TABLE_NAME)
44+
for pool_name, pool_data in buf_pools.items():
45+
config = []
46+
47+
print("Pool: " + pool_name)
48+
for field, value in pool_data.items():
49+
config.append([field, value])
50+
print(tabulate.tabulate(config) + "\n")
51+
if self.verbose:
52+
print("Total pools: %d\n\n" % len(buf_pools))
53+
54+
buf_profs = self.db.get_table(BUFFER_PROFILE_TABLE_NAME)
55+
for prof_name, prof_data in buf_profs.items():
56+
config = []
57+
58+
print("Profile: " + prof_name)
59+
for field, value in prof_data.items():
60+
config.append([field, value])
61+
print(tabulate.tabulate(config) + "\n")
62+
if self.verbose:
63+
print("Total profiles: %d" % len(buf_profs))
64+
65+
def set(self, profile, field_alias, value):
66+
if os.geteuid() != 0:
67+
sys.exit("Root privileges required for this operation")
68+
69+
field = BUFFER_PROFILE_FIELDS[field_alias]
70+
if field == DYNAMIC_THRESHOLD:
71+
v = int(value)
72+
if v < -8 or v > 8:
73+
sys.exit("Invalid alpha value: 2^(%s)" % (value))
74+
75+
buf_profs = self.db.get_table(BUFFER_PROFILE_TABLE_NAME)
76+
if profile in buf_profs and DYNAMIC_THRESHOLD not in buf_profs[profile]:
77+
sys.exit("%s not using dynamic thresholding" % (profile))
78+
else:
79+
sys.exit("Set field %s not supported" % (field))
80+
81+
if self.verbose:
82+
print("Setting %s %s value to %s" % (profile, field, value))
83+
self.db.mod_entry(BUFFER_PROFILE_TABLE_NAME, profile, {field: value})
84+
85+
86+
def main():
87+
parser = argparse.ArgumentParser(description='Show and change: mmu configuration',
88+
version='1.0.0',
89+
formatter_class=argparse.RawTextHelpFormatter)
90+
91+
parser.add_argument('-l', '--list', action='store_true', help='show mmu configuration')
92+
parser.add_argument('-p', '--profile', type=str, help='specify buffer profile name', default=None)
93+
parser.add_argument('-a', '--alpha', type=str, help='set n for dyanmic threshold alpha 2^(n)', default=None)
94+
parser.add_argument('-vv', '--verbose', action='store_true', help='verbose output', default=False)
95+
96+
args = parser.parse_args()
97+
98+
try:
99+
mmu_cfg = MmuConfig(args.verbose)
100+
if args.list:
101+
mmu_cfg.list()
102+
elif args.profile:
103+
if args.alpha:
104+
mmu_cfg.set(args.profile, "alpha", args.alpha)
105+
else:
106+
parser.print_help()
107+
sys.exit(1)
108+
109+
except Exception as e:
110+
print("Exception caught:", e.message, file=sys.stderr)
111+
sys.exit(1)
112+
113+
if __name__ == "__main__":
114+
main()

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def get_test_suite():
4646
'scripts/decode-syseeprom',
4747
'scripts/dropcheck',
4848
'scripts/ecnconfig',
49+
'scripts/mmuconfig',
4950
'scripts/fast-reboot',
5051
'scripts/fast-reboot-dump.py',
5152
'scripts/fdbclear',

show/main.py

+10
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,16 @@ def ecn():
14211421
click.echo(proc.stdout.read())
14221422

14231423

1424+
# 'mmu' command ("show mmu")
1425+
#
1426+
@cli.command('mmu')
1427+
def mmu():
1428+
"""Show mmu configuration"""
1429+
cmd = "mmuconfig -l"
1430+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
1431+
click.echo(proc.stdout.read())
1432+
1433+
14241434
#
14251435
# 'reboot-cause' command ("show reboot-cause")
14261436
#

0 commit comments

Comments
 (0)