Skip to content

Commit

Permalink
[PFCWD]: set default configuration when enabled by default
Browse files Browse the repository at this point in the history
Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
Sihui Han committed Feb 28, 2018
1 parent 252e9fa commit 2b9f40b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def load_minigraph():
command = "{} -H -m --write-to-db".format(SONIC_CFGGEN_PATH)
run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, 1)
run_command('pfcwd start_default', display_cmd=True)
if os.path.isfile('/etc/sonic/acl.json'):
run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)
run_command("config qos reload", display_cmd=True)
Expand Down
36 changes: 36 additions & 0 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from tabulate import tabulate
from natsort import natsorted

# Default configuration
DEFAULT_DETECTION_TIME = 200
DEFAULT_RESTORATION_TIME = 200
DEFAULT_POLL_INTERVAL = 200
DEFAULT_PORT_NUM = 32
DEFAULT_ACTION = 'drop'

STATS_DESCRIPTION = [
('STORM DETECTED/RESTORED', 'PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED', 'PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED'),
('TX OK/DROP', 'PFC_WD_QUEUE_STATS_TX_PACKETS', 'PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS'),
Expand Down Expand Up @@ -162,5 +169,34 @@ def stop(ports):
continue
configdb.mod_entry("PFC_WD_TABLE", port, None)

# Set WD default configuration on server facing ports when enable flag is on
@cli.command()
def start_default():
""" Start PFC WD by default configurations """
configdb = swsssdk.ConfigDBConnector()
configdb.connect()
enable = configdb.get_entry('DEVICE_METADATA', 'localhost').get('default_pfc_wd_status')
if enable != "enable":
return
device_type = configdb.get_entry('DEVICE_METADATA', 'localhost').get('type')
if device_type != "ToRRouter":
return
port_num = len(configdb.get_table('PORT').keys())
vlan_members = [p[1] for p in configdb.get_table('VLAN_MEMBER').keys()]

pfcwd_info = {
'detection_time': DEFAULT_DETECTION_TIME * max(port_num/DEFAULT_PORT_NUM, 1),
'restoration_time': DEFAULT_RESTORATION_TIME * max(port_num/DEFAULT_PORT_NUM, 1),
'action': DEFAULT_ACTION
}

for port in vlan_members:
configdb.mod_entry("PFC_WD_TABLE", port, None)
configdb.mod_entry("PFC_WD_TABLE", port, pfcwd_info)

pfcwd_info = {}
pfcwd_info['POLL_INTERVAL'] = DEFAULT_POLL_INTERVAL * max(port_num/DEFAULT_PORT_NUM, 1)
configdb.mod_entry("PFC_WD_TABLE", "GLOBAL", pfcwd_info)

if __name__ == '__main__':
cli()

0 comments on commit 2b9f40b

Please sign in to comment.