def increment_ip_addr(ipaddr, mask): s = '' if ipaddr.find('.') != -1: if mask == 31: valid_option, s = ipfeature.increment_ip_addr( ipaddr + '/' + str(mask), "host") else: valid_option, s = ipfeature.increment_ip_addr( ipaddr + '/' + str(mask), "network") s = s.split('/')[0] return valid_option, s valid_option = True if len(re.split('::', ipaddr)) == 2: cnt = 8 - len(re.split(':', ipaddr)) pattern = ':0' + ':0' * cnt + ':' ipaddr = re.sub(r'::', pattern, ipaddr) ip_split = re.split(':', ipaddr) iphex = [] i = 0 while i < 8: ip_split[i] = '0x' + ip_split[i] iphex.append('0x0') i = i + 1 revmask = 128 - mask iphex[7 - revmask / 16] = str(hex(pow(2, revmask % 16))) # Add 2 IP6 Addresses i = 7 ans = [] carry = 0 while i >= 0: sum = (int(ip_split[i], 0) + int(iphex[i], 0) + carry) carry = 0 if sum >= 0x10000: sum = sum % 0x10000 carry = 1 ans.append(':') ans.append(hex(sum)[2:]) i = i - 1 ans.reverse() s = s.join(ans) s = s[:-1] return valid_option, s
def test_ft_verify_interfaces_order(): ''' @author: Ramprakash Reddy ([email protected]) ipv4_intf_order : Verify order of interfaces in "show ip interfaces" ipv6_intf_order : Verify order of interfaces in "show ipv6 interfaces' Verify order of interfaces in "show ip/ipv6 interfaces" in sorted order or not :return: ''' flag = 1 st.log( "This test is to ensure that interfaces are listed in sorted order by 'interface name' in 'show ip/ipv6 " "interfaces'") free_ports = st.get_free_ports(vars.D1) if len(free_ports) < data.no_of_ports: data.no_of_ports = len(free_ports) req_ports = random.sample(free_ports, data.no_of_ports) ipv4_addr = data.ip4_addr[11] + '/' + data.ipv4_mask ipv6_addr = data.ip6_addr[0] + '/' + data.ipv6_mask intf_list = [] for i in range(int(math.ceil(float(data.no_of_ports) / 2))): _, ipv4_addr = ipfeature.increment_ip_addr(ipv4_addr, "network") ipfeature.config_ip_addr_interface(vars.D1, interface_name=req_ports[i], ip_address=ipv4_addr.split('/')[0], subnet=data.ipv4_mask, family="ipv4") for i in range(int(math.floor(float(data.no_of_ports) / 2))): _, ipv6_addr = ipfeature.increment_ip_addr(ipv6_addr, "network", family="ipv6") ipfeature.config_ip_addr_interface( vars.D1, interface_name=req_ports[ i + int(math.ceil(float(data.no_of_ports) / 2))], ip_address=ipv6_addr.split('/')[0], subnet=data.ipv6_mask, family="ipv6") output = ipfeature.get_interface_ip_address(vars.D1) for each in output: intf_list.append(each['interface']) temp = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [temp(c) for c in re.split('([0-9]+)', key)] intf_list_sorted = sorted(intf_list, key=alphanum_key) if intf_list == intf_list_sorted: st.log("Ipv4 interfaces are in sorted order") else: st.error("Ipv4 interfaces are not in soretd order") flag = 0 del intf_list[:] del intf_list_sorted[:] output = ipfeature.get_interface_ip_address(vars.D1, family="ipv6") for each in output: intf_list.append(each['interface']) temp = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [temp(c) for c in re.split('([0-9]+)', key)] intf_list_sorted = sorted(intf_list, key=alphanum_key) if intf_list == intf_list_sorted: st.log("Ipv6 interfaces are in sorted order") else: st.error("Ipv6 interfaces are not in soretd order") flag = 0 #Unconfig ipv4_addr = data.ip4_addr[11] + '/' + data.ipv4_mask ipv6_addr = data.ip6_addr[0] + '/' + data.ipv6_mask for i in range(int(math.ceil(float(data.no_of_ports) / 2))): _, ipv4_addr = ipfeature.increment_ip_addr(ipv4_addr, "network") ipfeature.delete_ip_interface(vars.D1, interface_name=req_ports[i], ip_address=ipv4_addr.split('/')[0], subnet=data.ipv4_mask, family="ipv4") for i in range(int(math.floor(float(data.no_of_ports) / 2))): _, ipv6_addr = ipfeature.increment_ip_addr(ipv6_addr, "network", family="ipv6") ipfeature.delete_ip_interface( vars.D1, interface_name=req_ports[ i + int(math.ceil(float(data.no_of_ports) / 2))], ip_address=ipv6_addr.split('/')[0], subnet=data.ipv6_mask, family="ipv6") if flag == 0: st.report_fail("test_case_failed") st.report_pass("test_case_passed")
def test_l3_ecmp_4paths_on_bo_tc(): (dut) = (data.dut) #count = 0 #intf_ip_addr = data.start_ip_addr #intf_ip_addr2 = data.start_ip_addr2 #nexthop = data.nexthop_start_ip_addr nexthop = "10.2.101.10/32" member1 = vars.D1T1P1 member2 = vars.D1T1P2 member3 = vars.D1T1P3 member4 = vars.D1T1P4 apply_file = False ipfeature.clear_ip_configuration([dut]) max_range = data.base_val+4 base_range = data.base_val-1 if apply_file is False: command = "config vlan range add 100 105" st.config(dut, command) command = "config vlan member add 100 {}".format(member4) st.config(dut, command) command = "config vlan member add 101 {}".format(member1) st.config(dut, command) command = "config vlan member add 102 {}".format(member2) st.config(dut, command) command = "config vlan member add 103 {}".format(member3) st.config(dut, command) command = "config vlan member add 104 {}".format(member4) st.config(dut, command) #ip_addr = data.start_ip_addr ip_addr = "10.2.100.1/24" for index in range(base_range, max_range): command = "config interface ip add "+ "Vlan" + str(index) + " " + ip_addr st.config(dut, command) (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") base_range = data.base_val max_range = data.base_val+3 for index in range(base_range, max_range): (_, nexthop) = ipfeature.increment_ip_addr(nexthop, "network") nexthop1 = nexthop formatted_next_hop = nexthop1.replace("/32","") ipfeature.create_static_route(dut, formatted_next_hop, data.static_route) data.my_dut_list = st.get_dut_names() #dut1 = data.my_dut_list[0] (tg1, tg_ph_1, tg2, tg_ph_2, tg3, tg_ph_3, tg4, tg_ph_4) = get_handles_1() tg1.tg_traffic_control(action='reset',port_handle=tg_ph_1) tg2.tg_traffic_control(action='reset',port_handle=tg_ph_2) tg2.tg_traffic_control(action='reset',port_handle=tg_ph_3) tg2.tg_traffic_control(action='reset',port_handle=tg_ph_4) h0=tg4.tg_interface_config(port_handle=tg_ph_4, mode='config', intf_ip_addr='10.2.100.10', gateway='10.2.100.1', src_mac_addr='00:0d:01:00:00:01', vlan='1', vlan_id='100', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.101.10', gateway='10.2.101.1', src_mac_addr='00:0d:02:00:00:01', vlan='1', vlan_id='101', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h2=tg2.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr='10.2.102.10', gateway='10.2.102.1', src_mac_addr='00:0c:01:00:00:01', vlan='1', vlan_id='102', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h3=tg3.tg_interface_config(port_handle=tg_ph_3, mode='config', intf_ip_addr='10.2.103.10', gateway='10.2.103.1', src_mac_addr='00:0c:02:00:00:01', vlan='1', vlan_id='103', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h4=tg4.tg_interface_config(port_handle=tg_ph_4, mode='config', intf_ip_addr='10.2.104.10', gateway='10.2.104.1', src_mac_addr='00:0a:02:00:00:01', vlan='1', vlan_id='104', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') mac_eth = macapi.get_sbin_intf_mac(vars.D1,'eth0') tr1=tg4.tg_traffic_config(port_handle=tg_ph_4, mac_src='00:11:01:00:00:01', mac_dst=mac_eth, ip_dst_mode='increment', ip_dst_count=200, ip_dst_step='0.0.0.1',ip_src_addr='10.2.100.10', ip_dst_addr='200.1.0.1', l3_protocol='ipv4', l2_encap='ethernet_ii_vlan', vlan_id='100', vlan='enable', mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=512000, enable_stream_only_gen='1') tg2.tg_traffic_control(action='run', handle=tr1['stream_id']) #count = 0 #Port Counters st.wait(20) st.show(dut, "show arp") #Port Counters ret = check_intf_traffic_bo_counters() if ret is True: st.log("Test Case PASSED") tg2.tg_traffic_control(action='stop', handle=tr1['stream_id']) tg1.tg_interface_config(port_handle=tg_ph_1, handle=h0['handle'], mode='destroy') tg1.tg_interface_config(port_handle=tg_ph_1, handle=h1['handle'], mode='destroy') tg2.tg_interface_config(port_handle=tg_ph_2, handle=h2['handle'], mode='destroy') tg3.tg_interface_config(port_handle=tg_ph_3, handle=h3['handle'], mode='destroy') tg4.tg_interface_config(port_handle=tg_ph_4, handle=h4['handle'], mode='destroy') if apply_file is False: base_range = data.base_val-1 ip_addr = data.start_ip_addr max_range = data.base_val+4 for index in range(base_range, max_range): command = "config interface ip remove "+ "Vlan" + str(index) + " " + ip_addr st.config(dut, command) (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") command = "config vlan member del 100 {}".format(member4) st.config(dut, command) command = "config vlan member del 101 {}".format(member1) st.config(dut, command) command = "config vlan member del 102 {}".format(member2) st.config(dut, command) command = "config vlan member del 103 {}".format(member3) st.config(dut, command) command = "config vlan member del 104 {}".format(member4) st.config(dut, command) command = "config vlan range del 100 105" st.config(dut, command) if ret is True: st.log("Test Case PASSED") st.report_pass("operation_successful") else: st.log("Test Case FAILED") st.report_fail("operation_failed")
def l3_ecmp_scaling_tc(max_ecmp, use_config_file): (dut) = (data.dut) count = 0 #intf_ip_addr = data.start_ip_addr #intf_ip_addr2 = data.start_ip_addr2 nexthop = data.nexthop_start_ip_addr member3 = vars.D1T1P3 member4 = vars.D1T1P4 # L3 INTF SCALING TEST CASE 1.1 START json_path = os.getcwd() apply_file = False if use_config_file is True: apply_file = True json_apply_path = json_path+"/routing/128_ecmp_config_db.json" #frr_apply_path = json_path+"/routing/64_ecmp_sr_config.frr" if apply_file is True: st.apply_files(dut, [json_apply_path]) #st.apply_files(dut, [json_apply_path, frr_apply_path]) max_range = data.base_val+max_ecmp base_range = data.base_val if apply_file is False: ipfeature.clear_ip_configuration(st.get_dut_names()) command = "config vlan add {}".format(data.vlan_val) st.config(dut, command) command = "config vlan member add {} {}".format(data.vlan_val, member3) st.config(dut, command) ip_addr = data.start_ip_addr #command = "config interface ip add "+ "Vlan" + str(data.vlan_val) + " " + ip_addr+'/24' command = "config interface ip add "+ "Vlan" + str(data.vlan_val) + " " + ip_addr st.config(dut, command) for index in range(base_range, max_range): command = "config vlan add {}".format(index) st.config(dut, command) command = "config vlan member add {} {}".format(index, member3) st.config(dut, command) (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") command = "config interface ip add "+ "Vlan" + str(index) + " " + ip_addr st.config(dut, command) tg_vlan = 101 command = "config vlan member del {} {}".format(tg_vlan, member3) st.config(dut, command) command = "config vlan member add {} {}".format(tg_vlan, member4) st.config(dut, command) for index in range(base_range, max_range): #vapi.add_member(dut, data.vlans[index], member, True) (_, nexthop) = ipfeature.increment_ip_addr(nexthop, "network") nexthop1 = nexthop formatted_next_hop = nexthop1.replace("/32","") ipfeature.create_static_route(dut, formatted_next_hop, data.static_route) # L3 INTF SCALING TEST CASE 1.1 END data.my_dut_list = st.get_dut_names() dut1 = data.my_dut_list[0] # L3 traffic streams #For now Spirent link with 100G is not working , so the below code from START to END just books spirent port, it will be rectified # once infra team provides support for RS-FEC #START (tg1, tg_ph_1, tg2, tg_ph_2) = get_handles() #import pdb;pdb.set_trace() tg1.tg_traffic_control(action='reset',port_handle=tg_ph_1) tg2.tg_traffic_control(action='reset',port_handle=tg_ph_2) #h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.101.10', gateway='10.2.101.1', count='8', gateway_step='0.0.1.0', netmask='255.255.255.0', vlan='1', vlan_id='101', vlan_id_count='8', intf_ip_addr_step='0.0.1.0', arp_send_req='1') #h2=tg2.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr='10.2.109.10', gateway='10.2.109.1', count='8', gateway_step='0.0.1.0', netmask='255.255.255.0', vlan='1', vlan_id='109', vlan_id_count='7', intf_ip_addr_step='0.0.1.0', arp_send_req='1') vid_count = max_ecmp-1 h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.102.10', gateway='10.2.102.1', src_mac_addr='00:0c:01:00:00:01', vlan='1', vlan_id='102', count=vid_count, arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h2=tg1.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr='10.2.101.10', gateway='10.2.101.1', src_mac_addr='00:0d:01:00:00:01', vlan='1', vlan_id='101', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') #h2=tg1.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr='10.2.109.10', gateway='10.2.109.1', src_mac_addr='00:0c:01:00:00:01', vlan='1', vlan_id='109', vlan_id_count='8', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') h3=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.100.10', gateway='10.2.100.1', netmask='255.255.255.0', vlan='1', vlan_id='100', arp_send_req='1') #tr1=tg1.tg_traffic_config(port_handle=tg_ph_1, emulation_src_handle=h3['handle'], ip_dst_addr='200.1.0.1', ip_dst_mode='increment', ip_dst_count='200', ip_dst_step='0.0.0.1', l3_protocol='ipv4', circuit_endpoint_type='ipv4', mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=512000, enable_stream_only_gen='1') asicapi.dump_l3_egress(dut) tr1=tg1.tg_traffic_config(port_handle=tg_ph_1, mac_src='00:11:01:00:00:01', mac_dst='b8:6a:97:fd:b6:06', ip_dst_mode='increment', ip_dst_count=200, ip_dst_step='0.0.0.1',ip_src_addr='10.2.100.10', ip_dst_addr='200.1.0.1', l3_protocol='ipv4', l2_encap='ethernet_ii_vlan', vlan_id='100', vlan='enable', mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=512000, enable_stream_only_gen='1') tg2.tg_traffic_control(action='run', handle=tr1['stream_id']) count = 0 #Port Counters st.wait(20) st.show(dut, "show arp") #Port Counters ret = check_intf_traffic_counters() if ret is True: count = count+1 st.log("Test Case 1.14 PASSED") tg1.tg_interface_config(port_handle=tg_ph_2, handle=h2['handle'], mode='destroy') h4=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.101.10', gateway='10.2.101.1', src_mac_addr='00:0e:01:00:00:01', vlan='1', vlan_id='101', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') tg_vlan = 101 command = "config vlan member del {} {}".format(tg_vlan, member4) st.config(dut, command) command = "config vlan member add {} {}".format(tg_vlan, member3) st.config(dut, command) tg_intf_ip_addr = data.tg_start_ip_addr max_range = data.base_val+max_ecmp base_range = data.base_val+1 for index in range(base_range, max_range): data.thresh = 4 command = "config vlan member del {} {}".format(index, member3) st.config(dut, command) command = "config vlan member add {} {}".format(index, member4) st.config(dut, command) (_, tg_intf_ip_addr) = ipfeature.increment_ip_addr(tg_intf_ip_addr, "network") tg_intf_ip_addr_x = tg_intf_ip_addr; tg_formatted_intf_addr = tg_intf_ip_addr_x.replace("/24","") tg_formatted_gw_addr = tg_intf_ip_addr_x.replace("10/24","1") #ping_formatted_gw_addr = tg_intf_ip_addr_x.replace("10/24","1") tg_vlan=index st.log("tg_vlan: "+str(tg_vlan)) st.log("tg_formatted_gw_addr: "+str(tg_formatted_gw_addr)) st.log("tg_formatted_intf_addr: "+str(tg_formatted_intf_addr)) h2=tg1.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr=tg_formatted_intf_addr, gateway=tg_formatted_gw_addr, src_mac_addr='00:0a:01:00:00:01', vlan='1', vlan_id=tg_vlan, vlan_id_count='1', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0') st.wait(3) #output = st.show(dut, "show arp") #Port Counters ret = check_intf_traffic_counters() if ret is True: count = count+1 st.log("Test Case 1.14 PASSED") else: st.log('Traffic test Failed') tg1.tg_interface_config(port_handle=tg_ph_2, handle=h2['handle'], mode='destroy') command = "config vlan member del {} {}".format(index, member4) st.config(dut, command) command = "config vlan member add {} {}".format(index, member3) st.config(dut, command) #res1=verify_ping(src_obj=tg1, port_handle=tg_ph_1, dev_handle=h1['handle'], dst_ip=ping_formatted_gw_addr,\ # ping_count='6', exp_count='6') #tg1.tg_traffic_config(mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=30, # mac_src='00:00:00:00:00:01', mac_dst='00:00:00:00:00:02', ip_src_addr ='11.11.11.2', # ip_dst_addr = '11.11.12.2') tg2.tg_traffic_control(action='stop', handle=tr1['stream_id']) asicapi.dump_l3_egress(dut) tg1.tg_interface_config(port_handle=tg_ph_1, handle=h1['handle'], mode='destroy') tg1.tg_interface_config(port_handle=tg_ph_1, handle=h3['handle'], mode='destroy') tg1.tg_interface_config(port_handle=tg_ph_1, handle=h4['handle'], mode='destroy') #import pdb;pdb.set_trace() if use_config_file is True: st.clear_config(dut1) # This code will not be needed if apply_file is True as config gets cleared already if apply_file is False: ip_addr = data.start_ip_addr base_range = data.base_val - 1 #max_range = data.base_val+max_ecmp-1 max_range = data.base_val+max_ecmp for index in range(base_range, max_range): command = "config interface ip remove "+ "Vlan" + str(index) + " " + ip_addr st.config(dut, command) command = "config vlan member del {} {}".format(index, member3) st.config(dut, command) command = "config vlan del {}".format(index) st.config(dut, command) (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") #del_vlan = max_range #command = "config interface ip remove "+ "Vlan" + str(del_vlan) + " " + ip_addr #st.config(dut, command) #command = "config vlan member del {} {}".format(del_vlan, member4) #st.config(dut, command) #command = "config vlan del {}".format(del_vlan) #st.config(dut, command) ret = False st.log("count: "+str(count)) if count >= data.thresh: ret = True st.log("Test Case PASSED") else: ret = False st.log("Test Case FAILED") st.log("operation_successful") return ret
def l3_max_route_max_path_scaling_tc(max_paths, max_routes, use_config_file, family="ipv4"): (dut) = (data.dut) #count = 0 data.my_dut_list = st.get_dut_names() dut1 = data.my_dut_list[0] dut2 = data.my_dut_list[1] #intf_ip_addr = data.dut1_start_ip_addr #intf_ip_addr2 = data.start_ip_addr2 #nexthop = data.nexthop_start_ip_addr vrf_flag = False member_dut1 = vars.D1T1P1 member_dut2 = vars.D2T1P1 # L3 INTF SCALING TEST CASE 1.1 START #json_path = os.getcwd() apply_file = False if apply_file is False: ipfeature.clear_ip_configuration(st.get_dut_names()) vapi.clear_vlan_configuration(st.get_dut_names()) st.banner("Started doing the needed config.") cmd = "config vlan range add 2 129" st.config(dut, cmd) st.config(dut2, cmd) command = "config vlan member add 2 {}".format(member_dut1) st.config(dut, command) command = "config vlan member add 2 {}".format(member_dut2) st.config(dut2, command) max_vlan = max_paths/4 base_vlan = 3 max_vlan = max_vlan - base_vlan v_range_t = str(base_vlan) + " " + str(base_vlan + max_vlan ) vapi.config_vlan_range_members(dut1, v_range_t, data.dut1_ports[0]) vapi.config_vlan_range_members(dut2, v_range_t, data.dut2_ports[0]) base_range = 1 max_range = 4 max_vlan = max_paths/4 incr_vlan = max_paths/4 for index in range(base_range, max_range): base_vlan = max_vlan + 1 max_vlan = max_vlan + incr_vlan #max_vlan = max_vlan + 32 v_range_t = str(base_vlan) + " " + str(max_vlan) vapi.config_vlan_range_members(dut1, v_range_t, data.dut1_ports[index]) vapi.config_vlan_range_members(dut2, v_range_t, data.dut2_ports[index]) ip_addr = data.dut1_start_ip_addr ip_addr2 = data.dut2_start_ip_addr v6_ip_addr = data.v6_start_ip_addr v6_ip_addr2 = data.v6_new_dut2_start_ip_addr ix_vlan_val = 2 #command = "config interface ip add "+ "Vlan" + str(data.vlan_val) + " " + ip_addr+'/24' if family == "ipv4": command1 = "config interface ip add "+ "Vlan" + str(ix_vlan_val) + " " + ip_addr command2 = "config interface ip add "+ "Vlan" + str(ix_vlan_val) + " " + ip_addr2 else: command1 = "config interface ip add "+ "Vlan" + str(ix_vlan_val) + " " + v6_ip_addr command2 = "config interface ip add "+ "Vlan" + str(ix_vlan_val) + " " + v6_ip_addr2 st.config(dut1, command1) st.config(dut2, command2) ip_addr2 = data.dut2_start_ip_addr base_vlan = 3 max_vlan = max_paths + 1 #max_vlan = 130 for index in range(base_vlan, max_vlan): if family == "ipv4": (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") (_, ip_addr2) = ipfeature.increment_ip_addr(ip_addr2, "network") command = "config interface ip add "+ "Vlan" + str(index) + " " + ip_addr command_dut2 = "config interface ip add "+ "Vlan" + str(index) + " " + ip_addr2 else: v6_tok = str(hex(index)[2:]) v6_ip_addr = "2100:0:" + v6_tok + "::1/64" v6_ip_addr2 = "2100:0:" + v6_tok + "::2/64" command = "config interface ip add "+ "Vlan" + str(index) + " " + v6_ip_addr command_dut2 = "config interface ip add "+ "Vlan" + str(index) + " " + v6_ip_addr2 st.config(dut, command) st.config(dut2, command_dut2) (tg1, tg_ph_1, tg2, tg_ph_2) = get_handles_2() tg1.tg_traffic_control(action='reset',port_handle=tg_ph_1) tg2.tg_traffic_control(action='reset',port_handle=tg_ph_2) #h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.2.2', gateway='10.2.2.1', arp_send_req='1') #h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.2.2', gateway='10.2.2.1', src_mac_addr='00:0a:01:00:00:01', vlan='1', vlan_id='2', arp_send_req='1', gateway_step='0.0.1.0', intf_ip_addr_step='0.0.1.0', vlan_id_step='1') if family == "ipv4": h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', intf_ip_addr='10.2.2.3', gateway='10.2.2.1', src_mac_addr='00:0a:01:00:00:01', vlan='1', vlan_id='2', arp_send_req='1') arp_obj.show_arp(dut) h2=tg1.tg_interface_config(port_handle=tg_ph_2, mode='config', intf_ip_addr='10.2.2.4', gateway='10.2.2.2', src_mac_addr='00:0b:01:00:00:01', vlan='1', vlan_id='2', arp_send_req='1') arp_obj.show_arp(dut2) else: h1=tg1.tg_interface_config(port_handle=tg_ph_1, mode='config', ipv6_intf_addr='2100:0:2::3', ipv6_gateway='2100:0:2::1', src_mac_addr='00:0a:01:00:00:01', vlan='1', vlan_id='2', arp_send_req='1') st.show(dut, "show ndp") arp_obj.show_arp(dut) h2=tg1.tg_interface_config(port_handle=tg_ph_2, mode='config', ipv6_intf_addr='2200:0:2::4', ipv6_gateway='2200:0:2::2', src_mac_addr='00:0b:01:00:00:01', vlan='1', vlan_id='2', arp_send_req='1') st.show(dut2, "show ndp") arp_obj.show_arp(dut2) if family == "ipv4": bgpfeature.create_bgp_router(dut, data.as_num, '') bgpfeature.create_bgp_router(dut2, data.new_as_num, '') dut1_neigh_ip_addr = data.neigh_ip_addr dut2_neigh_ip_addr = data.dut1_start_ip_addr #formatted_dut1_neigh_ip_addr = dut1_neigh_ip_addr.replace("/24","") #formatted_dut2_neigh_ip_addr = dut2_neigh_ip_addr.replace("/24","") formatted_dut1_neigh_ip_addr = "10.2.2.3" bgpfeature.create_bgp_neighbor(dut, data.as_num, formatted_dut1_neigh_ip_addr, data.remote_as_num) (_, dut1_neigh_ip_addr) = ipfeature.increment_ip_addr(dut1_neigh_ip_addr, "network") (_, dut2_neigh_ip_addr) = ipfeature.increment_ip_addr(dut2_neigh_ip_addr, "network") base_vlan = 3 max_vlan = max_paths + 1 #max_vlan = 130 # The below neighbor config is for inter dut links ibgp for index in range(base_vlan, max_vlan): formatted_dut1_neigh_ip_addr = dut1_neigh_ip_addr.replace("/24","") bgpfeature.create_bgp_neighbor(dut, data.as_num, formatted_dut1_neigh_ip_addr, data.new_as_num) (_, dut1_neigh_ip_addr) = ipfeature.increment_ip_addr(dut1_neigh_ip_addr, "network") formatted_dut2_neigh_ip_addr = dut2_neigh_ip_addr.replace("/24","") bgpfeature.create_bgp_neighbor(dut2, data.new_as_num, formatted_dut2_neigh_ip_addr, data.as_num) (_, dut2_neigh_ip_addr) = ipfeature.increment_ip_addr(dut2_neigh_ip_addr, "network") conf_var = { 'mode' : 'enable', 'active_connect_enable' : '1', 'local_as' : '200', 'remote_as' : '100', 'remote_ip_addr' : '10.2.2.1' } max_route_str = str(max_routes) route_var = { 'mode' : 'add', 'num_routes' : max_route_str, 'prefix' : '121.1.1.0', 'as_path' : 'as_seq:1' } #'num_routes' : '30000', ctrl_start = { 'mode' : 'start'} ctrl_stop = { 'mode' : 'stop'} # Configuring the BGP router. bgp_rtr1 = tgapi.tg_bgp_config(tg = tg1, handle = h1['handle'], conf_var = conf_var, route_var = route_var, ctrl_var = ctrl_start) st.log("BGP_HANDLE: "+str(bgp_rtr1)) # Verified at neighbor. st.log("BGP neighborship established.") st.wait(10) def f1(d): st.show(d, "show bgp ipv4 summary", type='vtysh') st.show(d, "show interface status") st.show(d, "show ip route | head -1000") arp_obj.show_arp(d) st.banner("ARP entries before traffic is initiated on Dut1 and Dut2") st.exec_each([dut, dut2], f1) #Port Counters tr1=tg2.tg_traffic_config(port_handle=tg_ph_2, emulation_src_handle=h2['handle'], emulation_dst_handle=bgp_rtr1['route'][0]['handle'], circuit_endpoint_type='ipv4', mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=512000, enable_stream_only_gen='0') else: v6_dut1_neigh_ip_addr = "2100:0:2::3" create_bgp_neighbor_route_map_config(dut, data.as_num, v6_dut1_neigh_ip_addr, data.routemap, vrf_flag) create_bgp_neighbor_route_map_config(dut2, data.new_as_num, v6_dut1_neigh_ip_addr, data.routemap, vrf_flag) bgpfeature.create_bgp_router(dut, data.as_num, '') create_bgp_neighbor_config(dut, data.as_num, v6_dut1_neigh_ip_addr, data.remote_as_num, data.routemap) #link_bgp_neighbor_to_routemap(dut, data.as_num, v6_dut1_neigh_ip_addr, data.routemap, vrf_flag) bgpfeature.create_bgp_router(dut2, data.new_as_num, '') base_vlan = 3 max_vlan = max_paths + 1 for index in range(base_vlan, max_vlan): v6_tok = str(hex(index)[2:]) v6_dut1_neigh_ip_addr = "2100:0:" + v6_tok + "::2" v6_dut2_neigh_ip_addr2 = "2100:0:" + v6_tok + "::1" create_bgp_neighbor_config(dut, data.as_num, v6_dut1_neigh_ip_addr, data.new_as_num, data.routemap) create_bgp_neighbor_config(dut2, data.new_as_num, v6_dut2_neigh_ip_addr2, data.as_num, data.routemap) #bgpfeature.create_bgp_neighbor(dut, data.as_num, v6_dut1_neigh_ip_addr, data.new_as_num, family="ipv6") #bgpfeature.create_bgp_neighbor(dut2, data.new_as_num, v6_dut2_neigh_ip_addr2, data.as_num, family="ipv6") bgp_conf=tg2.tg_emulation_bgp_config(handle=h1['handle'], mode='enable', ip_version='6', active_connect_enable='1', local_as='200', remote_as='100', remote_ipv6_addr='2100:0:2::1') max_route_str = str(max_routes) bgp_route=tg2.tg_emulation_bgp_route_config(handle=bgp_conf['handle'], mode='add', ip_version='6', num_routes=max_route_str, prefix='3300:0:0:2::1', as_path='as_seq:1') tg2.tg_emulation_bgp_control(handle=bgp_conf['handle'], mode='start') def f1(d): st.show(d, "show run bgp") st.show(d, "show ndp") st.show(d, "show bgp ipv6 summary", type='vtysh') st.show(d, "show ipv6 route | head -1000") arp_obj.show_arp(d) st.banner("ARP entries before traffic is initiated on Dut1 and Dut2") st.exec_each([dut, dut2], f1) tr1=tg2.tg_traffic_config(port_handle=tg_ph_2, emulation_src_handle=h2['handle'], emulation_dst_handle=bgp_route['handle'], circuit_endpoint_type='ipv6', mode='create', transmit_mode='continuous', length_mode='fixed', rate_pps=512000, enable_stream_only_gen='0') #tr1=tg1.tg_traffic_config(port_handle=tg_ph_2, mac_src='00:11:01:00:00:01', mac_dst='80:a2:35:97:eb:c1', # ipv6_dst_mode='increment', ipv6_dst_count=200, ipv6_dst_step='::1',ipv6_src_addr='2200:0:2::5', # ipv6_dst_addr='3300:0:0:2::1', l3_protocol='ipv6', l2_encap='ethernet_ii_vlan', vlan_id='2', # vlan='enable', mode='create', transmit_mode='continuous', length_mode='fixed', # rate_pps=512000, enable_stream_only_gen='1') tg2.tg_traffic_control(action='run', handle=tr1['stream_id']) ret1 = check_inter_dut_intf_traffic_counters() ret2 = check_end_to_end_intf_traffic_counters() tg2.tg_traffic_control(action='stop', handle=tr1['stream_id']) st.banner("ARP entries in both DUT's after traffic is stopped") st.exec_each([dut, dut2], arp_obj.show_arp) tg1.tg_traffic_control(action='reset',port_handle=tg_ph_2) if family == "ipv4": tgapi.tg_bgp_config(tg = tg1, handle = bgp_rtr1['conf']['handle'], ctrl_var=ctrl_stop) else: tg1.tg_emulation_bgp_control(handle=bgp_conf['handle'], mode='stop') tg1.tg_interface_config(port_handle=tg_ph_1, handle=h1['handle'], mode='destroy') tg1.tg_interface_config(port_handle=tg_ph_2, handle=h2['handle'], mode='destroy') #import pdb;pdb.set_trace() if apply_file is False: ip_addr = data.dut1_start_ip_addr ip_addr2 = data.dut2_start_ip_addr st.log("Un-Config previously config") base_range = 2 max_range = max_paths + 1 for index in range(base_range, max_range): if family == "ipv4": command1 = "config interface ip remove "+ "Vlan" + str(index) + " " + ip_addr command2 = "config interface ip remove "+ "Vlan" + str(index) + " " + ip_addr2 (_, ip_addr) = ipfeature.increment_ip_addr(ip_addr, "network") (_, ip_addr2) = ipfeature.increment_ip_addr(ip_addr2, "network") else: v6_tok = str(hex(index)[2:]) if index == 2: v6_ip_addr2 = "2200:0:" + v6_tok + "::2/64" else: v6_ip_addr2 = "2100:0:" + v6_tok + "::2/64" v6_ip_addr = "2100:0:" + v6_tok + "::1/64" command1 = "config interface ip remove "+ "Vlan" + str(index) + " " + v6_ip_addr command2 = "config interface ip remove "+ "Vlan" + str(index) + " " + v6_ip_addr2 st.config(dut, command1) st.config(dut2, command2) max_vlan = max_paths/4 base_vlan = 3 max_vlan = max_vlan - base_vlan v_range_t = str(base_vlan) + " " + str(base_vlan + max_vlan ) vapi.config_vlan_range_members(dut1, v_range_t, data.dut1_ports[0], config='del') vapi.config_vlan_range_members(dut2, v_range_t, data.dut2_ports[0], config='del') base_range = 1 max_range = 4 max_vlan = max_paths/4 incr_vlan = max_paths/4 for index in range(base_range, max_range): base_vlan = max_vlan + 1 #max_vlan = max_vlan + 32 max_vlan = max_vlan + incr_vlan v_range_t = str(base_vlan) + " " + str(max_vlan) vapi.config_vlan_range_members(dut1, v_range_t, data.dut1_ports[index], config='del') vapi.config_vlan_range_members(dut2, v_range_t, data.dut2_ports[index], config='del') cmd = "config vlan range del 2 129" st.config(dut, cmd) my_cmd = "no router bgp {}".format(data.as_num) st.vtysh_config(dut, my_cmd) my_cmd = "no router bgp {}".format(data.new_as_num) st.vtysh_config(dut2, my_cmd) st.debug("ret1: {} , ret2: {}".format(ret1, ret2)) if ret1 is True and ret2 is True: ret = True st.log("Test Case PASSED") else: ret = False st.log("Test Case FAILED") st.log("operation_successful") return ret
def test_ft_erspan_basic_functionality(): """ Author: Sesha Koilkonda ([email protected]) TC1 FtOpSoSyErspanFn019: Verify that maximum number of mirror sessions are created. TC2 FtOpSoSyErspanFn015: Verify that multiple mirror sessions can be created and assigned to rules from the same ACL. TC3 FtOpSoSyErspanFn011: Verify that ERSPAN is working as expected and intended traffic is mirrored to remote interface from multiple interfaces. Notes from dev: Only 1 Mirror ACL configuration is supported as of now. maximum Acl rules that can be configured in mirror sesssion(s) is 3. :return: """ ip_add_src, ip_add_dst = data.ip_T1D1P1, data.ip_T1D2P1 max_sessions, data.mask = 4, '32' tc_fail = 0 acl_dscp.config_classifier_table(vars.D1, enable='create', match_type="fields", class_name=data.acl_rule) acl_dscp.config_classifier_table(vars.D1, enable='yes', class_criteria='--src-ip', class_name=data.acl_rule, criteria_value="{}/{}".format(ip_add_src, data.mask), match_type="fields") acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='add', policy_type=data.type, class_name=data.acl_rule, priority_value=data.priority, description=data.description) acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='update',policy_type=data.type, class_name=data.acl_rule, priority_option='--mirror-session', priority_value=data.session_name) #Configure the maximum supported mirror sessions(Session1 alreday created as part of module config.) for ele in range(1, max_sessions): _, ip_add_src = ip.increment_ip_addr("{}/{}".format(ip_add_src.split('/')[0], data.mask), "host") _, ip_add_dst = ip.increment_ip_addr("{}/{}".format(ip_add_dst.split('/')[0], data.mask), "host") if ele == 2: _, ip_add_src = ip.increment_ip_addr("{}/{}".format(data.ip_D1T1P2, data.mask), "host") mirror_args = {'session_name': data.session_name + str(ele),'src_ip': ip_add_src.split('/')[0], 'dst_ip': ip_add_dst.split('/')[0], 'dscp':'50', 'ttl':'60', 'gre_type':'0x88ee', 'queue':data.queue} mirror.create_session(vars.D1, **mirror_args) if not mirror.verify_session(vars.D1, **mirror_args): st.log("failed to configure the mirror session: {} ".format(data.session_name + str(ele))) tc_fail = 1 acl_dscp.config_classifier_table(vars.D1, enable='create', match_type="fields", class_name=data.acl_rule+ str(ele)) acl_dscp.config_classifier_table(vars.D1, enable='yes', class_criteria='--src-ip', match_type="fields", class_name=data.acl_rule + str(ele), criteria_value="{}".format(ip_add_src)) acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='add', policy_type=data.type, class_name=data.acl_rule+str(ele),priority_value=int(data.priority) + ele, description=data.description) acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='update',policy_type=data.type, class_name=data.acl_rule+str(ele), priority_option='--mirror-session', priority_value=data.session_name + str(ele)) # Traffic validations for the mirror sessions. ip_add_src, ip_add_dst, tg_src = data.ip_T1D1P1, data.ip_T1D1P2, 'tg_ph_1' for ele in range(0, max_sessions): if ele == 2: _, ip_add_src = ip.increment_ip_addr("{}/{}".format(data.ip_D1T1P2.split('/')[0], data.mask), "host") _, ip_add_dst = ip.increment_ip_addr("{}/{}".format(data.ip_D1T1P1.split('/')[0], data.mask), "host") tg_src = 'tg_ph_2' retval = send_traffic(capture_values=[ip_add_dst], capture_fields=['dst_ip'], ip_src_addr= ip_add_src.split('/')[0], ip_dst_addr= ip_add_dst.split('/')[0], tg_src_port=tg_src) if not retval[0]: st.log('Traffic validation failed for the mirror session combination: source_ip {} , destination_ip {}'.format(ip_add_src,ip_add_dst)) tc_fail = ele _, ip_add_src = ip.increment_ip_addr("{}/{}".format(ip_add_src.split('/')[0], data.mask), "host") #Unconfigration part for ele in range(1, max_sessions): acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='del', policy_type=data.type, class_name=data.acl_rule + str(ele)) acl_dscp.config_classifier_table(dut=vars.D1, enable="del", class_name=data.acl_rule+str(ele)) mirror.delete_session(vars.D1, data.session_name + str(ele)) if tc_fail == 1: st.report_fail("mirror_session_fail", "") elif tc_fail == 2: st.report_fail("traffic_verification_fail", "packet count") st.report_pass("test_case_passed")
def test_ft_erspan_action_ip_protocol_ip_addr_l4_ports(): """ Author: Lakshminarayana D ([email protected]) Verify that ERSPAN is working as expected and intended traffic with configured IP Protocol, SRC_IP, DST_IP, L4_SRC_PORT and L4_DST_PORT from ACL rule is mirrored to remote interface . Topology: --------- TG1 ---- DUT1 ---- DUT2 ---- TG3 TG2 ---- """ # l4 port protocols l4_protocol_list = ['tcp'] for proto in l4_protocol_list: # l4 port values ip_port_val = {'src_port': 2000, 'dst_port': 3000, 'src_ip': data.ip_T1D1P1, 'dst_ip': data.ip_T1D1P2} # Used this dict for ACL rule to TG argument mapping acl_to_tg = {'src_ip': 'ip_dst_addr', 'dst_ip': 'ip_dst_addr'} # Parsing capture values in hexa decimal format c_values = [hex(ip_port_val['src_port']).lstrip('0x').zfill(4), hex(ip_port_val['dst_port']).lstrip('0x').zfill(4), ip_port_val['src_ip'], ip_port_val['dst_ip']] # Creating capture fileds for capture packet header and offset values formation c_fields = [proto + '_src_port', proto + '_dst_port', 'src_ip', 'dst_ip'] # Incrementing src and dst ip addresses _, incr_src = ip.increment_ip_addr("{}/{}".format(ip_port_val['src_ip'], data.mask), "host") _, incr_dst = ip.increment_ip_addr("{}/{}".format(ip_port_val['dst_ip'], data.mask), "host") # Parsing capture values in hexa decimal format for negative scenario cn_values = [hex(ip_port_val['src_port'] + 1).lstrip('0x').zfill(4), hex(ip_port_val['dst_port'] + 1).lstrip('0x').zfill(4), incr_src.split('/')[0], incr_dst.split('/')[0]] # Creating ip addresses and l4_port parameters to form TG stream tg_arg = {c_fields[0]: ip_port_val['src_port'], c_fields[1]: ip_port_val['dst_port'], acl_to_tg['src_ip']: ip_port_val['src_ip'], acl_to_tg['dst_ip']: ip_port_val['dst_ip']} # Creating ip addresses and l4_port parameters to form TG stream to verify negative scenario tg_argn = {c_fields[0]: ip_port_val['src_port'] + 1, c_fields[1]: ip_port_val['dst_port'] + 1, acl_to_tg['src_ip']: incr_src.split('/')[0], acl_to_tg['dst_ip']: incr_dst.split('/')[0]} # creation and verification of ACL Rule criteria_list = ['--ip-proto', '--src-port', '--dst-port', '--src-ip', '--dst-ip'] criteria_values = ['6', ip_port_val['src_port'], ip_port_val['dst_port'], "{}/{}".format(ip_port_val['src_ip'], data.mask), "{}/{}".format(ip_port_val['dst_ip'], data.mask)] acl_dscp.config_classifier_table(vars.D1, enable='create', match_type="fields", class_name=data.acl_rule) acl_dscp.config_classifier_table(vars.D1, enable='yes', class_criteria=criteria_list, class_name=data.acl_rule, criteria_value=criteria_values, match_type="fields") acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='add', policy_type=data.type, class_name=data.acl_rule, priority_value=data.priority, description=data.description) acl_dscp.config_flow_update_table(vars.D1, policy_name=data.acl_table_name, flow='update',policy_type=data.type, class_name=data.acl_rule, priority_option='--mirror-session', priority_value=data.mirror_action) # TG traffic verification: retval = send_traffic(capture_values=c_values, capture_fields=c_fields, l4_protocol=proto, **tg_arg) if not retval[0]: st.report_fail("traffic_verification_fail", 'packet count') # TG traffic verification-Negetive check: retval = send_traffic(capture_values=cn_values, capture_fields=c_fields, l4_protocol=proto, neg_check=True, **tg_argn) if retval[0]: st.report_fail("neg_traffic_verification_fail", 'packet count') st.report_pass("test_case_passed")