summaryrefslogtreecommitdiffstats
path: root/nfvbench
diff options
context:
space:
mode:
authorahothan <ahothan@cisco.com>2017-12-21 17:17:46 -0800
committerahothan <ahothan@cisco.com>2017-12-21 17:17:46 -0800
commitefc678c9d3843dcfd373b5749a88c51228b0b27c (patch)
tree9eb405d22720aa4332de10a525cfe10c1124724d /nfvbench
parenta3c54b7fdce6084d6f64aa3cc23740381286a8ff (diff)
[NFVBENCH-59] Add Unit Testing of the NDR/PDR convergence algorithm using the dummy traffic gen
[NFVBENCH-60] Fix pylint warnings Change-Id: I72deec060bf25774d1be33eaeefc74b42a576483 Signed-off-by: ahothan <ahothan@cisco.com>
Diffstat (limited to 'nfvbench')
-rw-r--r--nfvbench/chain_clients.py7
-rw-r--r--nfvbench/chain_managers.py2
-rw-r--r--nfvbench/compute.py17
-rw-r--r--nfvbench/config.py2
-rw-r--r--nfvbench/nfvbench.py4
-rw-r--r--nfvbench/summarizer.py3
-rw-r--r--nfvbench/traffic_client.py21
-rw-r--r--nfvbench/traffic_gen/dummy.py98
-rw-r--r--nfvbench/traffic_gen/traffic_utils.py32
-rw-r--r--nfvbench/utils.py2
10 files changed, 152 insertions, 36 deletions
diff --git a/nfvbench/chain_clients.py b/nfvbench/chain_clients.py
index 57b15ee..fa21359 100644
--- a/nfvbench/chain_clients.py
+++ b/nfvbench/chain_clients.py
@@ -18,13 +18,12 @@ import os
import re
import time
-import compute
-from log import LOG
-
from glanceclient.v2 import client as glanceclient
from neutronclient.neutron import client as neutronclient
from novaclient.client import Client
+import compute
+from log import LOG
class StageClientException(Exception):
pass
@@ -109,7 +108,7 @@ class BasicStageClient(object):
phys1=network['provider:physical_network'],
phys2=physical_network))
- LOG.info('Reusing existing network: ' + name)
+ LOG.info('Reusing existing network: %s', name)
network['is_reuse'] = True
return network
diff --git a/nfvbench/chain_managers.py b/nfvbench/chain_managers.py
index cbc53e2..8b605aa 100644
--- a/nfvbench/chain_managers.py
+++ b/nfvbench/chain_managers.py
@@ -111,7 +111,7 @@ class StatsManager(object):
def _generate_traffic(self):
if self.config.no_traffic:
- return
+ return {}
self.interval_collector = IntervalCollector(time.time())
self.interval_collector.attach_notifier(self.notifier)
diff --git a/nfvbench/compute.py b/nfvbench/compute.py
index 575744c..af1a0d6 100644
--- a/nfvbench/compute.py
+++ b/nfvbench/compute.py
@@ -16,16 +16,15 @@ import os
import time
import traceback
-import keystoneauth1
-from log import LOG
-import novaclient
-
from glanceclient import exc as glance_exception
-
try:
from glanceclient.openstack.common.apiclient.exceptions import NotFound as GlanceImageNotFound
except ImportError:
from glanceclient.v1.apiclient.exceptions import NotFound as GlanceImageNotFound
+import keystoneauth1
+import novaclient
+
+from log import LOG
class Compute(object):
@@ -75,7 +74,7 @@ class Compute(object):
"image at the specified location %s is correct.", image_file)
return False
except keystoneauth1.exceptions.http.NotFound as exc:
- LOG.error("Authentication error while uploading the image:" + str(exc))
+ LOG.error("Authentication error while uploading the image: %s", str(exc))
return False
except Exception:
LOG.error(traceback.format_exc())
@@ -258,7 +257,7 @@ class Compute(object):
if hyp.host == host:
return self.normalize_az_host(hyp.zone, host)
# no match on host
- LOG.error('Passed host name does not exist: ' + host)
+ LOG.error('Passed host name does not exist: %s', host)
return None
if self.config.availability_zone:
return self.normalize_az_host(None, host)
@@ -290,7 +289,7 @@ class Compute(object):
return az_host
# else continue - another zone with same host name?
# no match
- LOG.error('No match for availability zone and host ' + az_host)
+ LOG.error('No match for availability zone and host %s', az_host)
return None
else:
return self.auto_fill_az(host_list, az_host)
@@ -348,7 +347,7 @@ class Compute(object):
if not self.config.availability_zone:
LOG.error('Availability_zone must be configured')
elif host_list:
- LOG.error('No host matching the selection for availability zone: ' +
+ LOG.error('No host matching the selection for availability zone: %s',
self.config.availability_zone)
avail_list = []
else:
diff --git a/nfvbench/config.py b/nfvbench/config.py
index 8139389..5feeda5 100644
--- a/nfvbench/config.py
+++ b/nfvbench/config.py
@@ -14,9 +14,9 @@
#
from attrdict import AttrDict
-from log import LOG
import yaml
+from log import LOG
def config_load(file_name, from_cfg=None, whitelist_keys=None):
"""Load a yaml file into a config dict, merge with from_cfg if not None
diff --git a/nfvbench/nfvbench.py b/nfvbench/nfvbench.py
index 4c9f56c..6f59e24 100644
--- a/nfvbench/nfvbench.py
+++ b/nfvbench/nfvbench.py
@@ -481,11 +481,11 @@ def main():
# override default config options with start config at path parsed from CLI
# check if it is an inline yaml/json config or a file name
if os.path.isfile(opts.config):
- LOG.info('Loading configuration file: ' + opts.config)
+ LOG.info('Loading configuration file: %s', opts.config)
config = config_load(opts.config, config, whitelist_keys)
config.name = os.path.basename(opts.config)
else:
- LOG.info('Loading configuration string: ' + opts.config)
+ LOG.info('Loading configuration string: %s', opts.config)
config = config_loads(opts.config, config, whitelist_keys)
# traffic profile override options
diff --git a/nfvbench/summarizer.py b/nfvbench/summarizer.py
index 70ad389..1676e93 100644
--- a/nfvbench/summarizer.py
+++ b/nfvbench/summarizer.py
@@ -20,9 +20,10 @@ import math
import bitmath
import pytz
-from specs import ChainType
from tabulate import tabulate
+from specs import ChainType
+
class Formatter(object):
"""Collection of string formatter methods"""
diff --git a/nfvbench/traffic_client.py b/nfvbench/traffic_client.py
index a1c4954..8959cab 100644
--- a/nfvbench/traffic_client.py
+++ b/nfvbench/traffic_client.py
@@ -67,6 +67,9 @@ class TrafficRunner(object):
def poll_stats(self):
if not self.is_running():
return None
+ if self.client.skip_sleep:
+ self.stop()
+ return self.client.get_stats()
time_elapsed = self.time_elapsed()
if time_elapsed > self.duration_sec:
self.stop()
@@ -102,10 +105,10 @@ class IpBlock(object):
'''Reserve a range of count consecutive IP addresses spaced by step
'''
if self.next_free + count > self.max_available:
- raise IndexError('No more IP addresses next free=%d max_available=%d requested=%d',
- self.next_free,
- self.max_available,
- count)
+ raise IndexError('No more IP addresses next free=%d max_available=%d requested=%d' %
+ (self.next_free,
+ self.max_available,
+ count))
first_ip = self.get_ip(self.next_free)
last_ip = self.get_ip(self.next_free + count - 1)
self.next_free += count
@@ -393,7 +396,7 @@ class TrafficGeneratorFactory(object):
class TrafficClient(object):
PORTS = [0, 1]
- def __init__(self, config, notifier=None):
+ def __init__(self, config, notifier=None, skip_sleep=False):
generator_factory = TrafficGeneratorFactory(config)
self.gen = generator_factory.get_generator_client()
self.tool = generator_factory.get_tool()
@@ -414,6 +417,8 @@ class TrafficClient(object):
self.current_total_rate = {'rate_percent': '10'}
if self.config.single_run:
self.current_total_rate = utils.parse_rate_str(self.config.rate)
+ # UT with dummy TG can bypass all sleeps
+ self.skip_sleep = skip_sleep
def set_macs(self):
for mac, device in zip(self.gen.get_macs(), self.config.generator_config.devices):
@@ -461,7 +466,8 @@ class TrafficClient(object):
self.gen.clear_stats()
self.gen.start_traffic()
LOG.info('Waiting for packets to be received back... (%d / %d)', it + 1, retry_count)
- time.sleep(self.config.generic_poll_sec)
+ if not self.skip_sleep:
+ time.sleep(self.config.generic_poll_sec)
self.gen.stop_traffic()
stats = self.gen.get_stats()
@@ -481,7 +487,8 @@ class TrafficClient(object):
LOG.info('End-to-end connectivity ensured')
return
- time.sleep(self.config.generic_poll_sec)
+ if not self.skip_sleep:
+ time.sleep(self.config.generic_poll_sec)
raise TrafficClientException('End-to-end connectivity cannot be ensured')
diff --git a/nfvbench/traffic_gen/dummy.py b/nfvbench/traffic_gen/dummy.py
index d8c01e9..b43030f 100644
--- a/nfvbench/traffic_gen/dummy.py
+++ b/nfvbench/traffic_gen/dummy.py
@@ -13,6 +13,7 @@
# under the License.
from traffic_base import AbstractTrafficGenerator
+import traffic_utils as utils
class DummyTG(AbstractTrafficGenerator):
@@ -22,10 +23,13 @@ class DummyTG(AbstractTrafficGenerator):
Useful for unit testing without actually generating any traffic.
"""
- def __init__(self, runner):
- AbstractTrafficGenerator.__init__(self, runner)
+ def __init__(self, config):
+ AbstractTrafficGenerator.__init__(self, config)
self.port_handle = []
self.rates = []
+ self.l2_frame_size = 0
+ self.duration_sec = self.config.duration_sec
+ self.intf_speed = config.generator_config.intf_speed
def get_version(self):
return "0.1"
@@ -33,6 +37,59 @@ class DummyTG(AbstractTrafficGenerator):
def init(self):
pass
+ def get_tx_pps_dropped_pps(self, tx_rate):
+ '''Get actual tx packets based on requested tx rate
+
+ :param tx_rate: requested TX rate with unit ('40%', '1Mbps', '1000pps')
+
+ :return: the actual TX pps and the dropped pps corresponding to the requested TX rate
+ '''
+ dr, tx = self.__get_dr_actual_tx(tx_rate)
+ actual_tx_bps = utils.load_to_bps(tx, self.intf_speed)
+ avg_packet_size = utils.get_average_packet_size(self.l2_frame_size)
+ tx_packets = utils.bps_to_pps(actual_tx_bps, avg_packet_size)
+
+ dropped = tx_packets * dr / 100
+ # print '===get_tx_pkts_dropped_pkts req tex=', tx_rate, 'dr=', dr,
+ # 'actual tx rate=', tx, 'actual tx pkts=', tx_packets, 'dropped=', dropped
+ return int(tx_packets), int(dropped)
+
+ def set_response_curve(self, lr_dr=0, ndr=100, max_actual_tx=100, max_11_tx=100):
+ '''Set traffic gen response characteristics
+
+ Specifies the drop rate curve and the actual TX curve
+ :param float lr_dr: The actual drop rate at TX line rate (in %, 0..100)
+ :param float ndr: The true NDR (0 packet drop) in % (0..100) of line rate"
+ :param float max_actual_tx: highest actual TX when requested TX is 100%
+ :param float max_11_tx: highest requested TX that results in same actual TX
+ '''
+ self.target_ndr = ndr
+ if ndr < 100:
+ self.dr_slope = float(lr_dr) / (100 - ndr)
+ else:
+ self.dr_slope = 0
+ self.max_11_tx = max_11_tx
+ self.max_actual_tx = max_actual_tx
+ if max_11_tx < 100:
+ self.tx_slope = float(max_actual_tx - max_11_tx) / (100 - max_11_tx)
+ else:
+ self.tx_slope = 0
+
+ def __get_dr_actual_tx(self, requested_tx_rate):
+ '''Get drop rate at given requested tx rate
+ :param float requested_tx_rate: requested tx rate in % (0..100)
+ :return: the drop rate and actual tx rate at that requested_tx_rate in % (0..100)
+ '''
+ if requested_tx_rate <= self.max_11_tx:
+ actual_tx = requested_tx_rate
+ else:
+ actual_tx = self.max_11_tx + (requested_tx_rate - self.max_11_tx) * self.tx_slope
+ if actual_tx <= self.target_ndr:
+ dr = 0.0
+ else:
+ dr = (actual_tx - self.target_ndr) * self.dr_slope
+ return dr, actual_tx
+
def connect(self):
ports = list(self.config.generator_config.ports)
self.port_handle = ports
@@ -44,32 +101,57 @@ class DummyTG(AbstractTrafficGenerator):
pass
def create_traffic(self, l2frame_size, rates, bidirectional, latency=True):
- pass
+ self.rates = [utils.to_rate_str(rate) for rate in rates]
+ self.l2_frame_size = l2frame_size
def clear_streamblock(self):
pass
def get_stats(self):
+ '''Get stats from current run.
+
+ The binary search mainly looks at 2 results to make the decision:
+ actual tx packets
+ actual rx dropped packets
+ From the Requested TX rate - we get the Actual TX rate and the RX drop rate
+ From the Run duration and actual TX rate - we get the actual total tx packets
+ From the Actual tx packets and RX drop rate - we get the RX dropped packets
+ '''
result = {}
- for ph in self.port_handle:
+ total_tx_pps = 0
+
+ # use dummy values for all other result field as the goal is to
+ # test the ndr/pdr convergence code
+ for idx, ph in enumerate(self.port_handle):
+ requested_tx_rate = utils.get_load_from_rate(self.rates[idx])
+ tx_pps, dropped_pps = self.get_tx_pps_dropped_pps(requested_tx_rate)
+
+ # total packets sent per direction - used by binary search
+ total_pkts = tx_pps * self.duration_sec
+ dropped_pkts = dropped_pps * self.duration_sec
+ _, tx_pkt_rate = self.__get_dr_actual_tx(requested_tx_rate)
result[ph] = {
'tx': {
- 'total_pkts': 1000,
+ 'total_pkts': total_pkts,
'total_pkt_bytes': 100000,
- 'pkt_rate': 100,
+ 'pkt_rate': tx_pkt_rate,
'pkt_bit_rate': 1000000
},
'rx': {
- 'total_pkts': 1000,
+ # total packets received
+ 'total_pkts': total_pkts - dropped_pkts,
'total_pkt_bytes': 100000,
'pkt_rate': 100,
'pkt_bit_rate': 1000000,
- 'dropped_pkts': 0
+ 'dropped_pkts': dropped_pkts
}
}
result[ph]['rx']['max_delay_usec'] = 10.0
result[ph]['rx']['min_delay_usec'] = 1.0
result[ph]['rx']['avg_delay_usec'] = 2.0
+ total_tx_pps += tx_pps
+ # actual total tx rate in pps
+ result['total_tx_rate'] = total_tx_pps
return result
def clear_stats(self):
diff --git a/nfvbench/traffic_gen/traffic_utils.py b/nfvbench/traffic_gen/traffic_utils.py
index e618c28..4a7f855 100644
--- a/nfvbench/traffic_gen/traffic_utils.py
+++ b/nfvbench/traffic_gen/traffic_utils.py
@@ -75,6 +75,13 @@ def weighted_avg(weight, count):
return sum([x[0] * x[1] for x in zip(weight, count)]) / sum(weight)
return float('nan')
+def _get_bitmath_rate(rate_bps):
+ rate = rate_bps.replace('ps', '').strip()
+ bitmath_rate = bitmath.parse_string(rate)
+ if bitmath_rate.bits <= 0:
+ raise Exception('%s is out of valid range' % rate_bps)
+ return bitmath_rate
+
def parse_rate_str(rate_str):
if rate_str.endswith('pps'):
rate_pps = rate_str[:-3]
@@ -103,6 +110,26 @@ def parse_rate_str(rate_str):
else:
raise Exception('Unknown rate string format %s' % rate_str)
+def get_load_from_rate(rate_str, avg_frame_size=64, line_rate='10Gbps'):
+ '''From any rate string (with unit) return the corresponding load (in % unit)
+
+ :param str rate_str: the rate to convert - must end with a unit (e.g. 1Mpps, 30%, 1Gbps)
+ :param int avg_frame_size: average frame size in bytes (needed only if pps is given)
+ :param str line_rate: line rate ending with bps unit (e.g. 1Mbps, 10Gbps) is the rate that
+ corresponds to 100% rate
+ :return float: the corresponding rate in % of line rate
+ '''
+ rate_dict = parse_rate_str(rate_str)
+ if 'rate_percent' in rate_dict:
+ return float(rate_dict['rate_percent'])
+ lr_bps = _get_bitmath_rate(line_rate).bits
+ if 'rate_bps' in rate_dict:
+ bps = int(rate_dict['rate_bps'])
+ else:
+ # must be rate_pps
+ pps = rate_dict['rate_pps']
+ bps = pps_to_bps(pps, avg_frame_size)
+ return bps_to_load(bps, lr_bps)
def divide_rate(rate, divisor):
if 'rate_pps' in rate:
@@ -130,8 +157,9 @@ def to_rate_str(rate):
elif 'rate_percent' in rate:
load = rate['rate_percent']
return '{}%'.format(load)
- else:
- assert False
+ assert False
+ # avert pylint warning
+ return None
def nan_replace(d):
diff --git a/nfvbench/utils.py b/nfvbench/utils.py
index 412dfae..20dc588 100644
--- a/nfvbench/utils.py
+++ b/nfvbench/utils.py
@@ -61,7 +61,7 @@ def save_json_result(result, json_file, std_json_path, service_chain, service_ch
if filepaths:
for file_path in filepaths:
- LOG.info('Saving results in json file: ' + file_path + "...")
+ LOG.info('Saving results in json file: %s...', file_path)
with open(file_path, 'w') as jfp:
json.dump(result,
jfp,