test suite reviews and discussions
 help / color / mirror / Atom feed
From: yufengmx <yufengx.mo@intel.com>
To: dts@dpdk.org
Cc: yufengmx <yufengx.mo@intel.com>
Subject: [dts] [PATCH V1 9/10] [next]framework/pktgen: add new feature and fix internal
Date: Mon,  5 Aug 2019 13:50:43 +0800	[thread overview]
Message-ID: <1564984244-151448-10-git-send-email-yufengx.mo@intel.com> (raw)
In-Reply-To: <1564984244-151448-1-git-send-email-yufengx.mo@intel.com>

 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 <yufengx.mo@intel.com>
---
 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


  parent reply	other threads:[~2019-08-05  5:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-05  5:50 [dts] [PATCH V1 0/10] [next]dts/pktgen: add new feature and fix some internal bugs yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 1/10] [next]conf/pktgen: update option description yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 2/10] [next]doc/dts_gsg/pktgen_prog_guide: update description yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 3/10] [next]framework/logger: add pktgen logger and remove yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 4/10] [next]framework/dut: fix logger quit issue yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 5/10] [next]framework/tester: " yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 6/10] [next]framework/pktgen_base: add new feature and fix yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 7/10] [next]framework/pktgen_ixia: " yufengmx
2019-08-05  5:50 ` [dts] [PATCH V1 8/10] [next]framework/pktgen_trex: " yufengmx
2019-08-05  5:50 ` yufengmx [this message]
2019-08-05  5:50 ` [dts] [PATCH V1 0/10] [next]tests/nic_single_core_perf: update pktgen input yufengmx

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1564984244-151448-10-git-send-email-yufengx.mo@intel.com \
    --to=yufengx.mo@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).