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 50A75A0613 for ; Mon, 5 Aug 2019 07:50:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 48BA41BE47; Mon, 5 Aug 2019 07:50:00 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id E87341BE6B for ; Mon, 5 Aug 2019 07:49:58 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2019 22:49:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,348,1559545200"; d="scan'208";a="372969534" Received: from dpdk-moyufen01.sh.intel.com ([10.67.111.77]) by fmsmga005.fm.intel.com with ESMTP; 04 Aug 2019 22:49:57 -0700 From: yufengmx To: dts@dpdk.org Cc: yufengmx Date: Mon, 5 Aug 2019 13:50:43 +0800 Message-Id: <1564984244-151448-10-git-send-email-yufengx.mo@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1564984244-151448-1-git-send-email-yufengx.mo@intel.com> References: <1564984244-151448-1-git-send-email-yufengx.mo@intel.com> Subject: [dts] [PATCH V1 9/10] [next]framework/pktgen: add new feature and fix internal 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" bug *. add missing stream rate option in prepare_stream_from_tginput method. *. remove un-used libs import. *. remove set dts libs directory in system path. *. fix pep8 issue. Signed-off-by: yufengmx --- framework/pktgen.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/framework/pktgen.py b/framework/pktgen.py index 1c8acac..8132fe5 100644 --- a/framework/pktgen.py +++ b/framework/pktgen.py @@ -29,7 +29,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import os, sys +import os from copy import deepcopy from scapy.all import conf @@ -38,13 +38,6 @@ from scapy.packet import Packet as scapyPacket from scapy.fields import ConditionalField from scapy.utils import rdpcap -# import dts libs -cwd = os.getcwd() -sys.path.append(cwd + '/nics') -sys.path.append(cwd + '/framework') -sys.path.append(cwd + '/tests') -sys.path.append(cwd + '/dep') - # dts libs from utils import (convert_int2ip, convert_ip2int, convert_mac2long, convert_mac2str) @@ -59,13 +52,13 @@ from pktgen_trex import TrexPacketGenerator class PacketGeneratorHelper(object): ''' default packet generator stream option for all streams ''' default_opt = { - 'stream_config':{ - 'txmode' : {}, + 'stream_config': { + 'txmode': {}, 'transmit_mode': TRANSMIT_CONT, # for temporary usage because current pktgen design don't support # port level configuration, here using stream configuration to pass # rate percent - 'rate': 100,}} + 'rate': 100, }} def __init__(self): self.packetLayers = dict() @@ -78,7 +71,7 @@ class PacketGeneratorHelper(object): self.packetLayers[pkt_object.name] = dict() for curfield in pkt_object.fields_desc: if isinstance(curfield, ConditionalField) and \ - not curfield._evalcond(pkt_object): + not curfield._evalcond(pkt_object): continue field_value = pkt_object.getfieldval(curfield.name) if isinstance(field_value, scapyPacket) or (curfield.islist and \ @@ -87,7 +80,7 @@ class PacketGeneratorHelper(object): repr_value = curfield.i2repr(pkt_object, field_value) if isinstance(repr_value, str): repr_value = repr_value.replace(os.linesep, - os.linesep + " "*(len(curfield.name) +4)) + os.linesep + " " * (len(curfield.name) + 4)) self.packetLayers[pkt_object.name][curfield.name] = repr_value if isinstance(pkt_object.payload, NoPayload): @@ -107,7 +100,7 @@ class PacketGeneratorHelper(object): if len(pcap_pkts) == 0: warning = "{0} is empty".format(pcapFile) raise Exception(warning) - elif number>= len(pcap_pkts): + elif number >= len(pcap_pkts): warning = "{0} is missing No.{1} packet".format(pcapFile, number) raise Exception(warning) else: @@ -136,7 +129,8 @@ class PacketGeneratorHelper(object): range = config.get('range') or 64 step = config.get('step') or 1 start_mac = pcap_fields.get(name) - end_mac = convert_mac2str(convert_mac2long(start_mac) + range-1) + end_mac = convert_mac2str( + convert_mac2long(start_mac) + range - 1) fields_config[layer_name][name] = {} fields_config[layer_name][name]['start'] = start_mac fields_config[layer_name][name]['end'] = end_mac @@ -193,6 +187,7 @@ class PacketGeneratorHelper(object): stream_id = pktgen_inst.add_stream(*config) pcap = config[2] _options = deepcopy(self.default_opt) + _options['stream_config']['rate'] = ratePercent _options['pcap'] = pcap # if vm is set if vm_config: @@ -202,6 +197,7 @@ class PacketGeneratorHelper(object): stream_ids.append(stream_id) return stream_ids + def getPacketGenerator(tester, pktgen_type=PKTGEN_IXIA): """ Get packet generator object @@ -211,11 +207,11 @@ def getPacketGenerator(tester, pktgen_type=PKTGEN_IXIA): pktgen_cls = { PKTGEN_DPDK: DpdkPacketGenerator, PKTGEN_IXIA: IxiaPacketGenerator, - PKTGEN_TREX: TrexPacketGenerator,} + PKTGEN_TREX: TrexPacketGenerator, } if pktgen_type in pktgen_cls.keys(): CLS = pktgen_cls.get(pktgen_type) return CLS(tester) else: msg = "not support <{0}> packet generator".format(pktgen_type) - raise Exception(msg) \ No newline at end of file + raise Exception(msg) -- 1.9.3