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

[CLI][PFC] Add multi ASIC options for pfcstat and 'show pfc counters' #1057

Merged
merged 9 commits into from
Aug 27, 2020

Conversation

smaheshm
Copy link
Contributor

@smaheshm smaheshm commented Aug 19, 2020

- What I did
Added 'multi ASIC' support to the 'show pfc counters' CLI. Modified 'pfcstat' command to include multi ASIC args.

By default 'show pfc counters' or 'pfcstat' display the counters for the front end ports. To display on all ports "-s all" option must be specified. On single ASIC platforms by default all port counters are shown, there's no effect of '-s' (show) option.

- How I did it
Modified show/main.py and 'pfcstat' to include multi ASIC options and args respectively.
Used multi ASIC common APIs and decorator to collect information from specified namespaces or all namespaces (by default).

- How to verify it
Verified the commands on multi ASIC platform.

admin@str-n3164-acs-2:/usr/bin$ pfcstat --help
usage: pfcstat [-h] [-v] [-c] [-d] [-s SHOW] [-n NAMESPACE]

Display the pfc counters

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -c, --clear           Clear previous stats and save new ones
  -d, --delete          Delete saved stats
  -s SHOW, --show SHOW  Display all interfaces or only external interfaces
  -n NAMESPACE, --namespace NAMESPACE
                        Display interfaces for specific namespace

Examples:
  pfcstat
  pfcstat -c
  pfcstat -d
  pfcstat -n asic1
  pfcstat -s all -n asic0

admin@str-n3164-acs-2:/usr/bin$ pfcstat -n asic0                             
Last cached time was 2020-08-19 22:25:42.146378                              
   Port Rx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7   
----------  ------  ------  ------  ------  ------  ------  ------  ------   
 Ethernet0       0       0       0       0       0       0       0       0   
 Ethernet4       0       0       0       0       0       0       0       0
 Ethernet8       0       0       0       0       0       0       0       0
Ethernet12       0       0       0       0       0       0       0       0   
Ethernet16       0       0       0       0       0       0       0       0   
Ethernet20       0       0       0       0       0       0       0       0   
Ethernet24       0       0       0       0       0       0       0       0   
Ethernet28       0       0       0       0       0       0       0       0   
Ethernet32       0       0       0       0       0       0       0       0   
Ethernet36       0       0       0       0       0       0       0       0   
Ethernet40       0       0       0       0       0       0       0       0   
Ethernet44       0       0       0       0       0       0       0       0   
Ethernet48       0       0       0       0       0       0       0       0   
Ethernet52       0       0       0       0       0       0       0       0   
Ethernet56       0       0       0       0       0       0       0       0   
Ethernet60       0       0       0       0       0       0       0       0   
                                                                             
Last cached time was 2020-08-19 22:25:42.146378                              
   Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7   
----------  ------  ------  ------  ------  ------  ------  ------  ------   
 Ethernet0       0       0       0       0       0       0       0       0   
 Ethernet4       0       0       0       0       0       0       0       0   
 Ethernet8       0       0       0       0       0       0       0       0   
Ethernet12       0       0       0       0       0       0       0       0   
Ethernet16       0       0       0       0       0       0       0       0   
Ethernet20       0       0       0       0       0       0       0       0   
Ethernet24       0       0       0       0       0       0       0       0   
Ethernet28       0       0       0       0       0       0       0       0   
Ethernet32       0       0       0       0       0       0       0       0   
Ethernet36       0       0       0       0       0       0       0       0   
Ethernet40       0       0       0       0       0       0       0       0   
Ethernet44       0       0       0       0       0       0       0       0   
Ethernet48       0       0       0       0       0       0       0       0   
Ethernet52       0       0       0       0       0       0       0       0   
Ethernet56       0       0       0       0       0       0       0       0   
Ethernet60       0       0       0       0       0       0       0       0   

admin@str-n3164-acs-2:/usr/bin$ pfcstat -n asic0 -s all
Last cached time was 2020-08-19 22:25:42.146378
      Port Rx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-------------  ------  ------  ------  ------  ------  ------  ------  ------
    Ethernet0       0       0       0       0       0       0       0       0
    Ethernet4       0       0       0       0       0       0       0       0
    Ethernet8       0       0       0       0       0       0       0       0
   Ethernet12       0       0       0       0       0       0       0       0
   Ethernet16       0       0       0       0       0       0       0       0
   Ethernet20       0       0       0       0       0       0       0       0
   Ethernet24       0       0       0       0       0       0       0       0
   Ethernet28       0       0       0       0       0       0       0       0
   Ethernet32       0       0       0       0       0       0       0       0
   Ethernet36       0       0       0       0       0       0       0       0
   Ethernet40       0       0       0       0       0       0       0       0
   Ethernet44       0       0       0       0       0       0       0       0
   Ethernet48       0       0       0       0       0       0       0       0
   Ethernet52       0       0       0       0       0       0       0       0
   Ethernet56       0       0       0       0       0       0       0       0
   Ethernet60       0       0       0       0       0       0       0       0
 Ethernet-BP0       0       0       0       0       0       0       0       0
 Ethernet-BP4       0       0       0       0       0       0       0       0
 Ethernet-BP8       0       0       0       0       0       0       0       0
Ethernet-BP12       0       0       0       0       0       0       0       0
Ethernet-BP16       0       0       0       0       0       0       0       0
Ethernet-BP20       0       0       0       0       0       0       0       0
Ethernet-BP24       0       0       0       0       0       0       0       0
Ethernet-BP28       0       0       0       0       0       0       0       0
Ethernet-BP32       0       0       0       0       0       0       0       0
Ethernet-BP36       0       0       0       0       0       0       0       0
Ethernet-BP40       0       0       0       0       0       0       0       0
Ethernet-BP44       0       0       0       0       0       0       0       0
Ethernet-BP48       0       0       0       0       0       0       0       0
Ethernet-BP52       0       0       0       0       0       0       0       0
Ethernet-BP56       0       0       0       0       0       0       0       0
Ethernet-BP60       0       0       0       0       0       0       0       0
 
Last cached time was 2020-08-19 22:25:42.146378  
      Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-------------  ------  ------  ------  ------  ------  ------  ------  ------
    Ethernet0       0       0       0       0       0       0       0       0
    Ethernet4       0       0       0       0       0       0       0       0
    Ethernet8       0       0       0       0       0       0       0       0
   Ethernet12       0       0       0       0       0       0       0       0
   Ethernet16       0       0       0       0       0       0       0       0
   Ethernet20       0       0       0       0       0       0       0       0
   Ethernet24       0       0       0       0       0       0       0       0
   Ethernet28       0       0       0       0       0       0       0       0
   Ethernet32       0       0       0       0       0       0       0       0
   Ethernet36       0       0       0       0       0       0       0       0
   Ethernet40       0       0       0       0       0       0       0       0
   Ethernet44       0       0       0       0       0       0       0       0
   Ethernet48       0       0       0       0       0       0       0       0
   Ethernet52       0       0       0       0       0       0       0       0
   Ethernet56       0       0       0       0       0       0       0       0
   Ethernet60       0       0       0       0       0       0       0       0
 Ethernet-BP0       0       0       0       0       0       0       0       0
 Ethernet-BP4       0       0       0       0       0       0       0       0
 Ethernet-BP8       0       0       0       0       0       0       0       0
Ethernet-BP12       0       0       0       0       0       0       0       0
Ethernet-BP16       0       0       0       0       0       0       0       0
Ethernet-BP20       0       0       0       0       0       0       0       0
Ethernet-BP24       0       0       0       0       0       0       0       0
Ethernet-BP28       0       0       0       0       0       0       0       0
Ethernet-BP32       0       0       0       0       0       0       0       0
Ethernet-BP36       0       0       0       0       0       0       0       0
Ethernet-BP40       0       0       0       0       0       0       0       0
Ethernet-BP44       0       0       0       0       0       0       0       0
Ethernet-BP48       0       0       0       0       0       0       0       0
Ethernet-BP52       0       0       0       0       0       0       0       0
Ethernet-BP56       0       0       0       0       0       0       0       0
Ethernet-BP60       0       0       0       0       0       0       0       0

admin@str-n3164-acs-2:/usr/bin$ pfcstat                                    
Last cached time was 2020-08-19 22:25:42.146378                            
    Port Rx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-----------  ------  ------  ------  ------  ------  ------  ------  ------
  Ethernet0       0       0       0       0       0       0       0       0
  Ethernet4       0       0       0       0       0       0       0       0
  Ethernet8       0       0       0       0       0       0       0       0
 Ethernet12       0       0       0       0       0       0       0       0
 Ethernet16       0       0       0       0       0       0       0       0
 Ethernet20       0       0       0       0       0       0       0       0
 Ethernet24       0       0       0       0       0       0       0       0
 Ethernet28       0       0       0       0       0       0       0       0
 Ethernet32       0       0       0       0       0       0       0       0
 Ethernet36       0       0       0       0       0       0       0       0
 Ethernet40       0       0       0       0       0       0       0       0
 Ethernet44       0       0       0       0       0       0       0       0
 Ethernet48       0       0       0       0       0       0       0       0
 Ethernet52       0       0       0       0       0       0       0       0
 Ethernet56       0       0       0       0       0       0       0       0
 Ethernet60       0       0       0       0       0       0       0       0
 Ethernet64       0       0       0       0       0       0       0       0
 Ethernet68       0       0       0       0       0       0       0       0
....
.
.
.

Ethernet228       0       0       0       0       0       0       0       0 
Ethernet232       0       0       0       0       0       0       0       0 
Ethernet236       0       0       0       0       0       0       0       0 
Ethernet240       0       0       0       0       0       0       0       0
Ethernet244       0       0       0       0       0       0       0       0
Ethernet248       0       0       0       0       0       0       0       0
Ethernet252       0       0       0       0       0       0       0       0

Last cached time was 2020-08-19 22:25:42.146378   
    Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-----------  ------  ------  ------  ------  ------  ------  ------  ------
  Ethernet0       0       0       0       0       0       0       0       0
  Ethernet4       0       0       0       0       0       0       0       0
  Ethernet8       0       0       0       0       0       0       0       0
 Ethernet12       0       0       0       0       0       0       0       0
 Ethernet16       0       0       0       0       0       0       0       0
 Ethernet20       0       0       0       0       0       0       0       0
 Ethernet24       0       0       0       0       0       0       0       0
..
.
.
.
Ethernet216       0       0       0       0       0       0       0       0
Ethernet220       0       0       0       0       0       0       0       0
Ethernet224       0       0       0       0       0       0       0       0
Ethernet228       0       0       0       0       0       0       0       0
Ethernet232       0       0       0       0       0       0       0       0
Ethernet236       0       0       0       0       0       0       0       0
Ethernet240       0       0       0       0       0       0       0       0
Ethernet244       0       0       0       0       0       0       0       0
Ethernet248       0       0       0       0       0       0       0       0
Ethernet252       0       0       0       0       0       0       0       0

admin@str-n3164-acs-2:/usr/bin$ show pfc counters --help
Usage: show pfc counters [OPTIONS]

  Show pfc counters

Options:
  -d, --display [all|frontend]    Show internal interfaces  [default:
                                  frontend]
  -n, --namespace [asic0|asic1|asic2|asic3|asic4|asic5]
                                  Namespace name or all
  --verbose                       Enable verbose output
  -?, -h, --help                  Show this message and exit.

admin@str-n3164-acs-2:/usr/bin$ show pfc counters -d all -n asic0
Last cached time was 2020-08-19 22:25:42.146378
      Port Rx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-------------  ------  ------  ------  ------  ------  ------  ------  ------
    Ethernet0       0       0       0       0       0       0       0       0
    Ethernet4       0       0       0       0       0       0       0       0
    Ethernet8       0       0       0       0       0       0       0       0
   Ethernet12       0       0       0       0       0       0       0       0
   Ethernet16       0       0       0       0       0       0       0       0
   Ethernet20       0       0       0       0       0       0       0       0
   Ethernet24       0       0       0       0       0       0       0       0
   Ethernet28       0       0       0       0       0       0       0       0
   Ethernet32       0       0       0       0       0       0       0       0
.
.
.

   Ethernet60       0       0       0       0       0       0       0       0
 Ethernet-BP0       0       0       0       0       0       0       0       0
 Ethernet-BP4       0       0       0       0       0       0       0       0
 Ethernet-BP8       0       0       0       0       0       0       0       0
Ethernet-BP12       0       0       0       0       0       0       0       0
Ethernet-BP16       0       0       0       0       0       0       0       0
Ethernet-BP20       0       0       0       0       0       0       0       0
.
.
Last cached time was 2020-08-19 22:25:42.146378
      Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
-------------  ------  ------  ------  ------  ------  ------  ------  ------
    Ethernet0       0       0       0       0       0       0       0       0
    Ethernet4       0       0       0       0       0       0       0       0
    Ethernet8       0       0       0       0       0       0       0       0
.
.
.

   Ethernet56       0       0       0       0       0       0       0       0
   Ethernet60       0       0       0       0       0       0       0       0
 Ethernet-BP0       0       0       0       0       0       0       0       0
 Ethernet-BP4       0       0       0       0       0       0       0       0
 Ethernet-BP8       0       0       0       0       0       0       0       0
Ethernet-BP12       0       0       0       0       0       0       0       0

- Previous command output (if the output of a command-line utility has changed)

- New command output (if the output of a command-line utility has changed)

Unit test results:

samaddik@samaddik-vm-01:/data/sonic/sonic-utilities/tests$ py.test -s -k pfcstat_test.py 
=========================================================================================================================================================================== test session starts ============================================================================================================================================================================
platform linux2 -- Python 2.7.17, pytest-4.6.9, py-1.8.1, pluggy-0.13.1     
rootdir: /data/sonic/sonic-utilities/tests, inifile: pytest.ini             
plugins: flaky-3.6.1                                                        
collected 145 items / 138 deselected / 7 selected                                                                                                                                                                                                                                                                                                                          

pfcstat_test.py SETUP
  Port Rx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
---------  ------  ------  ------  ------  ------  ------  ------  ------
Ethernet0       0       0       0       0       0       0       0       0                                                                                                                                                                                                                                                                                                   
Ethernet4     400     401     402     403     404     405     406     407                                                                                    
Ethernet8     800     801     802     803     804     805     806     807                                                                                    
                                                          
  Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
---------  ------  ------  ------  ------  ------  ------  ------  ------
Ethernet0       0       0       0       0       0       0       0       0
Ethernet4     400     401     402     403     404     405     406     407
Ethernet8     800     801     802     803     804     805     806     807

.Clear saved counters

.
.
.
.
.
Last cached time was 2020-08-26 17:06:09.780171  
     Port Tx    PFC0    PFC1    PFC2    PFC3    PFC4    PFC5    PFC6    PFC7
------------  ------  ------  ------  ------  ------  ------  ------  ------
   Ethernet0       0       0       0       0       0       0       0       0
   Ethernet4       0       0       0       0       0       0       0       0
Ethernet-BP0       0       0       0       0       0       0       0       0
Ethernet-BP4       0       0       0       0       0       0       0       0

.TEARDOWN


================================================================================================================================================================= 7 passed, 138 deselected in 2.61 seconds =================================================================================================================================================================

@smaheshm
Copy link
Contributor Author

Unit test is pending on #1006 , which contains changes to multi ASIC mock DB APIs.

@lgtm-com
Copy link

lgtm-com bot commented Aug 19, 2020

This pull request introduces 1 alert when merging ae7516e into 5263b54 - view on LGTM.com

new alerts:

  • 1 for Unused import

@smaheshm
Copy link
Contributor Author

retest this please

Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as comments


pfcstat = Pfcstat()
pfcstat = Pfcstat(args.namespace, args.show)

if delete_all_stats:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pfcstat -c should clear stats on all ports and all namespace and save all ports stats in the cached file.
If not, it might lead to confusing output.
For example. if user does the following sequence

  • pfcstat -c
    Since the internal ports stats are not cleared, they will not be reset to zero,
  • pfcstat -s all
    External ports stats will start from zero while the Internal ports will still have the old value. This might lead to confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right, will change it. By default non-show commands should apply to all ports and namespaces, and should not have an option for 'namespace' or 'display'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at it further. It doesn't really clear the stats from counters DB. It updates that stats in "/tmp" and prints the diff from previous values. Since the script takes multiple arguments the 'namespace', 'display' also applies to '-c' arg. We can ignore '-c' option when 'namespace' is provided, but this will work as is as all the keys are different. Meaning, if a user runs '-c' with a namespace option and then runs -c with a different namespace option or no namespace, the command will output the 'diff' in counts for the cached ports, and prints as is for un-cached ports or new ports with counts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prints the "Last cached time was " which might me misleading since some of the ports were not cached.

The change I'm making is to collect stats from all ports when '-c' option is provided. In short the 'namespace' option will be ignored silently when '-c' arg is specified. Comments?

Copy link
Contributor

@arlakshm arlakshm Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this. I don't think we will be adding the multi asic options to sonic-clear commands. So the util script will not get the namespace or display, so we should be ok. I follow the similar approach for show interface counters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use '-c' with a namespace and then use the display for another namespace, the problem we have is the cached time that we display will be incorrect because we aren't actually caching any of those ports info.
Either we ignore the namespace for '-c' option and get the stats for all ports and write them to the file or we need to maintain separate files for the namespaces

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my comment. saw your change

@@ -235,7 +272,7 @@ Examples:
else:
pfcstat.cnstat_print(cnstat_dict_rx, True)

print()
print("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to add a 'line' between tx and rx outputs.

@neethajohn
Copy link
Contributor

LGTM, will wait for the unit test for approval

@smaheshm
Copy link
Contributor Author

retest this please

1 similar comment
@smaheshm
Copy link
Contributor Author

retest this please

@smaheshm smaheshm linked an issue Aug 26, 2020 that may be closed by this pull request
@smaheshm smaheshm merged commit 62e44d9 into sonic-net:master Aug 27, 2020
@abdosi
Copy link
Contributor

abdosi commented Sep 3, 2020

@smaheshm Create PR for 201911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit test for multi ASIC enhancements to PFC CLI.
4 participants