Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import click

import utilities_common.cli as clicommon

from natsort import natsorted
from sonic_py_common.multi_asic import get_external_ports
from tabulate import tabulate
Expand Down Expand Up @@ -98,10 +100,14 @@ def get_server_facing_ports(db):


class PfcwdCli(object):
def __init__(self, namespace=None, display=constants.DISPLAY_ALL):
def __init__(
self, db=None, namespace=None, display=constants.DISPLAY_ALL
):
self.db = None
self.config_db = None
self.multi_asic = multi_asic_util.MultiAsic(display, namespace)
self.multi_asic = multi_asic_util.MultiAsic(
display, namespace, db
)
self.table = []
self.all_ports = []

Expand Down Expand Up @@ -397,6 +403,7 @@ def big_red_switch(self, big_red_switch):
pfcwd_info
)


# Show stats
class Show(object):
# Show commands
Expand All @@ -408,19 +415,21 @@ def show():
@multi_asic_util.multi_asic_click_options
@click.option('-e', '--empty', is_flag=True)
@click.argument('queues', nargs=-1)
def stats(namespace, display, empty, queues):
@clicommon.pass_db
def stats(db, namespace, display, empty, queues):
""" Show PFC Watchdog stats per queue """
if (len(queues)):
display = constants.DISPLAY_ALL
PfcwdCli(namespace, display).show_stats(empty, queues)
PfcwdCli(db, namespace, display).show_stats(empty, queues)

# Show config
@show.command()
@multi_asic_util.multi_asic_click_options
@click.argument('ports', nargs=-1)
def config(namespace, display, ports):
@clicommon.pass_db
def config(db, namespace, display, ports):
""" Show PFC Watchdog configuration """
PfcwdCli(namespace, display).config(ports)
PfcwdCli(db, namespace, display).config(ports)


# Start WD
Expand All @@ -432,7 +441,8 @@ class Start(object):
@click.option('--restoration-time', '-r', type=click.IntRange(100, 60000))
@click.argument('ports', nargs=-1)
@click.argument('detection-time', type=click.IntRange(100, 5000))
def start(action, restoration_time, ports, detection_time):
@clicommon.pass_db
def start(db, action, restoration_time, ports, detection_time):
"""
Start PFC watchdog on port(s). To config all ports, use all as input.

Expand All @@ -441,51 +451,58 @@ def start(action, restoration_time, ports, detection_time):
sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400

"""
PfcwdCli().start(action, restoration_time, ports, detection_time)
PfcwdCli(db).start(
action, restoration_time, ports, detection_time
)


# Set WD poll interval
class Interval(object):
@cli.command()
@click.argument('poll_interval', type=click.IntRange(100, 3000))
def interval(poll_interval):
@clicommon.pass_db
def interval(db, poll_interval):
""" Set PFC watchdog counter polling interval """
PfcwdCli().interval(poll_interval)
PfcwdCli(db).interval(poll_interval)


# Stop WD
class Stop(object):
@cli.command()
@click.argument('ports', nargs=-1)
def stop(ports):
@clicommon.pass_db
def stop(db, ports):
""" Stop PFC watchdog on port(s) """
PfcwdCli().stop(ports)
PfcwdCli(db).stop(ports)


# Set WD default configuration on server facing ports when enable flag is on
class StartDefault(object):
@cli.command("start_default")
def start_default():
@clicommon.pass_db
def start_default(db):
""" Start PFC WD by default configurations """
PfcwdCli().start_default()
PfcwdCli(db).start_default()


# Enable/disable PFC WD counter polling
class CounterPoll(object):
@cli.command('counter_poll')
@click.argument('counter_poll', type=click.Choice(['enable', 'disable']))
def counter_poll(counter_poll):
@clicommon.pass_db
def counter_poll(db, counter_poll):
""" Enable/disable counter polling """
PfcwdCli().counter_poll(counter_poll)
PfcwdCli(db).counter_poll(counter_poll)


# Enable/disable PFC WD BIG_RED_SWITCH mode
class BigRedSwitch(object):
@cli.command('big_red_switch')
@click.argument('big_red_switch', type=click.Choice(['enable', 'disable']))
def big_red_switch(big_red_switch):
@clicommon.pass_db
def big_red_switch(db, big_red_switch):
""" Enable/disable BIG_RED_SWITCH mode """
PfcwdCli().big_red_switch(big_red_switch)
PfcwdCli(db).big_red_switch(big_red_switch)


def get_pfcwd_clis():
Expand Down
106 changes: 106 additions & 0 deletions tests/pfcwd_input/pfcwd_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@
Ethernet8 drop 600 600
"""

pfcwd_show_start_config_output_pass = """\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 forward 102 101
Ethernet4 drop 600 600
Ethernet8 drop 600 600
"""

pfcwd_show_start_action_forward_output = """\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 forward 302 301
Ethernet4 forward 302 301
Ethernet8 forward 302 301
"""

pfcwd_show_start_action_alert_output = """\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 alert 502 501
Ethernet4 alert 502 501
Ethernet8 alert 502 501
"""

pfcwd_show_start_action_drop_output = """\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 drop 602 601
Ethernet4 drop 602 601
Ethernet8 drop 602 601
"""

pfcwd_show_start_config_output_fail = """\
Failed to run command, invalid options:
Ethernet1000
"""

pfcwd_show_config_single_port_output="""\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
Expand Down Expand Up @@ -222,6 +263,71 @@
Ethernet-BP260 drop 200 200
"""

show_pfc_config_start_pass = """\
Changed polling interval to 199ms on asic0
BIG_RED_SWITCH status is enable on asic0
Changed polling interval to 199ms on asic1
BIG_RED_SWITCH status is enable on asic1
PORT ACTION DETECTION TIME RESTORATION TIME
-------------- -------- ---------------- ------------------
Ethernet0 forward 102 101
Ethernet4 drop 200 200
Ethernet-BP0 drop 200 200
Ethernet-BP4 forward 102 101
Ethernet-BP256 drop 200 200
Ethernet-BP260 drop 200 200
"""

show_pfc_config_start_action_drop_masic = """\
Changed polling interval to 199ms on asic0
BIG_RED_SWITCH status is enable on asic0
Changed polling interval to 199ms on asic1
BIG_RED_SWITCH status is enable on asic1
PORT ACTION DETECTION TIME RESTORATION TIME
-------------- -------- ---------------- ------------------
Ethernet0 drop 302 301
Ethernet4 drop 302 301
Ethernet-BP0 drop 302 301
Ethernet-BP4 drop 302 301
Ethernet-BP256 drop 302 301
Ethernet-BP260 drop 302 301
"""

show_pfc_config_start_action_alert_masic = """\
Changed polling interval to 199ms on asic0
BIG_RED_SWITCH status is enable on asic0
Changed polling interval to 199ms on asic1
BIG_RED_SWITCH status is enable on asic1
PORT ACTION DETECTION TIME RESTORATION TIME
-------------- -------- ---------------- ------------------
Ethernet0 alert 402 401
Ethernet4 alert 402 401
Ethernet-BP0 alert 402 401
Ethernet-BP4 alert 402 401
Ethernet-BP256 alert 402 401
Ethernet-BP260 alert 402 401
"""

show_pfc_config_start_action_forward_masic = """\
Changed polling interval to 199ms on asic0
BIG_RED_SWITCH status is enable on asic0
Changed polling interval to 199ms on asic1
BIG_RED_SWITCH status is enable on asic1
PORT ACTION DETECTION TIME RESTORATION TIME
-------------- -------- ---------------- ------------------
Ethernet0 forward 702 701
Ethernet4 forward 702 701
Ethernet-BP0 forward 702 701
Ethernet-BP4 forward 702 701
Ethernet-BP256 forward 702 701
Ethernet-BP260 forward 702 701
"""

show_pfc_config_start_fail = """\
Failed to run command, invalid options:
Ethernet-500
"""

show_pfcwd_stats_with_queues = """\
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
----------------- -------- ------------------------- ------------ ------------ ----------------- -----------------
Expand Down
Loading