Exemple #1
0
    def check_packet_transmission(self, pkt_types, layer_configs=None):
        time.sleep(1)
        for pkt_type in pkt_types.keys():
            pkt_names = pkt_types[pkt_type]
            pkt = Packet(pkt_type=pkt_type)
            if layer_configs:
                for layer in layer_configs.keys():
                    pkt.config_layer(layer, layer_configs[layer])
            inst = sniff_packets(self.tester_iface, count=1, timeout=8)
            pkt.send_pkt(tx_port=self.tester_iface)
            out = self.dut.get_session_output(timeout=2)
            time.sleep(1)
            load_sniff_packets(inst)
            if self.printFlag: # debug output
                print out
            for pkt_layer_name in pkt_names:
                if self.printFlag:# debug output
                    print pkt_layer_name
                if pkt_layer_name not in out:
                    print utils.RED("Fail to detect %s" % pkt_layer_name)
                    if not self.printFlag:
                        raise VerifyFailure("Failed to detect %s" % pkt_layer_name)
            else:
                print utils.GREEN("Detected %s successfully" % pkt_type)
	        time.sleep(1)
Exemple #2
0
 def get_tcpdump_package(self):  
     pkts = load_sniff_packets(self.inst)
     dsts = []  
     for packet in pkts:  
         dst = packet.strip_element_layer2("dst")  
         dsts.append(dst)
     return dsts  
Exemple #3
0
    def test_pvid_vf_tx(self):
        """
        Add port based vlan on vf device and check vlan tx work
        """
        random_vlan = random.randint(1, MAX_VLAN)

        self.dut.send_expect(
            "ip link set %s vf 0 vlan %d" % (self.host_intf0, random_vlan), "# ")
        out = self.dut.send_expect("ip link show %s" % self.host_intf0, "# ")
        self.verify("vlan %d" %
                    random_vlan in out, "Failed to add pvid on VF0")

        self.vm0_dut_ports = self.vm_dut_0.get_ports('any')

        self.vm0_testpmd = PmdOutput(self.vm_dut_0)
        self.vm0_testpmd.start_testpmd(VM_CORES_MASK)
        self.vm0_testpmd.execute_cmd('set fwd mac')
        self.vm0_testpmd.execute_cmd('start')

        pkt = Packet(pkt_type='UDP')
        pkt.config_layer('ether', {'dst': self.vf1_mac})
        inst = sniff_packets(self.tester_intf0, timeout=5)
        pkt.send_pkt(tx_port=self.tester_intf1)
        pkts = load_sniff_packets(inst)

        self.verify(len(pkts), "Not receive expected packet")
        self.vm0_testpmd.quit()

        # disable pvid
        self.dut.send_expect(
            "ip link set %s vf 0 vlan 0" % (self.host_intf0), "# ")
Exemple #4
0
 def get_tcpdump_package(self):
     pkts = load_sniff_packets(self.inst)
     vlans = []
     for packet in pkts:
         vlan = packet.strip_element_vlan("vlan")
         vlans.append(vlan)
     return vlans
 def strip_vlan(self, inst):
     """
     Load sniff packets, strip and return vlan id from dump message
     """
     pkts = load_sniff_packets(inst)
     vlans = []
     for pkt in pkts:
         vlan = pkt.strip_element_vlan("vlan")
         vlans.append(vlan)
     return vlans
 def strip_mac(self, inst, element="src"):
     """
     Load sniff packets, strip and return mac address from dump message
     """
     pkts = load_sniff_packets(inst)
     macs = []
     for pkt in pkts:
         mac = pkt.strip_element_layer2(element)
         macs.append(mac)
     return macs
Exemple #7
0
    def functional_check_ipv4(self, pkt_sizes, burst=1, flag=None):
        """
        Perform functional fragmentation checks.
        """
        for size in pkt_sizes[::burst]:
            # simulate to set TG properties
            if flag == 'frag':
                # do fragment, each packet max length 1518 - 18 - 20 = 1480
                expPkts = (size - HEADER_SIZE['eth'] - HEADER_SIZE['ip']) / 1480
                if (size - HEADER_SIZE['eth'] - HEADER_SIZE['ip']) % 1480:
                    expPkts += 1
                val = 0
            elif flag == 'nofrag':
                expPkts = 0
                val = 2
            else:
                expPkts = 1
                val = 2

            inst = sniff_packets(intf=self.rxItf, timeout=5)
            # send packet
            for times in range(burst):
                pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
                pkt = Packet(pkt_type='UDP', pkt_len=pkt_size)
                pkt.config_layer('ether', {'dst': self.dmac})
                pkt.config_layer('ipv4', {'dst': '100.10.0.1', 'src': '1.2.3.4', 'flags': val})
                pkt.send_pkt(tx_port=self.txItf)

            # verify normal packet just by number, verify fragment packet by all elements
            pkts = load_sniff_packets(inst)
            self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
            if flag == 'frag':
                idx = 1
                for pkt in pkts:
                    # packet index should be same
                    pkt_id = pkt.strip_element_layer3("id")
                    if idx == 1:
                        prev_idx = pkt_id
                    self.verify(prev_idx == pkt_id, "Fragmented packets index not match")
                    prev_idx = pkt_id

                    # last flags should be 0
                    flags = pkt.strip_element_layer3("flags")
                    if idx == expPkts:
                        self.verify(flags == 0, "Fragmented last packet flags not match")
                    else:
                        self.verify(flags == 1, "Fragmented packets flags not match")

                    # fragment offset should be correct
                    frag = pkt.strip_element_layer3("frag")
                    self.verify((frag == ((idx - 1) * 185)), "Fragment packet frag not match")
                    idx += 1
Exemple #8
0
    def tx_and_check(self, tx_vlan=1):
        inst = sniff_packets(self.tester_intf0, timeout=5)
        self.vm0_testpmd.execute_cmd('set burst 1')
        self.vm0_testpmd.execute_cmd('start tx_first')
        self.vm0_testpmd.execute_cmd('stop')

        # strip sniffered vlans
        pkts = load_sniff_packets(inst)
        vlans = []
        for pkt in pkts:
            vlan = pkt.strip_element_vlan("vlan")
            vlans.append(vlan)

        self.verify(tx_vlan in vlans, "Tx packet with vlan not received!!!")
Exemple #9
0
    def functional_check_ipv6(self, pkt_sizes, burst=1, flag=None, funtion=None):
        """
        Perform functional fragmentation checks.
        """
        for size in pkt_sizes[::burst]:
            # simulate to set TG properties
            if flag == 'frag':
                # each packet max len: 1518 - 18 (eth) - 40 (ipv6) - 8 (ipv6 ext hdr) = 1452
                expPkts = (size - HEADER_SIZE['eth'] - HEADER_SIZE['ipv6']) / 1452
                if (size - HEADER_SIZE['eth'] - HEADER_SIZE['ipv6']) % 1452:
                    expPkts += 1
                val = 0
            else:
                expPkts = 1
                val = 2

            inst = sniff_packets(intf=self.rxItf, timeout=5)
            # send packet
            for times in range(burst):
                pkt_size = pkt_sizes[pkt_sizes.index(size) + times]
                pkt = Packet(pkt_type='IPv6_UDP', pkt_len=pkt_size)
                pkt.config_layer('ether', {'dst': self.dmac})
                pkt.config_layer('ipv6', {'dst': '101:101:101:101:101:101:101:101', 'src': 'ee80:ee80:ee80:ee80:ee80:ee80:ee80:ee80'})
                pkt.send_pkt(tx_port=self.txItf)

            # verify normal packet just by number, verify fragment packet by all elements
            pkts = load_sniff_packets(inst)
            self.verify(len(pkts) == expPkts, "Failed on forward packet size " + str(size))
            if flag == 'frag':
                idx = 1
                for pkt in pkts:
                    # packet index should be same
                    pkt_id = pkt.strip_element_layer4("id")
                    if idx == 1:
                        prev_idx = pkt_id
                    self.verify(prev_idx == pkt_id, "Fragmented packets index not match")
                    prev_idx = pkt_id

                    # last flags should be 0
                    flags = pkt.strip_element_layer4("m")
                    if idx == expPkts:
                        self.verify(flags == 0, "Fragmented last packet flags not match")
                    else:
                        self.verify(flags == 1, "Fragmented packets flags not match")

                    # fragment offset should be correct
                    frag = pkt.strip_element_layer4("offset")
                    self.verify((frag == int((idx - 1) * 181.5)), "Fragment packet frag not match")
                    idx += 1
Exemple #10
0
    def scatter_pktgen_send_packet(self, pktsize):
        """
        Functional test for scatter packets.
        """
        dmac = self.dut.get_mac_address(self.port)

        inst = sniff_packets(self.intf)
        pkt = Packet(pkt_type="IP_RAW", pkt_len=pktsize)
        pkt.config_layer('ether', {'dst': dmac})
        pkt.send_pkt(tx_port=self.intf)
        sniff_pkts = load_sniff_packets(inst)

        res = ""
        if len(sniff_pkts):
            res = strip_pktload(sniff_pkts[0], layer="L4")
        return res
Exemple #11
0
    def check_packets_transfer(self, tx_port, rx_port, tgen_input, pkt_cnt=1):
        '''
        check packets transmission status
        '''
        # check forwarded mac has been changed
        rev_port = self.tester.get_local_port(rx_port)
        send_port = self.tester.get_local_port(tx_port)
        dst_mac = self.dut.get_mac_address(rx_port)
        rx_intf = self.tester.get_interface(rev_port)
        tx_intf = self.tester.get_interface(send_port)
        # send and sniff packet
        rx_inst = sniff_packets(rx_intf, timeout=5)
        self.send_pcap_pkt_by_scapy(self.tester, tgen_input[0][2], tx_intf)
        pkts = load_sniff_packets(rx_inst)
        self.verify(len(pkts) == pkt_cnt, "Packet not forwarded as expected")

        return
Exemple #12
0
    def test_mac_address(self):
        """
        Test ethtool app mac function
        """
        valid_mac = "00:10:00:00:00:00"
        self.dut.send_expect(self.cmd, "EthApp>", 60)
        for index in range(len(self.ports)):
            port = self.ports[index]
            mac = self.dut.ports_info[port]['mac']
            dump_mac = self.strip_mac(index)
            self.verify(mac == dump_mac, "Userspace tool failed to dump mac")
            self.dut.send_expect("macaddr %d %s" % (port, valid_mac),
                                 "EthApp>")
            dump_mac = self.strip_mac(index)
            self.verify(dump_mac == valid_mac,
                        "Userspace tool failed to set mac")
            # check forwarded mac has been changed
            pkt = Packet()
            tester_port = self.tester.get_local_port(port)
            intf = self.tester.get_interface(tester_port)
            # send and sniff packet
            inst = sniff_packets(intf, timeout=5)
            pkt.send_pkt(tx_port=intf)
            pkts = load_sniff_packets(inst)
            self.verify(len(pkts) == 1, "Packet not forwarded as expected")
            src_mac = pkts[0].strip_layer_element("layer2", "src")
            self.verify(src_mac == valid_mac,
                        "Forwarded packet not match default mac")

        # check multicase will not be valid mac
        invalid_mac = "01:00:00:00:00:00"
        out = self.dut.send_expect("validate %s" % invalid_mac, "EthApp>")
        self.verify("not unicast" in out,
                    "Failed to detect incorrect unicast mac")
        invalid_mac = "00:00:00:00:00:00"
        out = self.dut.send_expect("validate %s" % invalid_mac, "EthApp>")
        self.verify("not unicast" in out,
                    "Failed to detect incorrect unicast mac")
        out = self.dut.send_expect("validate %s" % valid_mac, "EthApp>")
        self.verify("is unicast" in out,
                    "Failed to detect correct unicast mac")
        self.dut.send_expect("quit", "# ")
Exemple #13
0
    def test_etag_insertion(self):
        '''
        When E-tag insertion enable in VF0
        '''
        host_cmds = [['port config 0 l2-tunnel E-tag enable'],
                     ['E-tag set insertion on port-tag-id 1000 port 0 vf 0'],
                     ['set fwd mac'], ['set verbose 1'], ['start']]
        guest_cmds = [['set fwd mac'], ['set verbose 1'], ['start']]
        self.preset_test_enviroment()
        self.execute_host_testpmd_cmd(host_cmds)
        self.execute_guest_testpmd_cmd(guest_cmds)

        self.vm0_dut_ports = self.vm_dut_0.get_ports('any')
        config_layers = {'ether': {'src': self.src_mac}}
        pkt_types = {'IP_RAW': {'layer_configs': config_layers}}

        intf = self.src_intf
        inst = sniff_packets(intf)

        self.check_packet_transmission(pkt_types)
        time.sleep(1)
        pkts = load_sniff_packets(inst)
        self.host_testpmd.execute_cmd(
            'E-tag set insertion off port-tag-id 1000 port 0 vf 0')

        # load sniff pcap file, check received packet's content
        packetContentFile = "/tmp/packetContent.log"
        pcap_file = "/tmp/sniff_%s.pcap" % intf
        fp = open(packetContentFile, 'w')
        backup_out = sys.stdout
        sys.stdout = fp
        pkts = rdpcap(pcap_file)
        pkts.show()
        fp.close()
        sys.stdout = backup_out
        fp = open(packetContentFile, 'r')
        out = fp.read()
        fp.close()
        if self.printFlag:  # debug output
            print out
        self.verify("Dot1BR" in out,
                    "tester %s hasn't receiver etag packet" % intf)
Exemple #14
0
    def send_packet(self, txPort, rxPort, nic, pktSize=64, received=True):
        """
        Send packages according to parameters.
        """
        rxitf = self.tester.get_interface(self.tester.get_local_port(rxPort))
        txitf = self.tester.get_interface(self.tester.get_local_port(txPort))

        dmac = self.dut.get_mac_address(txPort)

        pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
        inst = sniff_packets(rxitf)
        pkt.config_layer('ether', {'dst': dmac})
        pkt.send_pkt(tx_port=txitf)
        sniff_pkts = load_sniff_packets(inst)

        if received:
            res = strip_pktload(sniff_pkts[0], layer="L4")
            self.verify("58 58 58 58 58 58 58 58" in res,
                        "receive queue not work as expected")
        else:
            self.verify(
                len(sniff_pkts) == 0, "stop queue not work as expected")
Exemple #15
0
    def checksum_validate(self, packets_sent, packets_expected):
        """
        Validate the checksum.
        """
        tx_interface = self.tester.get_interface(
            self.tester.get_local_port(self.dut_ports[0]))
        rx_interface = self.tester.get_interface(
            self.tester.get_local_port(self.dut_ports[0]))

        sniff_src = self.dut.get_mac_address(self.dut_ports[0])
        checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)")

        chksum = dict()
        result = dict()

        self.tester.send_expect("scapy", ">>> ")

        for packet_type in packets_expected.keys():
            self.tester.send_expect("p = %s" % packets_expected[packet_type],
                                    ">>>")
            out = self.tester.send_expect("p.show2()", ">>>")
            chksums = checksum_pattern.findall(out)
            chksum[packet_type] = chksums

        self.tester.send_expect("exit()", "#")

        inst = sniff_packets(intf=rx_interface,
                             count=len(packets_sent),
                             filters=[{
                                 'layer': 'ether',
                                 'config': {
                                     'src': sniff_src
                                 }
                             }])

        for packet_type in packets_sent.keys():
            self.tester.scapy_append('sendp([%s], iface="%s")' %
                                     (packets_sent[packet_type], tx_interface))

        self.tester.scapy_execute()
        p = load_sniff_packets(inst)
        nr_packets = len(p)
        reslist = [
            p[i].pktgen.pkt.sprintf(
                "%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%")
            for i in range(nr_packets)
        ]
        out = string.join(reslist, ",")
        packets_received = out.split(',')
        self.verify(
            len(packets_sent) == len(packets_received),
            "Unexpected Packets Drop")

        for packet_received in packets_received:
            ip_checksum, tcp_checksum, udp_checksum, sctp_checksum = packet_received.split(
                ';')

            packet_type = ''
            l4_checksum = ''
            if tcp_checksum != '??':
                packet_type = 'TCP'
                l4_checksum = tcp_checksum
            elif udp_checksum != '??':
                packet_type = 'UDP'
                l4_checksum = udp_checksum
            elif sctp_checksum != '??':
                packet_type = 'SCTP'
                l4_checksum = sctp_checksum

            if ip_checksum != '??':
                packet_type = 'IP/' + packet_type
                if chksum[packet_type] != [ip_checksum, l4_checksum]:
                    result[packet_type] = packet_type + " checksum error"
            else:
                packet_type = 'IPv6/' + packet_type
                if chksum[packet_type] != [l4_checksum]:
                    result[packet_type] = packet_type + " checksum error"

        return result