コード例 #1
0
    def test_reply_qinq(self, port_number):
        intf = 'iif%d' % port_number
        stag = 10
        ctag = 20
        self.client.add_interface(intf)
        self.client.add_ip(intf, stag, ctag, 0x01020304)
        src_mac = self.my_mac[port_number]
        packet = simple_arp_packet(
            pktlen=42,
            eth_src=src_mac,
            ip_snd='1.2.3.1',
            ip_tgt='1.2.3.4',
            hw_snd=src_mac,
            hw_tgt='00:00:00:00:00:00',
        )
        tagged_packet = self.insert_tags(packet, stag, ctag)
        testutils.send_packet(self, (0, port_number), tagged_packet)
        self.client.del_ip(intf, stag, ctag)
        self.client.del_interface(intf)

        exp_packet = simple_arp_packet(pktlen=42,
                                       eth_dst=src_mac,
                                       eth_src=self.remote_mac[port_number],
                                       arp_op=2,
                                       ip_snd='1.2.3.4',
                                       ip_tgt='1.2.3.1',
                                       hw_snd=self.remote_mac[port_number],
                                       hw_tgt=src_mac)
        tagged_exp_packet = self.insert_tags(exp_packet, stag, ctag)
        testutils.verify_packet(self, tagged_exp_packet, port_number)
コード例 #2
0
    def runArpBroadcastTest(self, tagged_ports, untagged_ports):
        zero_mac_addr = ":".join(["00"] * 6)
        vlan_id = 10
        next_id = vlan_id
        mcast_group_id = vlan_id
        all_ports = set(tagged_ports + untagged_ports)
        arp_pkt = testutils.simple_arp_packet(pktlen=76)
        # Account for VLAN header size in total pktlen
        vlan_arp_pkt = testutils.simple_arp_packet(vlan_vid=vlan_id, pktlen=80)

        for port in tagged_ports:
            self.set_ingress_port_vlan(port, True, vlan_id, vlan_id)
        for port in untagged_ports:
            self.set_ingress_port_vlan(port, False, 0, vlan_id)
        self.add_bridging_entry(vlan_id, zero_mac_addr, zero_mac_addr, next_id)
        self.add_next_multicast(next_id, mcast_group_id)
        self.add_mcast_group(mcast_group_id, all_ports)
        for port in untagged_ports:
            self.set_egress_vlan_pop(port, vlan_id)

        for inport in all_ports:
            pkt_to_send = vlan_arp_pkt if inport in tagged_ports else arp_pkt
            testutils.send_packet(self, inport, str(pkt_to_send))
            # Packet should be received on all ports expect the ingress one.
            verify_tagged_ports = set(tagged_ports)
            verify_tagged_ports.discard(inport)
            for tport in verify_tagged_ports:
                testutils.verify_packet(self, vlan_arp_pkt, tport)
            verify_untagged_ports = set(untagged_ports)
            verify_untagged_ports.discard(inport)
            for uport in verify_untagged_ports:
                testutils.verify_packet(self, arp_pkt, uport)
        testutils.verify_no_other_packets(self)
コード例 #3
0
def packets_for_test(request, ptfadapter, duthost, config_facts, tbinfo,
                     ip_and_intf_info):
    ip_version = request.param
    src_addr_v4, src_addr_v6, ptf_intf = ip_and_intf_info
    ptf_intf_index = int(ptf_intf.replace('eth', ''))
    ptf_intf_mac = ptfadapter.dataplane.get_mac(0, ptf_intf_index)
    vlans = config_facts['VLAN']
    topology = tbinfo['topo']['name']
    dut_mac = ''
    for vlan_details in vlans.values():
        if 'dualtor' in topology:
            dut_mac = vlan_details['mac'].lower()
        else:
            dut_mac = duthost.shell(
                'sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\''
            )["stdout_lines"][0].decode("utf-8")
        break

    if ip_version == 'v4':
        tgt_addr = increment_ipv4_addr(src_addr_v4)
        out_pkt = testutils.simple_arp_packet(eth_dst='ff:ff:ff:ff:ff:ff',
                                              eth_src=ptf_intf_mac,
                                              ip_snd=src_addr_v4,
                                              ip_tgt=tgt_addr,
                                              arp_op=1,
                                              hw_snd=ptf_intf_mac)
        exp_pkt = testutils.simple_arp_packet(eth_dst=ptf_intf_mac,
                                              eth_src=dut_mac,
                                              ip_snd=tgt_addr,
                                              ip_tgt=src_addr_v4,
                                              arp_op=2,
                                              hw_snd=dut_mac,
                                              hw_tgt=ptf_intf_mac)
    elif ip_version == 'v6':
        tgt_addr = increment_ipv6_addr(src_addr_v6)
        ll_src_addr = generate_link_local_addr(ptf_intf_mac)
        multicast_tgt_addr = in6_getnsma(inet_pton(socket.AF_INET6, tgt_addr))
        multicast_tgt_mac = in6_getnsmac(multicast_tgt_addr)
        out_pkt = Ether(src=ptf_intf_mac, dst=multicast_tgt_mac)
        out_pkt /= IPv6(dst=inet_ntop(socket.AF_INET6, multicast_tgt_addr),
                        src=ll_src_addr)
        out_pkt /= ICMPv6ND_NS(tgt=tgt_addr)
        out_pkt /= ICMPv6NDOptSrcLLAddr(lladdr=ptf_intf_mac)

        exp_pkt = Ether(src=dut_mac, dst=ptf_intf_mac)
        exp_pkt /= IPv6(dst=ll_src_addr, src=generate_link_local_addr(dut_mac))
        exp_pkt /= ICMPv6ND_NA(tgt=tgt_addr, S=1, R=1, O=0)
        exp_pkt /= ICMPv6NDOptSrcLLAddr(type=2, lladdr=dut_mac)
        exp_pkt = mask.Mask(exp_pkt)
        exp_pkt.set_do_not_care_scapy(packet.IPv6, 'fl')

    return ip_version, out_pkt, exp_pkt
コード例 #4
0
def test_arp_garp_enabled(duthosts, enum_rand_one_per_hwsku_frontend_hostname, garp_setup, setup_ptf_arp, intfs_for_test, config_facts, ptfadapter):
    '''
    Send a gratuitous ARP (GARP) packet from the PTF to the DUT

    The DUT should learn the (previously unseen) ARP info from the packet
    '''
    duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
    ptf_intf_ipv4_addr, _, _ = setup_ptf_arp
    arp_accept_vals = garp_setup
    pytest_require(all(int(val) == 1 for val in arp_accept_vals), 'Gratuitous ARP not enabled for this device')

    arp_request_ip = increment_ipv4_addr(ptf_intf_ipv4_addr)
    arp_src_mac = '00:00:07:08:09:0a'
    _, _, intf1_index, _, = intfs_for_test

    pkt = testutils.simple_arp_packet(pktlen=60,
                                eth_dst='ff:ff:ff:ff:ff:ff',
                                eth_src=arp_src_mac,
                                vlan_pcp=0,
                                arp_op=2,
                                ip_snd=arp_request_ip,
                                ip_tgt=arp_request_ip,
                                hw_snd=arp_src_mac,
                                hw_tgt='ff:ff:ff:ff:ff:ff'
                            )

    logger.info("Sending GARP for target {} from PTF interface {}".format(arp_request_ip, intf1_index))
    testutils.send_packet(ptfadapter, intf1_index, pkt)

    vlan_intfs = config_facts['VLAN_INTERFACE'].keys()

    switch_arptable = duthost.switch_arptable()['ansible_facts']
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['macaddress'].lower() == arp_src_mac.lower())
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['interface'] in vlan_intfs)
コード例 #5
0
    def setUp(self):
        """
        Fetches all the parameters we need to run the tests.
        """

        self.dataplane = ptf.dataplane_instance

        self.test_params = testutils.test_params_get()
        self.hwsku = self.test_params['hwsku']
        self.asic_type = self.test_params['asic_type']
        self.router_mac = self.test_params['router_mac']
        self.src_port = int(self.test_params['src_port'])
        self.mirror_stage = self.test_params['mirror_stage']
        self.dst_mirror_ports = [
            int(p) for p in self.test_params['dst_mirror_ports'].split(",")
            if p
        ]
        self.dst_ports = [
            int(p) for p in self.test_params['dst_ports'].split(",")
        ]

        self.base_pkt = testutils.simple_arp_packet(
            eth_dst=self.router_mac, eth_src=self.dataplane.get_mac(0, 0))

        self.basev6_pkt = testutils.simple_icmpv6_packet(
            eth_dst=self.router_mac,
            eth_src=self.dataplane.get_mac(0, 0),
            icmp_type=135)

        testutils.add_filter(self.gre_filter)
コード例 #6
0
ファイル: test_fdb.py プロジェクト: robocoder99/sonic-mgmt
def send_arp_request(ptfadapter, source_port, source_mac, dest_mac, vlan_id):
    """
    send arp request packet
    :param ptfadapter: PTF adapter object
    :param source_port: source port
    :param source_mac: source MAC
    :param dest_mac: destination MAC
    :param vlan_id: VLAN id
    :return:
    """
    pkt = testutils.simple_arp_packet(
        pktlen=60,
        eth_dst=dest_mac,
        eth_src=source_mac,
        vlan_vid=vlan_id,
        vlan_pcp=0,
        arp_op=1,
        ip_snd='10.10.1.3',
        ip_tgt='10.10.1.2',
        hw_snd=source_mac,
        hw_tgt='ff:ff:ff:ff:ff:ff',
    )
    logger.debug(
        'send ARP request packet source port id {} smac: {} dmac: {} vlan: {}'.
        format(source_port, source_mac, dest_mac, vlan_id))
    testutils.send(ptfadapter, source_port, pkt)
コード例 #7
0
def test_arp_garp_enabled(rand_selected_dut, garp_enabled, ip_and_intf_info, intfs_for_test, config_facts, ptfadapter):
    """
    Send a gratuitous ARP (GARP) packet from the PTF to the DUT

    The DUT should learn the (previously unseen) ARP info from the packet
    """
    pytest_require(garp_enabled, 'Gratuitous ARP not enabled for this device')
    duthost = rand_selected_dut
    ptf_intf_ipv4_addr = ip_and_intf_info[0]

    arp_request_ip = increment_ipv4_addr(ptf_intf_ipv4_addr)
    arp_src_mac = '00:00:07:08:09:0a'
    _, _, intf1_index, _, = intfs_for_test

    pkt = testutils.simple_arp_packet(pktlen=60,
                                eth_dst='ff:ff:ff:ff:ff:ff',
                                eth_src=arp_src_mac,
                                vlan_pcp=0,
                                arp_op=2,
                                ip_snd=arp_request_ip,
                                ip_tgt=arp_request_ip,
                                hw_snd=arp_src_mac,
                                hw_tgt='ff:ff:ff:ff:ff:ff'
                            )

    clear_dut_arp_cache(duthost)

    logger.info("Sending GARP for target {} from PTF interface {}".format(arp_request_ip, intf1_index))
    testutils.send_packet(ptfadapter, intf1_index, pkt)

    vlan_intfs = config_facts['VLAN_INTERFACE'].keys()

    switch_arptable = duthost.switch_arptable()['ansible_facts']
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['macaddress'].lower() == arp_src_mac.lower())
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['interface'] in vlan_intfs)
コード例 #8
0
def start_linkmgrd_heartbeat(ptfadapter, duthost, tbinfo):
    '''
    Send a GARP from from PTF->ToR from each PTF port connected to a mux cable

    This is needed since linkmgrd will not start sending heartbeats until the PTF MAC is learned in the DUT neighbor table
    '''
    garp_pkts = {}

    ptf_indices = duthost.get_extended_minigraph_facts(
        tbinfo)["minigraph_ptf_indices"]
    mux_cable_table = duthost.get_running_config_facts()['MUX_CABLE']

    for vlan_intf, config in mux_cable_table.items():
        ptf_port_index = ptf_indices[vlan_intf]
        server_ip = ip_interface(config['server_ipv4'])
        ptf_mac = ptfadapter.dataplane.ports[(0, ptf_port_index)].mac()

        garp_pkt = testutils.simple_arp_packet(
            eth_src=ptf_mac,
            hw_snd=ptf_mac,
            ip_snd=str(server_ip.ip),
            ip_tgt=str(
                server_ip.ip
            ),  # Re-use server IP as target IP, since it is within the subnet of the VLAN IP
            arp_op=2)
        garp_pkts[ptf_port_index] = garp_pkt

    for port, pkt in garp_pkts.items():
        testutils.send_packet(ptfadapter, port, pkt)
コード例 #9
0
    def generatePkts(self, gw, port_ip, port_mac):
        pkt = testutils.simple_arp_packet(
            ip_snd=port_ip,
            ip_tgt=gw,
            eth_src=port_mac,
            hw_snd=port_mac,
        )
        exp_pkt = testutils.simple_arp_packet(
            ip_snd=gw,
            ip_tgt=port_ip,
            eth_src=self.dut_mac,
            eth_dst=port_mac,
            hw_snd=self.dut_mac,
            hw_tgt=port_mac,
            arp_op=2,
        )

        return str(pkt), str(exp_pkt)
コード例 #10
0
    def test_request(self):
        thr = Thread(target=self.request_mac_thread)
        thr.start()
        stag = 10
        ctag = 20
        exp_packet_1 = simple_arp_packet(pktlen=42,
                                         eth_dst='ff:ff:ff:ff:ff:ff',
                                         eth_src=self.remote_mac[0],
                                         ip_snd='1.2.3.4',
                                         ip_tgt='1.2.3.1',
                                         hw_snd=self.remote_mac[0],
                                         hw_tgt='ff:ff:ff:ff:ff:ff')
        t_exp_packet0 = self.insert_tags(exp_packet_1, stag, ctag)
        testutils.verify_packet(self, t_exp_packet0, 0)
        exp_packet_2 = simple_arp_packet(pktlen=42,
                                         eth_dst='ff:ff:ff:ff:ff:ff',
                                         eth_src=self.remote_mac[1],
                                         ip_snd='1.2.3.5',
                                         ip_tgt='1.2.3.1',
                                         hw_snd=self.remote_mac[1],
                                         hw_tgt='ff:ff:ff:ff:ff:ff')
        t_exp_packet1 = self.insert_tags(exp_packet_2, stag, ctag)
        testutils.verify_packet(self, t_exp_packet1, 1)

        packet = simple_arp_packet(pktlen=42,
                                   eth_dst=self.remote_mac[0],
                                   eth_src=self.my_mac[0],
                                   arp_op=2,
                                   ip_snd='1.2.3.1',
                                   ip_tgt='1.2.3.4',
                                   hw_snd=self.my_mac[0],
                                   hw_tgt=self.remote_mac[0])
        tagged_packet = self.insert_tags(packet, stag, ctag)
        testutils.send_packet(self, (0, 0), tagged_packet)
        thr.join()
        result_mac = ":".join(
            "%02x" % v
            for v in list(struct.unpack("BBBBBB", self.result[0].mac)))
        self.assertTrue(self.result[0].index == 0)
        self.assertTrue(self.result[0].is_found)
        self.assertTrue(result_mac == self.my_mac[0])
        self.assertTrue(self.result[0].request.stag == 10)
        self.assertTrue(self.result[0].request.ctag == 20)
        self.assertTrue(self.result[0].request.iface_name == 'iif0')
コード例 #11
0
ファイル: wr_arp.py プロジェクト: robocoder99/sonic-mgmt
    def generatePkts(self, gw, port_ip, port_mac, vlan_id):
        pkt = testutils.simple_arp_packet(ip_snd=port_ip,
                                          ip_tgt=gw,
                                          eth_src=port_mac,
                                          hw_snd=port_mac,
                                          vlan_vid=vlan_id)

        exp_pkt = testutils.simple_arp_packet(ip_snd=gw,
                                              ip_tgt=port_ip,
                                              eth_src=self.dut_mac,
                                              eth_dst=port_mac,
                                              hw_snd=self.dut_mac,
                                              hw_tgt=port_mac,
                                              arp_op=2,
                                              vlan_vid=vlan_id)
        masked_exp_pkt = Mask(exp_pkt)
        # Ignore the Ethernet padding zeros
        masked_exp_pkt.set_ignore_extra_bytes()
        return pkt, masked_exp_pkt
コード例 #12
0
def build_arp_packet(vlan_id, neighbor_mac, dst_mac, neighbor_ip):

    pkt = testutils.simple_arp_packet(pktlen=60 if vlan_id == 0 else 64,
                                      eth_dst=dst_mac,
                                      eth_src=neighbor_mac,
                                      vlan_vid=vlan_id,
                                      arp_op=2,
                                      hw_snd=neighbor_mac,
                                      ip_snd=neighbor_ip,
                                      ip_tgt=neighbor_ip)
    return pkt
コード例 #13
0
    def runTest(self):
        print ""
        print "Testing ARP request packet..."
        arp_pkt = testutils.simple_arp_packet()
        self.test(arp_pkt)

        print "Testing NDP NS packet..."
        ndp_pkt = genNdpNsPkt(src_mac=HOST1_MAC,
                              src_ip=HOST1_IPV6,
                              target_ip=HOST2_IPV6)
        self.test(ndp_pkt)
コード例 #14
0
ファイル: copp_tests.py プロジェクト: judyjoseph/sonic-mgmt
    def contruct_packet(self, port_number):
        src_mac = self.my_mac[port_number]
        src_ip = self.myip
        dst_ip = self.peerip

        packet = testutils.simple_arp_packet(eth_dst='ff:ff:ff:ff:ff:ff',
                                             eth_src=src_mac,
                                             arp_op=1,
                                             ip_snd=src_ip,
                                             ip_tgt=dst_ip,
                                             hw_snd=src_mac,
                                             hw_tgt='ff:ff:ff:ff:ff:ff')

        return packet
コード例 #15
0
    def runArpBroadcastTest(self, tagged_ports, untagged_ports):
        zero_mac_addr = ":".join(["00"] * 6)
        vlan_id = 10
        next_id = vlan_id
        mcast_group_id = vlan_id
        all_ports = tagged_ports + untagged_ports
        arp_pkt = testutils.simple_arp_packet(pktlen=MIN_PKT_LEN - 4)
        # Account for VLAN header size in total pktlen
        vlan_arp_pkt = testutils.simple_arp_packet(vlan_vid=vlan_id,
                                                   pktlen=MIN_PKT_LEN)
        for port in tagged_ports:
            self.set_ingress_port_vlan(port, True, vlan_id, vlan_id)
        for port in untagged_ports:
            self.set_ingress_port_vlan(port, False, 0, vlan_id)
        self.add_bridging_entry(vlan_id, zero_mac_addr, zero_mac_addr, next_id)
        self.add_forwarding_acl_cpu_entry(eth_type=ETH_TYPE_ARP, clone=True)
        self.add_next_multicast(next_id, mcast_group_id)
        # FIXME: use clone session APIs when supported on PI
        # For now we add the CPU port to the mc group.
        self.add_mcast_group(mcast_group_id, all_ports + [self.cpu_port])
        for port in untagged_ports:
            self.set_egress_vlan_pop(port, vlan_id)

        for inport in all_ports:
            pkt_to_send = vlan_arp_pkt if inport in tagged_ports else arp_pkt
            testutils.send_packet(self, inport, str(pkt_to_send))
            # Pkt should be received on CPU and on all ports, except the ingress one.
            self.verify_packet_in(exp_pkt=pkt_to_send, exp_in_port=inport)
            verify_tagged_ports = set(tagged_ports)
            verify_tagged_ports.discard(inport)
            for tport in verify_tagged_ports:
                testutils.verify_packet(self, vlan_arp_pkt, tport)
            verify_untagged_ports = set(untagged_ports)
            verify_untagged_ports.discard(inport)
            for uport in verify_untagged_ports:
                testutils.verify_packet(self, arp_pkt, uport)
        testutils.verify_no_other_packets(self)
コード例 #16
0
    def test_port(self, port_number):
        src_mac = self.my_mac[port_number]
        packet = simple_arp_packet(
            eth_src=src_mac,
            vlan_vid=0,
            vlan_pcp=0,
            ip_snd='192.168.0.1',
            ip_tgt='192.168.0.2',
            hw_snd=src_mac,
            hw_tgt='00:00:00:00:00:00',
        )
        testutils.send_packet(self, (0, port_number), packet)

        exp_packet = simple_arp_packet(pktlen=42,
                                       eth_dst=src_mac,
                                       eth_src=self.remote_mac[port_number],
                                       vlan_vid=0,
                                       vlan_pcp=0,
                                       arp_op=2,
                                       ip_snd='192.168.0.2',
                                       ip_tgt='192.168.0.1',
                                       hw_snd=self.remote_mac[port_number],
                                       hw_tgt=src_mac)
        testutils.verify_packet(self, exp_packet, port_number)
コード例 #17
0
    def runTest(self):
        print ""
        print "Testing ARP reply packet..."
        # op=1 request, op=2 relpy
        arp_pkt = testutils.simple_arp_packet(eth_src=HOST1_MAC,
                                              eth_dst=HOST2_MAC,
                                              arp_op=2)
        self.test(arp_pkt)

        print "Testing NDP NA packet..."
        ndp_pkt = genNdpNaPkt(src_mac=HOST1_MAC,
                              dst_mac=HOST2_MAC,
                              src_ip=HOST1_IPV6,
                              dst_ip=HOST2_IPV6)
        self.test(ndp_pkt)
コード例 #18
0
ファイル: test_stress_arp.py プロジェクト: xumia/sonic-mgmt
def add_arp(ptf_intf_ipv4_addr, intf1_index, ptfadapter):
    ip_num = 0
    for arp_request_ip in ptf_intf_ipv4_addr:
        arp_request_ip = str(arp_request_ip)
        arp_src_mac = IntToMac(MacToInt(ARP_SRC_MAC) + ip_num)
        ip_num += 1
        pkt = testutils.simple_arp_packet(pktlen=60,
                                          eth_dst='ff:ff:ff:ff:ff:ff',
                                          eth_src=arp_src_mac,
                                          vlan_pcp=0,
                                          arp_op=2,
                                          ip_snd=arp_request_ip,
                                          ip_tgt=arp_request_ip,
                                          hw_snd=arp_src_mac,
                                          hw_tgt='ff:ff:ff:ff:ff:ff')
        testutils.send_packet(ptfadapter, intf1_index, pkt)
    logger.info("Sending {} arp entries".format(ip_num))
コード例 #19
0
def test_arp_garp_enabled(setup_ptf_arp, intfs_for_test, config_facts,
                          ptfadapter):
    '''
    Send a gratuitous ARP (GARP) packet from the PTF to the DUT

    The DUT should learn the (previously unseen) ARP info from the packet
    '''

    ptf_intf_ipv4_addr, _, ptf_intf_name = setup_ptf_arp

    arp_request_ip = increment_ipv4_addr(ptf_intf_ipv4_addr)
    arp_src_mac = '00:00:07:08:09:0a'
    _, intf1_index, _, _, _, _, duthost = intfs_for_test

    clear_dut_arp_cache(duthost)

    vlan_intfs = config_facts['VLAN_INTERFACE'].keys()
    garp_enable_cmd = 'redis-cli -n 4 HSET "VLAN_INTERFACE|{}" grat_arp enabled'
    for vlan in vlan_intfs:
        res = duthost.shell(garp_enable_cmd.format(vlan))

        if res['rc'] != 0:
            pytest.fail("Unable to enable GARP for {}".format(vlan))
        else:
            logger.info("Enabled GARP for {}".format(vlan))

    pkt = testutils.simple_arp_packet(pktlen=60,
                                      eth_dst='ff:ff:ff:ff:ff:ff',
                                      eth_src=arp_src_mac,
                                      vlan_pcp=0,
                                      arp_op=2,
                                      ip_snd=arp_request_ip,
                                      ip_tgt=arp_request_ip,
                                      hw_snd=arp_src_mac,
                                      hw_tgt='ff:ff:ff:ff:ff:ff')

    logger.info("Sending GARP for target {} from PTF interface {}".format(
        arp_request_ip, intf1_index))
    testutils.send_packet(ptfadapter, intf1_index, pkt)

    switch_arptable = duthost.switch_arptable()['ansible_facts']
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]
                  ['macaddress'] == arp_src_mac)
    pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]
                  ['interface'] in vlan_intfs)
コード例 #20
0
def send_arp_reply(ptfadapter, source_port, source_mac, dest_mac):
    """
    send arp reply packet
    :param ptfadapter: PTF adapter object
    :param source_port: source port
    :param source_mac: source MAC
    :param dest_mac: destination MAC
    :return:
    """
    pkt = testutils.simple_arp_packet(eth_dst=dest_mac,
                eth_src=source_mac,
                arp_op=2,
                ip_snd='10.10.1.2',
                ip_tgt='10.10.1.3',
                hw_tgt=dest_mac,
                hw_snd=source_mac,
                )
    logger.debug('send ARP reply packet source port id {} smac: {} dmac: {}'.format(source_port, source_mac, dest_mac))
    testutils.send(ptfadapter, source_port, pkt)
コード例 #21
0
 def _announce_new_neighbor_gen():
     """Generator to announce the neighbor to a different interface at each iteration."""
     for dut_iface in dut_ifaces:
         update_iface_func = yield dut_iface
         if callable(update_iface_func):
             update_iface_func(dut_iface)
         ptf_iface = dut_to_ptf_intf_map[dut_iface]
         garp_packet = testutils.simple_arp_packet(
             eth_src=NEW_NEIGHBOR_HWADDR,
             hw_snd=NEW_NEIGHBOR_HWADDR,
             ip_snd=NEW_NEIGHBOR_IPV4_ADDR,
             ip_tgt=NEW_NEIGHBOR_IPV4_ADDR,
             arp_op=2)
         logging.info(
             "GARP packet to announce new neighbor %s to mux interface %s:\n%s",
             NEW_NEIGHBOR_IPV4_ADDR, dut_iface,
             dump_scapy_packet_show_output(garp_packet))
         testutils.send(ptfadapter, int(ptf_iface), garp_packet, count=5)
         # let the generator stops here to allow the caller to execute testings
         yield
コード例 #22
0
    def test_unicast_in_l2_vni(self, duthost, ptfadapter, neighbor_size,
                               access_ports_type, evpn_env):
        neighbor_list = evpn_neighbor_list[:
                                           1] if neighbor_size == "one_neighbor" else evpn_neighbor_list

        # for packet from local to remote
        dst_mac_1 = "00:11:22:33:33:33"
        dst_ip_1 = "192.168.1.10"

        # for packet from remote to local
        dst_mac_2 = "00:11:22:33:33:44"
        dst_ip_2 = "192.168.1.20"

        access_port_list = [self.INDEX_OF_PORT_SEND] if access_ports_type == "normal_port" \
            else self.pch_param.member_index_list

        # local -> remote #
        for item in neighbor_list:
            ptf_vtep_index = item.if_index
            ptf_vtep_ip = str(item.ip_ptf.ip)
            ptf_vtep_as = item.as_number_ptf
            gobgp_port = item.gobgp_port
            dut_mac = evpn_env.dut_helper.get_index_mac(ptf_vtep_index)
            ptf_mac = evpn_env.ptf_helper.get_index_mac(ptf_vtep_index)
            logging.info(
                "encap test: local to remote, index:{}, gobgp port:{}".format(
                    ptf_vtep_index, gobgp_port))
            # let dut learn mac route from remote
            evpn_env.gobgp_helper.add_type2(dst_mac_1,
                                            dst_ip_1,
                                            None,
                                            as_ptf=ptf_vtep_as,
                                            vni=self.vni,
                                            vtep_ip=ptf_vtep_ip,
                                            gobgp_port=gobgp_port)

            # tagged packet is for sending
            pkt_untagged = testutils.simple_udp_packet(
                eth_dst=dst_mac_1,
                eth_src="00:11:22:33:55:66",
                ip_dst=dst_ip_1,
                ip_src="192.168.100.1",
            )

            # expected packet is for receiving
            pkt_expected = evpn_env.pkt_helper.compose_expected_vxlan_packet(
                outer_sa=dut_mac,
                outer_da=ptf_mac,
                outer_sip=DUT_VTEP_IP,
                outer_dip=ptf_vtep_ip,
                vni=self.vni,
                pkt=pkt_untagged,
                GPE_flag=False)

            for port in access_port_list:
                ptfadapter.dataplane.flush()
                testutils.send(ptfadapter, port, pkt_untagged)
                testutils.verify_packets(ptfadapter, pkt_expected,
                                         [ptf_vtep_index])

            # recover
            evpn_env.gobgp_helper.del_type2(dst_mac_1,
                                            dst_ip_1,
                                            None,
                                            as_ptf=ptf_vtep_as,
                                            vni=self.vni,
                                            vtep_ip=ptf_vtep_ip,
                                            gobgp_port=gobgp_port)

        # remote -> local #
        # let dut learn mac route from local
        pkt = testutils.simple_arp_packet(
            eth_src=dst_mac_2,
            vlan_vid=self.VLAN_ID,
            arp_op=1,
            ip_snd=dst_ip_2,
            ip_tgt=self.VLAN_IP,
            hw_snd=dst_mac_2,
        )

        # vxlan packet is for sending
        for item in neighbor_list:
            ptf_vtep_index = item.if_index
            ptf_vtep_ip = str(item.ip_ptf.ip)
            ptf_vtep_as = item.as_number_ptf
            gobgp_port = item.gobgp_port

            dut_mac = evpn_env.dut_helper.get_index_mac(ptf_vtep_index)
            ptf_mac = evpn_env.ptf_helper.get_index_mac(ptf_vtep_index)

            pkt_vxlan, pkt_expected = evpn_env.pkt_helper.create_vxlan_packet(
                outer_da=dut_mac,
                outer_sa=ptf_mac,
                outer_dip=DUT_VTEP_IP,
                outer_sip=ptf_vtep_ip,
                vni=self.vni,
                inner_sa="00:11:22:33:55:66",
                inner_sip="192.168.0.44",
                inner_da=dst_mac_2,
                inner_dip=dst_ip_2)

            # port move from local to remote. mac="00:11:22:33:55:66" because it is the src mac of the packet sent in local->remote

            logging.info(
                "decap test: remote to local, index:{}, gobgp port:{}".format(
                    ptf_vtep_index, gobgp_port))

            for send_port in access_port_list:
                testutils.send(ptfadapter, send_port, pkt)
                evpn_env.gobgp_helper.add_type2("00:11:22:33:55:66",
                                                "192.168.0.44",
                                                None,
                                                as_ptf=ptf_vtep_as,
                                                vni=self.vni,
                                                vtep_ip=ptf_vtep_ip,
                                                gobgp_port=gobgp_port)
                try:
                    evpn_env.pkt_helper.verify_decap_receive_packet(
                        ptf_vtep_index, access_port_list, pkt_vxlan,
                        pkt_expected)
                finally:
                    evpn_env.gobgp_helper.del_type2("00:11:22:33:55:66",
                                                    "192.168.0.44",
                                                    None,
                                                    as_ptf=ptf_vtep_as,
                                                    vni=self.vni,
                                                    vtep_ip=ptf_vtep_ip,
                                                    gobgp_port=gobgp_port)
コード例 #23
0
ファイル: checks.py プロジェクト: vmittal-msft/sonic-mgmt
    def _check(*args, **kwargs):
        """
        @summary: Checks if the OVS bridge mux simulator is functioning correctly
        @return: A dictionary containing the testing result of the PTF interface tested:
            {
                'failed': <True/False>,
                'failed_reason': <reason string>,
                'intf': '<PTF interface name> mux simulator'
            }
        """
        results = {
            'failed': False,
            'failed_reason': '',
            'check_item': '{} mux simulator'.format(ptf_server_intf)
        }

        logger.info(
            "Checking mux simulator status for PTF interface {}".format(
                ptf_server_intf))
        ptf_port_index = int(ptf_server_intf.replace('eth', ''))
        recover_all_directions(tor_mux_intf)

        upper_tor_intf_mac, upper_tor_mgmt_ip = get_arp_pkt_info(
            upper_tor_host)
        lower_tor_intf_mac, lower_tor_mgmt_ip = get_arp_pkt_info(
            lower_tor_host)

        upper_tor_ping_tgt_ip = '10.10.10.1'
        lower_tor_ping_tgt_ip = '10.10.10.2'
        ptf_arp_tgt_ip = '10.10.10.3'
        ping_cmd = 'ping -I {} {} -c 1 -W 1; true'

        upper_tor_exp_pkt = testutils.simple_arp_packet(
            eth_dst='ff:ff:ff:ff:ff:ff',
            eth_src=upper_tor_intf_mac,
            ip_snd=upper_tor_mgmt_ip,
            ip_tgt=upper_tor_ping_tgt_ip,
            hw_snd=upper_tor_intf_mac)
        lower_tor_exp_pkt = testutils.simple_arp_packet(
            eth_dst='ff:ff:ff:ff:ff:ff',
            eth_src=lower_tor_intf_mac,
            ip_snd=lower_tor_mgmt_ip,
            ip_tgt=lower_tor_ping_tgt_ip,
            hw_snd=lower_tor_intf_mac)

        ptf_arp_pkt = testutils.simple_arp_packet(ip_tgt=ptf_arp_tgt_ip,
                                                  ip_snd=ptf_arp_tgt_ip,
                                                  arp_op=2)

        # Clear ARP tables to start in consistent state
        upper_tor_host.shell("ip neigh flush all")
        lower_tor_host.shell("ip neigh flush all")

        # Run tests with upper ToR active
        toggle_simulator_port_to_upper_tor(tor_mux_intf)

        try:
            pytest_assert(check_simulator_read_side(tor_mux_intf) == 1)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Unable to switch active link to upper ToR'
            return results

        # Ping from both ToRs, expect only message from upper ToR to reach PTF
        upper_tor_host.shell(
            ping_cmd.format(tor_mux_intf, upper_tor_ping_tgt_ip))
        try:
            testutils.verify_packet(ptfadapter, upper_tor_exp_pkt,
                                    ptf_port_index)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from active upper ToR not received'
            return results

        lower_tor_host.shell(
            ping_cmd.format(tor_mux_intf, lower_tor_ping_tgt_ip))
        try:
            testutils.verify_no_packet(ptfadapter, lower_tor_exp_pkt,
                                       ptf_port_index)
        except AssertionError:
            results['failed'] = True
            results['failed_reason'] = 'Packet from standby lower ToR received'
            return results

        # Send dummy ARP packets from PTF to ToR. Ensure that ARP is learned on both ToRs
        upper_tor_host.shell("ip neigh flush all")
        lower_tor_host.shell("ip neigh flush all")
        testutils.send_packet(ptfadapter, ptf_port_index, ptf_arp_pkt)

        upper_tor_arp_table = upper_tor_host.switch_arptable(
        )['ansible_facts']['arptable']['v4']
        lower_tor_arp_table = lower_tor_host.switch_arptable(
        )['ansible_facts']['arptable']['v4']
        try:
            pytest_assert(ptf_arp_tgt_ip in upper_tor_arp_table)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from PTF not received on active upper ToR'
            return results

        try:
            pytest_assert(ptf_arp_tgt_ip in lower_tor_arp_table)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from PTF not received on standby lower ToR'
            return results

        # Repeat all tests with lower ToR active
        toggle_simulator_port_to_lower_tor(tor_mux_intf)
        try:
            pytest_assert(check_simulator_read_side(tor_mux_intf) == 2)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Unable to switch active link to lower ToR'
            return results

        lower_tor_host.shell(
            ping_cmd.format(tor_mux_intf, lower_tor_ping_tgt_ip))
        try:
            testutils.verify_packet(ptfadapter, lower_tor_exp_pkt,
                                    ptf_port_index)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from active lower ToR not received'
            return results

        upper_tor_host.shell(
            ping_cmd.format(tor_mux_intf, upper_tor_ping_tgt_ip))
        try:
            testutils.verify_no_packet(ptfadapter, upper_tor_exp_pkt,
                                       ptf_port_index)
        except AssertionError:
            results['failed'] = True
            results['failed_reason'] = 'Packet from standby upper ToR received'
            return results

        upper_tor_host.shell("ip neigh flush all")
        lower_tor_host.shell("ip neigh flush all")
        testutils.send_packet(ptfadapter, ptf_port_index, ptf_arp_pkt)

        upper_tor_arp_table = upper_tor_host.switch_arptable(
        )['ansible_facts']['arptable']['v4']
        lower_tor_arp_table = lower_tor_host.switch_arptable(
        )['ansible_facts']['arptable']['v4']
        try:
            pytest_assert(ptf_arp_tgt_ip in upper_tor_arp_table)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from PTF not received on standby upper ToR'
            return results

        try:
            pytest_assert(ptf_arp_tgt_ip in lower_tor_arp_table)
        except AssertionError:
            results['failed'] = True
            results[
                'failed_reason'] = 'Packet from PTF not received on active lower ToR'
            return results

        logger.info('Finished mux simulator check')
        return results
コード例 #24
0
    def _check(*args, **kwargs):
        """
        @summary: Checks if the OVS bridge mux simulator is functioning correctly
        @return: A dictionary containing the testing result of the PTF interface tested:
            {
                'failed': <True/False>,
                'failed_reason': <reason string>,
                'intf': '<PTF interface name> mux simulator'
            }
        """
        results = {
            'failed': False,
            'failed_reason': '',
            'check_item': 'mux_simulator',
            'interface': ptf_server_intf
        }

        failed = False
        reason = ''
        host = None

        logger.info(
            "Checking mux simulator status for PTF interface {}".format(
                ptf_server_intf))
        ptf_port_index = int(ptf_server_intf.replace('eth', ''))
        recover_all_directions(tor_mux_intf)

        upper_tor_intf_mac, upper_tor_mgmt_ip = get_arp_pkt_info(
            upper_tor_host)
        lower_tor_intf_mac, lower_tor_mgmt_ip = get_arp_pkt_info(
            lower_tor_host)

        upper_tor_ping_tgt_ip = '10.10.10.1'
        lower_tor_ping_tgt_ip = '10.10.10.2'
        ptf_arp_tgt_ip = '10.10.10.3'

        upper_tor_exp_pkt = testutils.simple_arp_packet(
            eth_dst='ff:ff:ff:ff:ff:ff',
            eth_src=upper_tor_intf_mac,
            ip_snd=upper_tor_mgmt_ip,
            ip_tgt=upper_tor_ping_tgt_ip,
            hw_snd=upper_tor_intf_mac)
        lower_tor_exp_pkt = testutils.simple_arp_packet(
            eth_dst='ff:ff:ff:ff:ff:ff',
            eth_src=lower_tor_intf_mac,
            ip_snd=lower_tor_mgmt_ip,
            ip_tgt=lower_tor_ping_tgt_ip,
            hw_snd=lower_tor_intf_mac)

        ptf_arp_pkt = testutils.simple_arp_packet(ip_tgt=ptf_arp_tgt_ip,
                                                  ip_snd=ptf_arp_tgt_ip,
                                                  arp_op=2)

        # Run tests with upper ToR active
        try:
            # Stop linkmgrd to prevent it from switching over ports
            upper_tor_host.shell('systemctl stop mux')
            lower_tor_host.shell('systemctl stop mux')

            toggle_simulator_port_to_upper_tor(tor_mux_intf)
            if check_simulator_read_side(tor_mux_intf) != 1:
                failed = True
                reason = 'Unable to switch active link to upper ToR'

            if not failed:
                failed, reason, host = mux_sim_check_downstream(
                    upper_tor_host, lower_tor_host, ptfadapter,
                    upper_tor_ping_tgt_ip, lower_tor_ping_tgt_ip,
                    upper_tor_exp_pkt, lower_tor_exp_pkt, ptf_port_index,
                    tor_mux_intf)

            if not failed:
                failed, reason, host = mux_sim_check_upstream(
                    upper_tor_host, lower_tor_host, ptfadapter, ptf_arp_tgt_ip,
                    ptf_arp_pkt, ptf_port_index)

            # Repeat all tests with lower ToR active
            if not failed:
                toggle_simulator_port_to_lower_tor(tor_mux_intf)
                if check_simulator_read_side(tor_mux_intf) != 2:
                    failed = True
                    reason = 'Unable to switch active link to lower ToR'

            if not failed:
                failed, reason, host = mux_sim_check_downstream(
                    lower_tor_host, upper_tor_host, ptfadapter,
                    lower_tor_ping_tgt_ip, upper_tor_ping_tgt_ip,
                    lower_tor_exp_pkt, upper_tor_exp_pkt, ptf_port_index,
                    tor_mux_intf)

            if not failed:
                failed, reason, host = mux_sim_check_upstream(
                    upper_tor_host, lower_tor_host, ptfadapter, ptf_arp_tgt_ip,
                    ptf_arp_pkt, ptf_port_index)

            logger.info('Finished mux simulator check')
        finally:
            cmds = [
                'ip neigh flush all', 'systemctl reset-failed mux',
                'systemctl start mux'
            ]

            lower_tor_host.shell_cmds(cmds=cmds)
            upper_tor_host.shell_cmds(cmds=cmds)

        results['failed'] = failed
        results['failed_reason'] = reason
        if host is not None:
            results['host'] = host

        return results
コード例 #25
0
 def runTest(self):
     pkt = testutils.simple_arp_packet(pktlen=80)
     self.runPacketInTest(pkt)