test suite reviews and discussions
 help / color / mirror / Atom feed
From: yufengmx <yufengx.mo@intel.com>
To: dts@dpdk.org, lijuan.tu@intel.com
Cc: yufengmx <yufengx.mo@intel.com>
Subject: [dts] [PATCH V1 02/27] framework/pktgen: return throughput tx stats
Date: Mon, 25 Jan 2021 16:43:49 +0800	[thread overview]
Message-ID: <20210125084414.8503-3-yufengx.mo@intel.com> (raw)
In-Reply-To: <20210125084414.8503-1-yufengx.mo@intel.com>


support return tx_pps and tx_bps from pktgen.measure_throughput for trex.

Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
 framework/pktgen_base.py | 77 ++++++++++++++++++++++++++++++----------
 1 file changed, 59 insertions(+), 18 deletions(-)

diff --git a/framework/pktgen_base.py b/framework/pktgen_base.py
index 8003e01c..81c8830c 100644
--- a/framework/pktgen_base.py
+++ b/framework/pktgen_base.py
@@ -1,6 +1,6 @@
 # BSD LICENSE
 #
-# Copyright(c) 2010-2019 Intel Corporation. All rights reserved.
+# Copyright(c) 2010-2021 Intel Corporation. All rights reserved.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@ from abc import abstractmethod
 from copy import deepcopy
 from logger import getLogger
 from pprint import pformat
+from enum import Enum, unique
 
 from config import PktgenConf
 # packet generator name
@@ -46,6 +47,12 @@ TRANSMIT_M_BURST = 'multi_burst'
 TRANSMIT_S_BURST = 'single_burst'
 
 
+@unique
+class STAT_TYPE(Enum):
+    RX = 'rx'
+    TXRX = 'txrx'
+
+
 class PacketGenerator(object):
     """
     Basic class for packet generator, define basic function for each kinds of
@@ -106,8 +113,8 @@ class PacketGenerator(object):
         return port
 
     def add_stream(self, tx_port, rx_port, pcap_file):
-        pktgen_tx_port  = self._convert_tester_port(tx_port)
-        pktgen_rx_port  = self._convert_tester_port(rx_port)
+        pktgen_tx_port = self._convert_tester_port(tx_port)
+        pktgen_rx_port = self._convert_tester_port(rx_port)
 
         stream_id = len(self.__streams)
         stream = {'tx_port': pktgen_tx_port,
@@ -168,28 +175,50 @@ class PacketGenerator(object):
         time.sleep(delay)
         self._stop_transmission(stream_ids)
 
-    def __get_single_throughput_statistic(self, stream_ids):
+    def __get_single_throughput_statistic(self, stream_ids, stat_type=None):
         bps_rx = []
         pps_rx = []
+        bps_tx = []
+        pps_tx = []
         used_rx_port = []
         msg = 'begin get port statistic ...'
         self.logger.info(msg)
         for stream_id in stream_ids:
             if self.__streams[stream_id]['rx_port'] not in used_rx_port:
-                rxbps_rates, rxpps_rates = self._retrieve_port_statistic(
+                bps_rate, pps_rate = self._retrieve_port_statistic(
                     stream_id, 'throughput')
                 used_rx_port.append(self.__streams[stream_id]['rx_port'])
-                bps_rx.append(rxbps_rates)
-                pps_rx.append(rxpps_rates)
-        bps_rx_total = self._summary_statistic(bps_rx)
-        pps_rx_total = self._summary_statistic(pps_rx)
-        self.logger.info(
-            "throughput: pps_rx %f, bps_rx %f" % (pps_rx_total, bps_rx_total))
+                if stat_type and stat_type is STAT_TYPE.TXRX:
+                    bps_tx.append(bps_rate[0])
+                    pps_tx.append(pps_rate[0])
+
+                if isinstance(bps_rate, tuple) and isinstance(pps_rate, tuple):
+                    bps_rx.append(bps_rate[1])
+                    pps_rx.append(pps_rate[1])
+                else:
+                    bps_rx.append(bps_rate)
+                    pps_rx.append(pps_rate)
+        if stat_type and stat_type is STAT_TYPE.TXRX:
+            bps_tx_total = self._summary_statistic(bps_tx)
+            pps_tx_total = self._summary_statistic(pps_tx)
+            bps_rx_total = self._summary_statistic(bps_rx)
+            pps_rx_total = self._summary_statistic(pps_rx)
+            self.logger.info(
+                "throughput: pps_tx %f, bps_tx %f" % (pps_tx_total, bps_tx_total))
+            self.logger.info(
+                "throughput: pps_rx %f, bps_rx %f" % (pps_rx_total, bps_rx_total))
+
+            return (bps_tx_total, bps_rx_total), (pps_tx_total, pps_rx_total)
+        else:
+            bps_rx_total = self._summary_statistic(bps_rx)
+            pps_rx_total = self._summary_statistic(pps_rx)
+            self.logger.info(
+                "throughput: pps_rx %f, bps_rx %f" % (pps_rx_total, bps_rx_total))
 
-        return bps_rx_total, pps_rx_total
+            return bps_rx_total, pps_rx_total
 
     def __get_multi_throughput_statistic(
-            self, stream_ids, duration, interval, callback=None):
+            self, stream_ids, duration, interval, callback=None, stat_type=None):
         """
         duration: traffic duration (second)
         interval: interval of get throughput statistics (second)
@@ -202,7 +231,7 @@ class PacketGenerator(object):
         stats = []
         while time_elapsed < duration:
             time.sleep(interval)
-            stats.append(self.__get_single_throughput_statistic(stream_ids))
+            stats.append(self.__get_single_throughput_statistic(stream_ids, stat_type))
             if callback and callable(callback):
                 callback()
             time_elapsed += interval
@@ -237,23 +266,35 @@ class PacketGenerator(object):
 
             duration:
                 traffic lasting time(second). Default value is 10 second.
+
+            stat_type(for trex only):
+                STAT_TYPE.RX  return (rx bps, rx_pps)
+                STAT_TYPE.TXRX return ((tx bps, rx_bps), (tx pps, rx_pps))
         """
         interval = options.get('interval')
         callback = options.get('callback')
         duration = options.get('duration') or 10
         delay = options.get('delay')
+        if self.pktgen_type == PKTGEN_TREX:
+            stat_type = options.get('stat_type') or STAT_TYPE.RX
+        else:
+            if options.get('stat_type') is not None:
+                msg = ("'stat_type' option is only for trex, "
+                       "should not set when use other pktgen tools")
+                raise Exception(msg)
+            stat_type = STAT_TYPE.RX
         self._prepare_transmission(stream_ids=stream_ids)
         # start warm up traffic
         self.__warm_up_pktgen(stream_ids, options, delay)
         # main traffic
-        self._start_transmission(stream_ids)
+        self._start_transmission(stream_ids, options)
         # keep traffic within a duration time and get throughput statistic
         if interval and duration:
             stats = self.__get_multi_throughput_statistic(
-                stream_ids, duration, interval, callback)
+                stream_ids, duration, interval, callback, stat_type)
         else:
             time.sleep(duration)
-            stats = self.__get_single_throughput_statistic(stream_ids)
+            stats = self.__get_single_throughput_statistic(stream_ids, stat_type)
         self._stop_transmission(stream_ids)
         return stats
 
@@ -366,7 +407,7 @@ class PacketGenerator(object):
             return True
 
     def measure_rfc2544(self, stream_ids=[], options={}):
-        """ check loss rate with rate percent dropping 
+        """ check loss rate with rate percent dropping
 
         options usage:
             rate:
-- 
2.21.0


  parent reply	other threads:[~2021-01-25  8:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25  8:43 [dts] [PATCH V1 00/27] dts: enable IxNetwork and enhance perf testing yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 01/27] framework/pktgen: return trex tx stats yufengmx
2021-01-25  8:43 ` yufengmx [this message]
2021-01-25  8:43 ` [dts] [PATCH V1 03/27] framework/pktgen: return throughput " yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 04/27] conf/pktgen: enable ixNetwork yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 05/27] " yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 06/27] conf/l3fwd: add packet types comment yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 07/27] conf/testpmd: testpmd perf config yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 08/27] framework/pktgen: enable ixNetwork yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 09/27] " yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 10/27] " yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 11/27] " yufengmx
2021-01-25  8:43 ` [dts] [PATCH V1 12/27] " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 13/27] conf/pktgen: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 14/27] framework/pktgen: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 15/27] " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 16/27] " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 17/27] " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 18/27] tests/perf_test: rename l3fwd_base module yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 19/27] tests/perf_test: cover testpmd testing scenario yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 20/27] tests/perf_test: save rfc2544 expected throughput yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 21/27] tests/l3fwd_em: update script yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 22/27] tests/lpm_ipv4_rfc2544: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 23/27] tests/l3fwd_lpm_ipv4: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 24/27] tests/l3fwd_lpm_ipv6: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 25/27] tests/l3fwd: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 26/27] tests/vf_l3fwd_kernelpf: " yufengmx
2021-01-25  8:44 ` [dts] [PATCH V1 27/27] tests/testpmd_perf: upload script yufengmx
2021-02-19  7:02 ` [dts] [PATCH V1 00/27] dts: enable IxNetwork and enhance perf testing Tu, Lijuan

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=20210125084414.8503-3-yufengx.mo@intel.com \
    --to=yufengx.mo@intel.com \
    --cc=dts@dpdk.org \
    --cc=lijuan.tu@intel.com \
    /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).