sonic-utilities: Add support for sFlow#592
sonic-utilities: Add support for sFlow#592prsunny merged 16 commits intosonic-net:masterfrom GarrickHe:sflow-cli
Conversation
* Add configuration CLI to add/delete collector * Add configuration CLI to set sampling-rate * Add show CLI to display sFlow information Signed-off-by: Garrick He <garrick_he@dell.com>
* Updated config/show commands to conform with HDL * Updated with code-review suggestions Signed-off-by: Garrick He <garrick_he@dell.com>
* Added logic to query AppsDB for sample-rate * Updated CLI to remove 'global' and 'all' option * Added logic to handle 'all' as interface name Signed-off-by: Garrick He <garrick_he@dell.com>
* Fixed a minor display bug in the 'show sflow interface' command where the global information will also be displayed. Signed-off-by: Garrick He <garrick_he@dell.com>
* Add sflow container to the restart service list Signed-off-by: Garrick He <garrick_he@dell.com>
* Add comments and some clean-ups Signed-off-by: Garrick He <garrick_he@dell.com>
* Fix the sFlow related code to ensure PEP8 compliance. Signed-off-by: Garrick He <garrick_he@dell.com>
* Address code review comments * Re-run PEP8 compliance check Signed-off-by: Garrick He <garrick_he@dell.com>
* Fix: Can't configure sFlow when daemon is disabled. * Fix: Interface admin-state are in correct * Fix: Collectors are shown in sorted (by name) order * Fix: Can add lo interface for sFlow agent-id * Fix: Can't ovewrite existing collector with the same name Signed-off-by: Garrick He <garrick_he@dell.com>
|
Closing this pull-request to fix some issues found during unit-test. Will create a new one soon. |
* Fix the polling intervals to be between 5-300 and 0 to disable. Signed-off-by: Garrick He <garrick_he@dell.com>
* Add sFlow container to support rollback and upgrade. Signed-off-by: Garrick He <garrick_he@dell.com>
config/main.py
Outdated
| else: | ||
| sflow_tbl['global']['admin_state'] = 'enable' | ||
|
|
||
| config_db.set_entry('SFLOW', 'global', sflow_tbl['global']) |
There was a problem hiding this comment.
You could just do a config_db.mod_entry for setting the admin_state field
config/main.py
Outdated
| else: | ||
| sflow_tbl['global']['admin_state'] = 'disable' | ||
|
|
||
| config_db.set_entry('SFLOW', 'global', sflow_tbl['global']) |
config/main.py
Outdated
| sflow_tbl = {'global': {'admin_state': 'disable'}} | ||
|
|
||
| sflow_tbl['global']['polling_interval'] = interval | ||
| config_db.set_entry('SFLOW', 'global', sflow_tbl['global']) |
| """Add a sFlow collector""" | ||
| ipaddr = ipaddr.lower() | ||
|
|
||
| if not is_valid_collector_info(name, ipaddr, port): |
There was a problem hiding this comment.
Do you see an issue with function being defined after invocation? I see that this is_valid_collector_info function is defined below and not above this.
There was a problem hiding this comment.
Didn't notice a problem, but will move it up.
config/main.py
Outdated
|
|
||
| import socket | ||
| try: | ||
| socket.inet_pton(socket.AF_INET, ip) |
There was a problem hiding this comment.
Please use is_ipaddress here
| """Show sFlow interface information""" | ||
| show_sflow_interface(ctx.obj['db']) | ||
|
|
||
| def sflow_appDB_connect(): |
There was a problem hiding this comment.
What is this function? Looks different from the objective. May be sflow_sample_rate ?
There was a problem hiding this comment.
We need to connect to applDB to get default sample-rate per port if the user doesn't configure them manually.
show/main.py
Outdated
| body_info.append(sflow_session_tbl[pname]['sample_rate']) | ||
| else: | ||
| body_info.append(sflow_sampling_tbl[port_tbl[pname]['speed']]) | ||
| else: |
There was a problem hiding this comment.
Ok so the session table is always present in APP_DB, right?. Then let show just read the table and display and not have a logic for individual ports. if the table is not present, don't add to the show output. What do you think?
There was a problem hiding this comment.
If the user configures the sampling-rate for a port, we will add a separate session for that port with the new sampling-rate. That is why we need to figure out whether there is a session for that particular port (in configDB) and if we do, we will use that information instead of the one in appLDB.
| if 'admin_state' in sflow_session_tbl['all']: | ||
| all_session_admin_state = sflow_session_tbl['all']['admin_state'] | ||
|
|
||
| if not port_tbl: |
There was a problem hiding this comment.
This check must be right after port_tbl = config_db.get_table('PORT')
show/main.py
Outdated
| global_admin_state = sflow_info['global']['admin_state'] | ||
|
|
||
| click.echo("\nsFlow Global Information:") | ||
| click.echo(" sFlow Daemon State: {}".format(global_admin_state)) |
There was a problem hiding this comment.
This is different from the output in description. What is the intention? Prefer the one in description
SFlow Global Information:
SFlow Admin State: enable
There was a problem hiding this comment.
Sure, will change it back to match description.
show/main.py
Outdated
| click.echo(tabulate(body, header, tablefmt='grid')) | ||
|
|
||
| def show_sflow_global(config_db): | ||
| default_polling = 20 |
There was a problem hiding this comment.
My thinking is CLI should not have a default but read from the APP/CONFIG DBs. Can you check if this is always present, if so, just read from DB and for some reason its missing, let it be an error.
There was a problem hiding this comment.
ConfigDB only stores information configured by the user, so the default polling-interval will not be present. According to @padmanarayana, we will just print the default (20) hence that variable. The default is not part of the ConfigDB or AppDB schema hence it will not be present. It will only be in ConfigDB if the user manually it.
There was a problem hiding this comment.
@prsunny I just clarified with @padmanarayana - He will make changes to the back-end to include polling-interval in the appDB and I will make changes to read that value.
* Use mod_entry instead of set_entry for configDB changes * Only query applDB for session information * Minor change to show command output to match HDL Signed-off-by: Garrick He <garrick_he@dell.com>
* Change to deleting agent-id logic Signed-off-by: Garrick He <garrick_he@dell.com>
* Change admin-state from enable/disable to up/down to match SONiC YANG. Signed-off-by: Garrick He <garrick_he@dell.com>
|
retest this please |
|
@prsunny - I ran some basic UT with the script and all was good. |
* Fix some minor alignment issues in the show sFlow global output. Signed-off-by: Garrick He <garrick_he@dell.com>
|
retest this please |
|
retest this please |
1 similar comment
|
retest this please |
|
@prsunny @dgsudharsan - not sure if you're asking me to retest or the robot. But here's mine, notice the output is aligned now regardless of the length of the collector name: |
|
retest this please |
2 similar comments
|
retest this please |
|
retest this please |
| @click.argument('rate', metavar='<sample_rate>', required=True, type=int) | ||
| @click.pass_context | ||
| def sample_rate(ctx, ifname, rate): | ||
| if not interface_name_is_valid(ifname) and ifname != 'all': |
There was a problem hiding this comment.
No need to include key all to be valid here as sflowmgrd only respond to field admin_state under SFLOW_SESSION|all
There was a problem hiding this comment.
This check is to ensure the user gives a valid interface name or all before writing to the dB.
| config_db = ctx.obj['db'] | ||
| collector_tbl = config_db.get_table('SFLOW_COLLECTOR') | ||
|
|
||
| if (collector_tbl and name not in collector_tbl.keys() and len(collector_tbl) == 2): |
There was a problem hiding this comment.
Collectors are limited to 2. Is this a limit from upper-layer hsflowd daemon?
Also confused about the output in the PR description that you were able to configure 4 collectors.
There was a problem hiding this comment.
Because you were reading the output from an outdated version of the code. I changed that afterwards:
admin@sonic:~$
admin@sonic:~$ sudo config sflow collector add collect1 1.1.1.1
admin@sonic:~$ sudo config sflow collector add collect2 1.1.1.2 --port 6100
admin@sonic:~$ sudo config sflow collector add collect3 1.1.1.3 --port 6100
Only 2 collectors can be configured, please delete one
There was a problem hiding this comment.
Is this a limitation from upper-layer hsflowd daemon?
What I did?
How I did it?
Added logic into config/main.py to add sFlow related information supplied by the user through a CLI. Also added logic into show/main.py to query configDB to show sFlow related information.
How to verify it?
Manually ran the new CLIs and verified it with the corresponding show command. Also use redis-cli command to verify entries inside the configDB.
Additional Information
Please DO NOT MERGE until these PRs are merged:
sonic-net/sonic-swss-common#299
sonic-net/sonic-swss#1011
sonic-net/sonic-swss#1012
sonic-net/sonic-linux-kernel#94
sonic-net/sonic-sairedis#498
Previous command output?
N/A - added new command
New command output?