##############################################################################
# Copyright (c) 2017 ZTE Corporation and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import abc
import getpass
import grp
import os
import pwd
import six
import stat
import subprocess
import time
from doctor_tests.common import utils
from doctor_tests.identity_auth import get_session
from doctor_tests.os_clients import nova_client
@six.add_metaclass(abc.ABCMeta)
class BaseInstaller(object):
def __init__(self, conf, log):
self.conf = conf
self.log = log
self.servers = list()
self.use_containers = False
@abc.abstractproperty
def node_user_name(self):
"""user name for login to cloud node"""
@abc.abstractmethod
def get_ssh_key_from_installer(self):
pass
@abc.abstractmethod
def get_host_ip_from_hostname(self, hostname):
pass
@abc.abstractmethod
def setup(self):
pass
@abc.abstractmethod
def cleanup(self):
pass
def create_flavor(self):
self.nova = \
nova_client(self.conf.nova_version,
get_session())
flavors = {flavor.name: flavor for flavor in self.nova.flavors.list()}
if self.conf.flavor not in flavors:
self.nova.flavors.create(self.conf.flavor, 512, 1, 1)
def setup_stunnel(self):
self.log.info('Setup ssh stunnel in %s installer......'
% self.conf.installer.type)
tunnels = [self.conf.consumer.port]
if self.conf.test_case == 'maintenance':
tunnel_uptime = 1200
tunnels += [self.conf.app_manager.port, self.conf.inspector.port]
elif self.conf.test_case == 'all':
tunnel_uptime = 1800
tunnels += [self.conf.app_manager.port, self.conf.inspector.port]
else:
tunnel_uptime = 600
for node_ip in self.controllers:
for port in tunnels:
self.log.info('tunnel for port %s' % port)
cmd = ("ssh -o UserKnownHostsFile=/dev/null"
" -o StrictHostKeyChecking=no"
" -i %s %s@%s -R %s:localhost:%s"
" sleep %s > ssh_tunnel.%s.%s"
" 2>&1 < /dev/null "
% (self.key_file,
self.node_user_name,
node_ip,
port,
port,
tunnel_uptime,
node_ip,
port))
server = subprocess.Popen('exec ' + cmd, shell
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
# Copyright 2016 Red Hat Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Contributors:
# Bill Michalowski, Red Hat Inc.
# Andrew Theurer, Red Hat Inc.
"""
Moongen Traffic Generator Model
"""
# python imports
from collections import OrderedDict
import logging
import math
import re
import subprocess
# VSPerf imports
from conf import settings
from core.results.results_constants import ResultsConstants
from tools.pkt_gen.trafficgen.trafficgenhelper import (
TRAFFIC_DEFAULTS,
merge_spec)
from tools.pkt_gen.trafficgen.trafficgen import ITrafficGenerator
class Moongen(ITrafficGenerator):
"""Moongen Traffic generator wrapper."""
_traffic_defaults = TRAFFIC_DEFAULTS.copy()
_logger = logging.getLogger(__name__)
def __init__(self):
"""Moongen class constructor."""
self._logger.info("In moongen __init__ method")
self._params = {}
self._moongen_host_ip_addr = (
settings.getValue('TRAFFICGEN_MOONGEN_HOST_IP_ADDR'))
self._moongen_base_dir = (
settings.getValue('TRAFFICGEN_MOONGEN_BASE_DIR'))
self._moongen_user = settings.getValue('TRAFFICGEN_MOONGEN_USER')
self._moongen_ports = settings.getValue('TRAFFICGEN_MOONGEN_PORTS')
if settings.getValue('TRAFFICGEN_MOONGEN_LINE_SPEED_GBPS') == '10':
self._moongen_line_speed = math.pow(10, 10)
else:
raise RuntimeError(
'MOONGEN: Invalid line speed in configuration ' + \
'file (today 10Gbps supported)')
@property
def traffic_defaults(self):
"""Default traffic values.
These can be expected to be constant across traffic generators,
so no setter is provided. Changes to the structure or contents
will likely break traffic generator implementations or tests
respectively.
"""
self._logger.info("In Moongen traffic_defaults method")
return self._traffic_defaults
def create_moongen_cfg_file(self, traffic, duration=60,
acceptable_loss_pct=1, one_shot=0):
"""Create the Moongen configuration file from VSPERF's traffic profile
:param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
:param duration: The length of time to generate packet throughput
:param acceptable_loss: Maximum packet loss acceptable
:param one_shot: No RFC 2544 binary search,
just packet flow at traffic specifics
"""
logging.debug("traffic['frame_rate'] = " + \
str(traffic['frame_rate']))
logging.debug("traffic['multistream'] = " + \
str(traffic['multistream']))
logging.debug("traffic['stream_type'] = " + \
str(traffic['stream_type']))
logging.debug("traffic['l2']['srcmac'] = " + \
str(traffic['l2']['srcmac']))
logging.debug("traffic['l2']['dstmac'] = " + \
str(traffic['l2']['dstmac']))
logging.debug("traffic['l3']['proto'] = " + \
str(traffic['l3']['proto']))
logging.debug("traffic['l3']['srcip'] = " + \
str(traffic['l3']['srcip']))
logging.debug("traffic['l3']['dstip'] = " + \
str(traffic['l3']['dstip']))
logging.debug("traffic['l4']['srcport'] = " + \
str(traffic['l4']['srcport']))
logging.debug("traffic['l4']['dstport'] = " + \
str(traffic['l4']['dstport']))
logging.debug("traffic['vlan']['enabled'] = " + \
str(traffic['vlan']['enabled']))
logging.debug("traffic['vlan']['id'] = " + \
str(traffic['vlan']['id']))
logging.debug("traffic['vlan']['priority'] = " + \
str(traffic['vlan']['priority']))
logging.debug("traffic['vlan']['cfi'] = " + \
str(traffic['vlan']['cfi']))
logging.debug(traffic['l2']['framesize'])
out_file = open("opnfv-vsperf-cfg.lua", "wt")
out_file.write("VSPERF {\n")
out_file.write("testType = \"throughput\",\n")
out_file.write("runBidirec = " + \
traffic['bidir'].lower() + ",\n")
out_file.write("frameSize = " + \
str(traffic['l2']['framesize']) + ",\n")
out_file.write("srcMac = \"" + \
str(traffic['l2']['srcmac']) + "\",\n")
out_file.write("dstMac = \"" + \
str(traffic['l2']['dstmac']) + "\",\n")
out_file.write("srcIp = \"" + \
str(traffic['l3']['srcip']) + "\",\n")
out_file.write("dstIp = \"" + \
str(traffic['l3']['dstip']) + "\",\n")
if traffic['vlan']['enabled']:
out_file.write("vlanId = " + \
str(traffic['vlan']['id']) + ",\n")
out_file.write("searchRunTime = " + \
str(duration) + ",\n")
out_file.write("validationRunTime = " + \
str(duration) + ",\n")
out_file.write("acceptableLossPct = " + \
str(acceptable_loss_pct) + ",\n")
out_file.write("ports = " +\
str(self._moongen_ports) + ",\n")
if one_shot:
out_file.write("oneShot = true,\n")
# Need to convert VSPERF frame_rate (percentage of line rate)
# to Mpps for Moongen
start_rate = str(
(traffic['frame_rate'] / 100) * (self._moongen_line_speed / \
(8 * (traffic['l2']['framesize'] + 20)) / math.pow(10, 6)))
logging.debug("startRate = " + start_rate)
out_file.write("startRate = " + \
start_rate + "\n")
out_file.write("}" + "\n")
out_file.close()
copy_moongen_cfg = "scp opnfv-vsperf-cfg.lua " + \
self._moongen_user + "@" + \
self._moongen_host_ip_addr + ":" + \
self._moongen_base_dir + \
"/. && rm opnfv-vsperf-cfg.lua"
find_moongen = subprocess.Popen(copy_moongen_cfg,
shell=True,
stderr=subprocess.PIPE)
output, error = find_moongen.communicate()
if error:
logging.error(output)
logging.error(error)
raise RuntimeError('MOONGEN: Error copying configuration file')
def connect(self):
"""Connect to Moongen traffic generator
Verify that Moongen is on the system indicated by
the configuration file
"""
self._logger.info("MOONGEN: In Moongen connect method...")
if self._moongen_host_ip_addr:
cmd_ping = "ping -c1 " + self._moongen_host_ip_addr
else:
raise RuntimeError('MOONGEN: Moongen host not defined')
ping = subprocess.Popen(cmd_ping, shell=True, stderr=subprocess.PIPE)
output, error = ping.communicate()
if ping.returncode:
self._logger.error(error)
self._logger.error(output)
raise RuntimeError('MOONGEN: Cannot ping Moongen host at ' + \
self._moongen_host_ip_addr)
connect_moongen = "ssh " + self._moongen_user + \
"@" + self._moongen_host_ip_addr
cmd_find_moongen = connect_moongen + " ls " + \
self._moongen_base_dir + "/examples/opnfv-vsperf.lua"
find_moongen = subprocess.Popen(cmd_find_moongen,
shell=True,
stderr=subprocess.PIPE)
output, error = find_moongen.communicate()
if find_moongen.returncode:
self._logger.error(error)
self._logger.error(output)
raise RuntimeError(
'MOONGEN: Cannot locate Moongen program at %s within %s' \
% (self._moongen_host_ip_addr, self._moongen_base_dir))
self._logger.info("MOONGEN: Moongen host successfully found...")
def disconnect(self):
"""Disconnect from the traffic generator.
As with :func:`connect`, this function is optional.
Where implemented, this function should raise an exception on
failure.
:returns: None
"""
self._logger.info("MOONGEN: In moongen disconnect method")
def send_burst_traffic(self, traffic=None, numpkts=100, duration=20):
"""Send a burst of traffic.
Send a ``numpkts`` packets of traffic, using ``traffic``
configuration, with a timeout of ``time``.
:param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
:param numpkts: Number of packets to send
:param duration: Time to wait to receive packets
:returns: dictionary of strings with following data:
- List of Tx Frames,
- List of Rx Frames,
- List of Tx Bytes,
- List of List of Rx Bytes,
- Payload Errors and Sequence Errors.
"""
self._logger.info("In Moongen send_burst_traffic method")
return NotImplementedError('Moongen Burst traffic not implemented')
def send_cont_traffic(self, traffic=None, duration=20):
"""Send a continuous flow of traffic
Send packets at ``frame rate``, using ``traffic`` configuration,
until timeout ``time`` occurs.
:param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
:param duration: Time to wait to receive packets (secs)
:returns: dictionary of strings with following data:
- Tx Throughput (fps),
- Rx Throughput (fps),
- Tx Throughput (mbps),
- Rx Throughput (mbps),
- Tx Throughput (% linerate),
- Rx Throughput (% linerate),
- Min Latency (ns),
- Max Latency (ns),
- Avg Latency (ns)
"""
self._logger.info("In Moongen send_cont_traffic method")
self._params.clear()
self._params['traffic'] = self.traffic_defaults.copy()
if traffic:
self._params['traffic'] = merge_spec(self._params['traffic'],
traffic)
Moongen.create_moongen_cfg_file(self,
traffic,
duration=duration,
acceptable_loss_pct=100.0,
one_shot=1)
collected_results = Moongen.run_moongen_and_collect_results(self,
test_run=1)
total_throughput_rx_fps = (
float(collected_results[ResultsConstants.THROUGHPUT_RX_FPS]))
total_throughput_rx_mbps = (
float(collected_results[ResultsConstants.THROUGHPUT_RX_MBPS]))
total_throughput_rx_pct = (
float(collected_results[ResultsConstants.THROUGHPUT_RX_PERCENT]))
total_throughput_tx_fps = (
float(collected_results[ResultsConstants.TX_RATE_FPS]))
total_throughput_tx_mbps = (
float(collected_results[ResultsConstants.TX_RATE_MBPS]))
total_throughput_tx_pct = (
float(collected_results[ResultsConstants.TX_RATE_PERCENT]))
total_min_latency_ns = 0
total_max_latency_ns = 0
total_avg_latency_ns = 0
results = OrderedDict()
results[ResultsConstants.THROUGHPUT_RX_FPS] = (
'{:.6f}'.format(total_throughput_rx_fps))
results[ResultsConstants.THROUGHPUT_RX_MBPS] = (
'{:.3f}'.format(total_throughput_rx_mbps))
results[ResultsConstants.THROUGHPUT_RX_PERCENT] = (
'{:.3f}'.format(total_throughput_rx_pct))
results[ResultsConstants.TX_RATE_FPS] = (
'{:.6f}'.format(total_throughput_tx_fps))
results[ResultsConstants.TX_RATE_MBPS] = (
'{:.3f}'.format(total_throughput_tx_mbps))
results[ResultsConstants.TX_RATE_PERCENT] = (
'{:.3f}'.format(total_throughput_tx_pct))
results[ResultsConstants.MIN_LATENCY_NS] = (
'{:.3f}'.format(total_min_latency_ns))
results[ResultsConstants.MAX_LATENCY_NS] = (
'{:.3f}'.format(total_max_latency_ns))
results[ResultsConstants.AVG_LATENCY_NS] = (
'{:.3f}'.format(total_avg_latency_ns))
return results
def start_cont_traffic(self, traffic=None, duration=20):
""" Non-blocking version of 'send_cont_traffic'.
Start transmission and immediately return. Do not wait for
results.
:param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
:param duration: Time to wait to receive packets (secs)
"""
self._logger.info("In Moongen start_cont_traffic method")
return NotImplementedError('moongen continuous traffic not implemented')
def stop_cont_traffic(self):
# Stop continuous transmission and return results.
self._logger.info("In Moongen stop_cont_traffic method")
def run_moongen_and_collect_results(self, test_run=1):
"""Execute Moongen and transform results into VSPERF format
:param test_run: The number of tests to run
"""
# Start Moongen and create logfile of the run
connect_moongen = "ssh " + self._moongen_user + "@" + \
self._moongen_host_ip_addr
cmd_moongen = " 'cd " + self._moongen_base_dir + \
"; ./build/MoonGen examples/opnfv-vsperf.lua | tee moongen_log.txt'"
cmd_start_moongen = connect_moongen + cmd_moongen
start_moongen = subprocess.Popen(cmd_start_moongen,
shell=True, stderr=subprocess.PIPE)
output, error = start_moongen.communicate()
if start_moongen.returncode:
logging.debug(error)
logging.debug(output)
raise RuntimeError(
'MOONGEN: Error starting Moongen program at %s within %s' \
% (self._moongen_host_ip_addr, self._moongen_base_dir))
cmd_moongen = "mkdir -p /tmp/moongen/" + str(test_run)
moongen_create_log_dir = subprocess.Popen(cmd_moongen,
shell=True,
stderr=subprocess.PIPE)
output, error = moongen_create_log_dir.communicate()
if moongen_create_log_dir.returncode:
logging.debug(error)
logging.debug(output)
raise RuntimeError(
'MOONGEN: Error obtaining Moongen log from %s within %s' \
% (self._moongen_host_ip_addr, self._moongen_base_dir))
cmd_moongen = " scp " + self._moongen_user + "@" + \
self._moongen_host_ip_addr + ":" + \
self._moongen_base_dir + "/moongen_log.txt /tmp/moongen/" + \
str(test_run) + "/moongen-run.log"
copy_moongen_log = subprocess.Popen(cmd_moongen,
shell=True,
stderr=subprocess.PIPE)
output, error = copy_moongen_log.communicate()
if copy_moongen_log.returncode:
logging.debug(error)
logging.debug(output)
raise RuntimeError(
'MOONGEN: Error obtaining Moongen log from %s within %s' \
% (self._moongen_host_ip_addr, self._moongen_base_dir))
log_file = "/tmp/moongen/" + str(test_run) + "/moongen-run.log"
with open(log_file, 'r') as logfile_handle:
mytext = logfile_handle.read()
# REPORT results line
# match.group(1) = Tx frames
# match.group(2) = Rx frames
# match.group(3) = Frame loss (count)
# match.group(4) = Frame loss (percentage)
# match.group(5) = Tx Mpps
# match.group(6) = Rx Mpps
search_pattern = re.compile(
r'\[REPORT\]\s+total\:\s+'
r'Tx\s+frames\:\s+(\d+)\s+'
r'Rx\s+Frames\:\s+(\d+)\s+'
r'frame\s+loss\:\s+(\d+)\,'
r'\s+(\d+\.\d+|\d+)%\s+'
r'Tx\s+Mpps\:\s+(\d+.\d+|\d+)\s+'
r'Rx\s+Mpps\:\s+(\d+\.\d+|\d+)',
re.IGNORECASE)
results_match = search_pattern.search(mytext)
if not results_match:
logging.error('There was a problem parsing ' +\
'Moongen REPORT section of Moongen log file')
moongen_results = OrderedDict()
moongen_results[ResultsConstants.THROUGHPUT_RX_FPS] = 0
moongen_results[ResultsConstants.THROUGHPUT_RX_MBPS] = 0
moongen_results[ResultsConstants.THROUGHPUT_RX_PERCENT] = 0
moongen_results[ResultsConstants.TX_RATE_FPS] = 0
moongen_results[ResultsConstants.TX_RATE_MBPS] = 0
moongen_results[ResultsConstants.TX_RATE_PERCENT] = 0
moongen_results[ResultsConstants.B2B_TX_COUNT] = 0
moongen_results[ResultsConstants.B2B_FRAMES] = 0
moongen_results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] = 0
moongen_results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] = 0
# find PARAMETERS line
# parameters_match.group(1) = Frame size
search_pattern = re.compile(
r'\[PARAMETERS\]\s+.*frameSize\:\s+(\d+)',
flags=re.IGNORECASE)
parameters_match = search_pattern.search(mytext)
if parameters_match:
frame_size = int(parameters_match.group(1))
else:
logging.error('There was a problem parsing Moongen ' +\
'PARAMETERS section of Moongen log file')
frame_size = 0
if results_match and parameters_match:
# Assume for now 10G link speed
max_theoretical_mfps = (
(self._moongen_line_speed / 8) / (frame_size + 20))
moongen_results[ResultsConstants.THROUGHPUT_RX_FPS] = (
float(results_match.group(6)) * 1000000)
moongen_results[ResultsConstants.THROUGHPUT_RX_MBPS] = (
(float(results_match.group(6)) * frame_size + 20) * 8)
moongen_results[ResultsConstants.THROUGHPUT_RX_PERCENT] = (
float(results_match.group(6)) * \
1000000 / max_theoretical_mfps * 100)
moongen_results[ResultsConstants.TX_RATE_FPS] = (
float(results_match.group(5)) * 1000000)
moongen_results[ResultsConstants.TX_RATE_MBPS] = (
float(results_match.group(5)) * (frame_size + 20) * 8)
moongen_results[ResultsConstants.TX_RATE_PERCENT] = (
float(results_match.group(5)) *
1000000 / max_theoretical_mfps * 100)
moongen_results[ResultsConstants.B2B_TX_COUNT] = (
float(results_match.group(1)))
moongen_results[ResultsConstants.B2B_FRAMES] = (
float(results_match.group(2)))
moongen_results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] = (
float(results_match.group(3)))
moongen_results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] = (
float(results_match.group(4)))
return moongen_results
def send_rfc2544_throughput(self, traffic=None, duration=20,
lossrate=0.0, trials=1):
#
# Send traffic per RFC2544 throughput test specifications.
#
# Send packets at a variable rate, using ``traffic``
# configuration, until minimum rate at which no packet loss is
# detected is found.
#
# :param traffic: Detailed "traffic" spec, see design docs for details
# :param trials: Number of trials to execute
# :param duration: Per iteration duration
# :param lossrate: Acceptable lossrate percentage
# :returns: dictionary of strings with following data:
# - Tx Throughput (fps),
# - Rx Throughput (fps),
# - Tx Throughput (mbps),
# - Rx Throughput (mbps),
# - Tx Throughput (% linerate),
# - Rx Throughput (% linerate),
# - Min Latency (ns),
# - Max Latency (ns),
# - Avg Latency (ns)
#
self._logger.info("In moongen send_rfc2544_throughput method")
self._params.clear()
self._params['traffic'] = self.traffic_defaults.copy()
if traffic:
self._params['traffic'] = merge_spec(self._params['traffic'],
traffic)
Moongen.create_moongen_cfg_file(self,
traffic,
duration=duration,
acceptable_loss_pct=lossrate)
total_throughput_rx_fps = 0
total_throughput_rx_mbps = 0
total_throughput_rx_pct = 0
total_throughput_tx_fps = 0
total_throughput_tx_mbps = 0
total_throughput_tx_pct = 0
total_min_latency_ns = 0
total_max_latency_ns = 0
total_avg_latency_ns = 0
for test_run in range(1, trials+1):
collected_results = (
Moongen.run_moongen_and_collect_results(self, test_run=test_run))
total_throughput_rx_fps += (
float(collected_results[ResultsConstants.THROUGHPUT_RX_FPS]))
total_throughput_rx_mbps += (
float(collected_results[ResultsConstants.THROUGHPUT_RX_MBPS]))
total_throughput_rx_pct += (
float(collected_results[ResultsConstants.THROUGHPUT_RX_PERCENT]))
total_throughput_tx_fps += (
float(collected_results[ResultsConstants.TX_RATE_FPS]))
total_throughput_tx_mbps += (
float(collected_results[ResultsConstants.TX_RATE_MBPS]))
total_throughput_tx_pct += (
float(collected_results[ResultsConstants.TX_RATE_PERCENT]))
# Latency not supported now, leaving as placeholder
total_min_latency_ns = 0
total_max_latency_ns = 0
total_avg_latency_ns = 0
results = OrderedDict()
results[ResultsConstants.THROUGHPUT_RX_FPS] = (
'{:.6f}'.format(total_throughput_rx_fps / trials))
results[ResultsConstants.THROUGHPUT_RX_MBPS] = (
'{:.3f}'.format(total_throughput_rx_mbps / trials))
results[ResultsConstants.THROUGHPUT_RX_PERCENT] = (
'{:.3f}'.format(total_throughput_rx_pct / trials))
results[ResultsConstants.TX_RATE_FPS] = (
'{:.6f}'.format(total_throughput_tx_fps / trials))
results[ResultsConstants.TX_RATE_MBPS] = (
'{:.3f}'.format(total_throughput_tx_mbps / trials))
results[ResultsConstants.TX_RATE_PERCENT] = (
'{:.3f}'.format(total_throughput_tx_pct / trials))
results[ResultsConstants.MIN_LATENCY_NS] = (
'{:.3f}'.format(total_min_latency_ns / trials))
results[ResultsConstants.MAX_LATENCY_NS] = (
'{:.3f}'.format(total_max_latency_ns / trials))
results[ResultsConstants.AVG_LATENCY_NS] = (
'{:.3f}'.format(total_avg_latency_ns / trials))
return results
def start_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
lossrate=0.0):
"""Non-blocking version of 'send_rfc2544_throughput'.
Start transmission and immediately return. Do not wait for
results.
"""
self._logger.info(
"MOONGEN: In moongen start_rfc2544_throughput method")
def wait_rfc2544_throughput(self):
"""Wait for and return results of RFC2544 test.
"""
self._logger.info('In moongen wait_rfc2544_throughput')
def send_rfc2544_back2back(self, traffic=None, duration=60,
lossrate=0.0, trials=1):
"""Send traffic per RFC2544 back2back test specifications.
Send packets at a fixed rate, using ``traffic``
configuration, for duration seconds.
:param traffic: Detailed "traffic" spec, see design docs for details
:param trials: Number of trials to execute
:param duration: Per iteration duration
:param lossrate: Acceptable loss percentage
:returns: Named tuple of Rx Throughput (fps), Rx Throughput (mbps),
Tx Rate (% linerate), Rx Rate (% linerate), Tx Count (frames),
Back to Back Count (frames), Frame Loss (frames), Frame Loss (%)
:rtype: :class:`Back2BackResult`
"""
self._params.clear()
self._params['traffic'] = self.traffic_defaults.copy()
if traffic:
self._params['traffic'] = merge_spec(self._params['traffic'],
traffic)
Moongen.create_moongen_cfg_file(self,
traffic,
duration=duration,
acceptable_loss_pct=lossrate)
results = OrderedDict()
results[ResultsConstants.B2B_RX_FPS] = 0
results[ResultsConstants.B2B_TX_FPS] = 0
results[ResultsConstants.B2B_RX_PERCENT] = 0
results[ResultsConstants.B2B_TX_PERCENT] = 0
results[ResultsConstants.B2B_TX_COUNT] = 0
results[ResultsConstants.B2B_FRAMES] = 0
results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] = 0
results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] = 0
results[ResultsConstants.SCAL_STREAM_COUNT] = 0
results[ResultsConstants.SCAL_STREAM_TYPE] = 0
results[ResultsConstants.SCAL_PRE_INSTALLED_FLOWS] = 0
for test_run in range(1, trials+1):
collected_results = (
Moongen.run_moongen_and_collect_results(self, test_run=test_run))
results[ResultsConstants.B2B_RX_FPS] += (
float(collected_results[ResultsConstants.THROUGHPUT_RX_FPS]))
results[ResultsConstants.B2B_RX_PERCENT] += (
float(collected_results[ResultsConstants.THROUGHPUT_RX_PERCENT]))
results[ResultsConstants.B2B_TX_FPS] += (
float(collected_results[ResultsConstants.TX_RATE_FPS]))
results[ResultsConstants.B2B_TX_PERCENT] += (
float(collected_results[ResultsConstants.TX_RATE_PERCENT]))
results[ResultsConstants.B2B_TX_COUNT] += (
int(collected_results[ResultsConstants.B2B_TX_COUNT]))
results[ResultsConstants.B2B_FRAMES] += (
int(collected_results[ResultsConstants.B2B_FRAMES]))
results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] += (
int(collected_results[ResultsConstants.B2B_FRAME_LOSS_FRAMES]))
results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] += (
int(collected_results[ResultsConstants.B2B_FRAME_LOSS_PERCENT]))
# Calculate average results
results[ResultsConstants.B2B_RX_FPS] = (
results[ResultsConstants.B2B_RX_FPS] / trials)
results[ResultsConstants.B2B_RX_PERCENT] = (
results[ResultsConstants.B2B_RX_PERCENT] / trials)
results[ResultsConstants.B2B_TX_FPS] = (
results[ResultsConstants.B2B_TX_FPS] / trials)
results[ResultsConstants.B2B_TX_PERCENT] = (
results[ResultsConstants.B2B_TX_PERCENT] / trials)
results[ResultsConstants.B2B_TX_COUNT] = (
results[ResultsConstants.B2B_TX_COUNT] / trials)
results[ResultsConstants.B2B_FRAMES] = (
results[ResultsConstants.B2B_FRAMES] / trials)
results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] = (
results[ResultsConstants.B2B_FRAME_LOSS_FRAMES] / trials)
results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] = (
results[ResultsConstants.B2B_FRAME_LOSS_PERCENT] / trials)
results[ResultsConstants.SCAL_STREAM_COUNT] = 0
results[ResultsConstants.SCAL_STREAM_TYPE] = 0
results[ResultsConstants.SCAL_PRE_INSTALLED_FLOWS] = 0
return results
def start_rfc2544_back2back(self, traffic=None, trials=1, duration=20,
lossrate=0.0):
#
# Non-blocking version of 'send_rfc2544_back2back'.
#
# Start transmission and immediately return. Do not wait for results.
#
self._logger.info("In Moongen start_rfc2544_back2back method")
return NotImplementedError(
'Moongen start back2back traffic not implemented')
def wait_rfc2544_back2back(self):
self._logger.info("In moongen wait_rfc2544_back2back method")
#
# Wait and set results of RFC2544 test.
#
return NotImplementedError(
'Moongen wait back2back traffic not implemented')
if __name__ == "__main__":
pass