Skip to content

Commit

Permalink
[PFCWD]: set default configuration when enabled by default (sonic-net…
Browse files Browse the repository at this point in the history
…#213)

* [PFCWD]: set default configuration when enabled by default

Signed-off-by: Sihui Han <sihan@microsoft.com>

* update as comments

Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
sihuihan88 committed Mar 5, 2018
1 parent 93796b3 commit ca6fb49
Show file tree
Hide file tree
Showing 2 changed files with 53 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
52 changes: 52 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 @@ -35,6 +42,17 @@ def get_all_ports(db):
port_names = db.get_all(db.COUNTERS_DB, 'COUNTERS_PORT_NAME_MAP')
return natsorted(port_names.keys())

def get_server_facing_ports(db):
candidates = db.get_table('DEVICE_NEIGHBOR')
server_facing_ports = []
for port in candidates.keys():
neighbor = db.get_entry('DEVICE_NEIGHBOR_METADATA', candidates[port]['name'])
if neighbor and neighbor['type'].lower() == 'server':
server_facing_ports.append(port)
if not server_facing_ports:
server_facing_ports = [p[1] for p in db.get_table('VLAN_MEMBER').keys()]
return server_facing_ports

# Show commands
@cli.group()
def show():
Expand Down Expand Up @@ -162,5 +180,39 @@ 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_pfcwd_status')

server_facing_ports = get_server_facing_ports(configdb)

if not enable or enable.lower() != "enable":
return

device_type = configdb.get_entry('DEVICE_METADATA', 'localhost').get('type')
if device_type.lower() != "torrouter":
return

port_num = len(configdb.get_table('PORT').keys())

# Paramter values positively correlate to the number of ports.
multiply = max(1, (port_num-1)/DEFAULT_PORT_NUM+1)
pfcwd_info = {
'detection_time': DEFAULT_DETECTION_TIME * multiply,
'restoration_time': DEFAULT_RESTORATION_TIME * multiply,
'action': DEFAULT_ACTION
}

for port in server_facing_ports:
configdb.set_entry("PFC_WD_TABLE", port, pfcwd_info)

pfcwd_info = {}
pfcwd_info['POLL_INTERVAL'] = DEFAULT_POLL_INTERVAL * multiply
configdb.mod_entry("PFC_WD_TABLE", "GLOBAL", pfcwd_info)

if __name__ == '__main__':
cli()

0 comments on commit ca6fb49

Please sign in to comment.