-
Notifications
You must be signed in to change notification settings - Fork 666
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 utility to configure ECN WRED parameters #153
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/usr/bin/python | ||
""" | ||
ecnconfig is the utility to show and change ECN configuration | ||
|
||
usage: ecnconfig [-h] [-v] [-l] [-p PROFILE] [-gmin GREEN_MIN] | ||
[-gmax GREEN_MAX] [-ymin YELLOW_MIN] [-ymax YELLOW_MAX] | ||
[-rmin RED_MIN] [-rmax RED_MAX] [-vv] | ||
|
||
optional arguments: | ||
-h --help show this help message and exit | ||
-v --version show program's version number and exit | ||
-vv --verbose verbose output | ||
-l --list show ECN WRED configuration | ||
-p' --profile specify WRED profile name | ||
-gmin --green-min set min threshold for packets marked green | ||
-gmax --green-max set max threshold for packets marked green | ||
-ymin --yellow-min set min threshold for packets marked yellow | ||
-ymax --yellow-max set max threshold for packets marked yellow | ||
-rmin --red-min set min threshold for packets marked red | ||
-rmax --red-max set max threshold for packets marked red | ||
""" | ||
from __future__ import print_function | ||
|
||
import os | ||
import sys | ||
import json | ||
import argparse | ||
import swsssdk | ||
from tabulate import tabulate | ||
|
||
WRED_PROFILE_TABLE_NAME = "WRED_PROFILE" | ||
WRED_CONFIG_FIELDS = { | ||
"gmax": "green_max_threshold", | ||
"gmin": "green_min_threshold", | ||
"ymax": "yellow_max_threshold", | ||
"ymin": "yellow_min_threshold", | ||
"rmax": "red_max_threshold", | ||
"rmin": "red_min_threshold" | ||
} | ||
|
||
class EcnConfig(object): | ||
""" | ||
Process aclstat | ||
""" | ||
def __init__(self, verbose): | ||
self.ports = [] | ||
self.queues = [] | ||
self.verbose = verbose | ||
|
||
# Set up db connections | ||
self.db = swsssdk.ConfigDBConnector() | ||
self.db.connect() | ||
|
||
def list(self): | ||
wred_tables = self.db.get_table(WRED_PROFILE_TABLE_NAME) | ||
for table in wred_tables: | ||
profile_name = table | ||
profile_data = wred_tables[table] | ||
config = [] | ||
print("Profile: " + profile_name) | ||
for field in profile_data: | ||
line = [field, profile_data[field]] | ||
config.append(line) | ||
print(tabulate(config) + "\n") | ||
if self.verbose: | ||
print("Total profiles: %d" % len(wred_tables)) | ||
|
||
def set_wred_threshold(self, profile, threshold, value): | ||
field = WRED_CONFIG_FIELDS[threshold] | ||
if self.verbose: | ||
print("Setting %s value to %s" % (field, value)) | ||
self.db.set_entry(WRED_PROFILE_TABLE_NAME, profile, {field: value}) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Show and change ECN WRED configuration', | ||
version='1.0.0', | ||
formatter_class=argparse.RawTextHelpFormatter) | ||
# group = parser.add_mutually_exclusive_group() | ||
parser.add_argument('-l', '--list', action='store_true', help='show ECN WRED configuration') | ||
parser.add_argument('-p', '--profile', type=str, help='specify WRED profile name', default=None) | ||
parser.add_argument('-gmin', '--green-min', type=str, help='set min threshold for packets marked \'green\'', default=None) | ||
parser.add_argument('-gmax', '--green-max', type=str, help='set max threshold for packets marked \'green\'', default=None) | ||
parser.add_argument('-ymin', '--yellow-min', type=str, help='set min threshold for packets marked \'yellow\'', default=None) | ||
parser.add_argument('-ymax', '--yellow-max', type=str, help='set max threshold for packets marked \'yellow\'', default=None) | ||
parser.add_argument('-rmin', '--red-min', type=str, help='set min threshold for packets marked \'red\'', default=None) | ||
parser.add_argument('-rmax', '--red-max', type=str, help='set max threshold for packets marked \'red\'', default=None) | ||
parser.add_argument('-vv', '--verbose', action='store_true', help='Verbose output', default=False) | ||
args = parser.parse_args() | ||
|
||
try: | ||
ecn = EcnConfig(args.verbose) | ||
if args.list: | ||
if len(sys.argv) > (3 if args.verbose else 2): | ||
raise Exception("Input arguments error. No set options allowed when -l[ist] specified") | ||
ecn.list() | ||
elif args.profile: | ||
if len(sys.argv) < (5 if args.verbose else 4): | ||
raise Exception("Input arguments error. Specify at least one threshold parameter to set") | ||
# the following parameters can be combined in one run | ||
if args.green_max: | ||
ecn.set_wred_threshold(args.profile, "gmax", args.green_max) | ||
if args.green_min: | ||
ecn.set_wred_threshold(args.profile, "gmin", args.green_min) | ||
if args.yellow_max: | ||
ecn.set_wred_threshold(args.profile, "ymax", args.yellow_max) | ||
if args.yellow_min: | ||
ecn.set_wred_threshold(args.profile, "ymin", args.yellow_min) | ||
if args.red_max: | ||
ecn.set_wred_threshold(args.profile, "rmax", args.red_max) | ||
if args.red_min: | ||
ecn.set_wred_threshold(args.profile, "rmin", args.red_min) | ||
else: | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
except Exception as e: | ||
print(e.message, file=sys.stderr) | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe deleting comments is not the best thing.
I figured out that args are returning values in strings, so we don't have a risk of ignoring integer value 0 here.