def enable_counters(): db = swsssdk.ConfigDBConnector() db.connect() enable_counter_group(db, 'PORT') enable_counter_group(db, 'RIF') enable_counter_group(db, 'QUEUE') enable_counter_group(db, 'PFCWD') enable_counter_group(db, 'PG_WATERMARK') enable_counter_group(db, 'PG_DROP') enable_counter_group(db, 'QUEUE_WATERMARK') enable_counter_group(db, 'BUFFER_POOL_WATERMARK') enable_counter_group(db, 'PORT_BUFFER_DROP') enable_counter_group(db, 'ACL') enable_rates()
def __init__(self, is_dbg_test): self.my_args = dispArgs() self.my_args.cfgdb = swsssdk.ConfigDBConnector() self.my_args.cfgdb.connect() self.my_args.appdb = swsssdk.SonicV2Connector(host='127.0.0.1') self.my_args.appdb.connect(self.my_args.appdb.APPL_DB) self.my_args.appdb.connect(self.my_args.appdb.COUNTERS_DB) self.my_args.appdb.connect(self.my_args.appdb.ASIC_DB) # check if port table is ready is_pcfg_done = False chk_cnt = 0 while True: pcfg_val = self.my_args.appdb.get_all(self.my_args.appdb.APPL_DB, "PORT_TABLE:PortConfigDone") is_pcfg_done = pcfg_val != None chk_cnt += 1 if is_pcfg_done or chk_cnt % 3 == 1: util_utl.utl_log( "PORT TABLE was%sready...(%s)" % ([" not ", " "][is_pcfg_done], chk_cnt), logging.CRITICAL) if is_pcfg_done: break time.sleep(10) # create the full yang tree # for performance, only update the tree node requested self.oc_yph = YANGPathHelper() for k in ocTable.keys(): if ocTable[k]["cls"]: ocTable[k]["cls"](path_helper = self.oc_yph) # create obj for "/" to only return subtree of depth 1 openconfig_root_dpt_1(self.oc_yph) # create all interfaces to speed up processing request for interfaces later util_interface.interface_create_all_infs(self.oc_yph, is_dbg_test, self.my_args) # create default network instance util_nwi.nwi_create_dflt_nwi(self.oc_yph, is_dbg_test) # create default objects util_qos.qos_create_dflt_obj(self.oc_yph, is_dbg_test) # check if new teammgrd is used test_cmd = 'docker run --rm=true --privileged=true --entrypoint="/bin/bash" "docker-teamd" -c "[ -f /usr/bin/teammgrd ]"' util_interface.IS_NEW_TEAMMGRD = util_utl.utl_execute_cmd(test_cmd)
def start(action, restoration_time, ports, detection_time): """ Start PFC watchdog on port(s). To config all ports, use all as input. Example: sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400 """ if os.geteuid() != 0: exit("Root privileges are required for this operation") allowed_strs = ['ports', 'all', 'detection-time'] configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) allowed_strs = allowed_strs + all_ports for p in ports: if p not in allowed_strs: raise click.BadOptionUsage( "Bad command line format. Try 'pfcwd start --help' for usage") if len(ports) == 0: ports = all_ports pfcwd_info = { 'detection_time': detection_time, } if action is not None: pfcwd_info['action'] = action if restoration_time is not None: pfcwd_info['restoration_time'] = restoration_time else: pfcwd_info['restoration_time'] = 2 * detection_time click.echo( "restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time)) for port in ports: if port == "all": for p in all_ports: configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, p, None) configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, p, pfcwd_info) else: if port not in all_ports: continue configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, None) configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, pfcwd_info)
def interval(poll_interval): """ Set port_buffer_drop counter query interval This counter group causes high CPU usage when polled, hence the allowed interval is between 30s and 300s. This is a short term solution and should be changed once the performance is enhanced """ configdb = swsssdk.ConfigDBConnector() configdb.connect() port_info = {} if poll_interval: port_info['POLL_INTERVAL'] = poll_interval configdb.mod_entry("FLEX_COUNTER_TABLE", PORT_BUFFER_DROP, port_info)
def show_summary(self): """ CRM Handler to display general information. """ configdb = swsssdk.ConfigDBConnector() configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') if crm_info: click.echo('\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n') else: click.echo('\nError! Could not get CRM configuration.\n')
def interval(poll_interval): """ Set watermark counter query interval for both queue and PG watermarks """ configdb = swsssdk.ConfigDBConnector() configdb.connect() queue_wm_info = {} pg_wm_info = {} buffer_pool_wm_info = {} if poll_interval is not None: queue_wm_info['POLL_INTERVAL'] = poll_interval pg_wm_info['POLL_INTERVAL'] = poll_interval buffer_pool_wm_info['POLL_INTERVAL'] = poll_interval configdb.mod_entry("FLEX_COUNTER_TABLE", "QUEUE_WATERMARK", queue_wm_info) configdb.mod_entry("FLEX_COUNTER_TABLE", "PG_WATERMARK", pg_wm_info) configdb.mod_entry("FLEX_COUNTER_TABLE", BUFFER_POOL_WATERMARK, buffer_pool_wm_info)
def show(): """ Show the counter configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE') port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PORT') header = ("Type", "Interval", "Status") data = [] if queue_info: data.append(["QUEUE_STAT", queue_info["POLL_INTERVAL"], queue_info["FLEX_COUNTER_STATUS"]]) if port_info: data.append(["PORT_STAT", port_info["POLL_INTERVAL"], port_info["FLEX_COUNTER_STATUS"]]) print tabulate(data, headers=header, tablefmt="simple", missingval="")
def show(): """ Show the counter configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE') port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PORT') rif_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'RIF') queue_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE_WATERMARK') pg_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_WATERMARK') header = ("Type", "Interval (in ms)", "Status") data = [] if queue_info: data.append([ "QUEUE_STAT", queue_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in queue_info else 'default (10000)', queue_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in queue_info else 'disable' ]) if port_info: data.append([ "PORT_STAT", port_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in port_info else 'default (1000)', port_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in port_info else 'disable' ]) if rif_info: data.append([ "RIF_STAT", rif_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in rif_info else 'default (1000)', rif_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in rif_info else 'disable' ]) if queue_wm_info: data.append([ "QUEUE_WATERMARK_STAT", queue_wm_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in queue_wm_info else 'default (1000)', queue_wm_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in queue_wm_info else 'disable' ]) if pg_wm_info: data.append([ "PG_WATERMARK_STAT", pg_wm_info["POLL_INTERVAL"] if 'POLL_INTERVAL' in pg_wm_info else 'default (1000)', pg_wm_info["FLEX_COUNTER_STATUS"] if 'FLEX_COUNTER_STATUS' in pg_wm_info else 'disable' ]) print tabulate(data, headers=header, tablefmt="simple", missingval="")
def stop(ports): """ Stop PFC watchdog on port(s) """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: if port not in all_ports: continue configdb.mod_entry("PFC_WD_TABLE", port, None)
def show_thresholds(self, resource): """ CRM Handler to display thresholds information. """ configdb = self.cfgdb if configdb is None: # Get the namespace list namespaces = multi_asic.get_namespace_list() configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') header = ("Resource Name", "Threshold Type", "Low Threshold", "High Threshold") data = [] if crm_info: if resource == 'all': for res in [ "ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry" ]: data.append([ res, crm_info[res + "_threshold_type"], crm_info[res + "_low_threshold"], crm_info[res + "_high_threshold"] ]) else: data.append([ resource, crm_info[resource + "_threshold_type"], crm_info[resource + "_low_threshold"], crm_info[resource + "_high_threshold"] ]) else: click.echo('\nError! Could not get CRM configuration.') click.echo() click.echo( tabulate(data, headers=header, tablefmt="simple", missingval="")) click.echo()
def stop(ports): """ Stop PFC watchdog on port(s) """ if os.geteuid() != 0: exit("Root privileges are required for this operation") configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: if port not in all_ports: continue configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, None)
def enable_counters(): db = swsssdk.ConfigDBConnector() db.connect() default_enabled_counters = [ 'PORT', 'RIF', 'QUEUE', 'PFCWD', 'PG_WATERMARK', 'PG_DROP', 'QUEUE_WATERMARK', 'BUFFER_POOL_WATERMARK', 'PORT_BUFFER_DROP', 'ACL' ] # Enable those default counters for key in default_enabled_counters: enable_counter_group(db, key) # Set FLEX_COUNTER_DELAY_STATUS to false for those non-default counters keys = db.get_keys('FLEX_COUNTER_TABLE') for key in keys: if key not in default_enabled_counters: enable_counter_group(db, key) enable_rates()
def show_summary(self): """ CRM Handler to display general information. """ configdb = self.cfgdb if configdb is None: # Get the namespace list namespaces = multi_asic.get_namespace_list() configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') if crm_info: click.echo('\nPolling Interval: ' + crm_info['polling_interval'] + ' second(s)\n') else: click.echo('\nError! Could not get CRM configuration.\n')
def config(ports): """ Show PFC Watchdog configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) table = [] all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: config_list = [] config_entry = configdb.get_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port) if config_entry is None or config_entry == {}: continue for config in CONFIG_DESCRIPTION: line = config_entry.get(config[1], config[2]) config_list.append(line) table.append([port] + config_list) poll_interval = configdb.get_entry(CONFIG_DB_PFC_WD_TABLE_NAME, 'GLOBAL').get('POLL_INTERVAL') if poll_interval is not None: click.echo("Changed polling interval to " + poll_interval + "ms") big_red_switch = configdb.get_entry(CONFIG_DB_PFC_WD_TABLE_NAME, 'GLOBAL').get('BIG_RED_SWITCH') if big_red_switch is not None: click.echo("BIG_RED_SWITCH status is " + big_red_switch) click.echo( tabulate(table, CONFIG_HEADER, stralign='right', numalign='right', tablefmt='simple'))
def show_thresholds(self, resource): """ CRM Handler to display thresholds information. """ configdb = swsssdk.ConfigDBConnector() configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') header = ("Resource Name", "Threshold Type", "Low Threshold", "High Threshold") data = [] if crm_info: if resource == 'all': for res in [ "ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry", "acl_counter", "fdb_entry" ]: data.append([ res, crm_info[res + "_threshold_type"], crm_info[res + "_low_threshold"], crm_info[res + "_high_threshold"] ]) else: data.append([ resource, crm_info[resource + "_threshold_type"], crm_info[resource + "_low_threshold"], crm_info[resource + "_high_threshold"] ]) else: print '\nError! Could not get CRM configuration.' print '\n' print tabulate(data, headers=header, tablefmt="simple", missingval="") print '\n'
def showPfcAsym(interface): """ PFC handler to display asymmetric PFC information. """ i = {} table = [] key = [] header = ('Interface', 'Asymmetric') configdb = swsssdk.ConfigDBConnector() configdb.connect() if interface: db_keys = configdb.keys(configdb.CONFIG_DB, 'PORT|{0}'.format(interface)) else: db_keys = configdb.keys(configdb.CONFIG_DB, 'PORT|*') for i in db_keys or [None]: if i: key = i.split('|')[-1] if key and key.startswith('Ethernet'): entry = configdb.get_entry('PORT', key) table.append([key, entry.get('pfc_asym', 'N/A')]) sorted_table = natsorted(table) print '\n' print tabulate(sorted_table, headers=header, tablefmt="simple", missingval="") print '\n'
def interval(poll_interval): """ Set PFC watchdog counter polling interval """ if os.geteuid() != 0: exit("Root privileges are required for this operation") configdb = swsssdk.ConfigDBConnector() configdb.connect() pfcwd_info = {} if poll_interval is not None: pfcwd_table = configdb.get_table(CONFIG_DB_PFC_WD_TABLE_NAME) entry_min = 3000 for entry in pfcwd_table: if ("Ethernet" not in entry): continue detection_time_entry_value = int( configdb.get_entry(CONFIG_DB_PFC_WD_TABLE_NAME, entry).get('detection_time')) restoration_time_entry_value = int( configdb.get_entry(CONFIG_DB_PFC_WD_TABLE_NAME, entry).get('restoration_time')) if ((detection_time_entry_value != None) and (detection_time_entry_value < entry_min)): entry_min = detection_time_entry_value entry_min_str = "detection time" if ((restoration_time_entry_value != None) and (restoration_time_entry_value < entry_min)): entry_min = restoration_time_entry_value entry_min_str = "restoration time" if entry_min < poll_interval: click.echo( "unable to use polling interval = {}ms, value is bigger than one of the configured {} values, please choose a smaller polling_interval" .format(poll_interval, entry_min_str), err=True) exit(1) pfcwd_info['POLL_INTERVAL'] = poll_interval configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, "GLOBAL", pfcwd_info)
def config(ports): """ Show PFC Watchdog configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) table = [] all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: config_list = [] config_entry = configdb.get_entry('PFC_WD_TABLE', port) if config_entry is None or config_entry == {}: continue for config in CONFIG_DESCRIPTION: line = config_entry.get(config[1], config[2]) config_list.append(line) table.append([port] + config_list) click.echo(tabulate(table, CONFIG_HEADER, stralign='right', numalign='right', tablefmt='simple'))
def enable_counters(): db = swsssdk.ConfigDBConnector() db.connect() enable_counter_group(db, 'PORT') enable_counter_group(db, 'QUEUE') enable_counter_group(db, 'PFCWD')