test suite reviews and discussions
 help / color / Atom feed
From: yufengmx <yufengx.mo@intel.com>
To: dts@dpdk.org, yinan.wang@intel.com
Cc: yufengmx <yufengx.mo@intel.com>
Subject: [dts] [PATCH V2 3/5] framework/pktgen_base: measure throughput supports multiple
Date: Fri, 22 Nov 2019 16:58:41 +0800
Message-ID: <20191122085843.97671-4-yufengx.mo@intel.com> (raw)
In-Reply-To: <20191122085843.97671-1-yufengx.mo@intel.com>

 return values

*. add test method(latency/loss/throughput) delay/duration options new usage
   definition and relevant process source code.
*. set delay option to be the warm up time after start transmission.
*. add __get_single_throughput_statistic/__get_multi_throughput_statistic methods to realize
   measure_throughput support return several throughput numbers in a duration.
*. set duration option default value to 10 second.
*. add test method(latency/loss/throughput/rfc2544) options parameter usage comment,
   which is the same as doc pktgen_prog_guide.rst.
*. add a callback to deal with executing other tools query actions in throughput traffic lasting status.

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

diff --git a/framework/pktgen_base.py b/framework/pktgen_base.py
index 7855f6f..26f2f1a 100644
--- a/framework/pktgen_base.py
+++ b/framework/pktgen_base.py
@@ -157,39 +157,119 @@ class PacketGenerator(object):
     def reset_streams(self):
         self.__streams = []
 
-    def measure_throughput(self, stream_ids=[], options={}):
-        """
-        Measure throughput on each tx ports
-        """
-        bps_rx = []
-        pps_rx = []
-        self._prepare_transmission(stream_ids=stream_ids)
+    def __warm_up_pktgen(self, stream_ids, options, delay):
+        ''' run warm up traffic before start main traffic '''
+        if not delay:
+            return
+        msg = '{1} packet generator: run traffic {0}s to warm up ... '.format(
+            delay, self.pktgen_type)
+        self.logger.info(msg)
         self._start_transmission(stream_ids, options)
-
-        delay = options.get('delay') or 5
         time.sleep(delay)
+        self._stop_transmission(stream_ids)
+
+    def __get_single_throughput_statistic(self, stream_ids):
+        bps_rx = []
+        pps_rx = []
         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(
-                                                        stream_id, 'throughput')
+                    stream_id, 'throughput')
                 used_rx_port.append(self.__streams[stream_id]['rx_port'])
                 bps_rx.append(rxbps_rates)
                 pps_rx.append(rxpps_rates)
-        self._stop_transmission(stream_id)
-
         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))
+        self.logger.info(
+            "throughput: pps_rx %f, bps_rx %f" % (pps_rx_total, bps_rx_total))
 
         return bps_rx_total, pps_rx_total
 
+    def __get_multi_throughput_statistic(
+            self, stream_ids, duration, interval, callback=None):
+        """
+        duration: traffic duration (second)
+        interval: interval of get throughput statistics (second)
+        callback: a callback method of suite, which is used to do some actions
+            during traffic lasting.
+
+        Return: a list of throughput instead of a single tuple of pps/bps rate
+        """
+        time_elapsed = 0
+        stats = []
+        while time_elapsed < duration:
+            time.sleep(interval)
+            stats.append(self.__get_single_throughput_statistic(stream_ids))
+            if callback and callable(callback):
+                callback()
+            time_elapsed += interval
+        return stats
+
+    def measure_throughput(self, stream_ids=[], options={}):
+        """
+        Measure throughput on each tx ports
+
+        options usage:
+            rate:
+                port rate percent, float(0--100). Default value is 100.
+
+            delay:
+                warm up time before start main traffic. If it is set, it will start
+                a delay time traffic to make sure packet generator under good status.
+                Warm up flow is ignored by default.
+
+            interval:
+                a interval time of get throughput statistic (second)
+                If set this key value, pktgen will return several throughput statistic
+                data within a duration traffic. If not set this key value, only
+                return one statistic data. It is ignored by default.
+                
+            callback:
+                this key works with ``interval`` key. If it is set, the callback
+                of suite level will be executed after getting throughput statistic.
+                callback method should define as below, don't add sleep in this method.
+
+                def callback(self):
+                    xxxx()
+
+            duration:
+                traffic lasting time(second). Default value is 10 second.
+        """
+        interval = options.get('interval')
+        callback = options.get('callback')
+        duration = options.get('duration') or 10
+        delay = options.get('delay')
+        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)
+        # 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)
+        else:
+            time.sleep(duration)
+            stats = self.__get_single_throughput_statistic(stream_ids)
+        self._stop_transmission(stream_ids)
+        return stats
+
     def _measure_loss(self, stream_ids=[], options={}):
         """
         Measure lost rate on each tx/rx ports
         """
+        delay = options.get('delay')
+        duration = options.get('duration') or 10
         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, options)
+        # keep traffic within a duration time
+        time.sleep(duration)
         self._stop_transmission(None)
         result = {}
         used_rx_port = []
@@ -210,6 +290,19 @@ class PacketGenerator(object):
         return result
 
     def measure_loss(self, stream_ids=[], options={}):
+        '''
+        options usage:
+            rate:
+                port rate percent, float(0--100). Default value is 100.
+
+            delay:
+                warm up time before start main traffic. If it is set, it will
+                start a delay time traffic to make sure packet generator
+                under good status. Warm up flow is ignored by default.
+
+            duration:
+                traffic lasting time(second). Default value is 10 second.
+        '''
         result = self._measure_loss(stream_ids, options)
         # here only to make sure that return value is the same as dts/etgen format
         # In real testing scenario, this method can offer more data than it
@@ -218,9 +311,28 @@ class PacketGenerator(object):
     def measure_latency(self, stream_ids=[], options={}):
         """
         Measure latency on each tx/rx ports
+
+        options usage:
+            rate:
+                port rate percent, float(0--100). Default value is 100.
+
+            delay:
+                warm up time before start main traffic. If it is set, it will
+                start a delay time transmission to make sure packet generator
+                under correct status. Warm up flow is ignored by default.
+
+            duration:
+                traffic lasting time(second). Default value is 10 second.
         """
+        delay = options.get('delay')
+        duration = options.get('duration') or 10
         self._prepare_transmission(stream_ids=stream_ids, latency=True)
+        # start warm up traffic
+        self.__warm_up_pktgen(stream_ids, options, delay)
+        # main traffic
         self._start_transmission(stream_ids, options)
+        # keep traffic within a duration time
+        time.sleep(duration)
         self._stop_transmission(None)
 
         result = {}
@@ -248,7 +360,26 @@ 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:
+                port rate percent at first round testing(0 ~ 100), default is 100.
+
+            pdr:
+                permit packet drop rate, , default is 0.
+
+            drop_step:
+                port rate percent drop step(0 ~ 100), default is 1.
+
+            delay:
+                warm up time before start main traffic. If it is set, it will
+                start a delay time traffic to make sure packet generator
+                under good status. Warm up flow is ignored by default.
+
+            duration:
+                traffic lasting time(second). Default value is 10 second.
+        """
         loss_rate_table = []
         rate_percent = options.get('rate') or float(100)
         permit_loss_rate = options.get('pdr') or 0
@@ -265,6 +396,9 @@ class PacketGenerator(object):
             tx_num, rx_num = result.values()[0][1:]
             return rate_percent, tx_num, rx_num
         _options = deepcopy(options)
+        # if warm up option  'delay' is set, ignore it in next work flow
+        if 'delay' in _options:
+            _options.pop('delay')
         if 'rate' in _options:
             _options.pop('rate')
         while not status and rate_percent > 0:
-- 
2.21.0


  parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  8:58 [dts] [PATCH V2 0/5] dts/pktgen: measure throughput supports multiple return values and callback yufengmx
2019-11-22  8:58 ` [dts] [PATCH V2 1/5] conf/pktgen: remove un-used optons yufengmx
2019-11-22  8:58 ` [dts] [PATCH V2 2/5] doc/dts_gsg/pktgen_prog_guide: update description yufengmx
2019-11-22  8:58 ` yufengmx [this message]
2019-11-22  8:58 ` [dts] [PATCH V2 4/5] framework/pktgen_ixia: measure throughput supports multiple yufengmx
2019-11-22  8:58 ` [dts] [PATCH V2 5/5] framework/pktgen_trex: " yufengmx

Reply instructions:

You may reply publically 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=20191122085843.97671-4-yufengx.mo@intel.com \
    --to=yufengx.mo@intel.com \
    --cc=dts@dpdk.org \
    --cc=yinan.wang@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

test suite reviews and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dts/0 dts/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dts dts/ http://inbox.dpdk.org/dts \
		dts@dpdk.org
	public-inbox-index dts


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dts


AGPL code for this site: git clone https://public-inbox.org/ public-inbox