test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [[PATCH V2]tests/l3fwd: l3fwd script refactoring
@ 2019-07-08 15:56 hanyingya
  2019-07-10  2:11 ` Tu, Lijuan
  0 siblings, 1 reply; 2+ messages in thread
From: hanyingya @ 2019-07-08 15:56 UTC (permalink / raw)
  To: dts; +Cc: hanyingya

Signed-off-by: hanyingya <yingyax.han@intel.com>
---
 tests/TestSuite_l3fwd.py | 600 +++++++++++++++++++++------------------
 1 file changed, 316 insertions(+), 284 deletions(-)

diff --git a/tests/TestSuite_l3fwd.py b/tests/TestSuite_l3fwd.py
index 7ffdcba..afac1c8 100644
--- a/tests/TestSuite_l3fwd.py
+++ b/tests/TestSuite_l3fwd.py
@@ -36,43 +36,31 @@ Layer-3 forwarding test script.
 
 import utils
 import string
+import time
 import re
 import os
 from test_case import TestCase
-from exception import VerifyFailure
 from settings import HEADER_SIZE
 from pktgen import PacketGeneratorHelper
 
+
 class TestL3fwd(TestCase):
 
     path = "./examples/l3fwd/build/"
-
-    test_cases_2_ports = [(1,"1S/1C/1T","%s -c %s -n %d -- -P -p %s  --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.0})'"),
-                          #"1S/1C/2T": "%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.1})'",
-                          (1,"1S/2C/1T","%s -c %s -n %d -- -P -p %s  --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0})'"),
-                          (1,"1S/4C/1T", "%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}),(P0,1,C{1.3.0}), (P1,1,C{1.4.0})'"),
-                          #"2S/2C/1T": "%s -c %s -n %d -- -p %s  --config '(P0,0,C{0.1.0}), (P1,0,C{0.2.0}),(P0,1,C{1.3.0}), (P1,1,C{1.4.0})'",
-                          ]
-
-    test_cases_4_ports = [(1, "1S/1C/1T",
-                           "%s -c %s -n %d -- -P -p %s  --config '(P0,0,C{1.1.0}),(P1,0,C{1.1.0}),(P2,0,C{1.1.0}),(P3,0,C{1.1.0})'"),
-                          #(1, "1S/2C/2T",
-                          # "%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}),(P1,0,C{1.1.1}),(P2,0,C{1.2.0}),(P3,0,C{1.2.1})'"),
-                          (1, "1S/4C/1T",
-                           "%s -c %s -n %d -- -P -p %s  --config '(P0,0,C{1.1.0}),(P1,0,C{1.2.0}),(P2,0,C{1.3.0}),(P3,0,C{1.4.0})'"),
-                          #(2, "1S/8C/1T",
-                           #"%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}),(P0,1,C{1.2.0}),(P1,0,C{1.3.0}),(P1,1,C{1.4.0}),(P2,0,C{1.5.0}),(P2,1,C{1.6.0}),(P3,0,C{1.7.0}),(P3,1,C{1.8.0})'"),
-                          #(2, "2S/2C/1T",
-                          # "%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}),(P1,0,C{1.2.0}),(P2,0,C{0.3.0}),(P3,0,C{0.4.0})'"),
-                          ]
-
-    queues_4_ports = []
-
-    for case in test_cases_4_ports:
-        if case[0] * 4 not in queues_4_ports:
-            queues_4_ports.append(case[0] * 4)
-
-    host_table = [
+    cmdline_2_ports = {
+        "1S/1C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.0})'",
+        "1S/1C/2T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.1})'",
+        "1S/2C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0})'",
+        "1S/4C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}), (P0,1,C{1.3.0}), (P1,1,C{1.4.0})'"}
+
+    cmdline_4_ports = {
+        "1S/1C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.0}), (P2,0,C{1.1.0}), (P3,0,C{1.1.0})'",
+        "1S/2C/2T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.1.1}), (P2,0,C{1.2.0}), (P3,0,C{1.2.1})'",
+        "1S/4C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}), (P2,1,C{1.3.0}), (P3,1,C{1.4.0})'",
+        "1S/8C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}), (P2,0,C{1.3.0}), (P3,0,C{1,4,0}),\
+        (P0,1,C{1.5.0}), (P1,1,C{1.6.0}), (P2,1,C{1.7.0}), (P3,1,C{1,8,0})'"}
+
+    ipv4_em_table = [
         "{{IPv4(10,100,0,1), IPv4(1,2,3,4), 1, 10, IPPROTO_UDP}, P0}",
         "{{IPv4(10,101,0,1), IPv4(1,2,3,4), 1, 10, IPPROTO_UDP}, P0}",
         "{{IPv4(11,100,0,1), IPv4(1,2,3,4), 1, 11, IPPROTO_UDP}, P1}",
@@ -83,7 +71,7 @@ class TestL3fwd(TestCase):
         "{{IPv4(13,101,0,1), IPv4(1,2,3,4), 1, 13, IPPROTO_UDP}, P3}",
     ]
 
-    lpm_table = [
+    ipv4_lpm_table = [
         "{IPv4(10,100,0,0), 24, P0}",
         "{IPv4(10,101,0,0), 24, P0}",
         "{IPv4(11,100,0,0), 24, P1}",
@@ -94,135 +82,139 @@ class TestL3fwd(TestCase):
         "{IPv4(13,101,0,0), 24, P3}",
     ]
 
-    frame_sizes = [64, 72, 128, 256, 512, 1024, 1518, 2048]  # 65, 128
-
-    methods = ['lpm']#, 'exact']
-
-    #
-    #
-    # Utility methods and other non-test code.
-    #
-    # Insert or move non-test functions here.
-    def portRepl(self, match):
-        """
-        Function to replace P([0123]) pattern in tables
-        """
-
-        portid = match.group(1)
-        self.verify(int(portid) in range(4), "invalid port id")
-        if int(portid) >= len(valports):
-            return '0'
-        else:
-            return '%s' % valports[int(portid)]
+    ipv6_em_table = [
+        "{{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 10, IPPROTO_UDP}, P0}",
+        "{{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 10, IPPROTO_UDP}, P0}",
+        "{{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 11, IPPROTO_UDP}, P1}",
+        "{{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 11, IPPROTO_UDP}, P1}",
+        "{{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 12, IPPROTO_UDP}, P2}",
+        "{{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 12, IPPROTO_UDP}, P2}",
+        "{{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 13, IPPROTO_UDP}, P3}",
+        "{{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 13, IPPROTO_UDP}, P3}",
+    ]
 
-    #
-    # Test cases.
-    #
+    ipv6_lpm_table = [
+        "{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P0}",
+        "{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P0}",
+        "{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P1}",
+        "{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P1}",
+        "{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P2}",
+        "{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P2}",
+        "{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P3}",
+        "{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05}, 64,P3}",
+    ]
 
     def set_up_all(self):
         """
         Run at the start of each test suite.
-
-
         L3fwd Prerequisites
         """
-        # Based on h/w type, choose how many ports to use
-        ports = self.dut.get_ports(socket=1)
-        if not ports:
-            ports = self.dut.get_ports(socket=0)
-
         self.tester.extend_external_packet_generator(TestL3fwd, self)
-        # Verify that enough ports are available
-        self.verify(len(ports) >= 2, "Insufficient ports for speed testing")
-        
-        netdev = self.dut.ports_info[ports[0]]['port']
-        
-        self.port_socket = netdev.socket
-        if self.port_socket == -1:
-            self.port_socket = 0
-        
-
-        # Verify that enough threads are available
-        cores = self.dut.get_core_list("1S/4C/1T")
-        self.verify(cores is not None, "Insufficient cores for speed testing")
-
+        # Based on h/w type, choose how many ports to use
+        self.dut_ports = self.dut.get_ports(self.nic)
         global valports
-        valports = [_ for _ in ports if self.tester.get_local_port(_) != -1]
-        
-        self.verify(len(valports) >= 2, "Insufficient active ports for speed testing")
-
-        pat = re.compile("P([0123])")
-        # Update config file and rebuild to get best perf on FVL
-        self.dut.send_expect("sed -i -e 's/CONFIG_RTE_PCI_CONFIG=n/CONFIG_RTE_PCI_CONFIG=y/' ./config/common_base", "#", 20)
-        self.dut.send_expect("sed -i -e 's/CONFIG_RTE_PCI_EXTENDED_TAG=.*$/CONFIG_RTE_PCI_EXTENDED_TAG=\"on\"/' ./config/common_base", "#", 20)
-        self.dut.send_expect("sed -i -e 's/define RTE_TEST_RX_DESC_DEFAULT.*$/define RTE_TEST_RX_DESC_DEFAULT 2048/' ./examples/l3fwd/main.c", "#", 20)
-        self.dut.send_expect("sed -i -e 's/define RTE_TEST_TX_DESC_DEFAULT.*$/define RTE_TEST_TX_DESC_DEFAULT 2048/' ./examples/l3fwd/main.c", "#", 20)
-        self.dut.build_install_dpdk(self.target)
-
-        # Prepare long prefix match table, replace P(x) port pattern
-        lpmStr = "static struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {\\\n"
-        for idx in range(len(TestL3fwd.lpm_table)):
-            TestL3fwd.lpm_table[idx] = pat.sub(self.portRepl, TestL3fwd.lpm_table[idx])
-            lpmStr = lpmStr + ' ' * 4 + TestL3fwd.lpm_table[idx] + ",\\\n"
-        lpmStr = lpmStr + "};"
-        self.logger.debug(lpmStr)
-
-        # Prepare host route table, replace P(x) port pattern
-        exactStr = "static struct ipv4_l3fwd_em_route ipv4_l3fwd_em_route_array[] = {\\\n"
-        for idx in range(len(TestL3fwd.host_table)):
-            TestL3fwd.host_table[idx] = pat.sub(self.portRepl, TestL3fwd.host_table[idx])
-            exactStr = exactStr + ' ' * 4 + TestL3fwd.host_table[idx] + ",\\\n"
-        exactStr = exactStr + "};"
-        self.logger.debug(exactStr)
-
-        # Compile l3fwd with LPM lookup.
-        self.dut.send_expect(r"sed -i '/ipv4_l3fwd_lpm_route_array\[\].*{/,/^\}\;/c\\%s' examples/l3fwd/l3fwd_lpm.c" % lpmStr, "# ")
-        out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-DAPP_LOOKUP_METHOD=1")
-        self.verify("Error" not in out, "compilation error 1")
-        self.verify("No such file" not in out, "compilation error 2")
+        valports = [_ for _ in self.dut_ports if self.tester.get_local_port(_) != -1]
 
-        # Backup the LPM exe and clean up the build.
-        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd examples/l3fwd/build/l3fwd_lpm", "# ")
-        out = self.dut.send_expect("make clean -C examples/l3fwd", "# ")
+        # Verify that enough ports are available
+        self.verify(len(valports) == 2 or len(valports) == 4, "Port number must be 2 or 4.")
 
-        # Compile l3fwd with hash/exact lookup.
-        self.dut.send_expect(r"sed -i -e '/ipv4_l3fwd_em_route_array\[\].*{/,/^\}\;/c\\%s' examples/l3fwd/l3fwd_em.c" % exactStr, "# ")
-        out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-DAPP_LOOKUP_METHOD=0")
+        # get socket and cores
+        self.socket = self.dut.get_numa_id(self.dut_ports[0])
+        self.cores = self.dut.get_core_list("1S/8C/1T", socket=self.socket)
+        self.verify(self.cores is not None, "Insufficient cores for speed testing")
 
-        self.verify("Error" not in out, "compilation error 1")
-        self.verify("No such file" not in out, "compilation error 2")
+        self.frame_sizes = [64, 128, 256, 512, 1024, 1518]
 
-        # Backup the Hash/Exact exe.
-        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd examples/l3fwd/build/l3fwd_exact", "# ")
-
-        self.l3fwd_test_results = {'header': [],
-                                   'data': []}
+        # Update config file and rebuild to get best perf on FVL
+        if self.nic in ["fortville_sprit", "fortville_eagle", "fortville_25g"]:
+            self.dut.send_expect("sed -i -e 's/CONFIG_RTE_LIBRTE_I40E_16BYTE_RX_DESC=n/CONFIG_RTE_LIBRTE_"
+                                 "I40E_16BYTE_RX_DESC=y/' ./config/common_base", "#", 20)
+            self.dut.build_install_dpdk(self.target)
+
+        self.logger.info("Configure RX/TX descriptor to 2048, and re-build ./examples/l3fwd")
+        self.dut.send_expect("sed -i -e 's/define RTE_TEST_RX_DESC_DEFAULT.*$/"
+                             + "define RTE_TEST_RX_DESC_DEFAULT 2048/' ./examples/l3fwd/main.c", "#", 20)
+        self.dut.send_expect("sed -i -e 's/define RTE_TEST_TX_DESC_DEFAULT.*$/"
+                             + "define RTE_TEST_TX_DESC_DEFAULT 2048/' ./examples/l3fwd/main.c", "#", 20)
+        self.method_table = {"ipv4_l3fwd_lpm": TestL3fwd.ipv4_lpm_table, "ipv4_l3fwd_em": TestL3fwd.ipv4_em_table,
+                             "ipv6_l3fwd_lpm": TestL3fwd.ipv6_lpm_table, "ipv6_l3fwd_em": TestL3fwd.ipv6_em_table}
+
+        self.pat = re.compile("P([0123])")
+        self.test_results = {'header': [], 'data': []}
 
         # get dts output path
         if self.logger.log_path.startswith(os.sep):
             self.output_path = self.logger.log_path
         else:
             cur_path = os.path.dirname(
-                                os.path.dirname(os.path.realpath(__file__)))
+                os.path.dirname(os.path.realpath(__file__)))
             self.output_path = os.sep.join([cur_path, self.logger.log_path])
         # create an instance to set stream field setting
         self.pktgen_helper = PacketGeneratorHelper()
 
+    def set_up(self):
+        """
+        Run before each test case.
+        """
+        pass
+
+    def portRepl(self, match):
+        """
+        Function to replace P([0123]) pattern in tables
+        """
+        portid = match.group(1)
+        self.verify(int(portid) in range(4), "invalid port id")
+        if int(portid) >= len(valports):
+            return '0'
+        else:
+            return '%s' % valports[int(portid)]
+
+    def install_l3fwd_application(self, l3_proto, mode):
+        """
+        Prepare long prefix match table, replace P(x) port pattern
+        """
+        l3fwd_method = l3_proto + "_l3fwd_" + mode
+        l3fwdStr = "static struct %s_route %s_route_array[] = {\\\n" % (l3fwd_method, l3fwd_method)
+        for idx in range(len(self.method_table[l3fwd_method])):
+            self.method_table[l3fwd_method][idx] = self.pat.sub(self.portRepl, self.method_table[l3fwd_method][idx])
+            l3fwdStr = l3fwdStr + '' * 4 + self.method_table[l3fwd_method][idx] + ",\\\n"
+        l3fwdStr = l3fwdStr + "};"
+        self.dut.send_expect(r"sed -i '/%s_route_array\[\].*{/,/^\}\;/c\\%s' examples/l3fwd/l3fwd_%s.c"
+                             % (l3fwd_method, l3fwdStr, mode), "# ")
+        self.dut.send_expect("make clean -C examples/l3fwd", "# ")
+        if "lpm" in l3fwd_method:
+            out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-DAPP_LOOKUP_METHOD=1")
+        elif "em" in l3fwd_method:
+            out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-DAPP_LOOKUP_METHOD=0")
+        self.verify("Error" not in out, "compilation error 1")
+        self.verify("No such file" not in out, "compilation error 2")
+
+        # Backup the l3fwd exe.
+        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd examples/l3fwd/build/%s" % l3fwd_method, "# ")
+
     def flows(self):
         """
         Return a list of packets that implements the flows described in the
         l3fwd test plan.
-
-        """   
-        return [
-            'IP(src="1.2.3.4",dst="11.100.0.1")',
-            'IP(src="1.2.3.4",dst="11.101.0.1")',
-            'IP(src="1.2.3.4",dst="10.100.0.1")',
-            'IP(src="1.2.3.4",dst="10.101.0.1")',
-            'IP(src="1.2.3.4",dst="13.100.0.1")',
-            'IP(src="1.2.3.4",dst="13.101.0.1")',
-            'IP(src="1.2.3.4",dst="12.100.0.1")',
-            'IP(src="1.2.3.4",dst="12.101.0.1")']
+        """
+        return {"ipv4": ['IP(src="1.2.3.4",dst="192.18.1.0")',
+                         'IP(src="1.2.3.4",dst="192.18.1.1")',
+                         'IP(src="1.2.3.4",dst="192.18.0.0")',
+                         'IP(src="1.2.3.4",dst="192.18.0.1")',
+                         'IP(src="1.2.3.4",dst="192.18.3.0")',
+                         'IP(src="1.2.3.4",dst="192.18.3.1")',
+                         'IP(src="1.2.3.4",dst="192.18.2.0")',
+                         'IP(src="1.2.3.4",dst="192.18.2.1")'],
+                "ipv6": [
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="fe80:0000:0000:0000:021b:21ff:fe91:3805")/UDP(sport=10,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="fe80:0000:0000:0000:031b:21ff:fe91:3805")/UDP(sport=10,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2a80:0000:0000:0000:021b:21ff:fe91:3805")/UDP(sport=11,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2a80:0000:0000:0000:031b:21ff:fe91:3805")/UDP(sport=11,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2b80:0000:0000:0000:021b:21ff:fe91:3805")/UDP(sport=12,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2b80:0000:0000:0000:031b:21ff:fe91:3805")/UDP(sport=12,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2c80:0000:0000:0000:021b:21ff:fe91:3805")/UDP(sport=13,dport=1)',
+                    'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2c80:0000:0000:0000:031b:21ff:fe91:3805")/UDP(sport=13,dport=1)'
+                ]}
 
     def repl(self, match):
         pid = match.group(1)
@@ -233,178 +225,218 @@ class TestL3fwd(TestCase):
 
         global corelist
         corelist.append(int(lcid))
-
         self.verify(int(pid) in range(4), "invalid port id")
         self.verify(lcid, "invalid thread id")
-
         return '%s,%s,%s' % (str(valports[int(pid)]), qid, lcid)
 
-    def set_up(self):
+    def perpare_commandline(self, ports):
         """
-        Run before each test case.
+        Generate the command line based on the number of ports
         """
-        pass
+        global corelist
+        pat = re.compile("P([0123]),([0123]),(C\{\d.\d.\d\})")
+        core_mask = {}
+        if ports == 2:
+            rtCmdLines = dict(TestL3fwd.cmdline_2_ports)
+        elif ports == 4:
+            rtCmdLines = dict(TestL3fwd.cmdline_4_ports)
+
+        for key in rtCmdLines.keys():
+            corelist = []
+            while pat.search(rtCmdLines[key]):
+                print rtCmdLines[key]
+                rtCmdLines[key] = pat.sub(self.repl, rtCmdLines[key])
+            core_mask[key] = utils.create_mask(set(corelist))
+        return rtCmdLines, core_mask
+
+    def create_pcap_file(self, frame_size, l3_proto):
+        """
+        Prepare traffic flow for packet generator
+        """
+        if l3_proto == 'ipv4':
+            payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] - HEADER_SIZE['udp']
+        else:
+            # l3_proto == 'ipv6'
+            payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ipv6'] - HEADER_SIZE['udp']
+            if frame_size == 64:
+                payload_size = frame_size + 2 - HEADER_SIZE['eth'] - HEADER_SIZE['ipv6'] - HEADER_SIZE['udp']
+
+        pcaps = {}
+        for _port in valports:
+            index = valports[_port]
+            dmac = self.dut.get_mac_address(index)
+            cnt = 0
+            layer3s = self.flows()[l3_proto][_port * 2:(_port + 1) * 2]
+            for l3 in layer3s:
+                flow = ['Ether(dst="%s")/%s/UDP()/("X"*%d)' % (dmac, l3, payload_size)]
+                pcap = os.sep.join([self.output_path, "dst{0}_{1}.pcap".format(index, cnt)])
+                self.tester.scapy_append('wrpcap("%s", [%s])' % (pcap, string.join(flow, ',')))
+                self.tester.scapy_execute()
+                if index not in pcaps:
+                    pcaps[index] = []
+                pcaps[index].append(pcap)
+                cnt += 1
+        return pcaps
+
+    def prepare_steam(self, pcaps):
+        """
+        create streams for ports, one port one stream
+        """
+        tgen_input = []
+        for rxPort in valports:
+            if rxPort % len(valports) == 0 or len(valports) % rxPort == 2:
+                txIntf = self.tester.get_local_port(valports[rxPort + 1])
+                port_id = valports[rxPort + 1]
+            else:
+                txIntf = self.tester.get_local_port(valports[rxPort - 1])
+                port_id = valports[rxPort - 1]
+            rxIntf = self.tester.get_local_port(valports[rxPort])
+            for pcap in pcaps[port_id]:
+                tgen_input.append((txIntf, rxIntf, pcap))
+        return tgen_input
 
-    def test_perf_rfc2544(self):
+    def create_result_table(self, ttl, ttl1, ttl2, ttl3, ttl4):
 
-        ports = self.dut.get_ports()
-        ports_num = len(ports)
-        header_row = ["Frame_size(byte)", "mode", "S/C/T", "zero_loss_throughput(Mpps)", " % zero_loss_rate"]# "LR_tx_pkts(1min)", "LR_rx_pkts(1min)", "LR_loss_pkts(1min)", "% zero_loss_rate", "zero_loss_throughput(Mpps)"]
-        self.l3fwd_test_results['header'] = header_row
+        header_row = [ttl, ttl1, ttl2, ttl3, ttl4]
+        self.test_results['header'] = header_row
         self.result_table_create(header_row)
-        self.l3fwd_test_results['data'] = []
-
-        for frame_size in TestL3fwd.frame_sizes:
-
-            # Prepare traffic flow
-            payload_size = frame_size -  \
-                HEADER_SIZE['ip'] - HEADER_SIZE['eth'] - HEADER_SIZE['tcp']
-
-            pcaps = {}
-            flows = []
-            for _port in range(ports_num):
-                index = valports[_port]
-                dmac = self.dut.get_mac_address(index)
-                cnt = 0
-                for layer in self.flows()[_port *2:(_port +1)*2]:
-                    flow = 'Ether(dst="%s")/%s/TCP()/("X"*%d)' % (
-                                                    dmac, layer, payload_size)
-                    flows.append(flow)
-                    pcap = os.sep.join([
-                                self.output_path,
-                                "dst{0}_{1}.pcap".format(index, cnt)])
-                    self.tester.scapy_append('wrpcap("%s", [%s])' % (
-                                                pcap, flow))
-                    self.tester.scapy_execute()
-                    if index not in pcaps:
-                        pcaps[index] = []
-                    pcaps[index].append(pcap)
-                    cnt += 1
-
-            self.rst_report("Flows for %d ports, %d frame size.\n" % (ports_num, frame_size),
-                       annex=True)
-            self.rst_report("%s" % string.join(flows, '\n'),
-                       frame=True, annex=True)
-
-            # Prepare the command line
-            global corelist
-            pat = re.compile("P([0123]),([0123]),(C\{\d.\d.\d\})")
-
-            pat2 = re.compile("C\{\d")
-            repl1 = "C{" + str(self.port_socket)
-
-            coreMask = {}
-            rtCmdLines = {}
-            cmdlist = []
-            if ports_num == 4:
-                for i in TestL3fwd.test_cases_4_ports:
-                    cmdlist.append(i)
-            else:
-                for i in TestL3fwd.test_cases_2_ports:
-                    cmdlist.append(i)
-                if 'eagle' in self.nic:
-                    del cmdlist[2]
-                else:
-                    del cmdlist[1]
-            for cmdline_pat in cmdlist:
-                corelist = []
-                rtCmdLines[cmdline_pat[1]] = cmdline_pat[2]
-                while pat.search(rtCmdLines[cmdline_pat[1]]):
-                    # Change the socket to the NIC's socket
-                    if cmdline_pat[1].find('1S')>=0:
-                        rtCmdLines[cmdline_pat[1]] = pat2.sub(repl1, rtCmdLines[cmdline_pat[1]])
-                    rtCmdLines[cmdline_pat[1]] = pat.sub(self.repl, rtCmdLines[cmdline_pat[1]])
-
-                self.logger.info("%s\n" % str(corelist))
-                coreMask[cmdline_pat[1]] = utils.create_mask(set(corelist))
-
-            # measure by two different mode
-            for mode in TestL3fwd.methods:
-
-                # start l3fwd
-                index = 0
-                subtitle = []
-                for cores in rtCmdLines.keys():
-
-                    #in order to save time, only some of the cases will be run.
-                    if mode == "lpm" and (cores == "1S/2C/1T" or cores == "1S/4C/1T"):
-                        info = "Executing l3fwd using %s mode, %d ports, %s and %d frame size.\n" % (
-                               mode, ports_num, cores, frame_size)
-
-                        self.logger.info(info)
-                        self.rst_report(info, annex=True)
-
-                        subtitle.append(cores)
-                        cmdline = rtCmdLines[cores] % (TestL3fwd.path + "l3fwd_" + mode, coreMask[cores],
-                                                       self.dut.get_memory_channels(), utils.create_mask(valports[:ports_num]))
-                        if self.nic == "niantic":
-                            cmdline = cmdline + " --parse-ptype"
-
-                        if frame_size > 1518:
-                            cmdline = cmdline + " --enable-jumbo --max-pkt-len %d" % frame_size
-                        self.rst_report(cmdline + "\n", frame=True, annex=True)
-
-                        out = self.dut.send_expect(cmdline, "L3FWD:", 120)
-
-                        # Measure test
-                        tgenInput = []
-                        for rxPort in range(ports_num):
-                            # No use on rx/tx limitation
-                            if rxPort % 2 == 0:
-                                txIntf = self.tester.get_local_port(valports[rxPort + 1])
-                            else:
-                                txIntf = self.tester.get_local_port(valports[rxPort - 1])
-
-                            rxIntf = self.tester.get_local_port(valports[rxPort])
-                            port_id = valports[rxPort+1] if rxPort % 2 == 0 else \
-                                      valports[rxPort-1]
-                            for pcap in pcaps[port_id]:
-                                tgenInput.append((txIntf, rxIntf, pcap))
-
-                        # Run traffic generator
-
-                        vm_config = self.set_fields()
-                        # clear streams before add new streams
-                        self.tester.pktgen.clear_streams()
-                        # run packet generator
-                        streams = self.pktgen_helper.prepare_stream_from_tginput(tgenInput,
-                                            100, vm_config, self.tester.pktgen)
-                        # set traffic option
-                        traffic_opt = {'duration': 60}
-                        zero_loss_rate, tx_pkts, rx_pkts = self.tester.pktgen.measure_rfc2544(stream_ids=streams, options=traffic_opt)
-
-                        loss_pkts = tx_pkts - rx_pkts
-                        self.dut.send_expect("^C", "#")
-                        linerate = self.wirespeed(self.nic, frame_size, ports_num)
-                        zero_loss_throughput = (linerate * zero_loss_rate) / 100
-
-                        tx_pkts = utils.human_read_number(tx_pkts)
-                        rx_pkts = utils.human_read_number(rx_pkts)
-                        loss_pkts = utils.human_read_number(loss_pkts)
-
-
-                        #data_row = [frame_size, mode, cores, tx_pkts, rx_pkts, loss_pkts, zero_loss_rate, zero_loss_throughput]
-                        data_row = [frame_size, mode, cores, zero_loss_throughput, zero_loss_rate]
-                        self.result_table_add(data_row)
-                        self.l3fwd_test_results['data'].append(data_row)
-                    else:
-                        pass
-
-                    index += 1
+        self.test_results['data'] = []
 
+    def measure_throughput(self, l3_proto, mode):
+        """
+        measure throughput according to Layer-3 Protocal and Lookup Mode
+        """
+        # create result table
+        self.create_result_table("Frame Size", "Mode", "S/C/T", "Mpps", "% Linerate")
+        # build application
+        self.install_l3fwd_application(l3_proto, mode)
+        # perpare commandline and core mask
+        rtCmdLines, core_mask = self.perpare_commandline(len(valports))
+
+        for cores in rtCmdLines.keys():
+            # Start L3fwd appliction
+            command_line = rtCmdLines[cores] % (TestL3fwd.path + l3_proto + "_l3fwd_" + mode, core_mask[cores],
+                                                self.dut.get_memory_channels(), utils.create_mask(valports))
+            self.dut.send_expect(command_line, "L3FWD:", 120)
+            for frame_size in self.frame_sizes:
+                # crete traffic flow
+                pcaps = self.create_pcap_file(frame_size, l3_proto)
+                # send the traffic and Measure test
+                tgenInput = self.prepare_steam(pcaps)
+
+                vm_config = self.set_fields()
+                # clear streams before add new streams
+                self.tester.pktgen.clear_streams()
+                # run packet generator
+                streams = self.pktgen_helper.prepare_stream_from_tginput(tgenInput, 100, vm_config, self.tester.pktgen)
+                # set traffic option
+                traffic_opt = {'delay': 30}
+                _, pps = self.tester.pktgen.measure_throughput(stream_ids=streams, options=traffic_opt)
+                self.verify(pps > 0, "No traffic detected")
+                # statistical result
+                pps /= 1000000.0
+                linerate = self.wirespeed(self.nic, frame_size, len(valports))
+                percentage = pps * 100 / linerate
+                if mode == "ipv6" and frame_size == 64:
+                    frame_size += 2
+                data_row = [frame_size, mode, cores, str(pps), str(percentage)]
+                self.result_table_add(data_row)
+                self.test_results['data'].append(data_row)
+            # Stop L3fwd
+            self.dut.send_expect("^C", "#")
+            time.sleep(1)
+        # Print result
+        self.result_table_print()
+
+    def measure_rfc2544(self, l3_proto, mode):
+        """
+        measure RFC2544 according to Layer-3 Protocal and Lookup Mode
+        """
+        # create result table
+        self.create_result_table("Frame Size", "Mode", "S/C/T", "Zero Loss Throughput(Mpps)", " % Zero Loss Rate")
+        # build application
+        self.install_l3fwd_application(l3_proto, mode)
+        # perpare commandline and core mask
+        rtCmdLines, core_mask = self.perpare_commandline(len(valports))
+
+        for frame_size in self.frame_sizes:
+            for cores in rtCmdLines.keys():
+                # in order to save time, only some of the cases will be run.
+                if cores in ["1S/2C/1T", "1S/4C/1T"]:
+                    # Start L3fwd appliction
+                    command_line = rtCmdLines[cores] % (TestL3fwd.path + l3_proto + "_l3fwd_" + mode, core_mask[cores],
+                                                        self.dut.get_memory_channels(), utils.create_mask(valports))
+                    if self.nic == "niantic":
+                        command_line += " --parse-ptype"
+                    if frame_size > 1518:
+                        command_line += " --enable-jumbo --max-pkt-len %d" % frame_size
+                    self.dut.send_expect(command_line, "L3FWD:", 120)
+                    self.logger.info("Executing l3fwd using %s mode, %d ports, %s and %d frame size"
+                                     % (mode, len(valports), cores, frame_size))
+                    # crete traffic flow
+                    pcaps = self.create_pcap_file(frame_size, l3_proto)
+                    # send the traffic and Measure test
+                    tgenInput = self.prepare_steam(pcaps)
+
+                    vm_config = self.set_fields()
+                    # clear streams before add new streams
+                    self.tester.pktgen.clear_streams()
+                    # run packet generator
+                    streams = self.pktgen_helper.prepare_stream_from_tginput(tgenInput, 100, vm_config, self.tester.pktgen)
+                    # set traffic option
+                    traffic_opt = {'duration': 15}
+                    zero_loss_rate, tx_pkts, rx_pkts = self.tester.pktgen.measure_rfc2544(stream_ids=streams,
+                                                                                          options=traffic_opt)
+                    # statistical result
+                    linerate = self.wirespeed(self.nic, frame_size, len(valports))
+                    zero_loss_throughput = (linerate * zero_loss_rate) / 100
+                    if mode == "ipv6" and frame_size == 64:
+                        frame_size += 2
+                    data_row = [frame_size, mode, cores, str(zero_loss_throughput), str(zero_loss_rate)]
+                    self.result_table_add(data_row)
+                    self.test_results['data'].append(data_row)
+                # Stop L3fwd
+                self.dut.send_expect("^C", "#")
+                time.sleep(1)
+        # Print result
         self.result_table_print()
 
+    def test_perf_rfc2544_ipv4_lpm(self):
+        self.measure_rfc2544(l3_proto="ipv4", mode="lpm")
+
+    def test_perf_rfc2544_ipv4_em(self):
+        self.measure_rfc2544(l3_proto="ipv4", mode="em")
+
+    def test_perf_throughput_ipv4_lpm(self):
+        self.measure_throughput(l3_proto="ipv4", mode="lpm")
+
+    def test_perf_throughput_ipv4_em(self):
+        self.measure_throughput(l3_proto="ipv4", mode="em")
+
+    def test_perf_rfc2544_ipv6_lpm(self):
+        self.measure_rfc2544(l3_proto="ipv6", mode="lpm")
+
+    def test_perf_rfc2544_ipv6_em(self):
+        self.measure_rfc2544(l3_proto="ipv6", mode="em")
+
+    def test_perf_throughput_ipv6_lpm(self):
+        self.measure_throughput(l3_proto="ipv6", mode="lpm")
+
+    def test_perf_throughput_ipv6_em(self):
+        self.measure_throughput(l3_proto="ipv6", mode="em")
+
     def set_fields(self):
-        ''' set ip protocol field behavior '''
-        fields_config = {
-        'ip':  {'src': {'action': 'random'},},}
+        """
+        set ip protocol field behavior
+        """
+        fields_config = {'ip':  {'src': {'action': 'random'}, }, }
         return fields_config
 
     def tear_down(self):
         """
         Run after each test case.
         """
-        pass
+        self.dut.kill_all()
 
     def tear_down_all(self):
         """
-- 
2.17.1


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

* Re: [dts] [[PATCH V2]tests/l3fwd: l3fwd script refactoring
  2019-07-08 15:56 [dts] [[PATCH V2]tests/l3fwd: l3fwd script refactoring hanyingya
@ 2019-07-10  2:11 ` Tu, Lijuan
  0 siblings, 0 replies; 2+ messages in thread
From: Tu, Lijuan @ 2019-07-10  2:11 UTC (permalink / raw)
  To: Han, YingyaX, dts; +Cc: Han, YingyaX

Applied, thanks

> -----Original Message-----
> From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of hanyingya
> Sent: Monday, July 8, 2019 11:56 PM
> To: dts@dpdk.org
> Cc: Han, YingyaX <yingyax.han@intel.com>
> Subject: [dts] [[PATCH V2]tests/l3fwd: l3fwd script refactoring
> 
> Signed-off-by: hanyingya <yingyax.han@intel.com>
> ---
>  tests/TestSuite_l3fwd.py | 600 +++++++++++++++++++++------------------
>  1 file changed, 316 insertions(+), 284 deletions(-)
> 
> diff --git a/tests/TestSuite_l3fwd.py b/tests/TestSuite_l3fwd.py index
> 7ffdcba..afac1c8 100644
> --- a/tests/TestSuite_l3fwd.py
> +++ b/tests/TestSuite_l3fwd.py
> @@ -36,43 +36,31 @@ Layer-3 forwarding test script.
> 
>  import utils
>  import string
> +import time
>  import re
>  import os
>  from test_case import TestCase
> -from exception import VerifyFailure
>  from settings import HEADER_SIZE
>  from pktgen import PacketGeneratorHelper
> 
> +
>  class TestL3fwd(TestCase):
> 
>      path = "./examples/l3fwd/build/"
> -
> -    test_cases_2_ports = [(1,"1S/1C/1T","%s -c %s -n %d -- -P -p %s  --config
> '(P0,0,C{1.1.0}), (P1,0,C{1.1.0})'"),
> -                          #"1S/1C/2T": "%s -c %s -n %d -- -p %s  --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.1.1})'",
> -                          (1,"1S/2C/1T","%s -c %s -n %d -- -P -p %s  --config
> '(P0,0,C{1.1.0}), (P1,0,C{1.2.0})'"),
> -                          (1,"1S/4C/1T", "%s -c %s -n %d -- -p %s  --config
> '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}),(P0,1,C{1.3.0}), (P1,1,C{1.4.0})'"),
> -                          #"2S/2C/1T": "%s -c %s -n %d -- -p %s  --config '(P0,0,C{0.1.0}),
> (P1,0,C{0.2.0}),(P0,1,C{1.3.0}), (P1,1,C{1.4.0})'",
> -                          ]
> -
> -    test_cases_4_ports = [(1, "1S/1C/1T",
> -                           "%s -c %s -n %d -- -P -p %s  --config
> '(P0,0,C{1.1.0}),(P1,0,C{1.1.0}),(P2,0,C{1.1.0}),(P3,0,C{1.1.0})'"),
> -                          #(1, "1S/2C/2T",
> -                          # "%s -c %s -n %d -- -p %s  --config
> '(P0,0,C{1.1.0}),(P1,0,C{1.1.1}),(P2,0,C{1.2.0}),(P3,0,C{1.2.1})'"),
> -                          (1, "1S/4C/1T",
> -                           "%s -c %s -n %d -- -P -p %s  --config
> '(P0,0,C{1.1.0}),(P1,0,C{1.2.0}),(P2,0,C{1.3.0}),(P3,0,C{1.4.0})'"),
> -                          #(2, "1S/8C/1T",
> -                           #"%s -c %s -n %d -- -p %s  --config
> '(P0,0,C{1.1.0}),(P0,1,C{1.2.0}),(P1,0,C{1.3.0}),(P1,1,C{1.4.0}),(P2,0,C{1.5.0}),(P2,1
> ,C{1.6.0}),(P3,0,C{1.7.0}),(P3,1,C{1.8.0})'"),
> -                          #(2, "2S/2C/1T",
> -                          # "%s -c %s -n %d -- -p %s  --config
> '(P0,0,C{1.1.0}),(P1,0,C{1.2.0}),(P2,0,C{0.3.0}),(P3,0,C{0.4.0})'"),
> -                          ]
> -
> -    queues_4_ports = []
> -
> -    for case in test_cases_4_ports:
> -        if case[0] * 4 not in queues_4_ports:
> -            queues_4_ports.append(case[0] * 4)
> -
> -    host_table = [
> +    cmdline_2_ports = {
> +        "1S/1C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.1.0})'",
> +        "1S/1C/2T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.1.1})'",
> +        "1S/2C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.2.0})'",
> +        "1S/4C/1T": "%s -c %s -n %d -- -p %s -P --config
> + '(P0,0,C{1.1.0}), (P1,0,C{1.2.0}), (P0,1,C{1.3.0}), (P1,1,C{1.4.0})'"}
> +
> +    cmdline_4_ports = {
> +        "1S/1C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.1.0}), (P2,0,C{1.1.0}), (P3,0,C{1.1.0})'",
> +        "1S/2C/2T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.1.1}), (P2,0,C{1.2.0}), (P3,0,C{1.2.1})'",
> +        "1S/4C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.2.0}), (P2,1,C{1.3.0}), (P3,1,C{1.4.0})'",
> +        "1S/8C/1T": "%s -c %s -n %d -- -p %s -P --config '(P0,0,C{1.1.0}),
> (P1,0,C{1.2.0}), (P2,0,C{1.3.0}), (P3,0,C{1,4,0}),\
> +        (P0,1,C{1.5.0}), (P1,1,C{1.6.0}), (P2,1,C{1.7.0}),
> + (P3,1,C{1,8,0})'"}
> +
> +    ipv4_em_table = [
>          "{{IPv4(10,100,0,1), IPv4(1,2,3,4), 1, 10, IPPROTO_UDP}, P0}",
>          "{{IPv4(10,101,0,1), IPv4(1,2,3,4), 1, 10, IPPROTO_UDP}, P0}",
>          "{{IPv4(11,100,0,1), IPv4(1,2,3,4), 1, 11, IPPROTO_UDP}, P1}", @@ -83,7
> +71,7 @@ class TestL3fwd(TestCase):
>          "{{IPv4(13,101,0,1), IPv4(1,2,3,4), 1, 13, IPPROTO_UDP}, P3}",
>      ]
> 
> -    lpm_table = [
> +    ipv4_lpm_table = [
>          "{IPv4(10,100,0,0), 24, P0}",
>          "{IPv4(10,101,0,0), 24, P0}",
>          "{IPv4(11,100,0,0), 24, P1}",
> @@ -94,135 +82,139 @@ class TestL3fwd(TestCase):
>          "{IPv4(13,101,0,0), 24, P3}",
>      ]
> 
> -    frame_sizes = [64, 72, 128, 256, 512, 1024, 1518, 2048]  # 65, 128
> -
> -    methods = ['lpm']#, 'exact']
> -
> -    #
> -    #
> -    # Utility methods and other non-test code.
> -    #
> -    # Insert or move non-test functions here.
> -    def portRepl(self, match):
> -        """
> -        Function to replace P([0123]) pattern in tables
> -        """
> -
> -        portid = match.group(1)
> -        self.verify(int(portid) in range(4), "invalid port id")
> -        if int(portid) >= len(valports):
> -            return '0'
> -        else:
> -            return '%s' % valports[int(portid)]
> +    ipv6_em_table = [
> +        "{{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
> 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 10, IPPROTO_UDP}, P0}",
> +        "{{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
> 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 10, IPPROTO_UDP}, P0}",
> +        "{{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21,
> 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 11, IPPROTO_UDP}, P1}",
> +        "{{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21,
> 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 11, IPPROTO_UDP}, P1}",
> +        "{{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21,
> 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 12, IPPROTO_UDP}, P2}",
> +        "{{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21,
> 0xff, 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 12, IPPROTO_UDP}, P2}",
> +        "{{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
> 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 13, IPPROTO_UDP}, P3}",
> +        "{{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
> 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a}, 1, 13, IPPROTO_UDP}, P3}",
> +    ]
> 
> -    #
> -    # Test cases.
> -    #
> +    ipv6_lpm_table = [
> +        "{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P0}",
> +        "{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P0}",
> +        "{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P1}",
> +        "{{0x2a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P1}",
> +        "{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P2}",
> +        "{{0x2b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P2}",
> +        "{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P3}",
> +        "{{0x2c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1b, 0x21, 0xff,
> 0xfe, 0x91, 0x38, 0x05}, 64,P3}",
> +    ]
> 
>      def set_up_all(self):
>          """
>          Run at the start of each test suite.
> -
> -
>          L3fwd Prerequisites
>          """
> -        # Based on h/w type, choose how many ports to use
> -        ports = self.dut.get_ports(socket=1)
> -        if not ports:
> -            ports = self.dut.get_ports(socket=0)
> -
>          self.tester.extend_external_packet_generator(TestL3fwd, self)
> -        # Verify that enough ports are available
> -        self.verify(len(ports) >= 2, "Insufficient ports for speed testing")
> -
> -        netdev = self.dut.ports_info[ports[0]]['port']
> -
> -        self.port_socket = netdev.socket
> -        if self.port_socket == -1:
> -            self.port_socket = 0
> -
> -
> -        # Verify that enough threads are available
> -        cores = self.dut.get_core_list("1S/4C/1T")
> -        self.verify(cores is not None, "Insufficient cores for speed testing")
> -
> +        # Based on h/w type, choose how many ports to use
> +        self.dut_ports = self.dut.get_ports(self.nic)
>          global valports
> -        valports = [_ for _ in ports if self.tester.get_local_port(_) != -1]
> -
> -        self.verify(len(valports) >= 2, "Insufficient active ports for speed testing")
> -
> -        pat = re.compile("P([0123])")
> -        # Update config file and rebuild to get best perf on FVL
> -        self.dut.send_expect("sed -i -e
> 's/CONFIG_RTE_PCI_CONFIG=n/CONFIG_RTE_PCI_CONFIG=y/' ./config/comm
> on_base", "#", 20)
> -        self.dut.send_expect("sed -i -e
> 's/CONFIG_RTE_PCI_EXTENDED_TAG=.*$/CONFIG_RTE_PCI_EXTENDED_TAG=
> \"on\"/' ./config/common_base", "#", 20)
> -        self.dut.send_expect("sed -i -e 's/define
> RTE_TEST_RX_DESC_DEFAULT.*$/define RTE_TEST_RX_DESC_DEFAULT
> 2048/' ./examples/l3fwd/main.c", "#", 20)
> -        self.dut.send_expect("sed -i -e 's/define
> RTE_TEST_TX_DESC_DEFAULT.*$/define RTE_TEST_TX_DESC_DEFAULT
> 2048/' ./examples/l3fwd/main.c", "#", 20)
> -        self.dut.build_install_dpdk(self.target)
> -
> -        # Prepare long prefix match table, replace P(x) port pattern
> -        lpmStr = "static struct ipv4_l3fwd_lpm_route
> ipv4_l3fwd_lpm_route_array[] = {\\\n"
> -        for idx in range(len(TestL3fwd.lpm_table)):
> -            TestL3fwd.lpm_table[idx] = pat.sub(self.portRepl,
> TestL3fwd.lpm_table[idx])
> -            lpmStr = lpmStr + ' ' * 4 + TestL3fwd.lpm_table[idx] + ",\\\n"
> -        lpmStr = lpmStr + "};"
> -        self.logger.debug(lpmStr)
> -
> -        # Prepare host route table, replace P(x) port pattern
> -        exactStr = "static struct ipv4_l3fwd_em_route
> ipv4_l3fwd_em_route_array[] = {\\\n"
> -        for idx in range(len(TestL3fwd.host_table)):
> -            TestL3fwd.host_table[idx] = pat.sub(self.portRepl,
> TestL3fwd.host_table[idx])
> -            exactStr = exactStr + ' ' * 4 + TestL3fwd.host_table[idx] + ",\\\n"
> -        exactStr = exactStr + "};"
> -        self.logger.debug(exactStr)
> -
> -        # Compile l3fwd with LPM lookup.
> -        self.dut.send_expect(r"sed -i
> '/ipv4_l3fwd_lpm_route_array\[\].*{/,/^\}\;/c\\%s'
> examples/l3fwd/l3fwd_lpm.c" % lpmStr, "# ")
> -        out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-
> DAPP_LOOKUP_METHOD=1")
> -        self.verify("Error" not in out, "compilation error 1")
> -        self.verify("No such file" not in out, "compilation error 2")
> +        valports = [_ for _ in self.dut_ports if
> + self.tester.get_local_port(_) != -1]
> 
> -        # Backup the LPM exe and clean up the build.
> -        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd
> examples/l3fwd/build/l3fwd_lpm", "# ")
> -        out = self.dut.send_expect("make clean -C examples/l3fwd", "# ")
> +        # Verify that enough ports are available
> +        self.verify(len(valports) == 2 or len(valports) == 4, "Port
> + number must be 2 or 4.")
> 
> -        # Compile l3fwd with hash/exact lookup.
> -        self.dut.send_expect(r"sed -i -e
> '/ipv4_l3fwd_em_route_array\[\].*{/,/^\}\;/c\\%s'
> examples/l3fwd/l3fwd_em.c" % exactStr, "# ")
> -        out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-
> DAPP_LOOKUP_METHOD=0")
> +        # get socket and cores
> +        self.socket = self.dut.get_numa_id(self.dut_ports[0])
> +        self.cores = self.dut.get_core_list("1S/8C/1T", socket=self.socket)
> +        self.verify(self.cores is not None, "Insufficient cores for
> + speed testing")
> 
> -        self.verify("Error" not in out, "compilation error 1")
> -        self.verify("No such file" not in out, "compilation error 2")
> +        self.frame_sizes = [64, 128, 256, 512, 1024, 1518]
> 
> -        # Backup the Hash/Exact exe.
> -        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd
> examples/l3fwd/build/l3fwd_exact", "# ")
> -
> -        self.l3fwd_test_results = {'header': [],
> -                                   'data': []}
> +        # Update config file and rebuild to get best perf on FVL
> +        if self.nic in ["fortville_sprit", "fortville_eagle", "fortville_25g"]:
> +            self.dut.send_expect("sed -i -e
> 's/CONFIG_RTE_LIBRTE_I40E_16BYTE_RX_DESC=n/CONFIG_RTE_LIBRTE_"
> +                                 "I40E_16BYTE_RX_DESC=y/' ./config/common_base", "#",
> 20)
> +            self.dut.build_install_dpdk(self.target)
> +
> +        self.logger.info("Configure RX/TX descriptor to 2048, and re-
> build ./examples/l3fwd")
> +        self.dut.send_expect("sed -i -e 's/define
> RTE_TEST_RX_DESC_DEFAULT.*$/"
> +                             + "define RTE_TEST_RX_DESC_DEFAULT
> 2048/' ./examples/l3fwd/main.c", "#", 20)
> +        self.dut.send_expect("sed -i -e 's/define
> RTE_TEST_TX_DESC_DEFAULT.*$/"
> +                             + "define RTE_TEST_TX_DESC_DEFAULT
> 2048/' ./examples/l3fwd/main.c", "#", 20)
> +        self.method_table = {"ipv4_l3fwd_lpm": TestL3fwd.ipv4_lpm_table,
> "ipv4_l3fwd_em": TestL3fwd.ipv4_em_table,
> +                             "ipv6_l3fwd_lpm":
> + TestL3fwd.ipv6_lpm_table, "ipv6_l3fwd_em": TestL3fwd.ipv6_em_table}
> +
> +        self.pat = re.compile("P([0123])")
> +        self.test_results = {'header': [], 'data': []}
> 
>          # get dts output path
>          if self.logger.log_path.startswith(os.sep):
>              self.output_path = self.logger.log_path
>          else:
>              cur_path = os.path.dirname(
> -                                os.path.dirname(os.path.realpath(__file__)))
> +                os.path.dirname(os.path.realpath(__file__)))
>              self.output_path = os.sep.join([cur_path, self.logger.log_path])
>          # create an instance to set stream field setting
>          self.pktgen_helper = PacketGeneratorHelper()
> 
> +    def set_up(self):
> +        """
> +        Run before each test case.
> +        """
> +        pass
> +
> +    def portRepl(self, match):
> +        """
> +        Function to replace P([0123]) pattern in tables
> +        """
> +        portid = match.group(1)
> +        self.verify(int(portid) in range(4), "invalid port id")
> +        if int(portid) >= len(valports):
> +            return '0'
> +        else:
> +            return '%s' % valports[int(portid)]
> +
> +    def install_l3fwd_application(self, l3_proto, mode):
> +        """
> +        Prepare long prefix match table, replace P(x) port pattern
> +        """
> +        l3fwd_method = l3_proto + "_l3fwd_" + mode
> +        l3fwdStr = "static struct %s_route %s_route_array[] = {\\\n" %
> (l3fwd_method, l3fwd_method)
> +        for idx in range(len(self.method_table[l3fwd_method])):
> +            self.method_table[l3fwd_method][idx] = self.pat.sub(self.portRepl,
> self.method_table[l3fwd_method][idx])
> +            l3fwdStr = l3fwdStr + '' * 4 + self.method_table[l3fwd_method][idx] +
> ",\\\n"
> +        l3fwdStr = l3fwdStr + "};"
> +        self.dut.send_expect(r"sed -i '/%s_route_array\[\].*{/,/^\}\;/c\\%s'
> examples/l3fwd/l3fwd_%s.c"
> +                             % (l3fwd_method, l3fwdStr, mode), "# ")
> +        self.dut.send_expect("make clean -C examples/l3fwd", "# ")
> +        if "lpm" in l3fwd_method:
> +            out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-
> DAPP_LOOKUP_METHOD=1")
> +        elif "em" in l3fwd_method:
> +            out = self.dut.build_dpdk_apps("./examples/l3fwd", "USER_FLAGS=-
> DAPP_LOOKUP_METHOD=0")
> +        self.verify("Error" not in out, "compilation error 1")
> +        self.verify("No such file" not in out, "compilation error 2")
> +
> +        # Backup the l3fwd exe.
> +        self.dut.send_expect("mv -f examples/l3fwd/build/l3fwd
> + examples/l3fwd/build/%s" % l3fwd_method, "# ")
> +
>      def flows(self):
>          """
>          Return a list of packets that implements the flows described in the
>          l3fwd test plan.
> -
> -        """
> -        return [
> -            'IP(src="1.2.3.4",dst="11.100.0.1")',
> -            'IP(src="1.2.3.4",dst="11.101.0.1")',
> -            'IP(src="1.2.3.4",dst="10.100.0.1")',
> -            'IP(src="1.2.3.4",dst="10.101.0.1")',
> -            'IP(src="1.2.3.4",dst="13.100.0.1")',
> -            'IP(src="1.2.3.4",dst="13.101.0.1")',
> -            'IP(src="1.2.3.4",dst="12.100.0.1")',
> -            'IP(src="1.2.3.4",dst="12.101.0.1")']
> +        """
> +        return {"ipv4": ['IP(src="1.2.3.4",dst="192.18.1.0")',
> +                         'IP(src="1.2.3.4",dst="192.18.1.1")',
> +                         'IP(src="1.2.3.4",dst="192.18.0.0")',
> +                         'IP(src="1.2.3.4",dst="192.18.0.1")',
> +                         'IP(src="1.2.3.4",dst="192.18.3.0")',
> +                         'IP(src="1.2.3.4",dst="192.18.3.1")',
> +                         'IP(src="1.2.3.4",dst="192.18.2.0")',
> +                         'IP(src="1.2.3.4",dst="192.18.2.1")'],
> +                "ipv6": [
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="fe80:0000:0000:000
> 0:021b:21ff:fe91:3805")/UDP(sport=10,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="fe80:0000:0000:000
> 0:031b:21ff:fe91:3805")/UDP(sport=10,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2a80:0000:0000:00
> 00:021b:21ff:fe91:3805")/UDP(sport=11,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2a80:0000:0000:00
> 00:031b:21ff:fe91:3805")/UDP(sport=11,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2b80:0000:0000:00
> 00:021b:21ff:fe91:3805")/UDP(sport=12,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2b80:0000:0000:00
> 00:031b:21ff:fe91:3805")/UDP(sport=12,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2c80:0000:0000:000
> 0:021b:21ff:fe91:3805")/UDP(sport=13,dport=1)',
> +
> 'IPv6(src="fe80:0000:0000:0000:021e:67ff:fe0d:b60a",dst="2c80:0000:0000:000
> 0:031b:21ff:fe91:3805")/UDP(sport=13,dport=1)'
> +                ]}
> 
>      def repl(self, match):
>          pid = match.group(1)
> @@ -233,178 +225,218 @@ class TestL3fwd(TestCase):
> 
>          global corelist
>          corelist.append(int(lcid))
> -
>          self.verify(int(pid) in range(4), "invalid port id")
>          self.verify(lcid, "invalid thread id")
> -
>          return '%s,%s,%s' % (str(valports[int(pid)]), qid, lcid)
> 
> -    def set_up(self):
> +    def perpare_commandline(self, ports):
>          """
> -        Run before each test case.
> +        Generate the command line based on the number of ports
>          """
> -        pass
> +        global corelist
> +        pat = re.compile("P([0123]),([0123]),(C\{\d.\d.\d\})")
> +        core_mask = {}
> +        if ports == 2:
> +            rtCmdLines = dict(TestL3fwd.cmdline_2_ports)
> +        elif ports == 4:
> +            rtCmdLines = dict(TestL3fwd.cmdline_4_ports)
> +
> +        for key in rtCmdLines.keys():
> +            corelist = []
> +            while pat.search(rtCmdLines[key]):
> +                print rtCmdLines[key]
> +                rtCmdLines[key] = pat.sub(self.repl, rtCmdLines[key])
> +            core_mask[key] = utils.create_mask(set(corelist))
> +        return rtCmdLines, core_mask
> +
> +    def create_pcap_file(self, frame_size, l3_proto):
> +        """
> +        Prepare traffic flow for packet generator
> +        """
> +        if l3_proto == 'ipv4':
> +            payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ip'] -
> HEADER_SIZE['udp']
> +        else:
> +            # l3_proto == 'ipv6'
> +            payload_size = frame_size - HEADER_SIZE['eth'] - HEADER_SIZE['ipv6']
> - HEADER_SIZE['udp']
> +            if frame_size == 64:
> +                payload_size = frame_size + 2 - HEADER_SIZE['eth'] -
> + HEADER_SIZE['ipv6'] - HEADER_SIZE['udp']
> +
> +        pcaps = {}
> +        for _port in valports:
> +            index = valports[_port]
> +            dmac = self.dut.get_mac_address(index)
> +            cnt = 0
> +            layer3s = self.flows()[l3_proto][_port * 2:(_port + 1) * 2]
> +            for l3 in layer3s:
> +                flow = ['Ether(dst="%s")/%s/UDP()/("X"*%d)' % (dmac, l3,
> payload_size)]
> +                pcap = os.sep.join([self.output_path,
> "dst{0}_{1}.pcap".format(index, cnt)])
> +                self.tester.scapy_append('wrpcap("%s", [%s])' % (pcap,
> string.join(flow, ',')))
> +                self.tester.scapy_execute()
> +                if index not in pcaps:
> +                    pcaps[index] = []
> +                pcaps[index].append(pcap)
> +                cnt += 1
> +        return pcaps
> +
> +    def prepare_steam(self, pcaps):
> +        """
> +        create streams for ports, one port one stream
> +        """
> +        tgen_input = []
> +        for rxPort in valports:
> +            if rxPort % len(valports) == 0 or len(valports) % rxPort == 2:
> +                txIntf = self.tester.get_local_port(valports[rxPort + 1])
> +                port_id = valports[rxPort + 1]
> +            else:
> +                txIntf = self.tester.get_local_port(valports[rxPort - 1])
> +                port_id = valports[rxPort - 1]
> +            rxIntf = self.tester.get_local_port(valports[rxPort])
> +            for pcap in pcaps[port_id]:
> +                tgen_input.append((txIntf, rxIntf, pcap))
> +        return tgen_input
> 
> -    def test_perf_rfc2544(self):
> +    def create_result_table(self, ttl, ttl1, ttl2, ttl3, ttl4):
> 
> -        ports = self.dut.get_ports()
> -        ports_num = len(ports)
> -        header_row = ["Frame_size(byte)", "mode", "S/C/T",
> "zero_loss_throughput(Mpps)", " % zero_loss_rate"]# "LR_tx_pkts(1min)",
> "LR_rx_pkts(1min)", "LR_loss_pkts(1min)", "% zero_loss_rate",
> "zero_loss_throughput(Mpps)"]
> -        self.l3fwd_test_results['header'] = header_row
> +        header_row = [ttl, ttl1, ttl2, ttl3, ttl4]
> +        self.test_results['header'] = header_row
>          self.result_table_create(header_row)
> -        self.l3fwd_test_results['data'] = []
> -
> -        for frame_size in TestL3fwd.frame_sizes:
> -
> -            # Prepare traffic flow
> -            payload_size = frame_size -  \
> -                HEADER_SIZE['ip'] - HEADER_SIZE['eth'] - HEADER_SIZE['tcp']
> -
> -            pcaps = {}
> -            flows = []
> -            for _port in range(ports_num):
> -                index = valports[_port]
> -                dmac = self.dut.get_mac_address(index)
> -                cnt = 0
> -                for layer in self.flows()[_port *2:(_port +1)*2]:
> -                    flow = 'Ether(dst="%s")/%s/TCP()/("X"*%d)' % (
> -                                                    dmac, layer, payload_size)
> -                    flows.append(flow)
> -                    pcap = os.sep.join([
> -                                self.output_path,
> -                                "dst{0}_{1}.pcap".format(index, cnt)])
> -                    self.tester.scapy_append('wrpcap("%s", [%s])' % (
> -                                                pcap, flow))
> -                    self.tester.scapy_execute()
> -                    if index not in pcaps:
> -                        pcaps[index] = []
> -                    pcaps[index].append(pcap)
> -                    cnt += 1
> -
> -            self.rst_report("Flows for %d ports, %d frame size.\n" % (ports_num,
> frame_size),
> -                       annex=True)
> -            self.rst_report("%s" % string.join(flows, '\n'),
> -                       frame=True, annex=True)
> -
> -            # Prepare the command line
> -            global corelist
> -            pat = re.compile("P([0123]),([0123]),(C\{\d.\d.\d\})")
> -
> -            pat2 = re.compile("C\{\d")
> -            repl1 = "C{" + str(self.port_socket)
> -
> -            coreMask = {}
> -            rtCmdLines = {}
> -            cmdlist = []
> -            if ports_num == 4:
> -                for i in TestL3fwd.test_cases_4_ports:
> -                    cmdlist.append(i)
> -            else:
> -                for i in TestL3fwd.test_cases_2_ports:
> -                    cmdlist.append(i)
> -                if 'eagle' in self.nic:
> -                    del cmdlist[2]
> -                else:
> -                    del cmdlist[1]
> -            for cmdline_pat in cmdlist:
> -                corelist = []
> -                rtCmdLines[cmdline_pat[1]] = cmdline_pat[2]
> -                while pat.search(rtCmdLines[cmdline_pat[1]]):
> -                    # Change the socket to the NIC's socket
> -                    if cmdline_pat[1].find('1S')>=0:
> -                        rtCmdLines[cmdline_pat[1]] = pat2.sub(repl1,
> rtCmdLines[cmdline_pat[1]])
> -                    rtCmdLines[cmdline_pat[1]] = pat.sub(self.repl,
> rtCmdLines[cmdline_pat[1]])
> -
> -                self.logger.info("%s\n" % str(corelist))
> -                coreMask[cmdline_pat[1]] = utils.create_mask(set(corelist))
> -
> -            # measure by two different mode
> -            for mode in TestL3fwd.methods:
> -
> -                # start l3fwd
> -                index = 0
> -                subtitle = []
> -                for cores in rtCmdLines.keys():
> -
> -                    #in order to save time, only some of the cases will be run.
> -                    if mode == "lpm" and (cores == "1S/2C/1T" or cores ==
> "1S/4C/1T"):
> -                        info = "Executing l3fwd using %s mode, %d ports, %s and %d
> frame size.\n" % (
> -                               mode, ports_num, cores, frame_size)
> -
> -                        self.logger.info(info)
> -                        self.rst_report(info, annex=True)
> -
> -                        subtitle.append(cores)
> -                        cmdline = rtCmdLines[cores] % (TestL3fwd.path + "l3fwd_" +
> mode, coreMask[cores],
> -                                                       self.dut.get_memory_channels(),
> utils.create_mask(valports[:ports_num]))
> -                        if self.nic == "niantic":
> -                            cmdline = cmdline + " --parse-ptype"
> -
> -                        if frame_size > 1518:
> -                            cmdline = cmdline + " --enable-jumbo --max-pkt-len %d" %
> frame_size
> -                        self.rst_report(cmdline + "\n", frame=True, annex=True)
> -
> -                        out = self.dut.send_expect(cmdline, "L3FWD:", 120)
> -
> -                        # Measure test
> -                        tgenInput = []
> -                        for rxPort in range(ports_num):
> -                            # No use on rx/tx limitation
> -                            if rxPort % 2 == 0:
> -                                txIntf = self.tester.get_local_port(valports[rxPort + 1])
> -                            else:
> -                                txIntf = self.tester.get_local_port(valports[rxPort - 1])
> -
> -                            rxIntf = self.tester.get_local_port(valports[rxPort])
> -                            port_id = valports[rxPort+1] if rxPort % 2 == 0 else \
> -                                      valports[rxPort-1]
> -                            for pcap in pcaps[port_id]:
> -                                tgenInput.append((txIntf, rxIntf, pcap))
> -
> -                        # Run traffic generator
> -
> -                        vm_config = self.set_fields()
> -                        # clear streams before add new streams
> -                        self.tester.pktgen.clear_streams()
> -                        # run packet generator
> -                        streams =
> self.pktgen_helper.prepare_stream_from_tginput(tgenInput,
> -                                            100, vm_config, self.tester.pktgen)
> -                        # set traffic option
> -                        traffic_opt = {'duration': 60}
> -                        zero_loss_rate, tx_pkts, rx_pkts =
> self.tester.pktgen.measure_rfc2544(stream_ids=streams, options=traffic_opt)
> -
> -                        loss_pkts = tx_pkts - rx_pkts
> -                        self.dut.send_expect("^C", "#")
> -                        linerate = self.wirespeed(self.nic, frame_size, ports_num)
> -                        zero_loss_throughput = (linerate * zero_loss_rate) / 100
> -
> -                        tx_pkts = utils.human_read_number(tx_pkts)
> -                        rx_pkts = utils.human_read_number(rx_pkts)
> -                        loss_pkts = utils.human_read_number(loss_pkts)
> -
> -
> -                        #data_row = [frame_size, mode, cores, tx_pkts, rx_pkts,
> loss_pkts, zero_loss_rate, zero_loss_throughput]
> -                        data_row = [frame_size, mode, cores, zero_loss_throughput,
> zero_loss_rate]
> -                        self.result_table_add(data_row)
> -                        self.l3fwd_test_results['data'].append(data_row)
> -                    else:
> -                        pass
> -
> -                    index += 1
> +        self.test_results['data'] = []
> 
> +    def measure_throughput(self, l3_proto, mode):
> +        """
> +        measure throughput according to Layer-3 Protocal and Lookup Mode
> +        """
> +        # create result table
> +        self.create_result_table("Frame Size", "Mode", "S/C/T", "Mpps", "%
> Linerate")
> +        # build application
> +        self.install_l3fwd_application(l3_proto, mode)
> +        # perpare commandline and core mask
> +        rtCmdLines, core_mask = self.perpare_commandline(len(valports))
> +
> +        for cores in rtCmdLines.keys():
> +            # Start L3fwd appliction
> +            command_line = rtCmdLines[cores] % (TestL3fwd.path + l3_proto +
> "_l3fwd_" + mode, core_mask[cores],
> +                                                self.dut.get_memory_channels(),
> utils.create_mask(valports))
> +            self.dut.send_expect(command_line, "L3FWD:", 120)
> +            for frame_size in self.frame_sizes:
> +                # crete traffic flow
> +                pcaps = self.create_pcap_file(frame_size, l3_proto)
> +                # send the traffic and Measure test
> +                tgenInput = self.prepare_steam(pcaps)
> +
> +                vm_config = self.set_fields()
> +                # clear streams before add new streams
> +                self.tester.pktgen.clear_streams()
> +                # run packet generator
> +                streams =
> self.pktgen_helper.prepare_stream_from_tginput(tgenInput, 100, vm_config,
> self.tester.pktgen)
> +                # set traffic option
> +                traffic_opt = {'delay': 30}
> +                _, pps =
> self.tester.pktgen.measure_throughput(stream_ids=streams,
> options=traffic_opt)
> +                self.verify(pps > 0, "No traffic detected")
> +                # statistical result
> +                pps /= 1000000.0
> +                linerate = self.wirespeed(self.nic, frame_size, len(valports))
> +                percentage = pps * 100 / linerate
> +                if mode == "ipv6" and frame_size == 64:
> +                    frame_size += 2
> +                data_row = [frame_size, mode, cores, str(pps), str(percentage)]
> +                self.result_table_add(data_row)
> +                self.test_results['data'].append(data_row)
> +            # Stop L3fwd
> +            self.dut.send_expect("^C", "#")
> +            time.sleep(1)
> +        # Print result
> +        self.result_table_print()
> +
> +    def measure_rfc2544(self, l3_proto, mode):
> +        """
> +        measure RFC2544 according to Layer-3 Protocal and Lookup Mode
> +        """
> +        # create result table
> +        self.create_result_table("Frame Size", "Mode", "S/C/T", "Zero Loss
> Throughput(Mpps)", " % Zero Loss Rate")
> +        # build application
> +        self.install_l3fwd_application(l3_proto, mode)
> +        # perpare commandline and core mask
> +        rtCmdLines, core_mask = self.perpare_commandline(len(valports))
> +
> +        for frame_size in self.frame_sizes:
> +            for cores in rtCmdLines.keys():
> +                # in order to save time, only some of the cases will be run.
> +                if cores in ["1S/2C/1T", "1S/4C/1T"]:
> +                    # Start L3fwd appliction
> +                    command_line = rtCmdLines[cores] % (TestL3fwd.path +
> l3_proto + "_l3fwd_" + mode, core_mask[cores],
> +                                                        self.dut.get_memory_channels(),
> utils.create_mask(valports))
> +                    if self.nic == "niantic":
> +                        command_line += " --parse-ptype"
> +                    if frame_size > 1518:
> +                        command_line += " --enable-jumbo --max-pkt-len %d" %
> frame_size
> +                    self.dut.send_expect(command_line, "L3FWD:", 120)
> +                    self.logger.info("Executing l3fwd using %s mode, %d ports, %s
> and %d frame size"
> +                                     % (mode, len(valports), cores, frame_size))
> +                    # crete traffic flow
> +                    pcaps = self.create_pcap_file(frame_size, l3_proto)
> +                    # send the traffic and Measure test
> +                    tgenInput = self.prepare_steam(pcaps)
> +
> +                    vm_config = self.set_fields()
> +                    # clear streams before add new streams
> +                    self.tester.pktgen.clear_streams()
> +                    # run packet generator
> +                    streams =
> self.pktgen_helper.prepare_stream_from_tginput(tgenInput, 100, vm_config,
> self.tester.pktgen)
> +                    # set traffic option
> +                    traffic_opt = {'duration': 15}
> +                    zero_loss_rate, tx_pkts, rx_pkts =
> self.tester.pktgen.measure_rfc2544(stream_ids=streams,
> +                                                                                          options=traffic_opt)
> +                    # statistical result
> +                    linerate = self.wirespeed(self.nic, frame_size, len(valports))
> +                    zero_loss_throughput = (linerate * zero_loss_rate) / 100
> +                    if mode == "ipv6" and frame_size == 64:
> +                        frame_size += 2
> +                    data_row = [frame_size, mode, cores, str(zero_loss_throughput),
> str(zero_loss_rate)]
> +                    self.result_table_add(data_row)
> +                    self.test_results['data'].append(data_row)
> +                # Stop L3fwd
> +                self.dut.send_expect("^C", "#")
> +                time.sleep(1)
> +        # Print result
>          self.result_table_print()
> 
> +    def test_perf_rfc2544_ipv4_lpm(self):
> +        self.measure_rfc2544(l3_proto="ipv4", mode="lpm")
> +
> +    def test_perf_rfc2544_ipv4_em(self):
> +        self.measure_rfc2544(l3_proto="ipv4", mode="em")
> +
> +    def test_perf_throughput_ipv4_lpm(self):
> +        self.measure_throughput(l3_proto="ipv4", mode="lpm")
> +
> +    def test_perf_throughput_ipv4_em(self):
> +        self.measure_throughput(l3_proto="ipv4", mode="em")
> +
> +    def test_perf_rfc2544_ipv6_lpm(self):
> +        self.measure_rfc2544(l3_proto="ipv6", mode="lpm")
> +
> +    def test_perf_rfc2544_ipv6_em(self):
> +        self.measure_rfc2544(l3_proto="ipv6", mode="em")
> +
> +    def test_perf_throughput_ipv6_lpm(self):
> +        self.measure_throughput(l3_proto="ipv6", mode="lpm")
> +
> +    def test_perf_throughput_ipv6_em(self):
> +        self.measure_throughput(l3_proto="ipv6", mode="em")
> +
>      def set_fields(self):
> -        ''' set ip protocol field behavior '''
> -        fields_config = {
> -        'ip':  {'src': {'action': 'random'},},}
> +        """
> +        set ip protocol field behavior
> +        """
> +        fields_config = {'ip':  {'src': {'action': 'random'}, }, }
>          return fields_config
> 
>      def tear_down(self):
>          """
>          Run after each test case.
>          """
> -        pass
> +        self.dut.kill_all()
> 
>      def tear_down_all(self):
>          """
> --
> 2.17.1


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

end of thread, other threads:[~2019-07-10  2:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 15:56 [dts] [[PATCH V2]tests/l3fwd: l3fwd script refactoring hanyingya
2019-07-10  2:11 ` Tu, Lijuan

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).