test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH V1 1/2] add tests/metering_and_policing script
@ 2019-02-21  7:16 Wenjie Li
  2019-02-21  7:16 ` [dts] [PATCH V1 2/2] add meter_and_policy config files Wenjie Li
  2019-02-21  9:54 ` [dts] [PATCH V1 1/2] add tests/metering_and_policing script Peng, Yuan
  0 siblings, 2 replies; 3+ messages in thread
From: Wenjie Li @ 2019-02-21  7:16 UTC (permalink / raw)
  To: dts; +Cc: Wenjie Li

Signed-off-by: Wenjie Li <wenjiex.a.li@intel.com>
---
 tests/TestSuite_metering_and_policing.py | 514 +++++++++++++++++++++++
 1 file changed, 514 insertions(+)
 create mode 100644 tests/TestSuite_metering_and_policing.py

diff --git a/tests/TestSuite_metering_and_policing.py b/tests/TestSuite_metering_and_policing.py
new file mode 100644
index 0000000..488e23f
--- /dev/null
+++ b/tests/TestSuite_metering_and_policing.py
@@ -0,0 +1,514 @@
+#BSD LICENSE
+#
+# Copyright(c) 2010-2016 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.
+Test metering_and_policing.
+"""
+import utils
+import string
+import time
+import re
+from test_case import TestCase
+from plotting import Plotting
+from settings import HEADER_SIZE
+from dut import Dut
+
+
+class TestMeteringAndPolicing(TestCase):
+
+    def copy_config_files_to_dut(self):
+        """
+        Copy firmware.cli, dscp_*.sh from tester to DUT.
+        """
+        file = 'meter_and_policy_config.tar.gz'
+        src_file = r'./dep/%s' % file
+        dst1 = '/tmp'
+        dst2 = '/root/dpdk/drivers/net/softnic'
+        self.dut.session.copy_file_to(src_file, dst1)
+        self.dut.send_expect("tar xf %s/%s -C %s" % (dst1, file, dst2), "#", 30)
+
+    def update_firmware_cli(self, caseID):
+        """
+        Update firmware.cli.
+        """
+        self.ori_firmware_cli = "/root/dpdk/drivers/net/softnic/meter_and_policing_firmware.cli"
+        if len(self.dut_ports) == 4:
+            self.ori_firmware_cli = "/root/dpdk/drivers/net/softnic/meter_and_policing_firmware_4ports.cli"
+        self.new_firmware_cli = "%s-%s" % (self.ori_firmware_cli, caseID)
+        self.dut.send_expect("rm -f %s" % self.new_firmware_cli, "#")
+        self.dut.send_expect("cp %s %s" % (self.ori_firmware_cli, self.new_firmware_cli), "#")
+
+        # link dev
+        self.dut.send_expect("sed -i -e 's/^.*link LINK0 dev.*$/link LINK0 dev %s/g' %s"
+                             % (self.dut_p0_pci, self.new_firmware_cli), "#")
+        self.dut.send_expect("sed -i -e 's/^.*link LINK1 dev.*$/link LINK1 dev %s/g' %s"
+                             % (self.dut_p1_pci, self.new_firmware_cli), "#")
+        if len(self.dut_ports) == 4:
+            self.dut.send_expect("sed -i -e 's/^.*link LINK2 dev.*$/link LINK2 dev %s/g' %s"
+                                 % (self.dut_p2_pci, self.new_firmware_cli), "#")
+            self.dut.send_expect("sed -i -e 's/^.*link LINK3 dev.*$/link LINK3 dev %s/g' %s"
+                                 % (self.dut_p3_pci, self.new_firmware_cli), "#")
+
+        # table action
+        temp = "table action profile AP0"
+        if caseID == 8:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s ipv6 offset 270 fwd meter trtcm tc 1 stats pkts/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        else:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s ipv4 offset 270 fwd meter trtcm tc 1 stats pkts/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+
+        # pipeline RX table
+        temp = "pipeline RX table match"
+        if caseID == 7:
+            target = "hash ext key 16 mask 00FF0000FFFFFFFFFFFFFFFFFFFFFFFF offset 278 buckets 16K size 65K action AP0"
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s %s/g' %s"
+                                 % (temp, temp, target, self.new_firmware_cli), "#")
+        elif caseID == 8:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s acl ipv6 offset 270 size 4K action AP0/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        else:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s acl ipv4 offset 270 size 4K action AP0/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+
+        # use .sh file as RX table
+        temp = "pipeline RX table 0 dscp"
+        if caseID == 10:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_red.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 11:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_yellow.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 12:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_green.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 13:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_default.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+
+        # thread * pipeline RX/TX enable
+        self.dut.send_expect("sed -i -e 's/thread 5 pipeline RX enable/thread %d pipeline RX enable/g' %s"
+                             % (len(self.dut_ports), self.new_firmware_cli), "#")
+        self.dut.send_expect("sed -i -e 's/thread 5 pipeline TX enable/thread %d pipeline TX enable/g' %s"
+                             % (len(self.dut_ports), self.new_firmware_cli), "#")
+
+    def start_testpmd(self, filename):
+        """
+        Start testpmd.
+        """
+        if len(self.dut_ports) == 2:
+            portmask = "0x4"
+            Corelist = "0x7"
+            Servicecorelist = "0x4"
+        if len(self.dut_ports) == 4:
+            portmask = "0x10"
+            Corelist = "0x1f"
+            Servicecorelist = "0x10"
+        self.path = "./%s/app/testpmd" % self.target
+        cmd = self.path + " -c %s -s %s -n %d --vdev 'net_softnic0,firmware=%s,cpu_id=0,conn_port=8086' \
+         -- -i --rxq=%d --txq=%d --portmask=%s" \
+              % (Corelist, Servicecorelist, self.dut.get_memory_channels(), filename, self.port_id, self.port_id, portmask)
+        self.dut.send_expect(cmd, "testpmd>", 60)
+
+    def add_port_meter_profile(self, profile_id, cbs=400, pbs=500):
+        """
+        Add port meter profile (trTCM rfc2968).
+        """
+        cir = 3125000000
+        pir = 3125000000
+        self.dut.send_expect("add port meter profile trtcm_rfc2698 %d %d %d %d %d %d"
+                             % (self.port_id, profile_id, cir, pir, cbs, pbs), "testpmd>")
+
+    def create_port_meter(self, mtr_id, profile_id, gyrd_action):
+        """
+        Create new meter object for the ethernet device.
+        """
+        self.dut.send_expect("create port meter %d %d %d yes %s"
+                             % (self.port_id, mtr_id, profile_id, gyrd_action), "testpmd>")
+
+    def create_flow_rule(self, ret_id, ip_ver, protocol, spec_id,  mtr_id, queue_index_id):
+        """
+        Create flow rule based on port meter.
+        """
+        if ip_ver == "ipv4":
+            src_mask = "255.255.255.255"
+            dst_mask = "255.255.255.255"
+            src_ip = "1.10.11.12"
+            dst_ip = "2.20.21.22"
+        if ip_ver == "ipv6":
+            src_mask = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
+            dst_mask = "0:0:0:0:0:0:0:0"
+            src_ip = "ABCD:EF01:2345:6789:ABCD:EF01:2345:5789"
+            dst_ip = "0:0:0:0:0:0:0:0"
+        protocol = protocol.lower()
+        if protocol == "tcp":
+            proto_id = 6
+        if protocol == "udp":
+            proto_id = 17
+        if protocol == "sctp":
+            proto_id = 132
+
+        out = self.dut.send_expect("flow create %d group 0 ingress pattern eth / %s proto mask 255 src mask %s dst mask"
+                                   " %s src spec %s dst spec %s proto spec %d / %s src mask 65535 dst mask 65535 src "
+                                   "spec %d dst spec %d / end actions meter mtr_id %d / queue index %d / end"
+                                   % (self.port_id, ip_ver, src_mask, dst_mask, src_ip, dst_ip, proto_id, protocol,
+                                      spec_id, spec_id, mtr_id, queue_index_id), "testpmd>")
+        if ret_id == 1:
+            self.verify("Flow rule #" in out, "flow create fail")
+        else:
+            self.verify("METER: Meter already attached to a flow: Invalid argument" in out,
+                        "flow create should fail, but NOT failed")
+
+    def scapy_send_packet(self, ip_ver, protocol, fwd_port, pktsize):
+        """
+        Send a packet to port
+        """
+        source_port = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
+        protocol = protocol.upper()
+        if ip_ver == "ipv4":
+            src_ip = "1.10.11.12"
+            dst_ip = "2.20.21.22"
+            tag = "IP"
+            if protocol == "TCP":
+                proto_str = "proto=6"
+            if protocol == "UDP":
+                proto_str = "proto=17"
+            if protocol == "SCTP":
+                proto_str = "proto=132"
+
+        if ip_ver == "ipv6":
+            src_ip = "ABCD:EF01:2345:6789:ABCD:EF01:2345:5789"
+            dst_ip = "2001::1"
+            tag = "IPv6"
+            if protocol == "TCP":
+                proto_str = "nh=6"
+            if protocol == "UDP":
+                proto_str = "nh=17"
+
+        self.tester.scapy_append(
+            'sendp([Ether(dst="%s")/%s(src="%s",dst="%s",%s)/%s(sport=%d,dport=%d)/Raw(load="P"*%d)], iface="%s")'
+            % (self.dut_p0_mac, tag, src_ip, dst_ip, proto_str, protocol, fwd_port, fwd_port, pktsize, source_port))
+        self.tester.scapy_execute()
+
+    def send_packet_and_check(self, ip_ver, protocol, fwd_port, pktsize, expect_port):
+        """
+        Send packet and check the stats
+        """
+        time.sleep(3)
+        rx_before = []
+        tx_before = []
+        for i in range(0, len(self.dut_ports)):
+            output = self.dut.send_expect("show port stats %d" %(i),"testpmd>")
+            rx_before.append(re.compile('RX-packets:\s+(.*?)\s+?').findall(output, re.S))
+            tx_before.append(re.compile('TX-packets:\s+(.*?)\s+?').findall(output, re.S))
+
+        self.scapy_send_packet(ip_ver, protocol, fwd_port, pktsize)
+
+        rx_after = []
+        tx_after = []
+        for i in range(0, len(self.dut_ports)):
+            output = self.dut.send_expect("show port stats %d" %(i),"testpmd>")
+            rx_after.append(re.compile('RX-packets:\s+(.*?)\s+?').findall(output, re.S))
+            tx_after.append(re.compile('TX-packets:\s+(.*?)\s+?').findall(output, re.S))
+
+        rx_packets_port = []
+        tx_packets_port = []
+        for i in range(0, len(self.dut_ports)):
+            temp1 = int(rx_after[i][0]) - int(rx_before[i][0])
+            temp2 = int(tx_after[i][0]) - int(tx_before[i][0])
+            rx_packets_port.append(temp1)
+            tx_packets_port.append(temp2)
+        print("-"*80)
+        if expect_port == -1:
+            print("expect: Dropped")
+        else:
+            print("expect: port %d" % expect_port)
+        print rx_packets_port
+        print tx_packets_port
+        print("-"*80)
+
+        if expect_port == -1:
+            for i in range(0, len(self.dut_ports)):
+                self.verify(int(rx_packets_port[0]) == 1 and int(tx_packets_port[i]) == 0,
+                        "Wrong: the packet is not dropped")
+        else:
+            self.verify(int(rx_packets_port[0]) == int(tx_packets_port[expect_port]) == 1,
+                    "Wrong: can't forward package to port %d " % expect_port)
+
+    def set_up_all(self):
+        """
+        Run at the start of each test suite.
+        """
+        self.dut_ports = self.dut.get_ports()
+        self.port_nums = 2
+        self.verify(len(self.dut_ports) >= self.port_nums,
+                    "Insufficient ports for speed testing")
+
+        self.dut_p0_pci = self.dut.get_port_pci(self.dut_ports[0])
+        self.dut_p1_pci = self.dut.get_port_pci(self.dut_ports[1])
+
+        self.dut_p0_mac = self.dut.get_mac_address(self.dut_ports[0])
+        self.dut_p1_mac = self.dut.get_mac_address(self.dut_ports[1])
+
+        self.pf0_interface = self.dut.ports_info[self.dut_ports[0]]['intf']
+        self.pf1_interface = self.dut.ports_info[self.dut_ports[1]]['intf']
+
+        if len(self.dut_ports) == 4:
+            self.dut_p2_pci = self.dut.get_port_pci(self.dut_ports[2])
+            self.dut_p3_pci = self.dut.get_port_pci(self.dut_ports[3])
+
+            self.dut_p2_mac = self.dut.get_mac_address(self.dut_ports[2])
+            self.dut_p3_mac = self.dut.get_mac_address(self.dut_ports[3])
+
+            self.pf2_interface = self.dut.ports_info[self.dut_ports[2]]['intf']
+            self.pf3_interface = self.dut.ports_info[self.dut_ports[3]]['intf']
+
+        self.port_id = len(self.dut_ports)
+        self.copy_config_files_to_dut()
+
+    def set_up(self):
+        """
+        Run before each test case.
+        """
+        pass
+
+    def run_param(self, cbs, pbs, protocol, head):
+        """
+        Set cbs, pbs and protocol; return the packet size
+        """
+        pkt1 = pbs - head + 1
+        pkt2 = pbs - head
+        pkt3 = cbs - head + 1
+        pkt4 = cbs - head
+        pkt_list = [pkt1,pkt2,pkt3,pkt4]
+        return pkt_list,cbs,pbs
+
+    def run_port_list(self,ip_ver,protocol,fwd_port,pkt_list,port_list):
+        flags = 0
+        for port in port_list:
+            self.send_packet_and_check(ip_ver=ip_ver, protocol=protocol, fwd_port=fwd_port, pktsize=pkt_list[port_list.index(port,flags)], expect_port=port)
+            flags = flags + 1
+
+    def run_testpmd(self,pkt_list,cbs,pbs,gyrd_action,ip_ver,protocol,queue_id,port_list):
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.create_port_meter(mtr_id=0, profile_id=0, gyrd_action=gyrd_action)
+        self.create_flow_rule(ret_id=1, ip_ver=ip_ver, protocol=protocol, spec_id=2, mtr_id=0, queue_index_id=queue_id)
+        self.dut.send_expect("start", "testpmd>")
+        self.run_port_list(ip_ver,protocol,2,pkt_list,port_list)
+
+    def test_ipv4_ACL_table_RFC2698_GYR(self):
+        """
+        Test Case 1: ipv4 ACL table RFC2698 GYR
+        """
+        self.update_firmware_cli(1)
+        pkt_list,cbs,pbs = self.run_param(400,500,'TCP',40)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y r 0 0 0", "ipv4", "tcp", 0, [0,0,0,0])
+
+    def test_ipv4_ACL_table_RFC2698_GYD(self):
+        """
+        Test Case 2: ipv4 ACL table RFC2698 GYD
+        """
+        self.update_firmware_cli(2)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y d 0 0 0", "ipv4", "tcp", 0,[-1, 0, 0, 0])
+
+    def test_ipv4_ACL_table_RFC2698_GDR(self):
+        """
+        Test Case 3: ipv4 ACL table RFC2698 GDR
+        """
+        self.update_firmware_cli(3)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", "sctp", 1,[1, -1, -1, 1])
+
+    def test_ipv4_ACL_table_RFC2698_DYR(self):
+        """
+        Test Case 4: ipv4 ACL table RFC2698 DYR
+        """
+        self.update_firmware_cli(4)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 28)
+        self.run_testpmd(pkt_list, cbs, pbs, "d y r 0 0 0", "ipv4", "udp", 0, [0, 0, 0, -1])
+
+    def test_ipv4_ACL_table_RFC2698_DDD(self):
+        """
+        Test Case 5: ipv4 ACL table RFC2698 DDD
+        """
+        self.update_firmware_cli(5)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "d d d 0 0 0", "ipv4", "tcp", 0, [-1, -1, -1, -1])
+
+    def test_ipv4_with_same_cbs_and_pbs_GDR(self):
+        """
+        Test Case 6: ipv4 with same cbs and pbs GDR
+        """
+        self.update_firmware_cli(6)
+        pkt_list, cbs, pbs = self.run_param(500, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", "sctp", 0, [0,0])
+
+    def test_ipv4_HASH_table_RFC2698(self):
+        """
+        Test Case 7: ipv4 HASH table RFC2698
+        """
+        self.update_firmware_cli(7)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y r 0 0 0", "ipv4", "tcp", 0, [0, 0, 0, 0])
+        self.dut.send_expect("quit", "#", 30)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y d 0 0 0", "ipv4", "tcp", 0, [-1,0,0,0])
+        self.dut.send_expect("quit", "#", 30)
+        self.run_testpmd(pkt_list, cbs, pbs, "d d d 0 0 0", "ipv4", "tcp", 0, [-1,-1,-1,-1])
+        self.dut.send_expect("quit", "#", 30)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", "sctp", 1, [1,-1,-1,1])
+        self.dut.send_expect("quit", "#", 30)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 28)
+        self.run_testpmd(pkt_list, cbs, pbs, "d y r 0 0 0", "ipv4", "udp", 0, [0,0,0,-1])
+        self.dut.send_expect("quit", "#", 30)
+
+
+    def test_ipv6_ACL_table_RFC2698(self):
+        """
+        Test Case 8: ipv6 ACL table RFC2698
+        """
+        self.update_firmware_cli(8)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 60)
+
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.create_port_meter(mtr_id=0, profile_id=0, gyrd_action="g y d 0 0 0")
+        self.create_port_meter(mtr_id=1, profile_id=0, gyrd_action="d y r 0 0 0")
+        self.create_flow_rule(ret_id=1, ip_ver="ipv6", protocol="tcp", spec_id=2, mtr_id=0, queue_index_id=0)
+        self.create_flow_rule(ret_id=1, ip_ver="ipv6", protocol="udp", spec_id=2, mtr_id=1, queue_index_id=1)
+        self.dut.send_expect("start","testpmd>")
+
+        self.run_port_list("ipv6","tcp",2,pkt_list,[-1,0,0,0])
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 48)
+        self.run_port_list("ipv6", "udp",2, pkt_list, [1,1,1,-1])
+
+    def test_ipv4_multiple_meter_and_profile(self):
+        """
+        Test Case 9: multiple meter and profile
+        """
+        self.update_firmware_cli(9)
+
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=400, pbs=500)
+        self.add_port_meter_profile(profile_id=1, cbs=300, pbs=400)
+        gyrd_list = ["g y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0", "d d d 0 0 0"]
+        for i in range(len(gyrd_list)):
+            self.create_port_meter(mtr_id=i, profile_id=i * 2 / len(gyrd_list), gyrd_action=gyrd_list[i])
+        for i in range(len(gyrd_list)):
+            self.create_flow_rule(ret_id=1, ip_ver="ipv4", protocol="tcp", spec_id=i, mtr_id=i, queue_index_id=i % len(self.dut_ports))
+        self.create_flow_rule(ret_id=0, ip_ver="ipv4", protocol="tcp", spec_id=len(gyrd_list), mtr_id=len(gyrd_list) - 1, queue_index_id=0)
+
+        self.dut.send_expect("start", "testpmd>")
+        output = self.dut.send_expect("flow list %d" % (self.port_id), "testpmd>")
+        print(output)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        ports_list = [[0,0,0,0], [-1,1,1,1], [0,-1,-1,0], [1,1,1,-1]]
+        if len(self.dut_ports) == 4:
+            ports_list = [[0,0,0,0], [-1,1,1,1], [2,-1,-1,2], [3,3,3,-1]]
+        for ports in ports_list:
+            self.run_port_list("ipv4", "tcp", ports_list.index(ports), pkt_list, ports)
+
+        pkt_list, cbs, pbs = self.run_param(300, 400, 'TCP', 40)
+        ports_list = [[-1,0,0,0], [1,-1,-1,1], [0,0,0,-1], [-1,-1,-1,-1]]
+        if len(self.dut_ports) == 4:
+            ports_list = [[-1,0,0,0], [1,-1,-1,1], [2,2,2,-1], [-1,-1,-1,-1]]
+        for ports in ports_list:
+            self.run_port_list("ipv4", "tcp", ports_list.index(ports) + 4, pkt_list, ports)
+
+        self.dut.send_expect("quit", "#")
+
+    def run_pre_colored_by_DSCP_table(self,ports_list):
+        """
+        ipv4 RFC2698 pre-colored by DSCP table
+        """
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.dut.send_expect("start", "testpmd>")
+
+        gyrd_list = ["g y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0"]
+        for gyrd in gyrd_list:
+            self.create_port_meter(mtr_id=gyrd_list.index(gyrd), profile_id=0, gyrd_action=gyrd)
+            self.create_flow_rule(ret_id=1, ip_ver="ipv4", protocol="tcp", spec_id=2, mtr_id=gyrd_list.index(gyrd),
+                                  queue_index_id=0)
+            self.run_port_list("ipv4", "tcp", 2, pkt_list, ports_list[gyrd_list.index(gyrd)])
+
+    def test_ipv4_RFC2698_pre_colored_red_by_DSCP_table(self):
+        """
+        Test Case 10: ipv4 RFC2698 pre-colored red by DSCP table
+        """
+        self.update_firmware_cli(10)
+        ports_list = [[0, 0, 0, 0], [-1, -1, -1, -1], [0, 0, 0, 0], [0, 0, 0, 0]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_yellow_by_DSCP_table(self):
+        """
+        Test Case 11: ipv4 RFC2698 pre-colored yellow by DSCP table
+        """
+        self.update_firmware_cli(11)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0,-1,-1, -1], [0, 0, 0, 0]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_green_by_DSCP_table(self):
+        """
+        Test Case 12: ipv4 RFC2698 pre-colored green by DSCP table
+        """
+        self.update_firmware_cli(12)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0, -1, -1, 0], [0, 0, 0, -1]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_default_by_DSCP_table(self):
+        """
+        Test Case 13: ipv4 RFC2698 pre-colored by default DSCP table
+        """
+        self.update_firmware_cli(13)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0, -1, -1, 0], [0, 0, 0, -1]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def tear_down(self):
+        """
+        Run after each test case.
+        """
+        self.dut.kill_all()
+        time.sleep(2)
+
+    def tear_down_all(self):
+        """
+        Run after each test suite.
+        """
+        pass
-- 
2.17.2

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

* [dts] [PATCH V1 2/2] add meter_and_policy config files
  2019-02-21  7:16 [dts] [PATCH V1 1/2] add tests/metering_and_policing script Wenjie Li
@ 2019-02-21  7:16 ` Wenjie Li
  2019-02-21  9:54 ` [dts] [PATCH V1 1/2] add tests/metering_and_policing script Peng, Yuan
  1 sibling, 0 replies; 3+ messages in thread
From: Wenjie Li @ 2019-02-21  7:16 UTC (permalink / raw)
  To: dts; +Cc: Wenjie Li

Add meter_and_policy config files, include:
1. dscp_default.sh
2. dscp_green.sh
3. dscp_red.sh
4. dscp_yellow.sh
5. meter_and_policing_firmware_4ports.cli
6. meter_and_policing_firmware.cli
Compress them into meter_and_policy_config.tar.gz.

Signed-off-by: Wenjie Li <wenjiex.a.li@intel.com>
---
 dep/meter_and_policy_config.tar.gz | Bin 0 -> 1031 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 dep/meter_and_policy_config.tar.gz

diff --git a/dep/meter_and_policy_config.tar.gz b/dep/meter_and_policy_config.tar.gz
new file mode 100644
index 0000000000000000000000000000000000000000..c5100d9bad7ea200cbc71161188c17a0f19a6d09
GIT binary patch
literal 1031
zcmV+i1o-<OiwFRIKssCi1MON(Z{kQ0&Dp=AZgYvDKa7b6aTv{MHLKO^h{N8HV>e(0
zY)^MP!Sn04T!HZA0S5+1A{R<Ksd`=AcD>gWB9RHRVWdVuKD8|~xjBb1G~e^+ine`a
zKK{<7$9+$BB=>I^7agyA1MDoj*|OZ&Km*+9G`0J1hvM(l7~sok#%qn&u76bOf2@^C
z&ZYjN^e=>L^nVE}SvW>6avBAV5=TycPJT{)PJTgtL4HAgL4HYoNq$LwN&b(W|CH$S
z-mYDL(!W;G`P6@m{<+`nH2S}Ul^oT?QB54x#8FKg)x=Rv`q88xP5RNKA5Hqvq#sTC
z(WD<u`q88x?R@O~r$nFkcJ2C;{tGporcY-(0*-k9_oUzG{}NVmv>=Wa#L<E{S`bGI
z;%GtoDM&vB>8Bw56r`Vm^iz<23erzO`YA|1h4ZoVpAvoE+qLUIQ&#C=kVL~QoyK9D
zjEAFG&z=IUhF+FxYg*wnK5dNy`uA9eFZAy*jvxFP?@A^b{a?a*@M8{HoT+J?D9DY1
zNnj>mgZrtvg~5NT*!RE~JJD%Ap0pgN_cfi(kTzgbP;(XLR)L-1k1{r!MG$0J&*_;w
zN}<)B-}yt|bCbZvkIKbt`5fc!I1Jl(Z7=7zQxM!09dHxyz;z!Z^$4F5Wrrpm*(46x
z?UI}Qc3F>hltmBiNMlxQ+6ZhffbBiBF8O>LX8ACV`s_ALlVn)(ynn~;{7<+lxG|2S
zR3kWYXKAGRi>&C@^Pl~4Yj$xhXU+oi&}Vbb90zah0sj8$pKlDxy_f9%%sQVLYq3>~
zZ^!s5CbnZ@6_eXB={PUd`GJ*EI!+_t4ARla;8QC%hj$5V6NX-h6Sz0OKnhsfGTvNG
zEPn-7yaFqKhfQ<41e>Ry=>E4Bh}Qv$Iv{-3qzMQ@8>b0mIvvIM=a=sc;_T5|JaZ6T
z2BW74h=5?V4QF6OJnHe7u?DgSYc`g9PC5&0IKkA@om?jVrNH~PTo#vedb{(HZrI1c
z0a0xBdX)uX%Y>CtzBelNM&(O%gzE=cj5nRZ7|)XoS4DwpWeil@+8W6R^+-P0Ay`?&
z!3Jl3i{Ujeq6S9pV%Au-raHUH_<dmh8nAc`SXO}7scCF}f39HV!>l0UV3&y1#aa@v
zx=c$V%8Fg#8JL$EkD|o}7vGF5<yR`3@>D%3UUxFDm@Mi}78R3a-O1%CHqk1GptB)0
zm6UlZVuP31wHuYj&SD1|r9ZO9f&O3kY_0#7=;xhor}_MU5qoR>zkK`szgYDDVzdAE
zj&J|pTpNFMyZu3$<kde!oYW=1yH58k9qN_3!OM1ZO<&bmV~xEx`yXswb7BA}004Uo
B41E9q

literal 0
HcmV?d00001

-- 
2.17.2

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

* Re: [dts] [PATCH V1 1/2] add tests/metering_and_policing script
  2019-02-21  7:16 [dts] [PATCH V1 1/2] add tests/metering_and_policing script Wenjie Li
  2019-02-21  7:16 ` [dts] [PATCH V1 2/2] add meter_and_policy config files Wenjie Li
@ 2019-02-21  9:54 ` Peng, Yuan
  1 sibling, 0 replies; 3+ messages in thread
From: Peng, Yuan @ 2019-02-21  9:54 UTC (permalink / raw)
  To: Li, WenjieX A, dts; +Cc: Li, WenjieX A

Hi wenjie,

Some comments inline.

Thanks.
Yuan.

-----Original Message-----
From: dts [mailto:dts-bounces@dpdk.org] On Behalf Of Wenjie Li
Sent: Thursday, February 21, 2019 3:17 PM
To: dts@dpdk.org
Cc: Li, WenjieX A <wenjiex.a.li@intel.com>
Subject: [dts] [PATCH V1 1/2] add tests/metering_and_policing script

Signed-off-by: Wenjie Li <wenjiex.a.li@intel.com>
---
 tests/TestSuite_metering_and_policing.py | 514 +++++++++++++++++++++++
 1 file changed, 514 insertions(+)
 create mode 100644 tests/TestSuite_metering_and_policing.py

diff --git a/tests/TestSuite_metering_and_policing.py b/tests/TestSuite_metering_and_policing.py
new file mode 100644
index 0000000..488e23f
--- /dev/null
+++ b/tests/TestSuite_metering_and_policing.py
@@ -0,0 +1,514 @@
+#BSD LICENSE
+#
+# Copyright(c) 2010-2016 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.
+Test metering_and_policing.
+"""
+import utils
+import string
+import time
+import re
+from test_case import TestCase
+from plotting import Plotting
+from settings import HEADER_SIZE
+from dut import Dut
+
+
+class TestMeteringAndPolicing(TestCase):
+
+    def copy_config_files_to_dut(self):
+        """
+        Copy firmware.cli, dscp_*.sh from tester to DUT.
+        """
+        file = 'meter_and_policy_config.tar.gz'
+        src_file = r'./dep/%s' % file
+        dst1 = '/tmp'
+        dst2 = '/root/dpdk/drivers/net/softnic'
+        self.dut.session.copy_file_to(src_file, dst1)
+        self.dut.send_expect("tar xf %s/%s -C %s" % (dst1, file, dst2), 
+ "#", 30)
+
+    def update_firmware_cli(self, caseID):
+        """
+        Update firmware.cli.
+        """
+        self.ori_firmware_cli = "/root/dpdk/drivers/net/softnic/meter_and_policing_firmware.cli"
+        if len(self.dut_ports) == 4:
+            self.ori_firmware_cli = "/root/dpdk/drivers/net/softnic/meter_and_policing_firmware_4ports.cli"
+        self.new_firmware_cli = "%s-%s" % (self.ori_firmware_cli, caseID)
+        self.dut.send_expect("rm -f %s" % self.new_firmware_cli, "#")
+        self.dut.send_expect("cp %s %s" % (self.ori_firmware_cli, 
+ self.new_firmware_cli), "#")
+
+        # link dev
+        self.dut.send_expect("sed -i -e 's/^.*link LINK0 dev.*$/link LINK0 dev %s/g' %s"
+                             % (self.dut_p0_pci, self.new_firmware_cli), "#")
+        self.dut.send_expect("sed -i -e 's/^.*link LINK1 dev.*$/link LINK1 dev %s/g' %s"
+                             % (self.dut_p1_pci, self.new_firmware_cli), "#")
+        if len(self.dut_ports) == 4:
+            self.dut.send_expect("sed -i -e 's/^.*link LINK2 dev.*$/link LINK2 dev %s/g' %s"
+                                 % (self.dut_p2_pci, self.new_firmware_cli), "#")
+            self.dut.send_expect("sed -i -e 's/^.*link LINK3 dev.*$/link LINK3 dev %s/g' %s"
+                                 % (self.dut_p3_pci, 
+ self.new_firmware_cli), "#")
+
+        # table action
+        temp = "table action profile AP0"
+        if caseID == 8:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s ipv6 offset 270 fwd meter trtcm tc 1 stats pkts/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        else:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s ipv4 offset 270 fwd meter trtcm tc 1 stats pkts/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), 
+ "#")
+
+        # pipeline RX table
+        temp = "pipeline RX table match"
+        if caseID == 7:
+            target = "hash ext key 16 mask 00FF0000FFFFFFFFFFFFFFFFFFFFFFFF offset 278 buckets 16K size 65K action AP0"
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s %s/g' %s"
+                                 % (temp, temp, target, self.new_firmware_cli), "#")
+        elif caseID == 8:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s acl ipv6 offset 270 size 4K action AP0/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        else:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s acl ipv4 offset 270 size 4K action AP0/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), 
+ "#")
+
+        # use .sh file as RX table
+        temp = "pipeline RX table 0 dscp"
+        if caseID == 10:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_red.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 11:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_yellow.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 12:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_green.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), "#")
+        elif caseID == 13:
+            self.dut.send_expect("sed -i -e 's/^.*%s.*$/%s  \/root\/dpdk\/drivers\/net\/softnic\/dscp_default.sh/g' %s"
+                                 % (temp, temp, self.new_firmware_cli), 
+ "#")
+
+        # thread * pipeline RX/TX enable
+        self.dut.send_expect("sed -i -e 's/thread 5 pipeline RX enable/thread %d pipeline RX enable/g' %s"
+                             % (len(self.dut_ports), self.new_firmware_cli), "#")
+        self.dut.send_expect("sed -i -e 's/thread 5 pipeline TX enable/thread %d pipeline TX enable/g' %s"
+                             % (len(self.dut_ports), 

[yuan]:
If it is not the "5" in the pipeline, the command can't be executed.


+ self.new_firmware_cli), "#")
+
+    def start_testpmd(self, filename):
+        """
+        Start testpmd.
+        """
+        if len(self.dut_ports) == 2:
+            portmask = "0x4"
+            Corelist = "0x7"
+            Servicecorelist = "0x4"
+        if len(self.dut_ports) == 4:
+            portmask = "0x10"
+            Corelist = "0x1f"
+            Servicecorelist = "0x10"
+        self.path = "./%s/app/testpmd" % self.target
+        cmd = self.path + " -c %s -s %s -n %d --vdev 'net_softnic0,firmware=%s,cpu_id=0,conn_port=8086' \
+         -- -i --rxq=%d --txq=%d --portmask=%s" \
+              % (Corelist, Servicecorelist, self.dut.get_memory_channels(), filename, self.port_id, self.port_id, portmask)
+        self.dut.send_expect(cmd, "testpmd>", 60)
+
+    def add_port_meter_profile(self, profile_id, cbs=400, pbs=500):
+        """
+        Add port meter profile (trTCM rfc2968).
+        """
+        cir = 3125000000
+        pir = 3125000000
+        self.dut.send_expect("add port meter profile trtcm_rfc2698 %d %d %d %d %d %d"
+                             % (self.port_id, profile_id, cir, pir, 
+ cbs, pbs), "testpmd>")
+
+    def create_port_meter(self, mtr_id, profile_id, gyrd_action):
+        """
+        Create new meter object for the ethernet device.
+        """
+        self.dut.send_expect("create port meter %d %d %d yes %s"
+                             % (self.port_id, mtr_id, profile_id, 
+ gyrd_action), "testpmd>")
+
+    def create_flow_rule(self, ret_id, ip_ver, protocol, spec_id,  mtr_id, queue_index_id):
+        """
+        Create flow rule based on port meter.
+        """
+        if ip_ver == "ipv4":
+            src_mask = "255.255.255.255"
+            dst_mask = "255.255.255.255"
+            src_ip = "1.10.11.12"
+            dst_ip = "2.20.21.22"
+        if ip_ver == "ipv6":
+            src_mask = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
+            dst_mask = "0:0:0:0:0:0:0:0"
+            src_ip = "ABCD:EF01:2345:6789:ABCD:EF01:2345:5789"
+            dst_ip = "0:0:0:0:0:0:0:0"
+        protocol = protocol.lower()
+        if protocol == "tcp":
+            proto_id = 6
+        if protocol == "udp":
+            proto_id = 17
+        if protocol == "sctp":
+            proto_id = 132
+
+        out = self.dut.send_expect("flow create %d group 0 ingress pattern eth / %s proto mask 255 src mask %s dst mask"
+                                   " %s src spec %s dst spec %s proto spec %d / %s src mask 65535 dst mask 65535 src "
+                                   "spec %d dst spec %d / end actions meter mtr_id %d / queue index %d / end"
+                                   % (self.port_id, ip_ver, src_mask, dst_mask, src_ip, dst_ip, proto_id, protocol,
+                                      spec_id, spec_id, mtr_id, queue_index_id), "testpmd>")
+        if ret_id == 1:
+            self.verify("Flow rule #" in out, "flow create fail")
+        else:
+            self.verify("METER: Meter already attached to a flow: Invalid argument" in out,
+                        "flow create should fail, but NOT failed")
+
+    def scapy_send_packet(self, ip_ver, protocol, fwd_port, pktsize):
+        """
+        Send a packet to port
+        """
+        source_port = self.tester.get_interface(self.tester.get_local_port(self.dut_ports[0]))
+        protocol = protocol.upper()
+        if ip_ver == "ipv4":
+            src_ip = "1.10.11.12"
+            dst_ip = "2.20.21.22"
+            tag = "IP"
+            if protocol == "TCP":
+                proto_str = "proto=6"
+            if protocol == "UDP":
+                proto_str = "proto=17"
+            if protocol == "SCTP":
+                proto_str = "proto=132"
+
+        if ip_ver == "ipv6":
+            src_ip = "ABCD:EF01:2345:6789:ABCD:EF01:2345:5789"
+            dst_ip = "2001::1"
+            tag = "IPv6"
+            if protocol == "TCP":
+                proto_str = "nh=6"
+            if protocol == "UDP":
+                proto_str = "nh=17"
+
+        self.tester.scapy_append(
+            'sendp([Ether(dst="%s")/%s(src="%s",dst="%s",%s)/%s(sport=%d,dport=%d)/Raw(load="P"*%d)], iface="%s")'
+            % (self.dut_p0_mac, tag, src_ip, dst_ip, proto_str, protocol, fwd_port, fwd_port, pktsize, source_port))
+        self.tester.scapy_execute()
+
+    def send_packet_and_check(self, ip_ver, protocol, fwd_port, pktsize, expect_port):
+        """
+        Send packet and check the stats
+        """
+        time.sleep(3)
+        rx_before = []
+        tx_before = []
+        for i in range(0, len(self.dut_ports)):
+            output = self.dut.send_expect("show port stats %d" %(i),"testpmd>")
+            rx_before.append(re.compile('RX-packets:\s+(.*?)\s+?').findall(output, re.S))
+            
+ tx_before.append(re.compile('TX-packets:\s+(.*?)\s+?').findall(output, 
+ re.S))
+
+        self.scapy_send_packet(ip_ver, protocol, fwd_port, pktsize)
+
+        rx_after = []
+        tx_after = []
+        for i in range(0, len(self.dut_ports)):
+            output = self.dut.send_expect("show port stats %d" %(i),"testpmd>")
+            rx_after.append(re.compile('RX-packets:\s+(.*?)\s+?').findall(output, re.S))
+            
+ tx_after.append(re.compile('TX-packets:\s+(.*?)\s+?').findall(output, 
+ re.S))
+
+        rx_packets_port = []
+        tx_packets_port = []
+        for i in range(0, len(self.dut_ports)):
+            temp1 = int(rx_after[i][0]) - int(rx_before[i][0])
+            temp2 = int(tx_after[i][0]) - int(tx_before[i][0])
+            rx_packets_port.append(temp1)
+            tx_packets_port.append(temp2)
+        print("-"*80)
+        if expect_port == -1:
+            print("expect: Dropped")
+        else:
+            print("expect: port %d" % expect_port)
+        print rx_packets_port
+        print tx_packets_port
+        print("-"*80)
+
+        if expect_port == -1:
+            for i in range(0, len(self.dut_ports)):
+                self.verify(int(rx_packets_port[0]) == 1 and int(tx_packets_port[i]) == 0,
+                        "Wrong: the packet is not dropped")
+        else:
+            self.verify(int(rx_packets_port[0]) == int(tx_packets_port[expect_port]) == 1,
+                    "Wrong: can't forward package to port %d " % 
+ expect_port)
+
+    def set_up_all(self):
+        """
+        Run at the start of each test suite.
+        """
+        self.dut_ports = self.dut.get_ports()
+        self.port_nums = 2
+        self.verify(len(self.dut_ports) >= self.port_nums,
+                    "Insufficient ports for speed testing")
+
+        self.dut_p0_pci = self.dut.get_port_pci(self.dut_ports[0])
+        self.dut_p1_pci = self.dut.get_port_pci(self.dut_ports[1])
+
+        self.dut_p0_mac = self.dut.get_mac_address(self.dut_ports[0])
+        self.dut_p1_mac = self.dut.get_mac_address(self.dut_ports[1])
+
+        self.pf0_interface = self.dut.ports_info[self.dut_ports[0]]['intf']
+        self.pf1_interface = 
+ self.dut.ports_info[self.dut_ports[1]]['intf']
+
+        if len(self.dut_ports) == 4:
+            self.dut_p2_pci = self.dut.get_port_pci(self.dut_ports[2])
+            self.dut_p3_pci = self.dut.get_port_pci(self.dut_ports[3])
+
+            self.dut_p2_mac = self.dut.get_mac_address(self.dut_ports[2])
+            self.dut_p3_mac = 
+ self.dut.get_mac_address(self.dut_ports[3])
+
+            self.pf2_interface = self.dut.ports_info[self.dut_ports[2]]['intf']
+            self.pf3_interface = 
+ self.dut.ports_info[self.dut_ports[3]]['intf']
+
+        self.port_id = len(self.dut_ports)
+        self.copy_config_files_to_dut()
+
+    def set_up(self):
+        """
+        Run before each test case.
+        """
+        pass
+
+    def run_param(self, cbs, pbs, protocol, head):
+        """
+        Set cbs, pbs and protocol; return the packet size
+        """

[yuan]:
"Protocol" is not used in this function.

+        pkt1 = pbs - head + 1
+        pkt2 = pbs - head
+        pkt3 = cbs - head + 1
+        pkt4 = cbs - head
+        pkt_list = [pkt1,pkt2,pkt3,pkt4]
+        return pkt_list,cbs,pbs
+
+    def run_port_list(self,ip_ver,protocol,fwd_port,pkt_list,port_list):
+        flags = 0
+        for port in port_list:
+            self.send_packet_and_check(ip_ver=ip_ver, protocol=protocol, fwd_port=fwd_port, pktsize=pkt_list[port_list.index(port,flags)], expect_port=port)
+            flags = flags + 1

[yuan]:
Sorry, I don't understand the logic
pkt_list[port_list.index(port,flags)]


+
+    def run_testpmd(self,pkt_list,cbs,pbs,gyrd_action,ip_ver,protocol,queue_id,port_list):
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.create_port_meter(mtr_id=0, profile_id=0, gyrd_action=gyrd_action)
+        self.create_flow_rule(ret_id=1, ip_ver=ip_ver, protocol=protocol, spec_id=2, mtr_id=0, queue_index_id=queue_id)
+        self.dut.send_expect("start", "testpmd>")
+        self.run_port_list(ip_ver,protocol,2,pkt_list,port_list)
+
+    def test_ipv4_ACL_table_RFC2698_GYR(self):
+        """
+        Test Case 1: ipv4 ACL table RFC2698 GYR
+        """
+        self.update_firmware_cli(1)
+        pkt_list,cbs,pbs = self.run_param(400,500,'TCP',40)

[yuan]:
I think you'd better define cbs and pbs instead of as a return value.


+        self.run_testpmd(pkt_list, cbs, pbs, "g y r 0 0 0", "ipv4", 
+ "tcp", 0, [0,0,0,0])
+
+    def test_ipv4_ACL_table_RFC2698_GYD(self):
+        """
+        Test Case 2: ipv4 ACL table RFC2698 GYD
+        """
+        self.update_firmware_cli(2)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y d 0 0 0", "ipv4", 
+ "tcp", 0,[-1, 0, 0, 0])
+
+    def test_ipv4_ACL_table_RFC2698_GDR(self):
+        """
+        Test Case 3: ipv4 ACL table RFC2698 GDR
+        """
+        self.update_firmware_cli(3)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", 
+ "sctp", 1,[1, -1, -1, 1])
+
+    def test_ipv4_ACL_table_RFC2698_DYR(self):
+        """
+        Test Case 4: ipv4 ACL table RFC2698 DYR
+        """
+        self.update_firmware_cli(4)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 28)
+        self.run_testpmd(pkt_list, cbs, pbs, "d y r 0 0 0", "ipv4", 
+ "udp", 0, [0, 0, 0, -1])
+
+    def test_ipv4_ACL_table_RFC2698_DDD(self):
+        """
+        Test Case 5: ipv4 ACL table RFC2698 DDD
+        """
+        self.update_firmware_cli(5)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "d d d 0 0 0", "ipv4", 
+ "tcp", 0, [-1, -1, -1, -1])
+
+    def test_ipv4_with_same_cbs_and_pbs_GDR(self):
+        """
+        Test Case 6: ipv4 with same cbs and pbs GDR
+        """
+        self.update_firmware_cli(6)
+        pkt_list, cbs, pbs = self.run_param(500, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", 
+ "sctp", 0, [0,0])
+
+    def test_ipv4_HASH_table_RFC2698(self):
+        """
+        Test Case 7: ipv4 HASH table RFC2698
+        """
+        self.update_firmware_cli(7)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y r 0 0 0", "ipv4", "tcp", 0, [0, 0, 0, 0])
+        self.dut.send_expect("quit", "#", 30)
+        self.run_testpmd(pkt_list, cbs, pbs, "g y d 0 0 0", "ipv4", "tcp", 0, [-1,0,0,0])
+        self.dut.send_expect("quit", "#", 30)
+        self.run_testpmd(pkt_list, cbs, pbs, "d d d 0 0 0", "ipv4", "tcp", 0, [-1,-1,-1,-1])
+        self.dut.send_expect("quit", "#", 30)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'SCTP', 32)
+        self.run_testpmd(pkt_list, cbs, pbs, "g d r 0 0 0", "ipv4", "sctp", 1, [1,-1,-1,1])
+        self.dut.send_expect("quit", "#", 30)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 28)
+        self.run_testpmd(pkt_list, cbs, pbs, "d y r 0 0 0", "ipv4", "udp", 0, [0,0,0,-1])
+        self.dut.send_expect("quit", "#", 30)
+
+
+    def test_ipv6_ACL_table_RFC2698(self):
+        """
+        Test Case 8: ipv6 ACL table RFC2698
+        """
+        self.update_firmware_cli(8)
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 60)
+
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.create_port_meter(mtr_id=0, profile_id=0, gyrd_action="g y d 0 0 0")
+        self.create_port_meter(mtr_id=1, profile_id=0, gyrd_action="d y r 0 0 0")
+        self.create_flow_rule(ret_id=1, ip_ver="ipv6", protocol="tcp", spec_id=2, mtr_id=0, queue_index_id=0)
+        self.create_flow_rule(ret_id=1, ip_ver="ipv6", protocol="udp", spec_id=2, mtr_id=1, queue_index_id=1)
+        self.dut.send_expect("start","testpmd>")
+
+        self.run_port_list("ipv6","tcp",2,pkt_list,[-1,0,0,0])
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'UDP', 48)
+        self.run_port_list("ipv6", "udp",2, pkt_list, [1,1,1,-1])
+
+    def test_ipv4_multiple_meter_and_profile(self):
+        """
+        Test Case 9: multiple meter and profile
+        """
+        self.update_firmware_cli(9)
+
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=400, pbs=500)
+        self.add_port_meter_profile(profile_id=1, cbs=300, pbs=400)
+        gyrd_list = ["g y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0", "d d d 0 0 0"]
+        for i in range(len(gyrd_list)):
+            self.create_port_meter(mtr_id=i, profile_id=i * 2 / len(gyrd_list), gyrd_action=gyrd_list[i])
+        for i in range(len(gyrd_list)):
+            self.create_flow_rule(ret_id=1, ip_ver="ipv4", protocol="tcp", spec_id=i, mtr_id=i, queue_index_id=i % len(self.dut_ports))
+        self.create_flow_rule(ret_id=0, ip_ver="ipv4", protocol="tcp", 
+ spec_id=len(gyrd_list), mtr_id=len(gyrd_list) - 1, queue_index_id=0)
+
+        self.dut.send_expect("start", "testpmd>")
+        output = self.dut.send_expect("flow list %d" % (self.port_id), "testpmd>")
+        print(output)
+
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        ports_list = [[0,0,0,0], [-1,1,1,1], [0,-1,-1,0], [1,1,1,-1]]
+        if len(self.dut_ports) == 4:
+            ports_list = [[0,0,0,0], [-1,1,1,1], [2,-1,-1,2], [3,3,3,-1]]
+        for ports in ports_list:
+            self.run_port_list("ipv4", "tcp", ports_list.index(ports), 
+ pkt_list, ports)
+
+        pkt_list, cbs, pbs = self.run_param(300, 400, 'TCP', 40)
+        ports_list = [[-1,0,0,0], [1,-1,-1,1], [0,0,0,-1], [-1,-1,-1,-1]]
+        if len(self.dut_ports) == 4:
+            ports_list = [[-1,0,0,0], [1,-1,-1,1], [2,2,2,-1], [-1,-1,-1,-1]]
+        for ports in ports_list:
+            self.run_port_list("ipv4", "tcp", ports_list.index(ports) + 
+ 4, pkt_list, ports)
+
+        self.dut.send_expect("quit", "#")
+
+    def run_pre_colored_by_DSCP_table(self,ports_list):
+        """
+        ipv4 RFC2698 pre-colored by DSCP table
+        """
+        pkt_list, cbs, pbs = self.run_param(400, 500, 'TCP', 40)
+        self.start_testpmd(self.new_firmware_cli)
+        self.add_port_meter_profile(profile_id=0, cbs=cbs, pbs=pbs)
+        self.dut.send_expect("start", "testpmd>")
+
+        gyrd_list = ["g y r 0 0 0", "g y d 0 0 0", "g d r 0 0 0", "d y r 0 0 0"]
+        for gyrd in gyrd_list:
+            self.create_port_meter(mtr_id=gyrd_list.index(gyrd), profile_id=0, gyrd_action=gyrd)
+            self.create_flow_rule(ret_id=1, ip_ver="ipv4", protocol="tcp", spec_id=2, mtr_id=gyrd_list.index(gyrd),
+                                  queue_index_id=0)
+            self.run_port_list("ipv4", "tcp", 2, pkt_list, 
+ ports_list[gyrd_list.index(gyrd)])
+
+    def test_ipv4_RFC2698_pre_colored_red_by_DSCP_table(self):
+        """
+        Test Case 10: ipv4 RFC2698 pre-colored red by DSCP table
+        """
+        self.update_firmware_cli(10)
+        ports_list = [[0, 0, 0, 0], [-1, -1, -1, -1], [0, 0, 0, 0], [0, 0, 0, 0]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_yellow_by_DSCP_table(self):
+        """
+        Test Case 11: ipv4 RFC2698 pre-colored yellow by DSCP table
+        """
+        self.update_firmware_cli(11)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0,-1,-1, -1], [0, 0, 0, 0]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_green_by_DSCP_table(self):
+        """
+        Test Case 12: ipv4 RFC2698 pre-colored green by DSCP table
+        """
+        self.update_firmware_cli(12)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0, -1, -1, 0], [0, 0, 0, -1]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def test_ipv4_RFC2698_pre_colored_default_by_DSCP_table(self):
+        """
+        Test Case 13: ipv4 RFC2698 pre-colored by default DSCP table
+        """
+        self.update_firmware_cli(13)
+        ports_list = [[0, 0, 0, 0], [-1, 0, 0, 0], [0, -1, -1, 0], [0, 0, 0, -1]]
+        self.run_pre_colored_by_DSCP_table(ports_list)
+
+    def tear_down(self):
+        """
+        Run after each test case.
+        """
+        self.dut.kill_all()
+        time.sleep(2)
+
+    def tear_down_all(self):
+        """
+        Run after each test suite.
+        """
+        pass
--
2.17.2

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

end of thread, other threads:[~2019-02-21  9:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21  7:16 [dts] [PATCH V1 1/2] add tests/metering_and_policing script Wenjie Li
2019-02-21  7:16 ` [dts] [PATCH V1 2/2] add meter_and_policy config files Wenjie Li
2019-02-21  9:54 ` [dts] [PATCH V1 1/2] add tests/metering_and_policing script Peng, Yuan

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