Skip to content

Commit

Permalink
Merge branch 'master' into nat_changes_in_sonic
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhileshSamineni authored Dec 10, 2019
2 parents a7c3274 + d803156 commit 6d2f1e0
Show file tree
Hide file tree
Showing 18 changed files with 895 additions and 32 deletions.
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/pddf_fanutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_pddf_fanutil_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_PDDF_FANUTIL_COMPLETE=complete $1 ) )
return 0
}

complete -F _pddf_fanutil_completion -o default pddf_fanutil;
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/pddf_ledutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_pddf_ledutil_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_PDDF_LEDUTIL_COMPLETE=complete $1 ) )
return 0
}

complete -F _pddf_ledutil_completion -o default pddf_ledutil;
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/pddf_psuutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_pddf_psuutil_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_PDDF_PSUUTIL_COMPLETE=complete $1 ) )
return 0
}

complete -F _pddf_psuutil_completion -o default pddf_psuutil;
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/pddf_thermalutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_pddf_thermalutil_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_PDDF_THERMALUTIL_COMPLETE=complete $1 ) )
return 0
}

complete -F _pddf_thermalutil_completion -o default pddf_thermalutil;
54 changes: 50 additions & 4 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2056,13 +2056,13 @@ Subsequent pages explain each of these commands in detail.

**show interfaces counters**

This show command displays packet counters for all interfaces since the last time the counters were cleared. There is no facility to display counters for one specific interface. Optional argument "-a" does not have any significance in this command.
Optional argument "-c" can be used to clear the counters for all interfaces.
This show command displays packet counters for all interfaces since the last time the counters were cleared. To display l3 counters "rif" subcommand can be used. There is no facility to display counters for one specific l2 interface. For l3 interfaces a single interface output mode is present. Optional argument "-a" provides two additional columns - RX-PPS and TX_PPS.
Optional argument "-p" specify a period (in seconds) with which to gather counters over.

- Usage:
```
show interfaces counters [-a|--printall] [-p|--period <period>]
show interfaces counters rif [-p|--period <period>] <interface_name>
```

- Example:
Expand All @@ -2079,10 +2079,49 @@ Optional argument "-p" specify a period (in seconds) with which to gather counte
Ethernet24 U 33,543,533,441 36.59 MB/s 0.71% 0 1,613 0 43,066,076,370 49.92 MB/s 0.97% 0 0 0
```

The "rif" subcommand is used to display l3 interface counters. Layer 3 interfaces include router interfaces, portchannels and vlan interfaces.

- Example:

```
admin@sonic:~$ show interfaces counters rif
IFACE RX_OK RX_BPS RX_PPS RX_ERR TX_OK TX_BPS TX_PPS TX_ERR
--------------- ------- ---------- -------- -------- ------- -------- -------- --------
PortChannel0001 62,668 107.81 B/s 1.34/s 3 6 0.02 B/s 0.00/s 0
PortChannel0002 62,645 107.77 B/s 1.34/s 3 2 0.01 B/s 0.00/s 0
PortChannel0003 62,481 107.56 B/s 1.34/s 3 3 0.01 B/s 0.00/s 0
PortChannel0004 62,732 107.88 B/s 1.34/s 2 3 0.01 B/s 0.00/s 0
Vlan1000 0 0.00 B/s 0.00/s 0 0 0.00 B/s 0.00/s 0
```


Optionally, you can specify a layer 3 interface name to display the counters in single interface mode.

- Example:

```
admin@sonic:~$ show interfaces counters rif PortChannel0001
PortChannel0001
---------------
RX:
3269 packets
778494 bytesq
3 error packets
292 error bytes
TX:
0 packets
0 bytes
0 error packets
0 error bytes
```


Optionally, you can specify a period (in seconds) with which to gather counters over. Note that this function will take `<period>` seconds to execute.

- Example:
```

```
admin@sonic:~$ show interfaces counters -p 5
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR
----------- ------- ------- ----------- --------- -------- -------- -------- ------- ----------- --------- -------- -------- --------
Expand All @@ -2093,13 +2132,20 @@ Optionally, you can specify a period (in seconds) with which to gather counters
Ethernet16 U 377 32.64 KB/s 0.00% 0 0 0 214 18.01 KB/s 0.00% 0 0 0
Ethernet20 U 284 36.81 KB/s 0.00% 0 0 0 138 8758.25 B/s 0.00% 0 0 0
Ethernet24 U 173 16.09 KB/s 0.00% 0 0 0 169 11.39 KB/s 0.00% 0 0 0
```
```

- NOTE: Interface counters can be cleared by the user with the following command:

```
root@sonic:~# sonic-clear counters
```

- NOTE: Layer 3 interface counters can be cleared by the user with the following command:

```
root@sonic:~# sonic-clear rifcounters
```

**show interfaces description**

This command displays the key fields of the interfaces such as Operational Status, Administrative Status, Alias and Description.
Expand Down
Empty file added pddf_fanutil/__init__.py
Empty file.
193 changes: 193 additions & 0 deletions pddf_fanutil/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#!/usr/bin/env python
#
# main.py
#
# Command-line utility for interacting with FAN Controller in PDDF mode in SONiC
#

try:
import sys
import os
import subprocess
import click
import imp
import syslog
import types
import traceback
from tabulate import tabulate
from utilities_common import util_base
from utilities_common.util_base import UtilLogger
from utilities_common.util_base import UtilHelper
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

VERSION = '1.0'

SYSLOG_IDENTIFIER = "fanutil"
PLATFORM_SPECIFIC_MODULE_NAME = "fanutil"
PLATFORM_SPECIFIC_CLASS_NAME = "FanUtil"

# Global platform-specific fanutil class instance
platform_fanutil = None

#logger = UtilLogger(SYSLOG_IDENTIFIER)

# This is our main entrypoint - the main 'fanutil' command
@click.group()
def cli():
"""pddf_fanutil - Command line utility for providing FAN information"""

if os.geteuid() != 0:
click.echo("Root privileges are required for this operation")
sys.exit(1)

# Load the helper class
helper = UtilHelper()

if not helper.check_pddf_mode():
click.echo("PDDF mode should be supported and enabled for this platform for this operation")
sys.exit(1)

# Load platform-specific fanutil class
global platform_fanutil
try:
platform_fanutil = helper.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
except Exception as e:
click.echo("Failed to load {}: {}".format(PLATFORM_SPECIFIC_MODULE_NAME, str(e)))
sys.exit(2)

# 'version' subcommand
@cli.command()
def version():
"""Display version info"""
click.echo("PDDF fanutil version {0}".format(VERSION))

# 'numfans' subcommand
@cli.command()
def numfans():
"""Display number of FANs installed on device"""
click.echo(str(platform_fanutil.get_num_fans()))

# 'status' subcommand
@cli.command()
@click.option('-i', '--index', default=-1, type=int, help="the index of FAN")
def status(index):
"""Display FAN status"""
supported_fan = range(1, platform_fanutil.get_num_fans() + 1)
fan_ids = []
if (index < 0):
fan_ids = supported_fan
else:
fan_ids = [index]

header = ['FAN', 'Status']
status_table = []

for fan in fan_ids:
msg = ""
fan_name = "FAN {}".format(fan)
if fan not in supported_fan:
click.echo("Error! The {} is not available on the platform.\n" \
"Number of supported FAN - {}.".format(fan_name, platform_fanutil.get_num_fans()))
continue
presence = platform_fanutil.get_presence(fan)
if presence:
oper_status = platform_fanutil.get_status(fan)
msg = 'OK' if oper_status else "NOT OK"
else:
msg = 'NOT PRESENT'
status_table.append([fan_name, msg])

if status_table:
click.echo(tabulate(status_table, header, tablefmt="simple"))

# 'direction' subcommand
@cli.command()
@click.option('-i', '--index', default=-1, type=int, help="the index of FAN")
def direction(index):
"""Display FAN airflow direction"""
supported_fan = range(1, platform_fanutil.get_num_fans() + 1)
fan_ids = []
if (index < 0):
fan_ids = supported_fan
else:
fan_ids = [index]

header = ['FAN', 'Direction']
status_table = []

for fan in fan_ids:
msg = ""
fan_name = "FAN {}".format(fan)
if fan not in supported_fan:
click.echo("Error! The {} is not available on the platform.\n" \
"Number of supported FAN - {}.".format(fan_name, platform_fanutil.get_num_fans()))
continue
direction = platform_fanutil.get_direction(fan)
status_table.append([fan_name, direction])

if status_table:
click.echo(tabulate(status_table, header, tablefmt="simple"))

# 'speed' subcommand
@cli.command()
@click.option('-i', '--index', default=-1, type=int, help="the index of FAN")
def getspeed(index):
"""Display FAN speed in RPM"""
supported_fan = range(1, platform_fanutil.get_num_fans() + 1)
fan_ids = []
if (index < 0):
fan_ids = supported_fan
else:
fan_ids = [index]

header = ['FAN', 'Front Fan RPM', 'Rear Fan RPM']
status_table = []

for fan in fan_ids:
msg = ""
fan_name = "FAN {}".format(fan)
if fan not in supported_fan:
click.echo("Error! The {} is not available on the platform.\n" \
"Number of supported FAN - {}.".format(fan_name, platform_fanutil.get_num_fans()))
continue
front = platform_fanutil.get_speed(fan)
rear = platform_fanutil.get_speed_rear(fan)
status_table.append([fan_name, front, rear])

if status_table:
click.echo(tabulate(status_table, header, tablefmt="simple"))

# 'setspeed' subcommand
@cli.command()
@click.argument('speed', type=int)
def setspeed(speed):
"""Set FAN speed in percentage"""
if speed is None:
click.echo("speed value is required")
raise click.Abort()

status = platform_fanutil.set_speed(speed)
if status:
click.echo("Successful")
else:
click.echo("Failed")

@cli.group()
def debug():
"""pddf_fanutil debug commands"""
pass

@debug.command()
def dump_sysfs():
"""Dump all Fan related SysFS paths"""
status = platform_fanutil.dump_sysfs()

if status:
for i in status:
click.echo(i)



if __name__ == '__main__':
cli()
Empty file added pddf_ledutil/__init__.py
Empty file.
Loading

0 comments on commit 6d2f1e0

Please sign in to comment.