test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH 1/3] Strip hugepage mount directory and netdev numa id for vxlan sample.
@ 2015-06-04  7:21 Yong Liu
  2015-06-04  7:21 ` [dts] [PATCH 2/3] Add vxlan sample test plan Yong Liu
  2015-06-04  7:21 ` [dts] [PATCH 3/3] Add vxlan sample test suite Yong Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Yong Liu @ 2015-06-04  7:21 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/crb.py b/framework/crb.py
index 7a86b31..c4553b6 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -101,6 +101,14 @@ class Crb(object):
         self.send_expect('mkdir -p /mnt/huge', '# ')
         self.send_expect('mount -t hugetlbfs nodev /mnt/huge', '# ')
 
+    def strip_hugepage_path(self):
+        mounts = self.send_expect("cat /proc/mounts |grep hugetlbfs", "# ")
+        infos = mounts.split()
+        if len(infos) >= 2:
+            return infos[1]
+        else:
+            return ''
+
     def set_huge_pages(self, huge_pages, numa=-1):
         """
         Set numbers of huge pages
diff --git a/framework/dut.py b/framework/dut.py
index caaae62..a9b4ed0 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -258,6 +258,8 @@ class Dut(Crb):
         """
         Setup Linux hugepages.
         """
+        if self.virttype == 'XEN':
+            return
         hugepages_size = self.send_expect("awk '/Hugepagesize/ {print $2}' /proc/meminfo", "# ")
 
         if int(hugepages_size) < (1024 * 1024):
@@ -275,6 +277,8 @@ class Dut(Crb):
             if total_huge_pages != arch_huge_pages:
                 self.set_huge_pages(arch_huge_pages)
 
+            self.hugepage_path = self.strip_hugepage_path()
+
     def setup_memory_freebsd(self, hugepages=-1):
         """
         Setup Freebsd hugepages.
diff --git a/framework/net_device.py b/framework/net_device.py
index 0e6614f..b8d785e 100644
--- a/framework/net_device.py
+++ b/framework/net_device.py
@@ -60,6 +60,7 @@ class NetDevice(object):
         if self.nic_is_pf():
             self.default_vf_driver = ''
         self.intf_name = self.get_interface_name()
+        self.socket = self.get_nic_socket()
 
     def __send_expect(self, cmds, expected, timeout=TIMEOUT, alt_session=True):
         """
@@ -98,6 +99,29 @@ class NetDevice(object):
         """
         return self.crb.get_pci_dev_driver(self.bus_id, self.devfun_id)
 
+    def get_nic_socket(self):
+        """
+        Get socket id of specified pci device.
+        """
+        get_nic_socket = getattr(
+            self, 'get_nic_socket_%s' %
+            self.__get_os_type())
+        return get_nic_socket(self.bus_id, self.devfun_id)
+
+    def get_nic_socket_linux(self, bus_id, devfun_id):
+        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/numa_node' %
+                   (bus_id, devfun_id))
+        try:
+            out = self.__send_expect(command, '# ')
+            socket = int(out)
+        except:
+            socket = -1
+        return socket
+
+
+    def get_nic_socket_freebsd(self, bus_id, devfun_id):
+        NotImplemented
+
     @nic_has_driver
     def get_interface_name(self):
         """
@@ -234,7 +258,7 @@ class NetDevice(object):
         """
         Get ipv4 address of specified pci device.
         """
-        get_ipv4_addr = getaddr(
+        get_ipv4_addr = getattr(
             self, 'get_ipv4_addr_%s' % self.__get_os_type())
         return get_ipv4_addr(self.intf_name, self.currenct_driver)
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dts] [PATCH 2/3] Add vxlan sample test plan.
  2015-06-04  7:21 [dts] [PATCH 1/3] Strip hugepage mount directory and netdev numa id for vxlan sample Yong Liu
@ 2015-06-04  7:21 ` Yong Liu
  2015-06-04  7:21 ` [dts] [PATCH 3/3] Add vxlan sample test suite Yong Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Yong Liu @ 2015-06-04  7:21 UTC (permalink / raw)
  To: dts

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 9394 bytes --]

From: Marvin Liu <yong.liu@intel.com>

Vxlan sample simulates a VXLAN Tunnel Endpoint (VTEP) termination in DPDK.
It is used to demonstrate the offload and filtering capabilities of i40 NIC
for VXLAN packet.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/test_plans/vxlan_sample_test_plan.rst b/test_plans/vxlan_sample_test_plan.rst
new file mode 100644
index 0000000..93136fd
--- /dev/null
+++ b/test_plans/vxlan_sample_test_plan.rst
@@ -0,0 +1,225 @@
+.. Copyright (c) <2015>, Intel Corporation
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+
+   - Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+
+   - Neither the name of Intel Corporation nor the names of its
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPR   ESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+   OF THE POSSIBILITY OF SUCH DAMAGE.
+
+============
+Vxlan Sample
+============
+Vxlan sample simulates a VXLAN Tunnel Endpoint (VTEP) termination in DPDK.
+It is used to demonstrate the offload and filtering capabilities of i40 NIC
+for VXLAN packet.
+
+Vxlan sample uses the basic virtio devices management function from vHOST 
+example, and the US-vHost interface and tunnel filtering mechanism to direct 
+the traffic to/from a specific VM.
+
+Vxlan sample is also designed to show how tunneling protocols can be handled. 
+
+Prerequisites
+=============
+1x Intel® X710 (Fortville) NICs (2x 40GbE full duplex optical ports per NIC)
+plugged into the available PCIe Gen3 8-lane slot.
+
+2x Intel® XL710-DA4 (Eagle Fountain) (1x 10GbE full duplex optical ports per NIC)
+plugged into the avaiable PCIe Gen3 8-lane slot.
+
+DUT board must be two sockets system and each cpu have more than 8 lcores.
+
+Update qemu-system-x86_64 to version 2.2.0 which support hugepage based memory.
+Prepare vhost-use requested modules::
+
+    modprobe fuse
+    modprobe cuse
+    insmod lib/librte_vhost/eventfd_link/eventfd_link.ko
+
+Allocate 4096*2M hugepages for vm and dpdk::
+
+    echo 4096 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
+
+Test Case: Vxlan Sample Encap packet
+====================================
+Start vxlan sample with only encapsulation enable::
+
+    tep_termination -c 0xf -n 3 --socket-mem 2048,2048 -- -p 0x1 \
+        --udp-port 4789 --nb-devices 2 --filter-type 3 --tx-checksum 0 \
+        --encap 1 --decap 0
+
+Wait for vhost-net socket device created and message dumped::
+
+    VHOST_CONFIG: bind to vhost-net
+
+Start virtual machine with hugepage based memory and two vhost-user devices::
+
+    qemu-system-x86_64 -name vm0 -enable-kvm -daemonize \
+      -cpu host -smp 4 -m 4096 \
+      -object memory-backend-file,id=mem,size=4096M,mem-path=/mnt/huge,share=on \
+      -numa node,memdev=mem -mem-prealloc \
+      -chardev socket,id=char0,path=./dpdk/vhost-net \
+      -netdev type=vhost-user,id=netdev0,chardev=char0,vhostforce \
+      -device virtio-net-pci,netdev=netdev0,mac=00:00:20:00:00:20 \
+      -chardev socket,id=char1,path=./dpdk/vhost-net \
+      -netdev type=vhost-user,id=netdev1,chardev=char1,vhostforce \
+      -device virtio-net-pci,netdev=netdev1,mac=00:00:20:00:00:21 \
+      -drive file=/storage/vm-image/vm0.img -vnc :1
+Login into virtual machine and start testpmd with additional arguments::
+
+    testpmd -c f -n 3 -- -i --txqflags=0xf00 --disable-hw-vlan
+
+Start packet forward of testpmd and transit several packets for mac learning::
+
+    testpmd> set fwd mac
+    testpmd> start tx_first
+
+Make sure virtIO port registered normally::
+
+    VHOST_CONFIG: virtio is now ready for processing.
+    VHOST_DATA: (1) Device has been added to data core 56
+    VHOST_DATA: (1) MAC_ADDRESS 00:00:20:00:00:21 and VNI 1000 registered
+    VHOST_DATA: (0) MAC_ADDRESS 00:00:20:00:00:20 and VNI 1000 registered
+
+Send normal udp packet to PF device and packet dmac match PF device 
+Verify packet has been recevied in virtIO port0 and forwarded by port1::
+
+      testpmd> show port stats all
+
+Verify encapsulated packet received on PF device
+
+Test Case: Vxlan Sample Decap packet
+====================================
+Start vxlan sample with only de-capsulation enable::
+
+  tep_termination -c 0xf -n 3 --socket-mem 2048,2048 -- -p 0x1 \
+    --udp-port 4789 --nb-devices 2 --filter-type 3 --tx-checksum 0 \
+    --encap 0 --decap 1
+
+Start vhost-user test environment like case vxlan_sample_encap.
+
+Send vxlan packet Ether(dst=PF mac)/IP/UDP/vni(1000)/
+  Ether(dst=virtIO port0)/IP/UDP to PF device::
+
+Verify that packet received by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify that PF received packet just the same as inner packet
+
+Send vxlan packet Ether(dst=PF mac)/IP/UDP/vni(1000)/
+    Ether(dst=virtIO port1)/IP/UDP to PF device
+
+Verify that packet received by virtIO port1 and forwarded by virtIO port0::
+
+  testpmd> show port stats all  
+
+Make sure PF received packet received inner packet with mac reversed.
+
+Test Case: Vxlan Sample Encap and Decap
+=======================================
+Start vxlan sample with only de-capsulation enable::
+
+  tep_termination -c 0xf -n 3 --socket-mem 2048,2048 -- -p 0x1 \
+    --udp-port 4789 --nb-devices 2 --filter-type 3 --tx-checksum 0 \
+    --encap 1 --decap 1
+
+Start vhost-user test environment like case vxlan_sample_encap
+
+Send vxlan packet Ether(dst=PF mac)/IP/UDP/vni(1000)/
+  Ether(dst=virtIO port0)/IP/UDP to PF device
+
+Verify that packet received by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify encapsulated packet received on PF device.
+Verify that inner packet src and dst mac address have been conversed.
+
+Test Case: Vxlan Sample Checksum
+================================
+Start vxlan sample with only decapsulation enable::
+
+  tep_termination -c 0xf -n 3 --socket-mem 2048,2048 -- -p 0x1 \
+    --udp-port 4789 --nb-devices 2 --filter-type 3 --tx-checksum 1 \
+    --encap 1 --decap 1
+
+Start vhost-user test environment like case vxlan_sample_encap
+
+Send vxlan packet with Ether(dst = PF mac)/IP/UDP/vni(1000)/ 
+  Ether(dst = virtIO port0)/IP wrong chksum/ UDP wrong chksum
+
+Verify that packet recevied by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify encapsulated packet received on PF device.
+Verify that inner packet src and dst mac address have been conversed.
+Verify that inner packet ip checksum and udp checksum were corrected.
+
+Send vxlan packet with Ether(dst = PF mac)/IP/UDP/vni(1000)/ 
+  Ether(dst = virtIO port0)/IP wrong chksum/ TCP wrong chksum
+
+Verify that packet recevied by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify encapsulated packet received on PF device.
+Verify that inner packet src and dst mac address have been conversed.
+Verify that inner packet ip checksum and tcp checksum were corrected.
+
+Send vxlan packet with Ether(dst = PF mac)/IP/UDP/vni(1000)/ 
+  Ether(dst = virtIO port0)/IP wrong chksum/ SCTP wrong chksum
+
+Verify that packet received by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify encapsulated packet received on PF device.
+Verify that inner packet src and dst mac address have been conversed.
+Verify that inner packet ip checksum and sctp checksum were corrected.
+
+Test Case: Vxlan Sample TSO
+===========================
+Start vxlan sample with tso enable, tx checksum must enable too.
+For hardware limitation, tso segment size must be larger 256::
+
+  tep_termination -c 0xf -n 3 --socket-mem 2048,2048 -- -p 0x1 \
+    --udp-port 4789 --nb-devices 2 --filter-type 3 --tx-checksum 1 \
+    --encap 1 --decap 1 --tso-segsz 256
+
+Start vhost-user test environment like case vxlan_sample_encap
+
+Send vxlan packet with Ether(dst = PF mac)/IP/UDP/vni(1000)/ 
+  Ether(dst = virtIO port0)/TCP/892 Bytes data, total length will be 1000
+
+Verify that packet recevied by virtIO port0 and forwarded by virtIO port1::
+
+  testpmd> show port stats all
+
+Verify that four separated vxlan packets received on PF devices.
+Make sure tcp packet payload is 256, 256, 256 and 124.
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dts] [PATCH 3/3] Add vxlan sample test suite.
  2015-06-04  7:21 [dts] [PATCH 1/3] Strip hugepage mount directory and netdev numa id for vxlan sample Yong Liu
  2015-06-04  7:21 ` [dts] [PATCH 2/3] Add vxlan sample test plan Yong Liu
@ 2015-06-04  7:21 ` Yong Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Yong Liu @ 2015-06-04  7:21 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Vxlan sample encap/decap/chksum/tso function will be verified in this suite.
And this suite based on vxlan test suite.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/tests/TestSuite_vxlan_sample.py b/tests/TestSuite_vxlan_sample.py
new file mode 100644
index 0000000..eccace7
--- /dev/null
+++ b/tests/TestSuite_vxlan_sample.py
@@ -0,0 +1,471 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of Intel Corporation nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+DPDK Test suite.
+
+Vxlan sample test suite.
+"""
+
+import os
+import dts
+import string
+import re
+import time
+from plotting import Plotting
+from test_case import TestCase
+from exception import VerifyFailure
+from settings import HEADER_SIZE
+from etgen import IxiaPacketGenerator
+from qemu_kvm import QEMUKvm
+from TestSuite_vxlan import VxlanTestConfig
+from pmd_output import PmdOutput
+
+from scapy.utils import struct, socket, wrpcap, rdpcap
+from scapy.layers.inet import Ether, IP, TCP, UDP
+from scapy.layers.inet6 import IPv6
+from scapy.layers.l2 import Dot1Q
+from scapy.layers.vxlan import Vxlan
+from scapy.layers.sctp import SCTP, SCTPChunkData
+from scapy.sendrecv import sniff
+from scapy.config import conf
+from scapy.route import *
+
+
+class TestVxlanSample(TestCase):
+    FEAT_ENABLE = 1
+    FEAT_DISABLE = 0
+    INNER_VLAN_VNI = 1
+    INNER_VNI = 2
+    OUTER_INNER_VNI = 3
+
+    def set_up_all(self):
+        """
+        Run before each test suite.
+        """
+        # Change the config file to support vhost and recompile the package.
+        self.dut.send_expect(
+            "sed -i -e 's/RTE_LIBRTE_VHOST=n$/RTE_LIBRTE_VHOST=y/' config/common_linuxapp", "# ", 30)
+        # temporary disable skip_setup
+        skip_setup = self.dut.skip_setup
+        self.dut.skip_setup = False
+        self.dut.build_install_dpdk(self.target)
+        self.dut.skip_setup = skip_setup
+
+        # this feature only enable in FVL now
+        self.verify(
+            self.nic in ["fortville_eagle", "fortville_spirit", "fortville_spirit_single"], "Vxlan Only supported by Fortville")
+        # Based on h/w type, choose how many ports to use
+        self.dut_ports = self.dut.get_ports(self.nic)
+
+        # Verify that enough ports are available
+        self.verify(len(self.dut_ports) >= 1, "Insufficient ports for testing")
+
+        # get pf socket
+        self.pf = self.dut_ports[0]
+        netdev = self.dut.ports_info[self.pf]['port']
+        self.socket = netdev.get_nic_socket()
+        self.pf_mac = self.dut.get_mac_address(self.pf)
+
+        # build sample app
+        out = self.dut.send_expect("make -C examples/tep_termination", "# ")
+        self.verify("Error" not in out, "compilation error 1")
+        self.verify("No such file" not in out, "compilation error 2")
+
+        # build for vhost user environment
+        self.dut.send_expect("cd lib/librte_vhost/eventfd_link", "# ")
+        self.dut.send_expect("make", "# ")
+        self.dut.send_expect("insmod ./eventfd_link.ko", "# ")
+        self.dut.send_expect("cd ../../..", "# ")
+        out = self.dut.send_expect("lsmod |grep eventfd_link", "# ")
+        self.verify("eventfd_link" in out, "Failed to insmod eventfd_link driver")
+
+        self.def_mac = "00:00:20:00:00:20"
+        self.vm_dut = None
+        self.tep_app = "./examples/tep_termination/build/tep_termination"
+        self.vxlan_port = 4789
+        self.vm_testpmd = "./x86_64-native-linuxapp-gcc/app/testpmd -c f -n 3 -- -i --txqflags=0xf00 --disable-hw-vlan"
+
+        # params for tep_termination
+        self.cores = self.dut.get_core_list("1S/4C/1T", socket=self.socket)
+        self.capture_file = "/tmp/vxlan_cap.pcap"
+        self.def_mss = 256
+
+    def set_up(self):
+        """
+        Run before each test case.
+        """
+        # create coremask
+        self.coremask = dts.create_mask(self.cores)
+
+        if "2VM" not in self.running_case:
+            vm_num = 1
+        else:
+            vm_num = 2
+
+        encap = self.FEAT_ENABLE
+        decap = self.FEAT_ENABLE
+        chksum = self.FEAT_DISABLE
+        if self.running_case == "test_vxlan_sample_encap":
+            encap = self.FEAT_ENABLE
+            decap = self.FEAT_DISABLE
+        elif self.running_case == "test_vxlan_sample_decap":
+            encap = self.FEAT_DISABLE
+            decap = self.FEAT_ENABLE
+        elif self.running_case == "test_vxlan_sample_chksum":
+            chksum = self.FEAT_ENABLE
+        elif self.running_case == "test_vxlan_sample_tso":
+            chksum = self.FEAT_ENABLE
+
+        tep_cmd_temp = self.tep_app + " -c %(COREMASK)s -n %(CHANNELS)d --socket-mem 2048,2048 -- -p 0x1 " \
+            + "--udp-port %(VXLAN_PORT)d --nb-devices %(NB_DEVS)d --filter-type %(FILTERS)d " \
+            + "--tx-checksum %(TX_CHKS)d --encap %(ENCAP)d --decap %(DECAP)d"
+
+        tep_cmd = tep_cmd_temp % {'COREMASK': self.coremask, 'CHANNELS': self.dut.get_memory_channels(),
+                                  'VXLAN_PORT': self.vxlan_port, 'NB_DEVS': vm_num * 2,
+                                  'FILTERS': self.OUTER_INNER_VNI, 'TX_CHKS': chksum,
+                                  'ENCAP': encap, 'DECAP': decap}
+
+        if self.running_case == "test_vxlan_sample_tso":
+            tep_cmd += " --tso-segsz=%d" % self.def_mss
+
+        self.prepare_vxlan_sample_env(tep_cmd, vm_num=vm_num)
+
+        pass
+
+    def prepare_vxlan_sample_env(self, tep_cmd, vm_num=1):
+        # start tep_termination first
+        self.dut.send_expect(tep_cmd, "VHOST_CONFIG: bind to vhost-net")
+
+        # start one vm
+        self.vm = QEMUKvm(self.dut, 'vm0', 'vxlan_sample')
+
+        # add two virtio user netdevices
+        vm_params = {}
+        vm_params['driver'] = 'vhost-user'
+        vm_params['opt_path'] = './vhost-net'
+        vm_params['opt_mac'] = self.def_mac
+        self.vm.set_vm_device(**vm_params)
+        vm_params['opt_mac'] = self.mac_address_add(1)
+        self.vm.set_vm_device(**vm_params)
+
+        try:
+            self.vm_dut = self.vm.start()
+            if self.vm_dut is None:
+                raise Exception("Set up VM ENV failed!")
+        except Exception as e:
+            print dts.RED("Failure for %s" % str(e))
+
+        # create another vm
+        if vm_num == 2:
+            print "not implemented now"
+
+        return True
+
+    def clear_vxlan_sample_env(self):
+        if self.vm_dut:
+            self.vm_dut.kill_all()
+            time.sleep(1)
+            self.vm_dut.close()
+            self.vm_dut.logger.logger_exit()
+            self.vm_dut = None
+
+        if self.vm:
+            self.vm.stop()
+            self.vm = None
+
+    def mac_address_add(self, number):
+        if number > 15:
+            return ''
+        mac = int(self.def_mac[-1]) + number
+        return self.def_mac[:-1] + '%x' % mac
+
+    def vm_testpmd_start(self, vm_id=0):
+        """
+        Start testpmd in virtual machine
+        """
+        if vm_id == 0 and self.vm_dut is not None:
+            # create coremask
+            self.vm_pmd = PmdOutput(self.vm_dut)
+            # start testpmd
+            self.vm_dut.send_expect(self.vm_testpmd, "testpmd>", 20)
+            # set fwd mac
+            self.vm_dut.send_expect("set fwd mac", "testpmd>")
+            # start tx_first
+            self.vm_dut.send_expect("start tx_first", "testpmd>")
+
+    def test_vxlan_sample_encap(self):
+        self.vm_testpmd_start(vm_id=0)
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="normal_udp")
+        self.send_and_verify(vm_id=0, vf_id=1, pkt_type="normal_udp")
+
+    def test_vxlan_sample_decap(self):
+        self.vm_testpmd_start(vm_id=0)
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_udp_decap")
+        self.send_and_verify(vm_id=0, vf_id=1, pkt_type="vxlan_udp_decap")
+
+    def test_vxlan_sample_encap_decap(self):
+        self.vm_testpmd_start(vm_id=0)
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_udp")
+        self.send_and_verify(vm_id=0, vf_id=1, pkt_type="vxlan_udp")
+
+    def test_vxlan_sample_chksum(self):
+        self.vm_testpmd_start(vm_id=0)
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_udp_chksum")
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_tcp_chksum")
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_sctp_chksum")
+
+    def test_vxlan_sample_tso(self):
+        self.vm_testpmd_start(vm_id=0)
+        self.send_and_verify(vm_id=0, vf_id=0, pkt_type="vxlan_tcp_tso")
+
+    def start_capture(self, itf, pkt_smac="", count=1):
+        self.tester.send_expect("rm -f %s" % self.capture_file, "# ")
+        self.tester.scapy_background()
+        self.tester.scapy_append(
+            'p = sniff(filter="ether src %s",' % pkt_smac +
+            'iface="%s", count=%d, timeout=5)' % (itf, count))
+        self.tester.scapy_append(
+            'wrpcap(\"%s\", p)' % self.capture_file)
+        self.tester.scapy_foreground()
+
+    def transfer_capture_file(self):
+        # copy capture file from tester
+        if os.path.isfile('vxlan_cap.pcap'):
+            os.remove('vxlan_cap.pcap')
+        self.tester.session.copy_file_from(self.capture_file)
+
+        if os.path.isfile('vxlan_cap.pcap'):
+            pkts = rdpcap('vxlan_cap.pcap')
+        else:
+            pkts = []
+        return pkts
+
+    def send_and_verify(self, vm_id, vf_id, pkt_type):
+        params = {}
+        case_pass = True
+        tester_recv_port = self.tester.get_local_port(self.pf)
+        tester_iface = self.tester.get_interface(tester_recv_port)
+
+        if pkt_type == "normal_udp":
+            self.start_capture(tester_iface, pkt_smac=self.pf_mac)
+            self.tester.scapy_append('sendp([Ether(dst="%s")/IP()/UDP()/Raw("X"*18)], iface="%s")' % (self.pf_mac, tester_iface))
+            self.tester.scapy_execute()
+            time.sleep(5)
+
+            pkts = self.transfer_capture_file()
+            self.verify(len(pkts) >= 1, "Failed to capture packets")
+            self.verify(pkts[0].haslayer(Vxlan) == 1, "Packet not encapsulated")
+            try:
+                payload = str(pkts[0][UDP][Vxlan][UDP].payload)
+                for i in range(18):
+                    self.verify(ord(payload[i]) == 88, "Check udp data failed")
+            except:
+                case_pass = False
+                print dts.RED("Failure in checking packet payload")
+
+            if case_pass:
+                print dts.GREEN("Check normal udp packet forward pass on virtIO port %d" % vf_id)
+
+        if pkt_type == "vxlan_udp_decap":
+            # create vxlan packet pf mac + vni=1000 + inner virtIO port0 mac
+            params['outer_mac_dst'] = self.pf_mac
+            params['vni'] = 1000 + vm_id
+            mac_incr = 2 * vm_id + vf_id
+            params['inner_mac_dst'] = self.mac_address_add(mac_incr)
+            if vf_id == 0:
+                smac = self.mac_address_add(2 * vm_id + 1)
+            else:
+                smac = self.mac_address_add(2 * vm_id)
+
+            # create vxlan pcap file and tranfer it to tester
+            vxlan_pkt = VxlanTestConfig(self, **params)
+            vxlan_pkt.create_pcap(scp=True)
+
+            # start capture
+            self.start_capture(tester_iface, pkt_smac=smac)
+            vxlan_pkt.send_pcap(tester_iface)
+            time.sleep(5)
+
+            # transfer capture pcap to dts server
+            pkts = self.transfer_capture_file()
+            # check packet number and payload
+            self.verify(len(pkts) >= 1, "Failed to capture packets")
+            self.verify(pkts[0].haslayer(Vxlan) == 0, "Packet not de-encapsulated")
+
+            try:
+                payload = str(pkts[0][UDP].payload)
+                for i in range(18):
+                    self.verify(ord(payload[i]) == 88, "Check udp data failed")
+            except:
+                case_pass = False
+                print dts.RED("Failure in checking packet payload")
+
+            if case_pass:
+                print dts.GREEN("Check vxlan packet decap pass on virtIO port %d" % vf_id)
+
+        if pkt_type == "vxlan_udp":
+            # create vxlan packet pf mac + vni=1000 + inner virtIO port0 mac
+            params['outer_mac_dst'] = self.pf_mac
+            params['vni'] = 1000 + vm_id
+            mac_incr = 2 * vm_id + vf_id
+            params['inner_mac_dst'] = self.mac_address_add(mac_incr)
+
+            # create vxlan pcap file and tranfer it to tester
+            vxlan_pkt = VxlanTestConfig(self, **params)
+            vxlan_pkt.create_pcap(scp=True)
+
+            # start capture
+            self.start_capture(tester_iface, pkt_smac=self.pf_mac)
+            vxlan_pkt.send_pcap(tester_iface)
+            time.sleep(5)
+
+            # transfer capture pcap to dts server
+            pkts = self.transfer_capture_file()
+            # check packet number and payload
+            self.verify(len(pkts) >= 1, "Failed to capture packets")
+            self.verify(pkts[0].haslayer(Vxlan) == 1, "Packet not encapsulated")
+            try:
+                payload = str(pkts[0][UDP][Vxlan][UDP].payload)
+                for i in range(18):
+                    self.verify(ord(payload[i]) == 88, "Check udp data failed")
+            except:
+                case_pass = False
+                print dts.RED("Failure in checking packet payload")
+
+            if case_pass:
+                print dts.GREEN("Check vxlan packet decap and encap pass on virtIO port %d" % vf_id)
+
+        if pkt_type == "vxlan_udp_chksum":
+            params['inner_l4_type'] = 'UDP'
+        if pkt_type == "vxlan_tcp_chksum":
+            params['inner_l4_type'] = 'TCP'
+        if pkt_type == "vxlan_sctp_chksum":
+            params['inner_l4_type'] = 'SCTP'
+
+        if 'chksum' in pkt_type:
+            # create vxlan packet pf mac + vni=1000 + inner virtIO port0 mac
+            params['outer_mac_dst'] = self.pf_mac
+            params['vni'] = 1000 + vm_id
+            mac_incr = 2 * vm_id + vf_id
+            params['inner_mac_dst'] = self.mac_address_add(mac_incr)
+            # extract reference chksum value
+            vxlan_pkt = VxlanTestConfig(self, **params)
+            vxlan_pkt.create_pcap()
+            chksums_ref = vxlan_pkt.get_chksums()
+
+            params['inner_ip_invalid'] = 1
+            params['inner_l4_invalid'] = 1
+
+            # create vxlan pcap file and tranfer it to tester
+            vxlan_pkt = VxlanTestConfig(self, **params)
+            vxlan_pkt.create_pcap(scp=True)
+
+            # start capture
+            self.start_capture(tester_iface, pkt_smac=self.pf_mac)
+            vxlan_pkt.send_pcap(tester_iface)
+            time.sleep(5)
+
+            # transfer capture pcap to dts server
+            pkts = self.transfer_capture_file()
+            # check packet number and payload
+            self.verify(len(pkts) >= 1, "Failed to capture packets")
+            self.verify(pkts[0].haslayer(Vxlan) == 1, "Packet not encapsulated")
+            chksums = vxlan_pkt.get_chksums(pcap='vxlan_cap.pcap')
+            for key in chksums_ref:
+                if 'inner' in key:  # only check inner packet chksum
+                    self.verify(chksums[key] == chksums_ref[key],
+                                "%s not matched to %s" % (key, chksums_ref[key]))
+
+            print dts.GREEN("%s checksum pass" % params['inner_l4_type'])
+
+        if pkt_type == "vxlan_tcp_tso":
+            # create vxlan packet pf mac + vni=1000 + inner virtIO port0 mac + tcp
+            params['inner_l4_type'] = 'TCP'
+            params['outer_mac_dst'] = self.pf_mac
+            params['vni'] = 1000 + vm_id
+            mac_incr = 2 * vm_id + vf_id
+            params['inner_mac_dst'] = self.mac_address_add(mac_incr)
+            params['payload_size'] = 892  # 256 + 256 + 256 + 124
+            # extract reference chksum value
+            vxlan_pkt = VxlanTestConfig(self, **params)
+            vxlan_pkt.create_pcap()
+
+            # start capture
+            self.start_capture(tester_iface, pkt_smac=self.pf_mac, count=4)
+            vxlan_pkt.send_pcap(tester_iface)
+            time.sleep(5)
+
+            # transfer capture pcap to dts server
+            pkts = self.transfer_capture_file()
+            # check packet number and payload
+            self.verify(len(pkts) == 4, "Failed to capture tso packets")
+            length = 0
+            for pkt in pkts:
+                self.verify(pkt.haslayer(Vxlan) == 1, "Packet not encapsulated")
+                try:
+                    payload = str(pkt[UDP][Vxlan][TCP].payload)
+                    self.verify(len(payload) <= self.def_mss, "TCP payload oversized")
+                    length += len(payload)
+                except:
+                    case_pass = False
+                    print dts.RED("Failure in checking tso payload")
+
+            self.verify(length == 892, "Total tcp payload size not match")
+            if case_pass:
+                print dts.GREEN("Vxlan packet tso pass on virtIO port %d" % vf_id)
+
+    def tear_down(self):
+        """
+        Run after each test suite.
+        """
+        # send packet to pf, verify capture packet sent from virtIO port1
+        self.clear_vxlan_sample_env()
+
+        self.dut.kill_all()
+        time.sleep(2)
+        pass
+
+    def tear_down_all(self):
+        """
+        Run after each test suite.
+        """
+        # Restore the config file and recompile the package.
+        self.dut.send_expect(
+            "sed -i -e 's/RTE_LIBRTE_VHOST=y$/RTE_LIBRTE_VHOST=n/' config/common_linuxapp", "# ", 30)
+        # temporary disable skip_setup
+        skip_setup = self.dut.skip_setup
+        self.dut.skip_setup = False
+        self.dut.build_install_dpdk(self.target)
+        self.dut.skip_setup = skip_setup
+        # wait for build done
+        time.sleep(20)
+        pass
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-04  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-04  7:21 [dts] [PATCH 1/3] Strip hugepage mount directory and netdev numa id for vxlan sample Yong Liu
2015-06-04  7:21 ` [dts] [PATCH 2/3] Add vxlan sample test plan Yong Liu
2015-06-04  7:21 ` [dts] [PATCH 3/3] Add vxlan sample test suite Yong Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).