def apply_queue_shaping_config(dut, shaper_data, **kwargs): """ API to configure Queue-Level shaper :param dut: :type dut: :param shaper_data: :type shaper_data: :param cli_type: :type cli_type: :return: :rtype: """ cli_type = st.get_ui_type(dut, **kwargs) skip_error = kwargs.get('skip_error', False) cli_type = 'klish' if skip_error and cli_type == 'click' else cli_type st.debug("Provided queue-shaper configuration is: {}".format(shaper_data)) ports = list() if shaper_data.get('port'): ports = make_list(shaper_data['port']) if not shaper_data.get("policy_name"): st.error("policy_name is not provided") return False if cli_type == 'click': config_data = {"QUEUE": {}, "SCHEDULER": {}} if shaper_data.get('shaper_data'): shaper_info = make_list(shaper_data['shaper_data']) for ent in shaper_info: policy = "{}@{}".format(shaper_data['policy_name'], ent['queue']) if ('cir' in ent) or ('cbs' in ent) or ('pir' in ent) or ('pbs' in ent): temp = dict() temp[policy] = {} if 'meter_type' in ent: temp[policy].update(meter_type=ent['meter_type']) if 'cir' in ent: temp[policy].update(cir=str(ent['cir'])) if 'cbs' in ent: temp[policy].update(cbs=str(ent['cbs'])) if 'pir' in ent: temp[policy].update(pir=str(ent['pir'])) if 'pbs' in ent: temp[policy].update(pbs=str(ent['pbs'])) config_data["SCHEDULER"].update(temp) if ports: queue_map = dict() queue_map = {"{}|{}".format(port, ent['queue']): {"scheduler": "[SCHEDULER|{}]".format(policy)} for port in ports} config_data["QUEUE"].update(queue_map) config_data2 = {key: value for key, value in config_data.items()} for key, value in config_data2.items(): if not value: config_data.pop(key) json_config = json.dumps(config_data) json.loads(json_config) st.apply_json2(dut, json_config) elif cli_type == 'klish': shaper_info = make_list(shaper_data['shaper_data']) commands = list() commands.append("qos scheduler-policy {}".format(shaper_data['policy_name'])) for ent in shaper_info: if ('cir' in ent) or ('cbs' in ent) or ('pir' in ent) or ('pbs' in ent): commands.append("queue {}".format(ent['queue'])) if 'cir' in ent: commands.append("cir {}".format(get_klish_rate(ent['cir']))) if 'cbs' in ent: commands.append("cbs {}".format(ent['cbs'])) if 'pir' in ent: commands.append("pir {}".format(get_klish_rate(ent['pir']))) if 'pbs' in ent: commands.append("pbs {}".format(ent['pbs'])) commands.append("exit") commands.append("exit") if ports: for port in ports: intf_data = get_interface_number_from_name(port) commands.append("interface {} {}".format(intf_data['type'], intf_data['number'])) commands.append("scheduler-policy {}".format(shaper_data['policy_name'])) commands.append("exit") response = st.config(dut, commands, type=cli_type, skip_error_check=skip_error) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') shaper_info = make_list(shaper_data['shaper_data']) for ent in shaper_info: if ('cir' in ent) or ('cbs' in ent) or ('pir' in ent) or ('pbs' in ent): url = rest_urls['shaper_create_config'] params_config = dict() if 'cir' in ent: params_config.update(cir = str(get_rest_rate(ent['cir']))) if 'cbs' in ent: params_config.update(bc=int(ent['cbs'])) if 'pir' in ent: params_config.update(pir = str(get_rest_rate(ent['pir']))) if 'pbs' in ent: params_config.update(be=int(ent['pbs'])) config_data = {"openconfig-qos:scheduler-policies": {"scheduler-policy": [{"name": shaper_data['policy_name'], "config": {"name": shaper_data['policy_name']}, "schedulers": {"scheduler": [{"sequence": int(ent['queue']), "config": {"sequence": int(ent['queue'])}, "two-rate-three-color": {"config": params_config}}]}}]}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error("Failed to create queue-level shaper with shaper-data: {}".format(ent)) return False if ports: for port in ports: url = rest_urls['apply_shaper_config'].format(port) config_data = {"openconfig-qos:config": {"name": shaper_data['policy_name']}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error("Failed to attach queue-shaper configuration to port: {}".format(port)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def eh_not_installed_route_options(dut, **kwargs): """ Error handing - Not installed route Show / Get / Clear API. Author : Prudvi Mangadu ([email protected]) :param dut: :param kwargs: :return: """ if 'mode' not in kwargs: st.error("Mandatory parameter mode not found") af1 = 'ipv6' af2 = 'ipv6' if 'ipv4' in kwargs['mode']: af1 = 'ipv4' af2 = 'ip' if kwargs['mode'] == "clear_{}_route_vtysh_not_installed".format(af1): out = st.config(dut, 'clear {} route not-installed '.format(af2), type='vtysh', conf=False) return out if kwargs['mode'] == "clear_{}_route_sonic_not_installed".format(af1): out = st.config(dut, 'sonic-clear {} route not-installed '.format(af2)) return out # Sonic - MODE if "{}_route_sonic_not_installed".format(af1) in kwargs['mode']: command = 'show {} route not-installed'.format(af2) if 'show' in kwargs['mode']: out = st.show(dut, command) out = _get_entries_with_native_port(dut, out, **kwargs) st.debug(out) return out else: out = st.config(dut, command + ' | wc -l', skip_error_check=True) check_for_container_error(out) count = re.search(r"\d+", out).group() st.log("Detected route count {}".format(count)) return int(count) if "{}_route_sonic_for_not_installed".format(af1) in kwargs['mode']: command = 'show {} route | grep "#" '.format(af2) if 'show' in kwargs['mode']: out = st.show(dut, command) out = _get_entries_with_native_port(dut, out, **kwargs) st.debug(out) return out else: out = st.config(dut, command + ' | wc -l', skip_error_check=True) check_for_container_error(out) count = re.search(r"\d+", out).group() st.log("Detected route count {}".format(count)) return int(count) # vtysh = MODE if "{}_route_vtysh_not_installed".format(af1) in kwargs['mode']: out = st.show(dut, 'show {} route not-installed'.format(af2), type='vtysh') out = _get_entries_with_native_port(dut, out, **kwargs) st.debug(out) if 'show' in kwargs['mode']: return out else: st.log("Detected route count {}".format(len(out))) return len(out) if "{}_route_vtysh_for_not_installed".format(af1) in kwargs['mode']: out = st.show(dut, 'show {} route | grep "#"'.format(af2), type='vtysh') out = _get_entries_with_native_port(dut, out, **kwargs) st.debug(out) if 'show' in kwargs['mode']: return out else: st.log("Detected route count {}".format(len(out))) return len(out)
def test_ft_stormcontrol_verification(): status = 1 msg_id = "storm_control_traffic_verification_successful" new_kbps_value = 1010 st.log("Module config got passed") st.report_tc_pass('ft_stormcontrol_config_all_same_interface', 'test_case_passed') if not verify_bum_traffic_mode( 'broadcast', tg_info['tg1_stream_id'], skip_traffic_verify=False): st.error("Broadcast traffic verification got failed") status = 0 if not verify_bum_traffic_mode('unknown-unicast', tg_info['tg1_stream_id'], skip_traffic_verify=False): st.error("Unknown-unicast traffic verification got failed") status = 0 if not verify_bum_traffic_mode('unknown-multicast', tg_info['tg1_stream_id'], skip_traffic_verify=False): st.error("Unknown-multicast traffic verification got failed") status = 0 if status: st.report_tc_pass('ft_stormcontrol_BUM_traffic_policer_params', 'test_case_passed') st.report_tc_pass('ft_stormcontrol_traffic_rate_limited_bpsvalue', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_BUM_traffic_policer_params', 'test_case_failed') st.report_tc_fail('ft_stormcontrol_traffic_rate_limited_bpsvalue', 'test_case_failed') status = 1 st.log( "Configuring kbps value on interface to verify kpbs value is independent of interface" ) scapi.config(vars.D1, type="broadcast", action="add", interface_name=vars.D1T1P1, bits_per_sec=new_kbps_value, cli_type="click") if not scapi.verify_config(vars.D1, interface_name=vars.D1T1P1, type="broadcast", rate=new_kbps_value, cli_type="click"): st.error( "KBPS value configured on interface is dependent to other interface" ) status = 0 if status: st.report_tc_pass('ft_stormcontrol_bps_intf_indp', 'test_case_passed') st.report_tc_pass('ft_stormcontrol_bps_overwrite_new_bps_value', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_bps_intf_indp', 'test_case_failed') st.report_tc_fail('ft_stormcontrol_bps_overwrite_new_bps_value', 'test_case_failed') status = 1 st.log("configuring back to previous config") scapi.config(vars.D1, type="broadcast", action="add", interface_name=vars.D1T1P1, bits_per_sec=sc_data.kbps, cli_type="click") scapi.verify_config(vars.D1, interface_name=vars.D1T1P1, type="broadcast", rate=sc_data.kbps, cli_type="click") if not verify_bum_traffic_mode( 'broadcast', tg_info['tg1_stream_id'], skip_traffic_verify=False): st.error("Broadcast traffic verification got failed") status = 0 if status: st.report_tc_pass('ft_stormcontrol_config_clear_noaffect_traffic', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_config_clear_noaffect_traffic', 'test_case_failed') status = 1 st.log( "clearing bum traffic type to verify othertraffic does not effect bum storm-control" ) scapi.config(vars.D1, type="unknown-unicast", action="del", interface_name=vars.D1T1P1, bits_per_sec=sc_data.kbps, cli_type="click") st.log("verifying the other traffic is not get effected.") if not verify_bum_traffic_mode('unknown-unicast', tg_info['tg1_stream_id'], skip_traffic_verify=True): st.error("Other_traffic traffic verification got failed") status = 0 if status: st.report_tc_pass('ft_stormcontrol_config_unaffect_other_traffic', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_config_unaffect_other_traffic', 'test_case_failed') st.log("configuring back to previous config") scapi.config(vars.D1, type="unknown-unicast", action="add", interface_name=vars.D1T1P1, bits_per_sec=sc_data.kbps, cli_type="click") if not status: msg_id = "storm_control_traffic_verification_failed" report_result(status, msg_id)
def verify_vrrpv3_summary(dut, **kwargs): """ Author: Raghukumar Rampur email : [email protected] :param dut: :param interface: :type string or list :param vrid: :type string or list :param vip: :type virtual-ip in string or list :param state: :type vrrp state as string or list :param config_prio: :type configured vrrp priority as list or string :param current_prio: :type Current vrrp priority as list or string :return: Usage verify_vrrpv3_summary(dut1,vrid=['49','85'],state=['Master','Backup'], interface=['Vlan2996','Vlan2998'],vip=['73.73.73.66','85.85.85.71'], config_prio=[222,97],current_prio=[222,99]) verify_vrrpv3_summary(dut1,vrid='49',state='Master') """ ret_val = True cli_type = kwargs.get("cli_type", st.get_ui_type(dut)) if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' output = st.show(dut, 'show vrrp6', type=cli_type) if len(output) == 0: st.error("Output is Empty") return False if 'return_output' in kwargs: return output #Converting all kwargs to list type to handle single or list of vrrp instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list = [] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output, None, match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format(dut, input_dict)) ret_val = False return ret_val
def configure_vrrpv3(dut, config="yes", addr_family='ipv6', skip_error=False, **kwargs): """ author:[email protected] :param vrid: :type virtual router id: :param interface: :type interface: :param adv_interval: :type advertisement interval: :param priority: :type vrrp priority: :param pre_empt: :type pre_empt: :param version: :type version: :param vip: :type virtual ip: :param dut: :type dut: :return: :rtype: usage: configure_vrrpv3(dut1, vrid="10",vip="50.1.1.2",interface="Ethernet0",config="yes",version ="3") configure_vrrpv3(dut1, vrid="11",vip="60.1.1.2",interface="Ethernet10",adv_interval="10",priority="101",track_interface_list=["Ethernet0",Ethernet4"],track_priority_list=[10,20]) """ if 'interface' not in kwargs or 'vrid' not in kwargs: st.error("Mandatory parameter - interface or vrid is missing") return False cli_type = kwargs.pop('cli_type', st.get_ui_type(dut)) if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' cmd = '' if cli_type == 'click': VRRP_CMD = 'sudo config interface vrrp6' if config.lower() == "yes": if 'version' in kwargs: cmd = "sudo config interface vrrp version {} {} {}\n".format( kwargs['interface'], kwargs['vrid'], kwargs['version']) if 'enable' in kwargs: cmd = "{} add {} {}\n".format(VRRP_CMD, kwargs['interface'], kwargs['vrid']) if 'adv_interval' in kwargs: cmd = " {} adv_interval {} {} {}\n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid'], kwargs['adv_interval']) if 'priority' in kwargs: cmd += "{} priority {} {} {}\n".format(VRRP_CMD, kwargs['interface'], kwargs['vrid'], kwargs['priority']) if 'preempt' in kwargs: cmd += "{} pre_empt enable {} {} \n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid']) if 'vip' in kwargs: cmd += "{} vip add {} {} {}\n".format(VRRP_CMD, kwargs['interface'], kwargs['vrid'], kwargs['vip']) if 'track_interface_list' in kwargs and 'track_priority_list' in kwargs: if len(kwargs['track_interface_list']) != len( kwargs['track_priority_list']): st.error( "Please check the track interface list and track priority list, number of entries should be same" ) return False for track_intf, track_prio in zip( kwargs['track_interface_list'], kwargs['track_priority_list']): cmd += "{} track_interface add {} {} {} {}\n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid'], track_intf, track_prio) elif config.lower() == "no": if 'disable' in kwargs: cmd = "{} remove {} {}\n".format(VRRP_CMD, kwargs['interface'], kwargs['vrid']) if 'vip' in kwargs: cmd += "{} vip remove {} {} {}\n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid'], kwargs['vip']) if 'adv_interval' in kwargs or 'priority' in kwargs: st.log( "Cannot remove/delete the adv_interval or priority, please set it to default value" ) if 'preempt' in kwargs: cmd += "{} pre_empt disable {} {}\n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid']) if 'track_interface_list' in kwargs and 'track_priority_list' in kwargs: if len(kwargs['track_interface_list']) != len( kwargs['track_priority_list']): st.error( "Please check the track interface list and track priority list, number of entries should be same" ) return False for track_intf, track_prio in zip( kwargs['track_interface_list'], kwargs['track_priority_list']): cmd += "{} track_interface remove {} {} {} \n".format( VRRP_CMD, kwargs['interface'], kwargs['vrid'], track_intf) output = st.config(dut, cmd, skip_error_check=skip_error, type=cli_type) return output elif cli_type == "klish": pintf = get_interface_number_from_name(kwargs['interface']) cmd = "interface {} {}".format(pintf['type'], pintf['number']) if config.lower() == "yes": if 'vrid' in kwargs: cmd += "\n" + " vrrp {} address-family {}\n".format( kwargs['vrid'], addr_family) if 'priority' in kwargs: cmd += "priority {}\n".format(kwargs['priority']) if 'adv_interval' in kwargs: cmd += "advertisement-interval {}\n".format( kwargs['adv_interval']) if 'vip' in kwargs: cmd += "vip {}\n".format(kwargs['vip']) if 'preempt' in kwargs: cmd += "preempt\n" if 'track_interface_list' in kwargs and 'track_priority_list' in kwargs: if len(kwargs['track_interface_list']) != len( kwargs['track_priority_list']): st.error( "lease check the track interface list and track priority list, number of entries should be same" ) return False for track_intf, track_prio in zip( kwargs['track_interface_list'], kwargs['track_priority_list']): cmd += "track-interface {} weight {}\n".format( track_intf, track_prio) cmd += "exit\n" elif config.lower() == "no": if 'vip' in kwargs: cmd += "\n" + " vrrp {} address-family {}\n".format( kwargs['vrid'], addr_family) cmd += "no vip {}\n".format(kwargs['vip']) if 'preempt' in kwargs: cmd += "\n" + " vrrp {} address-family {}\n".format( kwargs['vrid'], addr_family) cmd += "no preempt\n" if 'track_interface_list' in kwargs and 'track_priority_list' in kwargs: if len(kwargs['track_interface_list']) != len( kwargs['track_priority_list']): st.error( "Please check the track interface list and track priority list, number of entries should be same" ) return False cmd += "\n" + " vrrp {} address-family {}\n".format( kwargs['vrid'], addr_family) for track_intf, track_prio in zip( kwargs['track_interface_list'], kwargs['track_priority_list']): cmd += "no track-interface {}\n".format(track_intf) if 'vrid' in kwargs and 'disable' in kwargs: cmd += "\n" + "no vrrp {} address-family {}\n".format( kwargs['vrid'], addr_family) cmd += " exit\n" output = st.config(dut, cmd, skip_error_check=skip_error, type=cli_type) return output else: st.log("Unsupported CLI TYPE - {}".format(cli_type)) return False
def test_vrrpv3_scale_001(prologue_epilogue): #tc_list = ["FtOpSoRoVrrpv3Fn054","FtOpSoRoVrrpv3Fn055","FtOpSoRoVrrpv3Fn056"] tc_result = True ;err_list=[] ########################################################### hdrMsg("Step01 : Verify VRRP Master/Backup election for all {} configured sessions".format(vrrp_sessions)) ############################################################ result = verify_vrrp(summary="yes") if result is False: err = "VRRP Master/Backup election is incorrect for one or more VRRP sessions" st.report_fail('test_case_failure_message', err) result =vrrp.configure_vrrp(data.dut1, vrid='129',interface='Vlan8', config="yes",enable='',skip_error=True,scale_instance_error=1) expected_err ="Error" if expected_err not in str(result): err = "VRRP instance 129 is accepted but Max number of VRRP instances supported is 128 " st.error(err);tc_result=False;err_list.append(err) ########################################################### hdrMsg("Start Traffic for VRRP instance scale config") ########################################################### #data.tg1.tg_traffic_control(action='run', stream_handle=data.stream_handles.values()) run_traffic() ########################################################### hdrMsg("Step02 : Verify Traffic for scale config for all VRID") ############################################################ result = verify_tg_traffic_rate(data.tg1,data.tg2,data.tgd3_ports,data.tgd4_ports) if result is False: err = "Traffic check failed for configure VRRP {} and flap Vlan".format(vrrp_ip_list[0][0]) st.error(err);tc_result=False;err_list.append(err) ########################################################### hdrMsg("Stop Traffic for VRRP instance scale config") ########################################################### #data.tg1.tg_traffic_control(action='stop', stream_handle=data.stream_handles.values()) run_traffic(action='stop') ########################################################### hdrMsg("Step03 : Delete/Configure VRRP sessions {} on dut1(Master) and verify vrrp master backup role".format(vrid_list[0:int(vrrp_sessions/2)])) ############################################################ for vrid,vlan,vip,prio,vmac in zip(vrid_list[0:int(vrrp_sessions/2)],vrrp_vlan_intf[0:int(vrrp_sessions/2)], vip_list[0:int(vrrp_sessions/2)],vrrp_priority_list_dut1[0:int(vrrp_sessions/2)], vmac_list_1[0:int(vrrp_sessions/2)]): if vrid - (int(vrrp_sessions/2)) == -1 or vrid - (int(vrrp_sessions/2)) == 0 or vrid - (int(vrrp_sessions/2)) == 1: st.log(">>>> Delete/Configur VRRP session {} <<<<<".format(vrid)) vrrp.configure_vrrp(data.dut1, vrid=vrid, interface=vlan, config="no",disable='') vrrp.configure_vrrp(data.dut1, vrid=vrid, vip=vip, interface=vlan, priority=prio, config="yes",enable='') vrrp.configure_vrrp(data.dut1,vrid=vrid,interface=vlan,version=3) for vrid,vlan,vip,prio,vmac in zip(vrid_list[0:int(vrrp_sessions/2)],vrrp_vlan_intf[0:int(vrrp_sessions/2)], vip_list[0:int(vrrp_sessions/2)],vrrp_priority_list_dut1[0:int(vrrp_sessions/2)], vmac_list_1[0:int(vrrp_sessions/2)]): if vrid - (int(vrrp_sessions/2)) == -1 or vrid - (int(vrrp_sessions/2)) == 0 or vrid - (int(vrrp_sessions/2)) == 1: st.log("Verify dut1 elected as VRRP Master for VRID {} ".format(vrid)) result =verify_master_backup(vrid,vlan,vmac,vip,master_dut=data.dut1,backup_dut=data.dut2) if result is False: err = "dut1 not elected as VRRP Master for VRID {}".format(vrid) st.error(err);err_list.append(err);tc_result = False ########################################################### hdrMsg("Step04 : Shutdown/No-shutdown VRRP enabled LAG member port in master node dut1 and check new vrrp role") ############################################################ port.shutdown(data.dut1,data.d1d3_ports) for vrid,vlan,vip,prio,vmac in zip(vrid_list[0:int(vrrp_sessions/2)],vrrp_vlan_intf[0:int(vrrp_sessions/2)], vip_list[0:int(vrrp_sessions/2)],vrrp_priority_list_dut1[0:int(vrrp_sessions/2)], vmac_list_1[0:int(vrrp_sessions/2)]): if vrid - (int(vrrp_sessions/2)) == -2 or vrid - (int(vrrp_sessions/2)) == -1 or vrid - (int(vrrp_sessions/2)) == 0: st.log("Verify dut2 elected as VRRP Master for VRID {} ".format(vrid)) result =verify_master_backup(vrid,vlan,vmac,vip,master_dut=data.dut2,backup_dut=data.dut1,skip_backup_check='yes') if result is False: err = "dut2 not elected as VRRP Master for VRID {}".format(vrid) st.error(err);err_list.append(err);tc_result = False for vrid,intf,vmac,vip in zip(vrid_list[int(vrrp_sessions/2):],dut1_vlan_intf[int(vrrp_sessions/2):vrrp_sessions],vmac_list_1[int(vrrp_sessions/2):],vip_list[int(vrrp_sessions/2):]): if vrid - (int(vrrp_sessions/2)) == 1 or vrid - (int(vrrp_sessions/2)) == 2 or vrid - vrrp_sessions == 0: st.log("Verify dut2 elected as VRRP Master for VRID {} ".format(vrid)) result =verify_master_backup(vrid,intf,vmac,vip,master_dut=data.dut2,backup_dut=data.dut1,skip_backup_check='yes') if result is False: err = "dut1 not elected as VRRP Master for VRID {}".format(vrid) st.error(err);err_list.append(err);tc_result = False ########################################################### hdrMsg("Start Traffic for VRRP instance scale config after old master is down") ########################################################### #data.tg1.tg_traffic_control(action='run', stream_handle=data.stream_handles.values()) run_traffic() ########################################################### hdrMsg("Step05 : Verify Traffic for scale VRRP instances with new VRRP master ") ############################################################ result = verify_tg_traffic_rate(data.tg1,data.tg2,data.tgd3_ports,data.tgd4_ports) if result is False: err = "Traffic check failed with after delete/configure VRRP {} and flap Vlan".format(vrrp_ip_list[0][0]) st.error(err);tc_result=False;err_list.append(err) ########################################################### hdrMsg("Stop Traffic for VRRP instance scale config after after old master is down") ########################################################### #data.tg1.tg_traffic_control(action='stop', stream_handle=data.stream_handles.values()) run_traffic(action='stop') ########################################################### hdrMsg("No-shutdown VRRP enabled LAG member port in dut1") ############################################################ port.noshutdown(data.dut1,data.d1d3_ports) ########################################################################################### hdrMsg("Step06: Config save and fast boot DUT" ) ########################################################################################### reboot_api.config_save(data.dut1) reboot_api.config_save(data.dut1,shell='vtysh') st.reboot(data.dut1,'fast') ########################################################### hdrMsg("Step07 : Verify VRRP Master/Backup election for all {} configured sessions after dut1 fast reload".format(vrrp_sessions)) ############################################################ result = verify_vrrp(summary="yes",retry_count=20) if result is False: err = "VRRP Master/Backup election is incorrect for one or more VRRP sessions" st.report_fail('test_case_failure_message', err) ########################################################### hdrMsg("Start Traffic for VRRP instance scale config after dut1 fast reload") ########################################################### #data.tg1.tg_traffic_control(action='run', stream_handle=data.stream_handles.values()) run_traffic() ########################################################### hdrMsg("Step08 : Verify Traffic for scale VRRP instances after dut1 fast reload ") ############################################################ result = verify_tg_traffic_rate(data.tg1,data.tg2,data.tgd3_ports,data.tgd4_ports) if result is False: err = "Traffic check failed with after delete/configure VRRP {} and flap Vlan".format(vrrp_ip_list[0][0]) st.error(err);tc_result=False;err_list.append(err) ########################################################### hdrMsg("Stop Traffic for VRRP instance scale config after after dut1 fast reload") ########################################################### #data.tg1.tg_traffic_control(action='stop', stream_handle=data.stream_handles.values()) run_traffic(action='stop') if tc_result is False: st.report_fail('test_case_failure_message',err_list[0]) else: st.report_pass('test_case_passed')
def check_logging_result(data=[]): st.log('Checking logging result') msglist = slog_obj.show_logging(data.D1, severity='WARNING', filter_list=["THRESHOLD"]) global crm_test_result family_list = crm_obj.crm_get_family_list(data.D1) for family in family_list: crm_test_result[family] = 0 if family != 'all': if crmlogPresent(family, "THRESHOLD_EXCEEDED", "TH_USED", msglist=msglist, data=data): crm_test_result[family] += 1 st.log("Successsfully generated max thresholds for [{}] used". format(family)) else: st.error( "Failed to create max thresholds for [{}] used".format( family)) if crmlogPresent(family, "THRESHOLD_CLEAR", "TH_USED", msglist=msglist, data=data): crm_test_result[family] += 1 st.log( "Successsfully generated minimum thresholds for [{}] used". format(family)) else: st.error( "Failed to create minimum thresholds for [{}] used".format( family)) if crmlogPresent(family, "THRESHOLD_EXCEEDED", "TH_PERCENTAGE", msglist=msglist, data=data): crm_test_result[family] += 1 st.log( "Successsfully generated max thresholds for [{}] percentage" .format(family)) else: st.error("Failed to create max thresholds for [{}] percentage". format(family)) if crmlogPresent(family, "THRESHOLD_CLEAR", "TH_PERCENTAGE", msglist=msglist, data=data): crm_test_result[family] += 1 st.log( "Successsfully generated minimum thresholds for [{}] percentage" .format(family)) else: st.error( "Failed to create minimum thresholds for [{}] percentage". format(family)) if crmlogPresent(family, "THRESHOLD_EXCEEDED", "TH_FREE", msglist=msglist, data=data): crm_test_result[family] += 1 st.log("Successsfully generated max thresholds for [{}] free". format(family)) else: st.error( "Failed to create max thresholds for [{}] free".format( family)) if crmlogPresent(family, "THRESHOLD_CLEAR", "TH_FREE", msglist=msglist, data=data): crm_test_result[family] += 1 st.log( "Successsfully generated minimum thresholds for [{}] free". format(family)) else: st.error( "Failed to create minimum thresholds for [{}] free".format( family)) for family in family_list: if check_test_status(family): st.wait(5) return False return True
def config_dot1p_to_tc_map(dut, obj_name, dot1p_to_tc_map_dict, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) To map the dot1p to tc :param dut: :type dut: :param obj_name: :type obj_name: :param dot1p_to_tc_map_dict: :type dict: """ cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'click': final_data = dict() temp_data = dict() dot1p_to_tc_map_dict = get_non_range_map_data_from_range_map_data( dot1p_to_tc_map_dict) if not dot1p_to_tc_map_dict or not obj_name: st.log( "Please provide dot1p value to traffic class value map dict. For example - {'0':'0', '1':'1', ...} and Object name like 'AZURE'" ) return False else: temp_data[obj_name] = dot1p_to_tc_map_dict final_data['DOT1P_TO_TC_MAP'] = temp_data final_data = json.dumps(final_data) st.apply_json(dut, final_data) elif cli_type == 'klish': commands = list() commands.append('qos map dot1p-tc {}'.format(obj_name)) for dot1p, tc in dot1p_to_tc_map_dict.items(): commands.append('dot1p {} traffic-class {}'.format(dot1p, tc)) commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: cli_type = 'rest-patch' rest_urls = st.get_datastore(dut, 'rest_urls') url = rest_urls['dot1p_tc_map_config'].format(obj_name) dot1p_to_tc_map_dict = get_non_range_map_data_from_range_map_data( dot1p_to_tc_map_dict) maps_data = [{ "dot1p": int(dot1p), "config": { "dot1p": int(dot1p), "fwd-group": str(tc) } } for dot1p, tc in dot1p_to_tc_map_dict.items()] dot1p_tc_map_data = { "openconfig-qos-maps-ext:dot1p-map": [{ "name": obj_name, "config": { "name": obj_name }, "dot1p-map-entries": { "dot1p-map-entry": maps_data } }] } if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=dot1p_tc_map_data): st.error("Failed to map DOT1P to TC with data: {}".format( dot1p_to_tc_map_dict)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def config_pfc_priority_to_queue_map(dut, obj_name, pfc_priority_to_queue_map_dict, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) To map the PFC priority to queue :param dut: :type dut: :param obj_name: :type obj_name: :param pfc_priority_to_queue_map_dict: :type dict: """ cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'click': final_data = dict() temp_data = dict() pfc_priority_to_queue_map_dict = get_non_range_map_data_from_range_map_data( pfc_priority_to_queue_map_dict) if not pfc_priority_to_queue_map_dict or not obj_name: st.log( "Please provide pfc priority to queue map dict. For example - {'0':'0', '1':'1', ...} and Object name like 'AZURE'" ) return False else: temp_data[obj_name] = pfc_priority_to_queue_map_dict final_data['MAP_PFC_PRIORITY_TO_QUEUE'] = temp_data final_data = json.dumps(final_data) st.apply_json(dut, final_data) elif cli_type == 'klish': commands = list() commands.append('qos map pfc-priority-queue {}'.format(obj_name)) for pfc_priority, queue in pfc_priority_to_queue_map_dict.items(): commands.append('pfc-priority {} queue {}'.format( pfc_priority, queue)) commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: cli_type = 'rest-patch' rest_urls = st.get_datastore(dut, 'rest_urls') url = rest_urls['pfc_priority_queue_map_config'] pfc_priority_to_queue_map_dict = get_non_range_map_data_from_range_map_data( pfc_priority_to_queue_map_dict) maps_data = [{ "dot1p": int(dot1p), "config": { "dot1p": int(dot1p), "output-queue-index": int(queue) } } for dot1p, queue in pfc_priority_to_queue_map_dict.items()] pfc_priority_queue_map_data = { "openconfig-qos-maps-ext:pfc-priority-queue-map": [{ "name": obj_name, "config": { "name": obj_name }, "pfc-priority-queue-map-entries": { "pfc-priority-queue-map-entry": maps_data } }] } if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=pfc_priority_queue_map_data): st.error( "Failed to map PFC_PRIORITY to QUEUE with data: {}".format( pfc_priority_to_queue_map_dict)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def _get_rest_qos_map_output(data, table): """ To process and return the REST qos map output Author: Jagadish Chatrasi (jagadish.chatrasi@broadcom) :param data: :type data: :param table: :type table: """ table_map = { 'dot1p_to_tc_map': { 'parent': 'dot1p-map-entries', 'child': 'dot1p-map-entry', 'attr': 'dot1p,tc,dot1p,fwd-group' }, 'dscp_to_tc_map': { 'parent': 'dscp-map-entries', 'child': 'dscp-map-entry', 'attr': 'dscp,tc,dscp,fwd-group' }, 'pfc_to_queue_map': { 'parent': 'pfc-priority-queue-map-entries', 'child': 'pfc-priority-queue-map-entry', 'attr': 'pfc_priority,queue,dot1p,output-queue-index' }, 'tc_to_dot1p_map': { 'parent': 'forwarding-group-dot1p-map-entries', 'child': 'forwarding-group-dot1p-map-entry', 'attr': 'tc,dot1p,fwd-group,dot1p' }, 'tc_to_dscp_map': { 'parent': 'forwarding-group-dscp-map-entries', 'child': 'forwarding-group-dscp-map-entry', 'attr': 'tc,dscp,fwd-group,dscp' }, 'tc_to_pg_map': { 'parent': 'forwarding-group-priority-group-map-entries', 'child': 'forwarding-group-priority-group-map-entry', 'attr': 'tc,pg,fwd-group,priority-group-index' }, 'tc_to_queue_map': { 'parent': 'forwarding-group-queue-map-entries', 'child': 'forwarding-group-queue-map-entry', 'attr': 'tc,queue,fwd-group,output-queue-index' } } if table not in table_map: st.error("Invalid map: {}".format(table)) return False fields = table_map[table] retval = list() try: for entry in data: if fields['parent'] in entry: mappings = entry[fields['parent']][fields['child']] for mapping in mappings: attr = fields['attr'].split(',') temp = dict() temp['table'] = entry['name'] temp[attr[0]] = str(mapping['state'][attr[2]]) temp[attr[1]] = str(mapping['state'][attr[3]]) retval.append(temp) st.debug(retval) return retval except Exception as e: st.error("{} exception occurred".format(e)) st.debug("Given data is:{}".format(data)) st.debug("Given table is:{}".format(table)) st.debug(retval) return retval
def config_tc_to_pg_map(dut, obj_name, tc_to_pg_map_dict, **kwargs): cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'click': final_data = dict() temp_data = dict() tc_to_pg_map_dict = get_non_range_map_data_from_range_map_data( tc_to_pg_map_dict) if not tc_to_pg_map_dict or not obj_name: st.log( "Please provide traffic class to priority group map dict. For example - {'0':'0', '1':'1', ...} and Object name like 'AZURE'" ) return False else: temp_data[obj_name] = tc_to_pg_map_dict final_data['TC_TO_PRIORITY_GROUP_MAP'] = temp_data final_data = json.dumps(final_data) st.apply_json(dut, final_data) elif cli_type == 'klish': commands = list() commands.append('qos map tc-pg {}'.format(obj_name)) for tc, pg in tc_to_pg_map_dict.items(): commands.append('traffic-class {} priority-group {}'.format( tc, pg)) commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: cli_type = 'rest-patch' rest_urls = st.get_datastore(dut, 'rest_urls') url = rest_urls['tc_pg_map_config'] tc_to_pg_map_dict = get_non_range_map_data_from_range_map_data( tc_to_pg_map_dict) maps_data = [{ "fwd-group": str(tc), "config": { "fwd-group": str(tc), "priority-group-index": int(pg) } } for tc, pg in tc_to_pg_map_dict.items()] tc_pg_map_data = { "openconfig-qos-maps-ext:forwarding-group-priority-group-map": [{ "name": obj_name, "config": { "name": obj_name }, "forwarding-group-priority-group-map-entries": { "forwarding-group-priority-group-map-entry": maps_data } }] } if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=tc_pg_map_data): st.error("Failed to map TC to PG with data: {}".format( tc_to_pg_map_dict)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def reset_queue_shaper_params(dut, policy_name, params_dict, **kwargs): """ API to reset Queue-Level shaper parameters :param dut: :type dut: :param policy_name: :type policy_name: :param params_dict: :type params_dict: :return: :rtype: """ cli_type = st.get_ui_type(dut, **kwargs) cli_type = 'klish' if cli_type == 'click' else cli_type skip_error = kwargs.get('skip_error', False) if cli_type == 'klish': commands = list() commands.append("qos scheduler-policy {}".format(policy_name)) for queue, params in params_dict.items(): parameters = make_list(params) commands.append("queue {}".format(queue)) commands.extend(["no {}".format(param.lower()) for param in parameters]) commands.append("exit") commands.append("exit") response = st.config(dut, commands, type=cli_type, skip_error_check=skip_error) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') for queue, params in params_dict.items(): parameters = make_list(params) for param in parameters: if param.lower() not in ['pir', 'pbs', 'cir', 'cbs', 'type', 'weight']: st.error('Invalid queue shaper/scheduler parameter: {}'.format(param)) return False if param.lower() == 'pir': url = rest_urls['shaper_pir_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False if param.lower() == 'pbs': url = rest_urls['shaper_pbs_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False if param.lower() == 'cir': url = rest_urls['shaper_cir_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False if param.lower() == 'cbs': url = rest_urls['shaper_cbs_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False if param.lower() == 'type': url = rest_urls['scheduler_type_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False if param.lower() == 'weight': url = rest_urls['scheduler_weight_config'].format(policy_name, queue) if not delete_rest(dut, rest_url=url): st.error("Failed to reset {} on Queue: {} for shaper profile: {}".format(param, queue, policy_name)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def apply_queue_shcheduling_config(dut, scheduler_data, **kwargs): """ API to configure scheduler parameters :param dut: :type dut: :param scheduler_data: :type scheduler_data: :param cli_type: :type cli_type: :return: :rtype: """ cli_type = st.get_ui_type(dut, **kwargs) skip_error = kwargs.get('skip_error', False) cli_type = 'klish' if skip_error and cli_type == 'click' else cli_type st.debug("Provided scheduler configuration is: {}".format(scheduler_data)) ports = list() if scheduler_data.get('port'): ports = make_list(scheduler_data['port']) if not scheduler_data.get("policy_name"): st.error("policy_name is not provided") return False if cli_type == 'click': config_data = {"QUEUE": {}, "SCHEDULER": {}} scheduler_info = make_list(scheduler_data['scheduler_data']) for ent in scheduler_info: temp = dict() queue_map = dict() policy = "{}@{}".format(scheduler_data['policy_name'], ent['queue']) temp[policy] = dict() if 'weight' in ent: temp[policy].update(weight = str(ent['weight'])) if ent.get('type'): temp[policy].update(type = ent['type'].upper()) if ports: queue_map = {"{}|{}".format(port, ent['queue']) : {"scheduler": "[SCHEDULER|{}]".format(policy)} for port in ports} if temp[policy]: config_data['SCHEDULER'].update(temp) if queue_map: config_data['QUEUE'].update(queue_map) if not config_data['QUEUE']: config_data.pop('QUEUE') if not config_data['SCHEDULER']: config_data.pop('SCHEDULER') json_config = json.dumps(config_data) json.loads(json_config) st.apply_json2(dut, json_config) elif cli_type == 'klish': commands = list() commands.append("qos scheduler-policy {}".format(scheduler_data['policy_name'])) scheduler_info = make_list(scheduler_data['scheduler_data']) for ent in scheduler_info: commands.append("queue {}".format(ent['queue'])) if ent.get('type'): commands.append("type {}".format(ent['type'].lower())) if 'weight' in ent: commands.append("weight {}".format(ent['weight'])) commands.append("exit") commands.append("exit") if ports: for port in ports: intf_data = get_interface_number_from_name(port) commands.append("interface {} {}".format(intf_data['type'], intf_data['number'])) commands.append("scheduler-policy {}".format(scheduler_data['policy_name'])) commands.append("exit") response = st.config(dut, commands, type=cli_type, skip_error_check=skip_error) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') scheduler_info = make_list(scheduler_data['scheduler_data']) for ent in scheduler_info: if ent.get('type') or 'weight' in ent: url = rest_urls['shaper_create_config'] params_config = {"sequence": int(ent['queue'])} if ent.get('type'): params_config.update(priority=ent['type'].upper()) if 'weight' in ent: params_config.update({"openconfig-qos-ext:weight": int(ent['weight'])}) config_data = {"openconfig-qos:scheduler-policies": {"scheduler-policy": [{"name": scheduler_data['policy_name'], "config": {"name": scheduler_data['policy_name']}, "schedulers": {"scheduler": [{"sequence": int(ent['queue']), "config": params_config}]}}]}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error('Failed to create scheduler with data: {}'.format(ent)) return False if ports: for port in ports: url = rest_urls['apply_shaper_config'].format(port) config_data = {"openconfig-qos:config": {"name": scheduler_data['policy_name']}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error("Failed to attach queue-shaper configuration to port: {}".format(port)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def apply_port_shaping_config(dut, shaper_data, **kwargs): """ API to configure Port-Level shaper :param dut: :type dut: :param shaper_data: :type shaper_data: :param cli_type: :type cli_type: :return: :rtype: """ cli_type = st.get_ui_type(dut, **kwargs) skip_error = kwargs.get('skip_error', False) cli_type = 'klish' if skip_error and cli_type == 'click' else cli_type st.debug("Provided port-shaper configuration is: {}".format(shaper_data)) if not shaper_data.get("policy_name"): st.error("policy_name is not provided") return False if cli_type == 'click': policy_name = "{}@255".format(shaper_data["policy_name"]) json_data = {"PORT_QOS_MAP": {}, "SCHEDULER": {policy_name: {}}} if shaper_data.get("port"): ports = make_list(shaper_data["port"]) json_data["PORT_QOS_MAP"] = {port: {"scheduler": "[SCHEDULER|{}]".format(policy_name)} for port in ports} else: json_data.pop("PORT_QOS_MAP") if ("pir" in shaper_data) or ("pbs" in shaper_data) or shaper_data.get("meter_type"): if shaper_data.get("meter_type"): json_data["SCHEDULER"][policy_name].update(meter_type = shaper_data['meter_type']) if "pir" in shaper_data: json_data["SCHEDULER"][policy_name].update(pir = str(shaper_data['pir'])) if "pbs" in shaper_data: json_data["SCHEDULER"][policy_name].update(pbs = str(shaper_data['pbs'])) else: json_data.pop("SCHEDULER") json_config = json.dumps(json_data) json.loads(json_config) st.apply_json2(dut, json_config) elif cli_type == 'klish': commands = list() if ("pir" in shaper_data) or ("pbs" in shaper_data): commands.append("qos scheduler-policy {}".format(shaper_data['policy_name'])) commands.append("port") if "pir" in shaper_data: commands.append("pir {}".format(get_klish_rate(shaper_data['pir']))) if "pbs" in shaper_data: commands.append("pbs {}".format(shaper_data['pbs'])) commands.extend(["exit", "exit"]) if shaper_data.get("port"): ports = make_list(shaper_data["port"]) for port in ports: intf_data = get_interface_number_from_name(port) commands.append("interface {} {}".format(intf_data['type'], intf_data['number'])) commands.append("scheduler-policy {}".format(shaper_data['policy_name'])) commands.append("exit") response = st.config(dut, commands, type=cli_type, skip_error_check=skip_error) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') if ("pir" in shaper_data) or ("pbs" in shaper_data): url = rest_urls['shaper_create_config'] params_config = dict() if "pir" in shaper_data: params_config.update(pir=str(get_rest_rate(shaper_data['pir']))) if "pbs" in shaper_data: params_config.update(be=int(shaper_data['pbs'])) config_data = {"openconfig-qos:scheduler-policies": {"scheduler-policy": [{"name": shaper_data['policy_name'], "config": {"name": shaper_data['policy_name']}, "schedulers": {"scheduler": [{"sequence": 255, "config": {"sequence": 255}, "two-rate-three-color": {"config": params_config}}]}}]}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error("Failed to create port-level shaper with shaper-data: {}".format(shaper_data)) return False if shaper_data.get("port"): ports = make_list(shaper_data["port"]) for port in ports: url = rest_urls['apply_shaper_config'].format(port) config_data = {"openconfig-qos:config": {"name": shaper_data['policy_name']}} if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data): st.error("Failed to attach shaper configuration to port: {}".format(port)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def config(dut, **kwargs): """ 1. Add IP helper address on an interface. Click : config interface ip helper_address add <interface-name> <ip-address> [-vrf <vrf-name] Klish : ip helper-address [vrf <vrf-name>] <ip-address> 2. Remove IP helper address on an interface. Click : config interface ip helper_address remove <interface-name> <ip-address> [-vrf <vrf-name] Klish : no ip helper-address [vrf <vrf-name>] <ip-address> 3. Enable UDP broadcast forwarding. Click : config ip forward_protocol udp enable Klish : ip forward-protocol udp enable 4. Disable UDP broadcast forwarding. Click : config ip forward_protocol udp disable Klish : no ip forward-protocol udp enable 5. Add UDP port to the list of forwarding ports. Click : config ip forward_protocol udp add {[tftp/dns/ntp/netbios-name-server/netbios-datagram-server/tacacs] | <port>} Klish : ip forward-protocol udp include {[tftp/dns/ntp/netbios-name-server/netbios-datagram-server/tacacs] | <port>} 6. Remove UDP port from the list of forwarding ports. Click : config ip forward_protocol udp remove {[tftp/dns/ntp/netbios-name-server/netbios-datagram-server/tacacs] | <port>} Klish : ip forward-protocol udp exclude {[tftp/dns/ntp/netbios-name-server/netbios-datagram-server/tacacs] | <port>} 7. Configure the UDP broadcast packet rate limiting value in the range 600 - 10000 pps. The default value is 6000 pps. Click : config ip forward_protocol udp rate_limit <value-in-pps> Klish : ip forward-protocol udp rate-limit <value-in-pps> """ helper_address_config_keys = ["action_str", "intf_name", "ip_address"] fwd_protocol_config_keys = ["action_str", "protocol_or_port"] cli_type = kwargs.get("cli_type", st.get_ui_type(dut, **kwargs)) skip_error_check = kwargs.get("skip_error_check", True) command = '' if cli_type == 'click': if 'helper_status' in kwargs: command = "config ip forward_protocol udp {helper_status}".format( **kwargs) elif all(key in kwargs for key in helper_address_config_keys): ip_li = '' if isinstance(kwargs['ip_address'], list): for x in kwargs['ip_address']: ip_li += x + ' ' else: ip_li += kwargs['ip_address'] command = "config interface ip helper_address {action_str} {intf_name} {}".format( ip_li, **kwargs) if 'vrf_name' in kwargs: command = "{} -vrf {vrf_name}".format(command, **kwargs) elif all(key in kwargs for key in fwd_protocol_config_keys): command = "config ip forward_protocol udp {action_str} {protocol_or_port}".format( **kwargs) elif 'rate_limit_val' in kwargs: command = "config ip forward_protocol udp rate_limit {rate_limit_val}".format( **kwargs) else: st.log("Required keys are not passed to configure IP helper") return False if command: st.config(dut, command, type=cli_type) return True return False elif cli_type == "klish": command = list() if 'helper_status' in kwargs: if kwargs['helper_status'] == 'enable': command.append("ip forward-protocol udp enable") elif kwargs['helper_status'] == 'disable': command.append("no ip forward-protocol udp enable") else: st.error("Required enable or disable") return False elif all(key in kwargs for key in helper_address_config_keys): ip_li = '' if isinstance(kwargs['ip_address'], list): for x in kwargs['ip_address']: ip_li += x + ' ' else: ip_li += kwargs['ip_address'] intf_data = get_interface_number_from_name(kwargs["intf_name"]) command.append("interface {} {}".format(intf_data["type"], intf_data["number"])) if kwargs['action_str'] == 'add': if 'vrf_name' in kwargs: command.append( "ip helper-address vrf {vrf_name} {}".format( ip_li, **kwargs)) command.append("exit") else: command.append("ip helper-address {}".format(ip_li)) command.append("exit") elif kwargs['action_str'] == 'remove': if 'vrf_name' in kwargs: command.append( "no ip helper-address vrf {vrf_name} {}".format( ip_li, **kwargs)) else: command.append("no ip helper-address {}".format(ip_li)) else: st.error("Required add or remove for command") return False elif all(key in kwargs for key in fwd_protocol_config_keys): if kwargs['action_str'] == 'add': command.append( "ip forward-protocol udp include {protocol_or_port}". format(**kwargs)) elif kwargs['action_str'] == 'remove': command.append( "ip forward-protocol udp exclude {protocol_or_port}". format(**kwargs)) else: st.error("Required add or remove for command") return False elif 'rate_limit_val' in kwargs: command.append( "ip forward-protocol udp rate-limit {rate_limit_val}".format( **kwargs)) else: st.error("Required keys are not passed to configure IP helper") return False st.config(dut, command, type=cli_type, skip_error_check=skip_error_check) return True elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, "rest_urls") if 'helper_status' in kwargs: url = rest_urls['fwd_protocol_udp_enable'] if kwargs['helper_status'] == 'enable': data = {"openconfig-ip-helper:enable": True} if not config_rest( dut, http_method=cli_type, rest_url=url, json_data=data): return False elif kwargs['helper_status'] == 'disable': if not delete_rest(dut, rest_url=url): return False else: st.error("Required enable or disable") return False elif all(key in kwargs for key in helper_address_config_keys): ip_li = '' if isinstance(kwargs['ip_address'], list): for x in kwargs['ip_address']: ip_li += x + ' ' else: ip_li += kwargs['ip_address'] if kwargs['action_str'] == 'add': if 'vrf_name' in kwargs: index = 0 url = rest_urls['vrf_ip_helper_config'].format( kwargs['intf_name'], index, kwargs['vrf_name'], ip_li) data = { "openconfig-ip-helper:servers": { "server": [{ "vrf": str(kwargs['vrf_name']), "ip": str(ip_li), "config": { "vrf": str(kwargs['vrf_name']), "ip": str(ip_li) } }] } } if not config_rest(dut, http_method=cli_type, rest_url=url, json_data=data): return False else: index = 0 url = rest_urls['config_ip_helper_address'].format( kwargs['intf_name'], index) data = { "openconfig-ip-helper:servers": { "server": [{ "vrf": "default", "ip": str(ip_li), "config": { "vrf": "default", "ip": str(ip_li) } }] } } if not config_rest(dut, http_method=cli_type, rest_url=url, json_data=data): return False elif kwargs['action_str'] == 'remove': if 'vrf_name' in kwargs: index = 0 url = rest_urls['vrf_ip_helper_config'].format( kwargs['intf_name'], index, kwargs['vrf_name'], ip_li) if not delete_rest(dut, rest_url=url): return False else: index = 0 url = rest_urls['config_ip_helper_address'].format( kwargs['intf_name'], index) if not delete_rest(dut, rest_url=url): return False else: st.error("Required add or remove for command") return False elif all(key in kwargs for key in fwd_protocol_config_keys): if kwargs['action_str'] == 'add': url = rest_urls['ip_helper_config_ports'] data = { "openconfig-ip-helper:ports": [int(kwargs['protocol_or_port'])] } if not config_rest( dut, http_method=cli_type, rest_url=url, json_data=data): return False elif kwargs['action_str'] == 'remove': url = rest_urls['ip_helper_unconfig_ports'].format( int(kwargs['protocol_or_port'])) if not delete_rest(dut, rest_url=url): return False else: st.error("Required add or remove for command") return False elif 'rate_limit_val' in kwargs: url = rest_urls['ip_helper_rate_limit'] data = { "openconfig-ip-helper:incoming-rate-limit": int(kwargs['rate_limit_val']) } if not config_rest( dut, http_method=cli_type, rest_url=url, json_data=data): return False else: st.error("Required keys are not passed to configure IP helper") return False return True else: st.error("Unsupported CLI Type {}".format(cli_type)) return False
def config_port_qos_map_all(dut, qos_maps, cli_type=''): """ To configure port qos map for all types of mappings Author: Jagadish Chatrasi ([email protected]) :param dut: :type dut: :param qos_maps: :type qos_maps: :param cli_type: :type cli_type: """ qos_maps = make_list(qos_maps) cli_type = st.get_ui_type(dut, cli_type=cli_type) if cli_type == 'click': final_data = dict() temp_data = dict() for qos_map in qos_maps: if qos_map['port'] not in temp_data: temp_data[qos_map['port']] = {} if qos_map['map'] == 'dot1p_to_tc_map': temp_data[qos_map['port']].update( dot1p_to_tc_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'dscp_to_tc_map': temp_data[qos_map['port']].update( dscp_to_tc_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'pfc_to_queue_map': temp_data[qos_map['port']].update( pfc_to_queue_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_dot1p_map': temp_data[qos_map['port']].update( tc_to_dot1p_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_dscp_map': temp_data[qos_map['port']].update( tc_to_dscp_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_pg_map': temp_data[qos_map['port']].update( tc_to_pg_map="{}".format(qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_queue_map': temp_data[qos_map['port']].update( tc_to_queue_map="{}".format(qos_map['obj_name'])) else: st.error('Invalid map: {}'.format(qos_map['map'])) return False final_data['PORT_QOS_MAP'] = temp_data final_data = json.dumps(final_data) st.apply_json(dut, final_data) elif cli_type == 'klish': commands = list() for qos_map in qos_maps: intf_data = get_interface_number_from_name(qos_map['port']) commands.append('interface {} {}'.format(intf_data['type'], intf_data['number'])) if qos_map['map'] == 'dot1p_to_tc_map': commands.append('qos-map dot1p-tc {}'.format( qos_map['obj_name'])) elif qos_map['map'] == 'dscp_to_tc_map': commands.append('qos-map dscp-tc {}'.format( qos_map['obj_name'])) elif qos_map['map'] == 'pfc_to_queue_map': commands.append('qos-map pfc-priority-queue {}'.format( qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_dot1p_map': commands.append('qos-map tc-dot1p {}'.format( qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_dscp_map': commands.append('qos-map tc-dscp {}'.format( qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_pg_map': commands.append('qos-map tc-pg {}'.format(qos_map['obj_name'])) elif qos_map['map'] == 'tc_to_queue_map': commands.append('qos-map tc-queue {}'.format( qos_map['obj_name'])) else: st.error('Invalid map: {}'.format(qos_map['map'])) return False commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') for qos_map in qos_maps: url = rest_urls['port_qos_map_config'].format(qos_map['port']) if qos_map['map'] == 'dot1p_to_tc_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "dot1p-to-forwarding-group": qos_map['obj_name'] } } } elif qos_map['map'] == 'dscp_to_tc_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "dscp-to-forwarding-group": qos_map['obj_name'] } } } elif qos_map['map'] == 'pfc_to_queue_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "pfc-priority-to-queue": qos_map['obj_name'] } } } elif qos_map['map'] == 'tc_to_dot1p_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "forwarding-group-to-dot1p": qos_map['obj_name'] } } } elif qos_map['map'] == 'tc_to_dscp_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "forwarding-group-to-dscp": qos_map['obj_name'] } } } elif qos_map['map'] == 'tc_to_pg_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "forwarding-group-to-priority-group": qos_map['obj_name'] } } } elif qos_map['map'] == 'tc_to_queue_map': port_qos_map_data = { "openconfig-qos-maps-ext:interface-maps": { "config": { "forwarding-group-to-queue": qos_map['obj_name'] } } } else: st.error('Invalid map: {}'.format(qos_map['map'])) return False if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=port_qos_map_data): st.error("Failed configure PORT_QOS_MAP") return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def config_ecn(dut, status, profile, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) :param dut: :type dut: :param status: :type status: :param profile: :type profile: :return: :rtype: """ cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'klish': cli_type = 'rest-patch' ##Using OC-YANG even the cli_type is 'klish' because we don't have support to configure individual paramters. kwargs.pop('cli_type', None) data = kwargs if not data or not status or not profile: st.error( "Please provide ecn parameters to be configured. Mandatory are status on/off and profile name" ) return False if cli_type == 'click': command = "ecnconfig -p {} {} ".format(profile, status) command += ' '.join('-{} {}'.format(key, value) for key, value in data.items()) st.debug(command) st.config(dut, command) elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') if data.get('ecnmode'): url = rest_urls['wred_params_config'].format(profile) config_json = { "openconfig-qos-ext:wred-profile": [{ "name": profile, "config": { "name": profile, "ecn": data['ecnmode'].upper() } }] } if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=config_json): st.error( 'Failed to configure ECN: {} for WRED_PROFILE: {}'.format( data['ecnmode'], profile)) return False if data.get('gmax'): url = rest_urls['wred_green_max_threshold_config'].format(profile) config_json = { "openconfig-qos-ext:green-max-threshold": str(data['gmax']) } if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=config_json): st.error( 'Failed to configure the green_max_threshold: {} for WRED_PROFILE: {}' .format(data['gmax'], profile)) return False if data['gmin']: url = rest_urls['wred_green_min_threshold_config'].format(profile) config_json = { "openconfig-qos-ext:green-min-threshold": str(data['gmin']) } if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=config_json): st.error( 'Failed to configure the green_min_threshold: {} for WRED_PROFILE: {}' .format(data['gmin'], profile)) return False if data.get('gdrop'): url = rest_urls['wred_green_drop_probability_config'].format( profile) config_json = { "openconfig-qos-ext:green-drop-probability": str(data['gdrop']) } if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=config_json): st.error( 'Failed to configure the green_drop_probability: {} for WRED_PROFILE: {}' .format(data['gdrop'], profile)) return False if status: url = rest_urls['wred_green_enable_config'].format(profile) config_json = {"openconfig-qos-ext:wred-green-enable": True} if not config_rest( dut, rest_url=url, http_method=cli_type, json_data=config_json): st.error( 'Failed to configure the wred_green_enable for WRED_PROFILE: {}' .format(profile)) return False else: st.error("Unsupported CLI TYPE {}".format(cli_type)) return False return True
def config_tc_to_dscp_map(dut, obj_name, tc_to_dscp_map_dict, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) To map the tc to dscp :param dut: :type dut: :param obj_name: :type obj_name: :param tc_to_dscp_map_dict: :type dict: """ cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'click': final_data = dict() temp_data = dict() tc_to_dscp_map_dict = get_non_range_map_data_from_range_map_data( tc_to_dscp_map_dict) if not tc_to_dscp_map_dict or not obj_name: st.log( "Please provide traffic class to dscp map dict. For example - {'0':'0', '1':'1', ...} and Object name like 'AZURE'" ) return False else: temp_data[obj_name] = tc_to_dscp_map_dict final_data['TC_TO_DSCP_MAP'] = temp_data final_data = json.dumps(final_data) st.apply_json(dut, final_data) elif cli_type == 'klish': commands = list() commands.append('qos map tc-dscp {}'.format(obj_name)) for tc, dscp in tc_to_dscp_map_dict.items(): commands.append('traffic-class {} dscp {}'.format(tc, dscp)) commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: cli_type = 'rest-patch' rest_urls = st.get_datastore(dut, 'rest_urls') url = rest_urls['tc_dscp_map_config'].format(obj_name) tc_to_dscp_map_dict = get_non_range_map_data_from_range_map_data( tc_to_dscp_map_dict) maps_data = [{ "fwd-group": str(tc), "config": { "fwd-group": str(tc), "dscp": int(dscp) } } for tc, dscp in tc_to_dscp_map_dict.items()] tc_dscp_map_data = { "openconfig-qos-maps-ext:forwarding-group-dscp-map": [{ "name": obj_name, "config": { "name": obj_name }, "forwarding-group-dscp-map-entries": { "forwarding-group-dscp-map-entry": maps_data } }] } if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=tc_dscp_map_data): st.error("Failed to map TC to DSCP with data: {}".format( tc_to_dscp_map_dict)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def verify_thresholds(data=[]): max_threshold = 999999 var_delay = 2 opt_delay = 2 clear_wait = 8 final_wait = 20 mymode = "" family_list = crm_obj.crm_get_family_list(data.D1) for family in family_list: if family != 'all': (data.used_counter[family], data.free_counter[family]) = crm_obj.crm_get_resources_count( data.D1, family) data.resource_count_max[ family] = data.used_counter[family] + data.free_counter[family] st.log("verify_thresholds: {} used {} free {} max {}".format( family, data.used_counter[family], data.free_counter[family], data.resource_count_max[family])) ##################### USED ############################# for family in family_list: if family != 'all': crm_obj.set_crm_thresholds_type(data.D1, family=family, type="used") crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="high", value=max_threshold) crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="low", value=max_threshold) #show logs st.log("show log messages:") slog_obj.show_logging(data.D1, lines=50) # Clear Logs slog_obj.clear_logging(data.D1) st.log("configure Thresholds for used") for family in family_list: if family != 'all': hi_th = data.used_counter[family] - 1 if hi_th < 0: hi_th = 0 mymode = "high" if family in acl_family_list: mymode = "low" crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=hi_th) mymode = "low" if family in acl_family_list: mymode = "high" low_th = hi_th - 1 if low_th < 0: low_th = 0 #crm_obj.set_crm_thresholds_type(data.D1, family=family, type="used") crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=low_th) crm_obj.set_crm_thresholds_type(data.D1, family=family, type="used") st.wait(opt_delay) ## EXCEED st.wait(var_delay) ## EXCEED crm_obj.get_crm_resources(data.D1, "all") interface_obj.interface_shutdown(data.D1, data.dut_p1_interface, skip_verify=False) interface_obj.interface_shutdown(data.D1, data.dut_p2_interface, skip_verify=False) macapi.clear_mac(data.D1) crm_fdb_config_clear(data) st.wait(opt_delay) ## CLEAR # Restore interface_obj.interface_noshutdown(data.D1, data.dut_p1_interface, skip_verify=False) interface_obj.interface_noshutdown(data.D1, data.dut_p2_interface, skip_verify=False) st.wait(opt_delay) # delay is required to populate tables ##################### PERCENTAGE ############################# for family in family_list: if family != 'all': crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="high", value=max_threshold) crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="low", value=max_threshold) crm_fdb_send_traffic(data) st.log("Configure Thresholds for percentage") for family in family_list: if family != 'all' and family != 'snat' and family != 'dnat' and family != 'ipmc': hi_th = 0 mymode = "high" crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=hi_th) mymode = "low" low_th = 100 #crm_obj.set_crm_thresholds_type(data.D1, family=family, type="percentage") crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=low_th) crm_obj.set_crm_thresholds_type(data.D1, family=family, type="percentage") st.wait(opt_delay) ## EXCEED st.wait(var_delay) ## EXCEED crm_obj.get_crm_resources(data.D1, "all") crm_acl_unconfig(data) crm_acl_config(data) interface_obj.interface_shutdown(data.D1, data.dut_p1_interface, skip_verify=False) interface_obj.interface_shutdown(data.D1, data.dut_p2_interface, skip_verify=False) macapi.clear_mac(data.D1) crm_fdb_config_clear(data) st.wait(opt_delay) ## CLEAR st.wait(var_delay) ## EXCEED ##################### FREE ############################# crm_obj.get_crm_resources(data.D1, "all") for family in family_list: if family != 'all': crm_obj.set_crm_thresholds_type(data.D1, family=family, type="used") crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="high", value=max_threshold) crm_obj.set_crm_thresholds_value(data.D1, family=family, mode="low", value=max_threshold) st.wait(clear_wait) st.log("configure Thresholds for free") for family in family_list: if family != 'all': mymode = "high" hi_th = 0 crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=hi_th) mymode = "low" low_th = max_threshold #crm_obj.set_crm_thresholds_type(data.D1, family=family, type="free") crm_obj.set_crm_thresholds_value(data.D1, family=family, mode=mymode, value=low_th) crm_obj.set_crm_thresholds_type(data.D1, family=family, type="free") st.wait(opt_delay) ## EXCEED crm_obj.get_crm_resources(data.D1, "all") interface_obj.interface_noshutdown(data.D1, data.dut_p1_interface, skip_verify=False) interface_obj.interface_noshutdown(data.D1, data.dut_p2_interface, skip_verify=False) crm_fdb_send_traffic(data) # CLEAR TH st.wait(final_wait) ## CLEAR if not poll_wait(check_logging_result, 60, data): crm_obj.get_crm_resources(data.D1, "all") st.error('Failed to get threshold logs, CRM threshold tests failed')
def clear_qos_map_entries(dut, map_type, obj_name, maps_dict, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) To clear qos map entries :param dut: :type dut: :param map_type: :type map_type: :param obj_name: :type obj_name: :param maps_dict: :type maps_dict: """ cli_type = st.get_ui_type(dut, **kwargs) qos_clear = kwargs.get('qos_clear', False) if (not qos_clear) and cli_type == 'click': cli_type = 'klish' if cli_type == 'click': command = 'config qos clear' response = st.config(dut, command, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type == 'klish': commands = list() if map_type == 'dot1p_to_tc_map': commands.append('qos map dot1p-tc {}'.format(obj_name)) commands.extend( ['no dot1p {}'.format(map) for map in maps_dict.keys()]) elif map_type == 'dscp_to_tc_map': commands.append('qos map dscp-tc {}'.format(obj_name)) commands.extend( ['no dscp {}'.format(map) for map in maps_dict.keys()]) elif map_type == 'pfc_to_queue_map': commands.append('qos map pfc-priority-queue {}'.format(obj_name)) commands.extend( ['no pfc-priority {}'.format(map) for map in maps_dict.keys()]) elif map_type == 'tc_to_dot1p_map': commands.append('qos map tc-dot1p {}'.format(obj_name)) commands.extend([ 'no traffic-class {}'.format(map) for map in maps_dict.keys() ]) elif map_type == 'tc_to_dscp_map': commands.append('qos map tc-dscp {}'.format(obj_name)) commands.extend([ 'no traffic-class {}'.format(map) for map in maps_dict.keys() ]) elif map_type == 'tc_to_pg_map': commands.append('qos map tc-pg {}'.format(obj_name)) commands.extend([ 'no traffic-class {}'.format(map) for map in maps_dict.keys() ]) elif map_type == 'tc_to_queue_map': commands.append('qos map tc-queue {}'.format(obj_name)) commands.extend([ 'no traffic-class {}'.format(map) for map in maps_dict.keys() ]) else: st.error('Invalid map type: {}'.format(map_type)) return False if commands: commands.append('exit') response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') urls_map = { 'dot1p_to_tc_map': rest_urls['dot1p_tc_entry_config'], 'dscp_to_tc_map': rest_urls['dscp_tc_entry_config'], 'pfc_to_queue_map': rest_urls['pfc_priority_queue_entry_config'], 'tc_to_dot1p_map': rest_urls['tc_dot1p_entry_config'], 'tc_to_dscp_map': rest_urls['tc_dscp_entry_config'], 'tc_to_pg_map': rest_urls['tc_pg_entry_config'], 'tc_to_queue_map': rest_urls['tc_queue_entry_config'] } if map_type in urls_map: url = urls_map[map_type] else: st.error('Invalid map type: {}'.format(map_type)) return False for map in maps_dict.keys(): if not delete_rest(dut, rest_url=url.format(obj_name, map)): st.error("Failed to remove entry {} for {}".format( map, map_type)) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def crm_ft_test_all(): data = SpyTestDict() data.my_dut_list = st.get_dut_names() if len(data.my_dut_list) < 1: st.error("DUT Unavailable") return False data.D1 = data.my_dut_list[0] data.fdb_count = 0 data.crm_polling_interval = 1 crm_obj.set_crm_clear_config(data.D1) crm_obj.set_crm_polling_interval(data.D1, data.crm_polling_interval) data.af_ipv4 = "ipv4" data.af_ipv6 = "ipv6" data.local_asn = 65001 data.router_id_1 = "110.110.110.1" data.router_id_2 = "120.120.120.1" data.remote_asn = 65007 data.loopback_1 = "66.66.66.66" data.loopback_2 = "77.77.77.77" data.tg_bgp6_route_prfix = "1001::1" data.tg_bgp6_routes = '1100' data.shell_sonic = 'vtysh' data.used_counter = dict() data.free_counter = dict() data.resource_count_max = dict() data.thresh_percent_low = dict() data.thresh_percent_high = dict() data.thresh_used_low = dict() data.thresh_used_high = dict() data.thresh_free_low = dict() data.thresh_free_high = dict() data.cur_thresh_type = dict() data.cli_type = st.get_ui_type(data.D1) family_list = crm_obj.crm_get_family_list(data.D1) if base_obj.get_hwsku( vars.D1).lower() in vars.constants[vars.D1]["TH3_PLATFORMS"]: for family in family_list: if family in ['dnat', 'snat']: family_list.remove(family) st.log("Verify CRM polling interval:") st.wait(data.crm_polling_interval) if not crm_obj.verify_crm_summary( data.D1, pollinginterval=data.crm_polling_interval): st.error('polling interval did not match with the configured value') return False st.log("Calculate Max resources:") for family in family_list: if family != 'acl_group_counter' and family != 'acl_group_entry' and family != 'all': (data.used_counter[family], data.free_counter[family]) = crm_obj.crm_get_resources_count( data.D1, family) data.resource_count_max[ family] = data.used_counter[family] + data.free_counter[family] for family in family_list: if family != 'acl_group_counter' and family != 'acl_group_entry' and family != 'all': st.log('{} {}/{}/{}'.format(family, data.used_counter[family], data.free_counter[family], data.resource_count_max[family])) data.routing_subnet = 24 data.dut_p1 = vars.T1D1P1 data.dut_p1_interface = vars.D1T1P1 data.dut_p1_ipaddr = '7.7.7.1' data.dut_p1_ipaddr_subnet = 24 data.dut_p1_ipaddr_peer = '7.7.7.2' data.adv_routes_cnt = 1000 data.adv_routes_prefix = "100.0.0.0" data.neighbor_cnt = 100 data.dut_p2 = vars.T1D1P2 data.dut_p2_interface = vars.D1T1P2 data.dut_p2_ipaddr = '2001::1' data.dut_p2_ipaddr_subnet = 64 data.dut_p2_ipaddr_peer = '2001::2' data.adv_routes_cnt_v6 = 1000 data.adv_routes_prefix_v6 = '2121::0' data.neighbor_cnt_v6 = 100 data.vlanid = 777 st.log('crminfo: VLAN ID {}'.format(data.vlanid)) crm_fdb_config(data) crm_acl_config(data) crm_bgp_config_v4(data.local_asn, data.remote_asn, data) crm_ecmp_config(data) if st.is_feature_supported("config-ipv6-command", data.D1): crm_bgp_config_v6(data.local_asn, data.remote_asn, data) verify_thresholds(data) # debug trace crm_obj.get_crm_resources(data.D1, "all") global crm_test_status crm_test_status = True
def clear_qos_map_table(dut, qos_maps, **kwargs): """ Author: Jagadish Chatrasi ([email protected]) To clear qos map table :param dut: :type dut: :param qos_maps: :type qos_maps: """ cli_type = st.get_ui_type(dut, **kwargs) qos_maps = make_list(qos_maps) qos_clear = kwargs.get('qos_clear', False) skip_error = kwargs.get('skip_error', False) error_msg = kwargs.get('error_msg', False) errors = make_list(error_msg) if error_msg else errors_list if (not qos_clear) and cli_type == 'click': cli_type = 'klish' if cli_type == 'click': command = 'config qos clear' response = st.config(dut, command, type=cli_type, skip_error_check=skip_error) if any(error.lower() in response.lower() for error in errors): st.error("The response is: {}".format(response)) return False elif cli_type == 'klish': commands = list() for qos_map in qos_maps: commands_map = { 'dot1p_to_tc_map': "no qos map dot1p-tc {}", 'dscp_to_tc_map': "no qos map dscp-tc {}", 'pfc_to_queue_map': "no qos map pfc-priority-queue {}", 'tc_to_dot1p_map': "no qos map tc-dot1p {}", 'tc_to_dscp_map': "no qos map tc-dscp {}", 'tc_to_pg_map': "no qos map tc-pg {}", 'tc_to_queue_map': "no qos map tc-queue {}" } if qos_map['map'] in commands_map: commands.append(commands_map[qos_map['map']].format( qos_map['obj_name'])) else: st.error('Invalid map type: {}'.format(qos_map['map'])) return False response = st.config(dut, commands, type=cli_type, skip_error_check=skip_error) if any(error.lower() in response.lower() for error in errors): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') for qos_map in qos_maps: urls_map = { 'dot1p_to_tc_map': rest_urls['dot1p_tc_table_config'], 'dscp_to_tc_map': rest_urls['dscp_tc_table_config'], 'pfc_to_queue_map': rest_urls['pfc_priority_queue_table_config'], 'tc_to_dot1p_map': rest_urls['tc_dot1p_table_config'], 'tc_to_dscp_map': rest_urls['tc_dscp_table_config'], 'tc_to_pg_map': rest_urls['tc_pg_table_config'], 'tc_to_queue_map': rest_urls['tc_queue_table_config'] } if qos_map['map'] in urls_map: url = urls_map[qos_map['map']].format(qos_map['obj_name']) else: st.error('Invalid map type: {}'.format(qos_map['map'])) return False if skip_error: out = delete_rest(dut, rest_url=url, get_response=True) error_resp = str(out['output']).lower() if ((not rest_status(int(out['status']))) and any(error.lower() in error_resp for error in errors)): st.error("Failed clear {} table: {}".format( qos_map['map'], qos_map['obj_name'])) return False else: if not delete_rest(dut, rest_url=url): st.error("Failed clear {} table: {}".format( qos_map['map'], qos_map['obj_name'])) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def verify_vrrpv3(dut, **kwargs): """ Author:[email protected] :param interface: :type string :param vrid: :type string or integer :param version: :type string or interger :param vip: :type virtual-ip in string :param vmac: :type virtual-mac as string :param state: :type vrrp state as string :param config_prio: :type configured vrrp priority as integer or string :param current_prio: :type Current vrrp priority as integer or string :param adv_interval: :type advertrisement interval as integer or string :param track_interface_list: :type List of uplink track interfaces :param track_priority_list :type List of priorities for uplink tracking ports :param track_state_list :type List of states for uplink tracking ports :param preempt :type preempt state as string usage: verify_vrrpv3(dut1,vrid='1',interface='Vlan1000',state='Master',vip='10.0.0.10',track_interface_list=['Vlan10'],track_state_list=['Up'], track_priority_list=['10'],adv_interval=1,vmac='0000.5e00.0201',config_prio=90,current_prio=100,version=3,preempt='disabled') """ if 'interface' not in kwargs or 'vrid' not in kwargs: st.error("Mandatory arguments \'interface\' or \'vrid \' missing") return False cli_type = kwargs.get("cli_type", st.get_ui_type(dut)) if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' if cli_type == 'click': cmd = "show vrrp6 {} {}".format(kwargs['interface'], kwargs['vrid']) else: cmd = "show vrrp6 interface {} vrid {}".format(kwargs['interface'], kwargs['vrid']) parsed_output = st.show(dut, cmd, type=cli_type) if len(parsed_output) == 0: st.error("OUTPUT is Empty") return False if 'return_output' in kwargs: return parsed_output for each in kwargs.keys(): match = {each: kwargs[each]} entries = filter_and_select(parsed_output, None, match) if not entries: st.error( "Match not found for {}: Expected - {} Actual - {} ".format( each, kwargs[each], parsed_output[0][each])) return False return True
def clear_port_qos_map_all(dut, qos_maps, **kwargs): """ To clear port qos map for all types of mappings Author: Jagadish Chatrasi ([email protected]) :param dut: :type dut: :param qos_maps: :type qos_maps: :param cli_type: :type cli_type: """ qos_maps = make_list(qos_maps) cli_type = st.get_ui_type(dut, **kwargs) qos_clear = kwargs.get('qos_clear', False) if (not qos_clear) and cli_type == 'click': cli_type = 'klish' if cli_type == 'click': command = 'config qos clear' response = st.config(dut, command, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type == 'klish': commands = list() for qos_map in qos_maps: intf_data = get_interface_number_from_name(qos_map['port']) commands_map = { 'dot1p_to_tc_map': "no qos-map dot1p-tc", 'dscp_to_tc_map': "no qos-map dscp-tc", 'pfc_to_queue_map': "no qos-map pfc-priority-queue", 'tc_to_dot1p_map': "no qos-map tc-dot1p", 'tc_to_dscp_map': "no qos-map tc-dscp", 'tc_to_pg_map': "no qos-map tc-pg", 'tc_to_queue_map': "no qos-map tc-queue" } if qos_map['map'] in commands_map: commands.append('interface {} {}'.format( intf_data['type'], intf_data['number'])) commands.append(commands_map[qos_map['map']]) commands.append('exit') else: st.error('Invalid map type: {}'.format(qos_map['map'])) return False if commands: response = st.config(dut, commands, type=cli_type) if any(error in response.lower() for error in errors_list): st.error("The response is: {}".format(response)) return False elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') for qos_map in qos_maps: urls_map = { 'dot1p_to_tc_map': rest_urls['port_qos_dot1p_tc_map_config'], 'dscp_to_tc_map': rest_urls['port_qos_dscp_tc_map_config'], 'pfc_to_queue_map': rest_urls['port_qos_pfc_queue_map_config'], 'tc_to_dot1p_map': rest_urls['port_qos_tc_dot1p_map_config'], 'tc_to_dscp_map': rest_urls['port_qos_tc_dscp_map_config'], 'tc_to_pg_map': rest_urls['port_qos_tc_pg_map_config'], 'tc_to_queue_map': rest_urls['port_qos_tc_queue_map_config'] } if qos_map['map'] in urls_map: url = urls_map[qos_map['map']].format(qos_map['port']) else: st.error('Invalid map type: {}'.format(qos_map['map'])) return False if not delete_rest(dut, rest_url=url): st.error("Failed clear {} table on port: {}".format( qos_map['map'], qos_map['port'])) return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return True
def verify_sag(dut, **kwargs): ''' Author: [email protected] Verify sag output - show <ip|ipv6> static-anycast-gateway :param dut: :param kwargs: Parameters can be ['ip_type'] ['mac', 'status', 'total', 'total_admin', 'total_oper'] ['gateway', 'interface', 'mask', 'vrf', 'admin', 'oper'] :return: Usage: verify_sag(dut1, total=10, mac='00:00:00:ba:ba:12', gateway='13.3.3.3', interface='Vlan20') verify_sag(dut1, status='enable', gateway='2001::15', ip_type='ipv6') ''' ret_val = True cli_type = kwargs.get('cli_type', st.get_ui_type(dut)) cli_type = "klish" if cli_type in ["rest-put", "rest-patch"] else cli_type ip_type = kwargs.get('ip_type', 'ip') kwargs.pop('ip_type', None) cmd = 'show {} static-anycast-gateway'.format(ip_type) output = st.show(dut, cmd, type=cli_type) if len(output) == 0: st.error("Output is Empty") return False if "return_output" in kwargs: return output list1 = ['mac', 'status', 'total', 'total_admin', 'total_oper'] list2 = ['gateway', 'interface', 'mask', 'vrf', 'admin', 'oper'] match = {} status_dict = {'disabled': 'disable', 'enabled': 'enable'} mac_dict = {'Not': ''} for k in list1: if kwargs.get(k, None) != None: match[k] = kwargs[k] if cli_type == 'klish': if kwargs.get('status', None) != None: if match['status'] in status_dict.keys(): match['status'] = status_dict[match['status']] if kwargs.get('mac', None) != None: if match['mac'] in mac_dict.keys(): match['mac'] = mac_dict[match['mac']] entries = filter_and_select(output, None, match=match) if match != {}: if entries == []: ret_val = False st.error("Match NOT FOUND for {}.".format(match)) else: st.log("Match FOUND for {}.".format(match)) # API can be enhanced to accept the list for all items in list2. match = {} for k in list2: if kwargs.get(k, None) != None: match[k] = kwargs[k] entries = filter_and_select(output, None, match=match) if match != {}: if entries == []: ret_val = False st.error("Match NOT FOUND for {}.".format(match)) else: st.log("Match FOUND for {}.".format(match)) return ret_val
def show_qos_map_table(dut, type, obj_name='', **kwargs): """ To show qos map tables Author: Jagadish Chatrasi ([email protected]) :param dut: :type dut: :param type: :type type: :param obj_name: :type obj_name: """ cli_type = st.get_ui_type(dut, **kwargs) cli_type = 'klish' if cli_type == 'click' else cli_type if cli_type == 'klish': if type == 'dot1p_to_tc_map': command = 'show qos map dot1p-tc {}'.format( obj_name) if obj_name else 'show qos map dot1p-tc' elif type == 'dscp_to_tc_map': command = 'show qos map dscp-tc {}'.format( obj_name) if obj_name else 'show qos map dscp-tc' elif type == 'pfc_to_queue_map': command = 'show qos map pfc-priority-queue {}'.format( obj_name) if obj_name else 'show qos map pfc-priority-queue' elif type == 'tc_to_dot1p_map': command = 'show qos map tc-dot1p {}'.format( obj_name) if obj_name else 'show qos map tc-dot1p' elif type == 'tc_to_dscp_map': command = 'show qos map tc-dscp {}'.format( obj_name) if obj_name else 'show qos map tc-dscp' elif type == 'tc_to_pg_map': command = 'show qos map tc-pg {}'.format( obj_name) if obj_name else 'show qos map tc-pg' elif type == 'tc_to_queue_map': command = 'show qos map tc-queue {}'.format( obj_name) if obj_name else 'show qos map tc-queue' else: st.error("Invalid type: {}".format(type)) return False output = st.show(dut, command, type=cli_type) elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') key_maps = { "dot1p_to_tc_map": "openconfig-qos-maps-ext:dot1p-map", "dscp_to_tc_map": "openconfig-qos-maps-ext:dscp-map", "pfc_to_queue_map": "openconfig-qos-maps-ext:pfc-priority-queue-map", "tc_to_dot1p_map": "openconfig-qos-maps-ext:forwarding-group-dot1p-map", "tc_to_dscp_map": "openconfig-qos-maps-ext:forwarding-group-dscp-map", "tc_to_pg_map": "openconfig-qos-maps-ext:forwarding-group-priority-group-map", "tc_to_queue_map": "openconfig-qos-maps-ext:forwarding-group-queue-map" } if type == 'dot1p_to_tc_map': url = rest_urls['dot1p_tc_table_config'].format( obj_name ) if obj_name else rest_urls['dot1p_tc_table_all_config'] elif type == 'dscp_to_tc_map': url = rest_urls['dscp_tc_table_config'].format( obj_name ) if obj_name else rest_urls['dscp_tc_table_all_config'] elif type == 'pfc_to_queue_map': url = rest_urls['pfc_priority_queue_table_config'].format( obj_name ) if obj_name else rest_urls['pfc_priority_queue_table_all_config'] elif type == 'tc_to_dot1p_map': url = rest_urls['tc_dot1p_table_config'].format( obj_name ) if obj_name else rest_urls['tc_dot1p_table_all_config'] elif type == 'tc_to_dscp_map': url = rest_urls['tc_dscp_table_config'].format( obj_name ) if obj_name else rest_urls['tc_dscp_table_all_config'] elif type == 'tc_to_pg_map': url = rest_urls['tc_pg_table_config'].format( obj_name) if obj_name else rest_urls['tc_pg_table_all_config'] elif type == 'tc_to_queue_map': url = rest_urls['tc_queue_table_config'].format( obj_name ) if obj_name else rest_urls['tc_queue_table_all_config'] else: st.error("Invalid type: {}".format(type)) return False total_output = get_rest(dut, rest_url=url) if total_output['output']: output = _get_rest_qos_map_output( total_output['output'][key_maps[type]], type) else: return False else: st.error("Unsupported CLI Type: {}".format(cli_type)) return False return output
def test_ft_vlan_save_config_warm_and_fast_reboot(): ''' Author: Sai Durga <*****@*****.**> This script covers the below scenarios ft_max_vlan_save_reload Verify the save and reload functionality with max vlan configuration. ft_max_vlan_fast_reload Verify the max vlan configuration is retained after fast-reboot. FtOpSoSwVlFn026 Verify that VLAN is present and traffic is not disturbed during and after warm reboot FtOpSoSysFRFn005 Verify the Fast-Reboot must disrupt control plane not more than 90 seconds (from sonic test suite -configuration tests) ft_reboot_fdb_fast_reboot Verify that the FDB entry is retained after fast reboot. ''' status = True msg_id = "max_vlan_config_retain_after_save_fast_warm_reboot" vlan_module_epilog() vlan_module_config(config='yes') st.log("Device name is : {}".format(sc_data.dut_platform)) if sc_data.dut_platform and sc_data.dut_platform.lower( ) not in sc_data.warm_reboot_supported_platforms: st.error("Warm-Reboot is not supported for this platform ({})".format( sc_data.dut_platform)) st.report_unsupported('test_case_unsupported') st.log("Saving the MAX VLAN config on the device") reboot.config_save(vars.D1) st.log("Performing reboot and checking the VLAN configuration") st.reboot(vars.D1) st.log("Checking VLAN config after reboot") max_vlan_verify() st.log( "Sending traffic with 100 MAC,Checking FDB table updated with 100 MAC addresses and performing reboot and checking the VLAN configuration" ) tg.tg_traffic_control(action="reset", port_handle=tg_handler["tg_ph_list"]) tg_1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"], mode='create', length_mode='fixed', frame_size=72, mac_src='00:01:00:00:00:01', mac_src_step='00:00:00:00:00:01', mac_src_mode='increment', mac_src_count=sc_data.mac_count, mac_dst='00:02:00:00:00:02', rate_pps=2000, l2_encap='ethernet_ii_vlan', vlan="enable", vlan_id=sc_data.vlan, transmit_mode='continuous') tg_info['tg1_stream_id'] = tg_1['stream_id'] tg.tg_traffic_control(action='run', stream_handle=tg_info['tg1_stream_id']) st.wait(2) tg.tg_traffic_control(action='stop', stream_handle=tg_info['tg1_stream_id']) if not poll_wait(mac_verify, 300): st.error("mac_address_verification_fail") st.log("Performing fast-reboot and checking the VLAN configuration") st.reboot(vars.D1, 'fast') st.log("Checking VLAN config after fast-reboot") max_vlan_verify() st.log("Sending traffic after fast reboot and checking the FDB table") tg.tg_traffic_control(action='run', stream_handle=tg_info['tg1_stream_id']) st.wait(2) tg.tg_traffic_control(action='stop', stream_handle=tg_info['tg1_stream_id']) if not poll_wait(mac_verify, 300): st.error("mac_address_verification_fail") st.log("Performing warm reboot and checking the traffic") ifapi.clear_interface_counters(vars.D1) st.wait(2) ifapi.show_interface_counters_all(vars.D1) st.wait(2) tg.tg_traffic_control(action='run', stream_handle=tg_info['tg1_stream_id']) st.wait(2) st.reboot(vars.D1, 'warm') st.log("Checking VLAN config after warm-reboot") max_vlan_verify() tg.tg_traffic_control(action='stop', stream_handle=tg_info['tg1_stream_id']) st.log("Checking traffic is forwarded without any loss after warm-reboot") st.log("Fetching IXIA statistics") st.wait(2) ifapi.show_interface_counters_all(vars.D1) stats_tg1 = tgapi.get_traffic_stats(tg, mode="aggregate", port_handle=tg_handler["tg_ph_1"]) total_tx_tg1 = stats_tg1.tx.total_bytes stats_tg2 = tgapi.get_traffic_stats(tg, mode="aggregate", port_handle=tg_handler["tg_ph_2"]) total_rx_tg2 = stats_tg2.rx.total_bytes percentage_95_total_tx_tg1 = (95 * int(total_tx_tg1)) / 100 st.log("###############") st.log("Sent bytes: {} and Received bytes : {}".format( percentage_95_total_tx_tg1, total_rx_tg2)) st.log("##############") if not int(percentage_95_total_tx_tg1) <= int(total_rx_tg2): st.report_fail("traffic_transmission_failed", vars.T1D1P1) report_result(status, msg_id)
def config(dut, **kwargs): """ Add/Delete username with password and role to the device. Author : Prudvi Mangadu ([email protected]) :param :dut: :param :username: :param :password: :param :role: admin | operator :param :group: :param :cli_type: click | klish :param :no_form: 0[False] | 1[True] :Usage: config(vars.D1, username='******', password='******', role='operator', cli_type='kilsh') config(vars.D1, username='******', cli_type='kilsh', no_form=True) config(vars.D1, username='******', password='******', role='admin', cli_type='click', no_form=0) config(vars.D1, username='******', password_update='test1234', cli_type='click', no_form=0) config(vars.D1, group='admin_test', cli_type='click', no_form=0) config(vars.D1, group='admin_test', cli_type='click', no_form=1) config(vars.D1, username='******', password='******', role='admin', cli_type='click', no_form=1) """ cli_type = kwargs.get("cli_type", "klish") no_form = kwargs.get("no_form", False) if cli_type == "click": if not no_form: if kwargs.get('group'): st.config(dut, "groupadd {}".format(kwargs['group'])) if kwargs.get('username'): command = "useradd {} -m".format(kwargs['username']) if kwargs.get('role'): command += " -g {}".format(kwargs['role']) st.config(dut, command) if kwargs.get('username') and kwargs.get('password'): st.change_passwd(dut, kwargs['username'], kwargs['password']) if kwargs.get('username') and kwargs.get('append_role'): st.config( dut, "usermod -aG {} {}".format(kwargs['append_role'], kwargs['username'])) else: if kwargs.get('username') and kwargs.get('role'): st.config( dut, "gpasswd -d {} {}".format(kwargs['username'], kwargs['role'])) if kwargs.get('group'): st.config(dut, "groupdel {}".format(kwargs['group'])) if kwargs.get('username'): st.config(dut, "userdel {} -r".format(kwargs['username'])) elif cli_type == "klish": if not kwargs.get('username'): st.error("Mandatory parameter 'username' is missing") if not no_form: if not kwargs.get("password") and not kwargs.get('role'): st.error( "Mandatory parameter 'password' and 'role' is missing") return False command = "username {} password {} role {}".format( kwargs['username'], kwargs['password'], kwargs['role']) if no_form: command = "no username {} ".format(kwargs['username']) st.config(dut, command, type=cli_type, skip_error_check=True) else: return False return True
def test_ft_stormcontrol_portchannel_intf(): status = 1 msg_id = "storm_control_portchannel_verification_successful" portchannel_name = 'PortChannel13' vlan_info = [{ "dut": [vars.D2], "vlan_id": sc_data.vlan, "tagged": [vars.D2T1P1, vars.D2T1P2, portchannel_name] }] portchannel_interfaces_dut1 = [vars.D1D2P1, vars.D1D2P2] portchannel_interfaces_dut2 = [vars.D2D1P1, vars.D2D1P2] portchannel.config_portchannel(vars.D1, vars.D2, portchannel_name, portchannel_interfaces_dut1, portchannel_interfaces_dut2, config="add", thread=True) vlan.add_vlan_member(vars.D1, sc_data.vlan, portchannel_name, tagging_mode=True, cli_type=sc_data.cli_type) vlan.create_vlan_and_add_members(vlan_info, cli_type=sc_data.cli_type) st.log( "Verifying whether stormcontrol config can be applied on portchannel {} interfaces" .format(portchannel_name)) if scapi.config(vars.D1, type="broadcast", action="add", interface_name=portchannel_name, rate=sc_data.kbps, skip_error_check=True, cli_type="click"): st.error( "storm-control config can be applied on portchannel interface") status = 0 else: st.log( "storm-control config cannot be applied on portchannel interface.") if status: st.report_tc_pass('ft_stormcontrol_neg_config_vlan_portchannel', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_neg_config_vlan_portchannel', 'test_case_failed') status = 1 st.log("configuring bum stormcontrol on portchannel interfaces") scapi.config(vars.D1, type="broadcast", action="del", interface_name=vars.D1T1P1, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D1, type="broadcast", action="del", interface_name=vars.D1T1P2, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D2, type="broadcast", action="add", interface_name=vars.D2D1P1, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D2, type="broadcast", action="add", interface_name=vars.D2D1P2, bits_per_sec=sc_data.kbps, cli_type="click") verify_bum_traffic_mode('broadcast', tg_info['tg1_stream_id'], skip_traffic_verify=True) st.log("Clearing interface counters") ifapi.clear_interface_counters(vars.D2) tg.tg_traffic_control(action='run', stream_handle=tg_info['tg1_stream_id'], duration=10) st.wait(sc_data.wait_stream_run) st.log("Stopping of traffic from TGen to get interface counters") tg.tg_traffic_control(action='stop', stream_handle=tg_info['tg1_stream_id']) st.wait(sc_data.wait_for_stats) tg_1_stats = tgapi.get_traffic_stats(tg, mode='aggregate', port_handle=tg_handler["tg_ph_1"]) tg_3_stats = tgapi.get_traffic_stats(tg, mode='aggregate', port_handle=tg_handler["tg_ph_3"]) counter = tg_3_stats.rx.total_packets counter2 = tg_1_stats.tx.total_packets try: time = int(counter2 / sc_data.rate_pps) counters_avg = counter / time except: counters_avg = 0 st.log("Average of counters are : {}".format(counters_avg)) st.log("Higher packet count value is : {}".format( sc_data.higher_pkt_count)) st.log("Lower packet count value is : {}".format(sc_data.lower_pkt_count)) st.log("value of status is : {}".format(status)) if counters_avg > sc_data.higher_pkt_count or counters_avg < sc_data.lower_pkt_count: st.error("storm control traffic verification failed") status = 0 if status: st.report_tc_pass('ft_stormcontrol_portchannel_intf', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_portchannel_intf', 'test_case_failed') status = 1 st.log("Configuring stormcontrol without providing bps value") if scapi.config(vars.D1, type="broadcast", action="add", interface_name=vars.D1T1P1, skip_error_check=True, cli_type="click"): st.error("Storm-control config is accepting not throwing any error") status = 0 else: st.log("Config is not accepted and thrown an error") if status: st.report_tc_pass('ft_stormcontrol_neg_config_without_bpsvalue', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_neg_config_without_bpsvalue', 'test_case_failed') status = 1 st.log("unconfiguring of bum stormcontrol type by providing bps value") if scapi.config(vars.D1, type="broadcast", action="del", interface_name=vars.D1T1P1, rate=sc_data.kbps, skip_error_check=True, cli_type="click"): st.error("Storm-control config is removed and not throwing any error") status = 0 else: st.log("Config is not accepted and thrown an error") if status: st.report_tc_pass('ft_stormcontrol_neg_unconfig_with_bpsvalue', 'test_case_passed') else: st.report_tc_fail('ft_stormcontrol_neg_unconfig_with_bpsvalue', 'test_case_failed') st.log("Back to module config") scapi.config(vars.D2, type="broadcast", action="del", interface_name=vars.D2D1P1, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D2, type="broadcast", action="del", interface_name=vars.D2D1P2, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D1, type="broadcast", action="add", interface_name=vars.D1T1P1, bits_per_sec=sc_data.kbps, cli_type="click") scapi.config(vars.D1, type="broadcast", action="add", interface_name=vars.D1T1P2, bits_per_sec=sc_data.kbps, cli_type="click") st.log( "Unconfiguring portchannel config in both devices and only vlan configuration in device2" ) vlan.clear_vlan_configuration(vars.D2, cli_type=sc_data.cli_type) vlan.delete_vlan_member(vars.D1, sc_data.vlan, portchannel_name, cli_type=sc_data.cli_type) portchannel.clear_portchannel_configuration(st.get_dut_names(), thread=True) if not status: msg_id = "storm_control_portchannel_verification_failed" report_result(status, msg_id)
def sched_verify_queue_rate_ratio_dwrr(q_priority_1, percent_1, q_priority_2, percent_2): num_of_iterations = 5 bcm_ce = scheduling_data.pmap_details[vars.D1D2P1] try: for i in range(0, num_of_iterations): st.banner("Iteration: {}".format(i)) asicapi.clear_counters(vars.D1) asicapi.dump_counters(vars.D1, bcm_ce) st.wait(5, "Wait till rate interval") output = asicapi.get_counters(vars.D1, bcm_ce) cntr_uc_perq_byte_1 = "UC_PERQ_BYTE({}).{}".format( q_priority_1, bcm_ce) cntr_uc_perq_byte_2 = "UC_PERQ_BYTE({}).{}".format( q_priority_2, bcm_ce) st.debug("cntr_uc_perq_byte_1 = {}".format(cntr_uc_perq_byte_1)) st.debug("cntr_uc_perq_byte_2 = {}".format(cntr_uc_perq_byte_2)) queue_tx_rate_1 = filter_and_select(output, ['time'], {'key': cntr_uc_perq_byte_1}) queue_tx_rate_2 = filter_and_select(output, ['time'], {'key': cntr_uc_perq_byte_2}) if not (queue_tx_rate_1 and queue_tx_rate_1[0]['time'] and queue_tx_rate_2 and queue_tx_rate_2[0]['time']): st.debug('Actual Queue rate for Queue-{}: {}'.format( q_priority_1, queue_tx_rate_1)) st.debug('Actual Queue rate for Queue-{}: {}'.format( q_priority_2, queue_tx_rate_2)) st.debug('Output is: {}'.format(output)) st.debug("bcm_ce: {}".format(bcm_ce)) continue queue_tx_rate_1 = int(queue_tx_rate_1[0]['time'].replace( ',', '').replace('/s', '')) queue_tx_rate_2 = int(queue_tx_rate_2[0]['time'].replace( ',', '').replace('/s', '')) st.debug("Queue-{} rate:{}".format(q_priority_1, queue_tx_rate_1)) st.debug("Queue-{} rate:{}".format(q_priority_2, queue_tx_rate_2)) result_1 = False result_2 = False if not (queue_tx_rate_1 and queue_tx_rate_2): continue actual_ratio_1 = int( (queue_tx_rate_1 * 100) / (queue_tx_rate_1 + queue_tx_rate_2)) actual_ratio_2 = int( (queue_tx_rate_2 * 100) / (queue_tx_rate_1 + queue_tx_rate_2)) diff_rate_1 = abs(actual_ratio_1 - percent_1) diff_rate_2 = abs(actual_ratio_2 - percent_2) st.debug("The actual ratio of Queue: {} is {}".format( q_priority_1, actual_ratio_1)) st.debug("The actual ratio of Queue: {} is {}".format( q_priority_2, actual_ratio_2)) st.debug("The given ratio of Queue: {} is {}".format( q_priority_1, percent_1)) st.debug("The given ratio of Queue: {} is {}".format( q_priority_2, percent_2)) st.debug("diff_1:{}".format(diff_rate_1)) st.debug("diff_2:{}".format(diff_rate_2)) if diff_rate_1 <= scheduling_data.rate_tolerance: result_1 = True if diff_rate_2 <= scheduling_data.rate_tolerance: result_2 = True if result_1 and result_2: return True return False except Exception as e: st.error('Exception occurred is: {}'.format(e)) return False