From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D49E1A04FC; Fri, 27 Dec 2019 04:06:44 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8A5E61BFD9; Fri, 27 Dec 2019 04:06:44 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id E1C841BFC4 for ; Fri, 27 Dec 2019 04:06:42 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Dec 2019 19:06:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,361,1571727600"; d="scan'208";a="214707592" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga007.fm.intel.com with ESMTP; 26 Dec 2019 19:06:40 -0800 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 26 Dec 2019 19:06:40 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 26 Dec 2019 19:06:40 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.29]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.90]) with mapi id 14.03.0439.000; Fri, 27 Dec 2019 11:06:38 +0800 From: "Peng, Yuan" To: "Xie, WeiX" , "dts@dpdk.org" CC: "Xie, WeiX" , "Peng, Yuan" Thread-Topic: [dts] [PATCH V2] tests/macsec_for_ixgbe:add an automation Thread-Index: AQHVvGBhsT9Hbt25m0a24VRIJxnfqqfNTEqQ Date: Fri, 27 Dec 2019 03:06:37 +0000 Message-ID: <67D543A150B29E4CAAE53918F64EDAEA377B8BD9@SHSMSX103.ccr.corp.intel.com> References: <1577415303-87479-1-git-send-email-weix.xie@intel.com> In-Reply-To: <1577415303-87479-1-git-send-email-weix.xie@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjRmZjU4NGUtMzUyNy00ZGM5LTljMDItYWYwMTcyODk3OGNkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibTM3NU03UThlSjNxN1RcL2w1WVFFeVp2akdGeDVUY2cxOVlnMUtYdSthblJPOFZQSzg5RFljbVNXY0ZZRWVETHUifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V2] tests/macsec_for_ixgbe:add an automation X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Acked by Peng, Yuan -----Original Message----- From: dts On Behalf Of Xie Wei Sent: Friday, December 27, 2019 10:55 AM To: dts@dpdk.org Cc: Xie, WeiX Subject: [dts] [PATCH V2] tests/macsec_for_ixgbe:add an automation a new automation according to test plan Signed-off-by: Xie Wei --- tests/TestSuite_macsec_for_ixgbe.py | 469 ++++++++++++++++++++++++++++ 1 file changed, 469 insertions(+) create mode 100644 tests/TestSuite_macsec_for_ixgbe.py diff --git a/tests/TestSuite_macsec_for_ixgbe.py b/tests/TestSuite_macsec_f= or_ixgbe.py new file mode 100644 index 0000000..ad14383 --- /dev/null +++ b/tests/TestSuite_macsec_for_ixgbe.py @@ -0,0 +1,469 @@ +# BSD LICENSE +# +# Copyright (c) <2017>, Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without #=20 +modification, are permitted provided that the following conditions #=20 +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 #=20 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #=20 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #=20 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #=20 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #=20 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT #=20 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, #=20 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY #=20 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #=20 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #=20 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +import re +import time +import os + +from test_case import TestCase +from dut import Dut +from pktgen import PacketGeneratorHelper from packet import Packet + +class TestMacsecForIxgbe(TestCase): + def set_up_all(self): + """ + Prerequisite steps for each test suite. + """ + self.verify(self.nic in ["niantic"], "NIC Unsupported: " + str(sel= f.nic)) + self.dut_ports =3D self.dut.get_ports(self.nic) + self.verify(len(self.dut_ports) >=3D 2, "Insufficient ports") + self.core_list =3D self.dut.get_core_list('1S/4C/1T') + self.verify(len(self.core_list) >=3D 4, "There has not enought cor= es to test this suite") + self.session_sec =3D self.dut.new_session() + self.pci_rx =3D self.dut.ports_info[self.dut_ports[1]]['pci'] + self.pci_tx =3D self.dut.ports_info[self.dut_ports[0]]['pci'] + self.mac0 =3D self.dut.get_mac_address(self.dut_ports[0]) + self.mac1 =3D self.dut.get_mac_address(self.dut_ports[1]) + + if self.logger.log_path.startswith(os.sep): + self.output_path =3D self.logger.log_path + else: + cur_path =3D os.path.dirname(os.path.dirname(os.path.realpath(= __file__))) + self.output_path =3D os.sep.join([cur_path, self.logger.log_pa= th]) + # create an instance to set stream field setting + self.pktgen_helper =3D PacketGeneratorHelper() + + def set_up(self): + """ + Run before each test case. + """ + self.ol_flags =3D 1 + + def start_testpmd_rx(self): + eal_params =3D self.dut.create_eal_parameters(cores=3Dself.core_li= st[0:2], ports=3D[self.pci_rx], prefix=3D'rx') + cmd_rx =3D self.target + '/app/testpmd ' + eal_params + '-- -i --p= ort-topology=3Dchained' + return self.dut.send_expect(cmd_rx, "testpmd", 120) + + def start_testpmd_tx(self): + eal_params =3D self.dut.create_eal_parameters(cores=3Dself.core_li= st[2:4], ports=3D[self.pci_tx], prefix=3D'tx') + cmd_tx =3D self.target + '/app/testpmd ' + eal_params + '-- -i --p= ort-topology=3Dchained' + return self.session_sec.send_expect(cmd_tx, "testpmd", 120) + =20 + def start_testpmd_perf(self): + eal_params =3D self.dut.create_eal_parameters(cores=3Dself.core_li= st[0:2]) + cmd =3D self.target + '/app/testpmd ' + eal_params + '-- -i --port= -topology=3Dchained' + self.dut.send_expect(cmd, "testpmd", 120) + self.rx_set_macsec_offload('on', 'on') + self.dut.send_expect("set fwd mac", "testpmd>", 2) + self.dut.send_expect("start", "testpmd>", 2) + + def show_xstats(self): + time.sleep(0.1) + self.session_sec.send_expect("stop", "testpmd>", 2) + out_out =3D self.session_sec.send_expect("show port xstats 0", "te= stpmd>") + out_pkts_encrypted =3D int(re.compile('out_pkts_encrypted:\s+(.*?)= \s+?').findall(out_out, re.S)[0]) + out_octets_encrypted =3D int(re.compile('out_octets_encrypted:\s+(= .*?)\s+?').findall(out_out, re.S)[0]) + out_pkts_protected =3D int(re.compile('out_pkts_protected:\s+(.*?)= \s+?').findall(out_out, re.S)[0]) + out_octets_protected =3D int(re.compile('out_octets_protected:\s+(= .*?)\s+?').findall(out_out, re.S)[0]) + tx_good_packets =3D int(re.compile('tx_good_packets:\s+(.*?)\s+?')= .findall(out_out, re.S)[0]) + if self.ol_flags =3D=3D 0: + pkts_content =3D self.dut.get_session_output(timeout=3D2) + + self.dut.send_expect("stop", "testpmd>", 2) + out_in =3D self.dut.send_expect("show port xstats 0", "testpmd>") + rx_good_packets =3D int(re.compile('rx_good_packets:\s+(.*?)\s+?')= .findall(out_in, re.S)[0]) + in_pkts_ok =3D int(re.compile('in_pkts_ok:\s+(.*?)\s+?').findall(o= ut_in, re.S)[0]) + in_octets_decrypted =3D int(re.compile('in_octets_decrypted:\s+(.*= ?)\s+?').findall(out_in, re.S)[0]) + in_octets_validated =3D int(re.compile('in_octets_validated:\s+(.*= ?)\s+?').findall(out_in, re.S)[0]) + in_pkts_late =3D int(re.compile('in_pkts_late:\s+(.*?)\s+?').finda= ll(out_in, re.S)[0]) + in_pkts_notvalid =3D int(re.compile('in_pkts_notvalid:\s+(.*?)\s+?= ').findall(out_in, re.S)[0]) + in_pkts_nosci =3D int(re.compile('in_pkts_nosci:\s+(.*?)\s+?').fin= dall(out_in, re.S)[0]) + in_pkts_notusingsa =3D=20 + int(re.compile('in_pkts_notusingsa:\s+(.*?)\s+?').findall(out_in,=20 + re.S)[0]) + + list_1 =3D ['out_pkts_encrypted', 'out_octets_encrypted', 'out_pkt= s_protected', 'out_octets_protected', 'tx_good_packets', 'rx_good_packets', + 'in_pkts_ok', 'in_octets_decrypted', 'in_octets_valida= ted', 'in_pkts_late', 'in_pkts_notvalid', 'in_pkts_nosci', 'in_pkts_notusin= gsa'] + list_2 =3D [out_pkts_encrypted, out_octets_encrypted, out_pkts_pro= tected, out_octets_protected, tx_good_packets, rx_good_packets, + in_pkts_ok, in_octets_decrypted, in_octets_validated, = in_pkts_late, in_pkts_notvalid, in_pkts_nosci, in_pkts_notusingsa] + result_dict =3D dict(zip(list_1, list_2)) + print result_dict + + if self.ol_flags =3D=3D 0: + return result_dict, pkts_content + return result_dict + + def clear_port_xstats(self): + self.dut.send_expect("clear port xstats 0", "testpmd>") + self.session_sec.send_expect("clear port xstats 0", "testpmd>") + + def rx_set_macsec_offload(self, encrypt_rx, replay_rx): + # rx port + self.dut.send_expect("port stop 0", "testpmd>", 2) + self.dut.send_expect("set macsec offload 0 on encrypt %s replay-pr= otect %s" % (encrypt_rx, replay_rx), "testpmd>") + self.dut.send_expect("port start 0", "testpmd>", 2) + + def tx_set_macsec_offload(self, encrypt_tx, replay_tx): + # tx port + self.session_sec.send_expect("port stop 0", "testpmd>", 2) + self.session_sec.send_expect("set macsec offload 0 on encrypt %s r= eplay-protect %s" % (encrypt_tx, replay_tx), "testpmd>") + self.session_sec.send_expect("port start 0", "testpmd>", 2) + + def rx_set_macsec_various_param(self, pi, idx, an, pn, key): + # rx port + self.dut.send_expect("set macsec sc rx 0 %s %s" % (self.mac0, pi),= "testpmd>") + self.dut.send_expect("set macsec sa rx 0 %s %s %s %s" % (idx, an, = pn, key), "testpmd>") + self.dut.send_expect("set macsec sc tx 0 %s %s" % (self.mac1, pi),= "testpmd>") + self.dut.send_expect("set macsec sa tx 0 %s %s %s %s" % (idx, an, = pn, key), "testpmd>") + self.dut.send_expect("set fwd rxonly", "testpmd>") + self.dut.send_expect("set promisc all on", "testpmd>") + if self.ol_flags =3D=3D 0: + self.dut.send_expect("set verbose 1", "testpmd>") + self.dut.send_expect("start", "testpmd>", 2) + + def tx_set_macsec_various_param(self, pi, idx, an, pn, key): + # tx port + self.session_sec.send_expect("set macsec sc tx 0 %s %s" % (self.ma= c0, pi), "testpmd>") + self.session_sec.send_expect("set macsec sa tx 0 %s %s %s %s" % (i= dx, an, pn, key), "testpmd>") + self.session_sec.send_expect("set macsec sc rx 0 %s %s" % (self.ma= c1, pi), "testpmd>") + self.session_sec.send_expect("set macsec sa rx 0 %s %s %s %s" % (i= dx, an, pn, key), "testpmd>") + self.session_sec.send_expect("set fwd txonly", "testpmd>") + self.session_sec.send_expect("start", "testpmd>", 2) + + def packets_receive_num(self): + time.sleep(0.1) + self.session_sec.send_expect("stop", "testpmd>", 2) + self.dut.send_expect("stop", "testpmd>", 2) + out =3D self.dut.send_expect("show port stats 0", "testpmd>") + packet_number =3D re.compile('RX-packets:\s+(.*?)\s+?').findall(ou= t, re.S) + return packet_number + + def check_MACsec_pkts_receive(self): + xstats =3D self.show_xstats() + self.verify(xstats.get('out_pkts_protected') =3D=3D 0 + and xstats.get('out_pkts_encrypted') =3D=3D xstats.get= ('in_pkts_ok') =3D=3D xstats.get('tx_good_packets') =3D=3D xstats.get('rx_g= ood_packets') + and xstats.get('in_pkts_ok') !=3D 0 + and xstats.get('out_octets_encrypted') =3D=3D xstats.g= et('in_octets_decrypted') + and xstats.get('out_octets_encrypted') !=3D 0 + and xstats.get('out_octets_protected') =3D=3D xstats.g= et('in_octets_validated') + and xstats.get('out_octets_protected') !=3D 0,=20 + "MACsec pkts receive failed") + + def test_MACsec_pkts_tx_and_rx(self): + """ + MACsec packets send and receive + """ + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + self.rx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'on') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.check_MACsec_pkts_receive() + + def test_MACsec_encrypt_off_and_replay_protect_off(self): + """ + encrypt on/off, replay-protect on/off + """ + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + self.rx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.start_testpmd_tx() + self.tx_set_macsec_offload('off', 'on') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('out_pkts_encrypted') =3D=3D 0 + and xstats.get('out_pkts_protected') =3D=3D xstats.get= ('in_pkts_ok') =3D=3D xstats.get('tx_good_packets') =3D=3D xstats.get('rx_g= ood_packets') + and xstats.get('in_pkts_ok') !=3D 0 + and xstats.get('out_octets_encrypted') =3D=3D 0 and xs= tats.get('in_octets_decrypted') =3D=3D 0 + and xstats.get('out_octets_protected') =3D=3D xstats.g= et('in_octets_validated') + and xstats.get('out_pkts_protected') !=3D 0, "failed") + self.session_sec.send_expect("quit", "#") + self.dut.send_expect("quit", "#") + + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + self.rx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'off') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.check_MACsec_pkts_receive() + + def test_MACsec_tx_and_rx_with_various_param(self): + """ + Set MACsec packets send and receive with various parameters, but k= eep the same value on both sides. + """ + # rx side + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + # tx side + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'on') + + # subcase1:set various index on rx and tx port + for i in [1, 2]: + if i =3D=3D 2: + result =3D self.dut.send_expect("set macsec sa rx 0 %s 0 0= 00112200000000000000000000000000" % i, "testpmd>") + self.verify("invalid" in result, "set idx to 2 failed") + break + else: + self.rx_set_macsec_various_param(0, i, 0, 0, '001122000000= 00000000000000000000') + self.tx_set_macsec_various_param(0, i, 0, 0, '001122000000= 00000000000000000000') + self.check_MACsec_pkts_receive() + self.clear_port_xstats() + + # subcase2:set various an on rx and tx port + for i in range(1, 5): + if i =3D=3D 4: + result =3D self.dut.send_expect("set macsec sa rx 0 0 %s 0= 00112200000000000000000000000000" % i, "testpmd>") + self.verify("invalid" in result, "set an to 4 failed") + break + else: + self.rx_set_macsec_various_param(0, 0, i, 0, '001122000000= 00000000000000000000') + self.tx_set_macsec_various_param(0, 0, i, 0, '001122000000= 00000000000000000000') + self.check_MACsec_pkts_receive() + self.clear_port_xstats() + self.session_sec.send_expect("quit", "#") + self.dut.send_expect("quit", "#") + + # subcase3:set various pn on rx and tx port + for i in ['0xffffffed', '0xffffffee', '0xffffffef', '0xfffffff0', = '0xffffffec', '0x100000000']: + # rx side + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + # tx side + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'on') + if i =3D=3D '0x100000000': + result =3D self.dut.send_expect("set macsec sa rx 0 0 0 %s= 00112200000000000000000000000000" % i, "testpmd>") + self.verify("Bad arguments" in result, "set pn to 0x100000= 000 failed") + break + else: + self.rx_set_macsec_various_param(0, 0, 0, i, '001122000000= 00000000000000000000') + self.tx_set_macsec_various_param(0, 0, 0, i, '001122000000= 00000000000000000000') + pkt_num =3D self.packets_receive_num() + if i =3D=3D '0xffffffec': + self.verify(int(pkt_num[0]) =3D=3D 4, "Rx port can't r= eceive four pkts") + self.clear_port_xstats() + else: + self.verify(int(pkt_num[0]) =3D=3D 3, "Rx port can't r= eceive three pkts") + self.session_sec.send_expect("quit", "#") + self.dut.send_expect("quit", "#") + + # subcase4:set various key on rx and tx port + for i in ['00000000000000000000000000000000', 'fffffffffffffffffff= fffffffffffff']: + self.rx_set_macsec_various_param(0, 0, 0, 0, i) + self.tx_set_macsec_various_param(0, 0, 0, 0, i) + self.check_MACsec_pkts_receive() + self.clear_port_xstats() + + # subcase5:set various pi on rx and tx port + for i in [1, '0xffff', '0x10000']: + if i =3D=3D '0x10000': + result =3D self.dut.send_expect("set macsec sc rx 0 %s %s"= % (self.mac0, i), "testpmd>") + self.verify("Bad arguments" in result, "set pi to 0x10000 = failed") + break + else: + self.rx_set_macsec_various_param(i, 0, 0, 0, '011220000000= 0000000000000000000') + self.tx_set_macsec_various_param(i, 0, 0, 0, '011220000000= 0000000000000000000') + pkt_num =3D self.packets_receive_num() + self.verify(int(pkt_num[0]) =3D=3D 0, "MACsec pkts can't b= e=20 + received") + + def test_MACsec_pkts_send_and_normal_receive(self): + """ + Disable MACsec offload on rx port,enable MACsec offload on tx port + """ + self.ol_flags =3D 0 + # rx port + self.start_testpmd_rx() + self.dut.send_expect("port stop 0", "testpmd>", 2) + self.dut.send_expect("set macsec offload 0 off", "testpmd>") + self.dut.send_expect("port start 0", "testpmd>", 2) + self.dut.send_expect("set fwd rxonly", "testpmd>") + self.dut.send_expect("set promisc all on", "testpmd>") + self.dut.send_expect("set verbose 1", "testpmd>") + self.dut.send_expect("start", "testpmd>", 2) + + # tx port + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'on') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + xstats, pkts_content =3D self.show_xstats() + self.verify("L2_ETHER" in pkts_content + and "L3_IPV4" not in pkts_content + and "L4_UDP" not in pkts_content, "The received packet= s are not encrypted") + self.verify(xstats.get('in_octets_decrypted') =3D=3D 0 and xstats.= get('in_octets_validated') =3D=3D 0, + "Error:in_octets_decrypted and in_octets_validated=20 + increase") + + def test_normal_pkts_send_and_MACsec_receive(self): + """ + Enable MACsec offload on rx port,disable MACsec offload on tx port + """ + # rx port + self.ol_flags =3D 0 + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + self.rx_set_macsec_various_param(0, 0, 0, 0,=20 + '00112200000000000000000000000000') + + # tx port + self.start_testpmd_tx() + self.session_sec.send_expect("port stop 0", "testpmd>", 2) + self.session_sec.send_expect("set macsec offload 0 off", "testpmd>= ") + self.session_sec.send_expect("port start 0", "testpmd>", 2) + self.session_sec.send_expect("set fwd txonly", "testpmd>") + self.session_sec.send_expect("start", "testpmd>", 2) + + xstats, pkts_content=3D self.show_xstats() + self.verify("L2_ETHER L3_IPV4 L4_UDP" in pkts_content, "The receiv= ed packets are encrypted") + self.verify(xstats.get('in_octets_decrypted') =3D=3D 0 and xstats.= get('out_pkts_encrypted') =3D=3D 0, + "Error:in_octets_decrypted and out_pkts_encrypted=20 + increase") + + def test_MACsec_tx_and_rx_with_wrong_param(self): + """ + MACsec packets send and receive with wrong parameters + """ + # rx side + self.start_testpmd_rx() + self.rx_set_macsec_offload('on', 'on') + # tx side + self.start_testpmd_tx() + self.tx_set_macsec_offload('on', 'on') + + # subcase1:set different pn on rx and tx port + self.rx_set_macsec_various_param(0, 0, 0, 2, '00112200000000000000= 000000000000') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('out_pkts_encrypted') =3D=3D xstats.get('in= _pkts_ok') + xstats.get('in_pkts_late') + and xstats.get('out_octets_encrypted') =3D=3D xstats.g= et('in_octets_decrypted'), "subcase1:failed") + self.clear_port_xstats() + # Rx port can receive the packets until the pn equals the pn of tx= port + self.rx_set_macsec_various_param(0, 0, 0, 2, '00112200000000000000= 000000000000') + self.tx_set_macsec_various_param(0, 0, 0, 2, '00112200000000000000= 000000000000') + self.check_MACsec_pkts_receive() + self.clear_port_xstats() + + # subcase2:set different keys on rx and tx port + self.rx_set_macsec_various_param(0, 0, 0, 0, '00000000000000000000= 000000000000') + self.tx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('in_pkts_ok') =3D=3D 0 + and xstats.get('out_pkts_encrypted') =3D=3D xstats.get= ('in_pkts_notvalid') + and xstats.get('out_octets_encrypted') =3D=3D xstats.g= et('in_octets_decrypted'), "subcase2:failed") + pkt_num =3D self.packets_receive_num() + self.verify(int(pkt_num[0]) =3D=3D 0, "Rx port can't receive pkts"= ) + self.clear_port_xstats() + + # subcase3:set different pi on rx and tx port + self.rx_set_macsec_various_param(1, 0, 0, 0, '01122000000000000000= 00000000000') + self.tx_set_macsec_various_param(0, 0, 0, 0, '01122000000000000000= 00000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('in_pkts_ok') =3D=3D 0 and xstats.get('out_= pkts_encrypted') =3D=3D xstats.get('in_pkts_nosci') + and xstats.get('out_octets_encrypted') =3D=3D xstats.g= et('in_octets_decrypted'), "subcase3:failed") + self.clear_port_xstats() + + # subcase4:set different an on rx and tx port + self.rx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.tx_set_macsec_various_param(0, 0, 1, 0, '00112200000000000000= 000000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('in_pkts_ok') =3D=3D 0 and xstats.get('out_= pkts_encrypted') =3D=3D xstats.get('in_pkts_notusingsa') + and xstats.get('out_octets_encrypted') =3D=3D xstats.g= et('in_octets_decrypted'), "subcase4:failed") + self.clear_port_xstats() + + # subcase5:set different index on rx and tx port + self.rx_set_macsec_various_param(0, 0, 0, 0, '00112200000000000000= 000000000000') + self.tx_set_macsec_various_param(0, 1, 0, 0, '00112200000000000000= 000000000000') + xstats =3D self.show_xstats() + self.verify(xstats.get('out_pkts_encrypted') =3D=3D xstats.get('in= _pkts_ok') + and xstats.get('out_octets_encrypted') =3D=3D=20 + xstats.get('in_octets_decrypted'), "subcase5:failed") + + def test_packet_length(self): + """ + On IXIA side, start IXIA port6 transmit, start the IXIA capture. + View the IXIA port5 captured packet, the protocol is MACsec, the E= therType + is 0x88E5, and the packet length is 96bytes, while the normal pack= et length + is 64bytes. + """ + self.tester_itf_0 =3D self.tester.get_interface(self.dut_ports[0]) + self.tester_itf_1 =3D self.tester.get_interface(self.dut_ports[1]) + self.start_testpmd_perf() + # start tcpdump + self.tester.send_expect("rm -rf ./tcpdump_test.cap", "#") + self.tester.send_expect("tcpdump -i %s ether src %s -w ./tcpdump_t= est.cap 2> /dev/null& " % (self.tester_itf_0, self.mac0), "#") + p =3D Packet() + pkt =3D 'Ether(dst=3D"%s", src=3D"02:00:00:00:00:01")/IP()/UDP()/(= "X"*22)' % self.mac1 + p.append_pkt(pkt) + p.send_pkt(self.tester, tx_port=3Dself.tester_itf_1, count=3D10, t= imeout=3D3) + # get tcpdump package + self.tester.send_expect("killall tcpdump", "#") + out =3D self.tester.send_expect("tcpdump -nn -e -v -r ./tcpdump_te= st.cap", "#", 120) + self.verify("length 96" in out and "0x88e5" in out, "the=20 + EtherType isn't 0x88E5, and the packet length isn't 96bytes") + + def test_perf_Tx_linerate(self): + """ + performance test + """ + self.table_header =3D ['Frame Size', 'Mpps', '% linerate'] + self.result_table_create(self.table_header) + txPort =3D self.tester.get_local_port(self.dut_ports[1]) + rxPort =3D self.tester.get_local_port(self.dut_ports[0]) + self.start_testpmd_perf() + # prepare traffic generator input + flow =3D 'Ether(dst=3D"%s", src=3D"02:00:00:00:00:01")/IP()/UDP()/= ("X"*22)' % self.mac1 + pcap =3D os.sep.join([self.output_path, "test.pcap"]) + self.tester.scapy_append('wrpcap("%s", [%s])' % (pcap, flow)) + self.tester.scapy_execute() + tgenInput =3D [] + pcap =3D os.sep.join([self.output_path, "test.pcap"]) + tgenInput.append((txPort, rxPort, pcap)) + + # clear streams before add new streams + self.tester.pktgen.clear_streams() + # run packet generator + streams =3D self.pktgen_helper.prepare_stream_from_tginput(tgenInp= ut, 100, None, self.tester.pktgen) + _, pps =3D self.tester.pktgen.measure_throughput(stream_ids=3Dstre= ams) + self.verify(pps > 0, "No traffic detected") + pps /=3D 1000000.0 + rate =3D (pps * 100) / self.wirespeed(self.nic, 96, 1) + self.result_table_add([96, pps, rate]) + self.result_table_print() + self.verify(rate >=3D 96, "performance test failed") + + def tear_down(self): + """ + Run after each test case. + """ + self.session_sec.send_expect("quit", "#") + self.dut.send_expect("quit", "#") + + def tear_down_all(self): + """ + Run after each test suite. + """ + self.dut.kill_all() + self.dut.close_session(self.session_sec) -- 2.17.2