aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/Constants.py8
-rw-r--r--resources/libraries/python/CoreDumpUtil.py4
-rw-r--r--resources/libraries/python/DUTSetup.py82
-rw-r--r--resources/libraries/python/HoststackUtil.py287
-rw-r--r--resources/libraries/python/IPUtil.py104
-rw-r--r--resources/libraries/python/Namespaces.py81
-rw-r--r--resources/libraries/python/VPPUtil.py7
-rw-r--r--resources/libraries/python/VatExecutor.py4
-rw-r--r--resources/libraries/python/VppConfigGenerator.py21
-rw-r--r--resources/libraries/python/topology.py20
10 files changed, 561 insertions, 57 deletions
diff --git a/resources/libraries/python/Constants.py b/resources/libraries/python/Constants.py
index 0a8470ec65..dc9eda7505 100644
--- a/resources/libraries/python/Constants.py
+++ b/resources/libraries/python/Constants.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -224,6 +224,12 @@ class Constants:
u"FAIL_ON_CRC_MISMATCH"
)
+ # Default IP4 prefix length (if not defined in topology file)
+ DEFAULT_IP4_PREFIX_LENGTH = u"24"
+
+ # Maximum number of interfaces in a data path
+ DATAPATH_INTERFACES_MAX = 100
+
# Mapping from NIC name to its bps limit.
NIC_NAME_TO_BPS_LIMIT = {
u"Cisco-VIC-1227": 10000000000,
diff --git a/resources/libraries/python/CoreDumpUtil.py b/resources/libraries/python/CoreDumpUtil.py
index 57f0c1d896..e1c7b65765 100644
--- a/resources/libraries/python/CoreDumpUtil.py
+++ b/resources/libraries/python/CoreDumpUtil.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -113,7 +113,7 @@ class CoreDumpUtil:
:type node: dict
"""
if node[u"type"] == NodeType.DUT and self.is_core_limit_enabled():
- vpp_pid = DUTSetup.get_vpp_pid(node)
+ vpp_pid = DUTSetup.get_pid(node, u"vpp")
self.enable_coredump_limit(node, vpp_pid)
def enable_coredump_limit_vpp_on_all_duts(self, nodes):
diff --git a/resources/libraries/python/DUTSetup.py b/resources/libraries/python/DUTSetup.py
index d0da4645d2..431ccfb8ae 100644
--- a/resources/libraries/python/DUTSetup.py
+++ b/resources/libraries/python/DUTSetup.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -13,10 +13,11 @@
"""DUT setup library."""
+from time import sleep
from robot.api import logger
from resources.libraries.python.Constants import Constants
-from resources.libraries.python.ssh import SSH, exec_cmd_no_error
+from resources.libraries.python.ssh import SSH, exec_cmd, exec_cmd_no_error
from resources.libraries.python.topology import NodeType, Topology
@@ -157,11 +158,62 @@ class DUTSetup:
DUTSetup.stop_service(node, service)
@staticmethod
- def get_vpp_pid(node):
- """Get PID of running VPP process.
+ def kill_program(node, program, namespace=None):
+ """Kill program on the specified topology node.
+
+ :param node: Topology node.
+ :param program: Program name.
+ :param namespace: Namespace program is running in.
+ :type node: dict
+ :type program: str
+ :type namespace: str
+ """
+ host = node[u"host"]
+ cmd_timeout = 5
+ if namespace in (None, u"default"):
+ shell_cmd = u"sh -c"
+ else:
+ shell_cmd = f"ip netns exec {namespace} sh -c"
+
+ pgrep_cmd = f"{shell_cmd} \'pgrep {program}\'"
+ ret_code, _, _ = exec_cmd(node, pgrep_cmd, timeout=cmd_timeout,
+ sudo=True)
+ if ret_code == 0:
+ logger.trace(f"{program} is not running on {host}")
+ return
+ ret_code, _, _ = exec_cmd(node, f"{shell_cmd} \'pkill {program}\'",
+ timeout=cmd_timeout, sudo=True)
+ for attempt in range(5):
+ ret_code, _, _ = exec_cmd(node, pgrep_cmd, timeout=cmd_timeout,
+ sudo=True)
+ if ret_code != 0:
+ logger.trace(f"Attempt {attempt}: {program} is dead on {host}")
+ return
+ sleep(1)
+ logger.trace(f"SIGKILLing {program} on {host}")
+ ret_code, _, _ = exec_cmd(node, f"{shell_cmd} \'pkill -9 {program}\'",
+ timeout=cmd_timeout, sudo=True)
+
+ @staticmethod
+ def verify_program_installed(node, program):
+ """Verify that program is installed on the specified topology node.
+
+ :param node: Topology node.
+ :param program: Program name.
+ :type node: dict
+ :type program: str
+ """
+ cmd = f"command -v {program}"
+ exec_cmd_no_error(node, cmd, message=f"{program} is not installed")
+
+ @staticmethod
+ def get_pid(node, process):
+ """Get PID of running process.
:param node: DUT node.
+ :param process: process name.
:type node: dict
+ :type process: str
:returns: PID
:rtype: int
:raises RuntimeError: If it is not possible to get the PID.
@@ -171,26 +223,24 @@ class DUTSetup:
retval = None
for i in range(3):
- logger.trace(f"Try {i}: Get VPP PID")
- ret_code, stdout, stderr = ssh.exec_command(u"pidof vpp")
+ logger.trace(f"Try {i}: Get {process} PID")
+ ret_code, stdout, stderr = ssh.exec_command(f"pidof {process}")
if int(ret_code):
raise RuntimeError(
- f"Not possible to get PID of VPP process on node: "
+ f"Not possible to get PID of {process} process on node: "
f"{node[u'host']}\n {stdout + stderr}"
)
pid_list = stdout.split()
if len(pid_list) == 1:
- retval = int(stdout)
- elif not pid_list:
- logger.debug(f"No VPP PID found on node {node[u'host']}")
+ return [int(stdout)]
+ if not pid_list:
+ logger.debug(f"No {process} PID found on node {node[u'host']}")
continue
- else:
- logger.debug(
- f"More then one VPP PID found on node {node[u'host']}"
- )
- retval = [int(pid) for pid in pid_list]
+ logger.debug(f"More than one {process} PID found " \
+ f"on node {node[u'host']}")
+ retval = [int(pid) for pid in pid_list]
return retval
@@ -206,7 +256,7 @@ class DUTSetup:
pids = dict()
for node in nodes.values():
if node[u"type"] == NodeType.DUT:
- pids[node[u"host"]] = DUTSetup.get_vpp_pid(node)
+ pids[node[u"host"]] = DUTSetup.get_pid(node, u"vpp")
return pids
@staticmethod
diff --git a/resources/libraries/python/HoststackUtil.py b/resources/libraries/python/HoststackUtil.py
new file mode 100644
index 0000000000..9e6e20014c
--- /dev/null
+++ b/resources/libraries/python/HoststackUtil.py
@@ -0,0 +1,287 @@
+# Copyright (c) 2020 Cisco and/or its affiliates.
+# 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.
+
+"""Host Stack util library."""
+from time import sleep
+from robot.api import logger
+
+from resources.libraries.python.ssh import exec_cmd, exec_cmd_no_error
+from resources.libraries.python.PapiExecutor import PapiSocketExecutor
+from resources.libraries.python.DUTSetup import DUTSetup
+
+class HoststackUtil():
+ """Utilities for Host Stack tests."""
+
+ @staticmethod
+ def get_vpp_echo_command(vpp_echo_attributes):
+ """Construct the vpp_echo command using the specified attributes.
+
+ :param vpp_echo_attributes: vpp_echo test program attributes.
+ :type vpp_echo_attributes: dict
+ :returns: Command line components of the vpp_echo command
+ 'name' - program name
+ 'args' - command arguments.
+ :rtype: dict
+ """
+ # TODO: Use a python class instead of dictionary for the return type
+ proto = vpp_echo_attributes[u"uri_protocol"]
+ addr = vpp_echo_attributes[u"uri_ip4_addr"]
+ port = vpp_echo_attributes[u"uri_port"]
+ vpp_echo_cmd = {}
+ vpp_echo_cmd[u"name"] = u"vpp_echo"
+ vpp_echo_cmd[u"args"] = f"{vpp_echo_attributes[u'role']} " \
+ f"socket-name {vpp_echo_attributes[u'vpp_api_socket']} " \
+ f"{vpp_echo_attributes[u'json_output']} " \
+ f"uri {proto}://{addr}/{port} " \
+ f"nclients {vpp_echo_attributes[u'nclients']} " \
+ f"quic-streams {vpp_echo_attributes[u'quic_streams']} " \
+ f"time {vpp_echo_attributes[u'time']} " \
+ f"fifo-size {vpp_echo_attributes[u'fifo_size']} " \
+ f"TX={vpp_echo_attributes[u'tx_bytes']} " \
+ f"RX={vpp_echo_attributes[u'rx_bytes']}"
+ if vpp_echo_attributes[u"rx_results_diff"]:
+ vpp_echo_cmd[u"args"] += u" rx-results-diff"
+ if vpp_echo_attributes[u"tx_results_diff"]:
+ vpp_echo_cmd[u"args"] += u" tx-results-diff"
+ return vpp_echo_cmd
+
+ @staticmethod
+ def set_hoststack_quic_fifo_size(node, fifo_size):
+ """Set the QUIC protocol fifo size.
+
+ :param node: Node to set the QUIC fifo size on.
+ :param fifo_size: fifo size, passed to the quic set fifo-size command.
+ :type node: dict
+ :type fifo_size: str
+ """
+ cmd = f"quic set fifo-size {fifo_size}"
+ PapiSocketExecutor.run_cli_cmd(node, cmd)
+
+ @staticmethod
+ def set_hoststack_quic_crypto_engine(node, quic_crypto_engine,
+ fail_on_error=False):
+ """Set the Hoststack QUIC crypto engine on node
+
+ :param node: Node to enable/disable HostStack.
+ :param quic_crypto_engine: type of crypto engine
+ :type node: dict
+ :type quic_crypto_engine: str
+ """
+ vpp_crypto_engines = {u"openssl", u"ia32", u"ipsecmb"}
+ if quic_crypto_engine == u"nocrypto":
+ logger.trace(u"No QUIC crypto engine.")
+ return
+
+ if quic_crypto_engine in vpp_crypto_engines:
+ cmds = [u"quic set crypto api vpp",
+ f"set crypto handler aes-128-gcm {quic_crypto_engine}",
+ f"set crypto handler aes-256-gcm {quic_crypto_engine}"]
+ elif quic_crypto_engine == u"picotls":
+ cmds = [u"quic set crypto api picotls"]
+ else:
+ raise ValueError(f"Unknown QUIC crypto_engine {quic_crypto_engine}")
+
+ for cmd in cmds:
+ try:
+ PapiSocketExecutor.run_cli_cmd(node, cmd)
+ except AssertionError:
+ if fail_on_error:
+ raise
+
+ @staticmethod
+ def get_hoststack_test_program_logs(node, program):
+ """Get HostStack test program stdout log.
+
+ :param node: DUT node.
+ :param program: test program.
+ :type node: dict
+ :type program: dict
+ """
+ program_name = program[u"name"]
+ cmd = f"sh -c \'cat /tmp/{program_name}_stdout.log\'"
+ stdout_log, _ = exec_cmd_no_error(node, cmd, sudo=True, \
+ message=f"Get {program_name} stdout log failed!")
+
+ cmd = f"sh -c \'cat /tmp/{program_name}_stderr.log\'"
+ stderr_log, _ = exec_cmd_no_error(node, cmd, sudo=True, \
+ message=f"Get {program_name} stderr log failed!")
+ return stdout_log, stderr_log
+
+ @staticmethod
+ def start_hoststack_test_program(node, namespace, program):
+ """Start the specified HostStack test program.
+
+ :param node: DUT node.
+ :param namespace: Net Namespace to run program in.
+ :param program: Test program.
+ :type node: dict
+ :type namespace: str
+ :type program: dict
+ :returns: Process ID
+ :rtype: int
+ :raises RuntimeError: If node subtype is not a DUT or startup failed.
+ """
+ # TODO: Pin test program to core(s) on same numa node as VPP.
+ if node[u"type"] != u"DUT":
+ raise RuntimeError(u"Node type is not a DUT!")
+
+ program_name = program[u"name"]
+ DUTSetup.kill_program(node, program_name, namespace)
+
+ if namespace == u"default":
+ shell_cmd = u"sh -c"
+ else:
+ shell_cmd = f"ip netns exec {namespace} sh -c"
+
+ env_vars = f"{program[u'env_vars']} " if u"env_vars" in program else u""
+ args = program[u"args"]
+ cmd = f"nohup {shell_cmd} \'{env_vars}{program_name} {args} " \
+ f">/tmp/{program_name}_stdout.log " \
+ f"2>/tmp/{program_name}_stderr.log &\'"
+ try:
+ exec_cmd_no_error(node, cmd, sudo=True)
+ return DUTSetup.get_pid(node, program_name)[0]
+ except RuntimeError:
+ stdout_log, stderr_log = \
+ HoststackUtil.get_hoststack_test_program_logs(node,
+ program)
+ raise RuntimeError(f"Start {program_name} failed!\nSTDERR:\n" \
+ f"{stderr_log}\nSTDOUT:\n{stdout_log}")
+ return None
+
+ @staticmethod
+ def stop_hoststack_test_program(node, program, pid):
+ """Stop the specified Hoststack test program.
+
+ :param node: DUT node.
+ :param program: Test program.
+ :param pid: Process ID of test program.
+ :type node: dict
+ :type program: dict
+ :type pid: int
+ """
+ program_name = program[u"name"]
+ if program_name == u"nginx":
+ cmd = u"nginx -s quit"
+ errmsg = u"Quit nginx failed!"
+ else:
+ cmd = f'if [ -n "$(ps {pid} | grep {program_name})" ] ; ' \
+ f'then kill -s SIGTERM {pid}; fi'
+ errmsg = f"Kill {program_name} ({pid}) failed!"
+
+ exec_cmd_no_error(node, cmd, message=errmsg, sudo=True)
+
+ @staticmethod
+ def hoststack_test_program_finished(node, program_pid):
+ """Wait for the specified HostStack test program process to complete.
+
+ :param node: DUT node.
+ :param program_pid: test program pid.
+ :type node: dict
+ :type program_pid: str
+ :raises RuntimeError: If node subtype is not a DUT.
+ """
+ if node[u"type"] != u"DUT":
+ raise RuntimeError(u"Node type is not a DUT!")
+
+ cmd = f"sh -c 'strace -qqe trace=none -p {program_pid}'"
+ exec_cmd(node, cmd, sudo=True)
+ # Wait a bit for stdout/stderr to be flushed to log files
+ # TODO: see if sub-second sleep works e.g. sleep(0.1)
+ sleep(1)
+
+ @staticmethod
+ def analyze_hoststack_test_program_output(node, role, nsim_attr,
+ program):
+ """Gather HostStack test program output and check for errors.
+
+ :param node: DUT node.
+ :param role: Role (client|server) of test program.
+ :param nsim_attr: Network Simulation Attributes.
+ :param program: Test program.
+ :param program_args: List of test program args.
+ :type node: dict
+ :type role: str
+ :type nsim_attr: dict
+ :type program: dict
+ :returns: tuple of no results bool and test program results.
+ :rtype: bool, str
+ :raises RuntimeError: If node subtype is not a DUT.
+ """
+ if node[u"type"] != u"DUT":
+ raise RuntimeError(u"Node type is not a DUT!")
+
+ program_name = program[u"name"]
+ program_stdout, program_stderr = \
+ HoststackUtil.get_hoststack_test_program_logs(node, program)
+ if len(program_stdout) == 0 and len(program_stderr) == 0:
+ logger.trace(f"Retrying {program_name} log retrieval")
+ program_stdout, program_stderr = \
+ HoststackUtil.get_hoststack_test_program_logs(node, program)
+
+ no_results = False
+ env_vars = f"{program[u'env_vars']} " if u"env_vars" in program else u""
+ program_cmd = f"{env_vars}{program_name} {program[u'args']}"
+ test_results = f"Test Results of '{program_cmd}':\n"
+
+ if nsim_attr[u"output_feature_enable"] or \
+ nsim_attr[u"cross_connect_feature_enable"]:
+ if nsim_attr[u"output_feature_enable"]:
+ feature_name = u"output"
+ else:
+ feature_name = u"cross-connect"
+ test_results += \
+ f"NSIM({feature_name}): delay " \
+ f"{nsim_attr[u'delay_in_usec']} usecs, " \
+ f"avg-pkt-size {nsim_attr[u'average_packet_size']}, " \
+ f"bandwidth {nsim_attr[u'bandwidth_in_bits_per_second']} " \
+ f"bits/sec, pkt-drop-rate {nsim_attr[u'packets_per_drop']} " \
+ f"pkts/drop\n"
+
+ if u"error" in program_stderr.lower():
+ test_results += f"ERROR DETECTED:\n{program_stderr}"
+ raise RuntimeError(test_results)
+ if program_stdout:
+ bad_test_results = False
+ if program == u"vpp_echo" and u"JSON stats" not in program_stdout:
+ test_results += u"Invalid test data output!\n"
+ bad_test_results = True
+ test_results += program_stdout
+ if bad_test_results:
+ raise RuntimeError(test_results)
+ else:
+ no_results = True
+ test_results += f"\nNo {program} test data retrieved!\n"
+ cmd = u"ls -l /tmp/*.log"
+ ls_stdout, _ = exec_cmd_no_error(node, cmd, sudo=True)
+ test_results += f"{ls_stdout}\n"
+
+ # TODO: Incorporate show error stats into results analysis
+ host = node[u"host"]
+ test_results += \
+ f"\n{role} VPP 'show errors' on host {host}:\n" \
+ f"{PapiSocketExecutor.run_cli_cmd(node, u'show error')}\n"
+
+ return no_results, test_results
+
+ @staticmethod
+ def no_hoststack_test_program_results(server_no_results, client_no_results):
+ """Return True if no HostStack test program output was gathered.
+
+ :param server_no_results: server no results value.
+ :param client_no_results: client no results value.
+ :type server_no_results: bool
+ :type client_no_results: bool
+ :rtype: bool
+ """
+ return server_no_results and client_no_results
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py
index c3df1fe376..1e0d90f065 100644
--- a/resources/libraries/python/IPUtil.py
+++ b/resources/libraries/python/IPUtil.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -12,7 +12,6 @@
# limitations under the License.
"""Common IP utilities library."""
-
import re
from enum import IntEnum
@@ -25,6 +24,7 @@ from resources.libraries.python.PapiExecutor import PapiSocketExecutor
from resources.libraries.python.ssh import exec_cmd_no_error, exec_cmd
from resources.libraries.python.topology import Topology
from resources.libraries.python.VatExecutor import VatTerminal
+from resources.libraries.python.Namespaces import Namespaces
# from vpp/src/vnet/vnet/mpls/mpls_types.h
@@ -243,31 +243,31 @@ class IPUtil:
raise AssertionError(f"IP addresses are not equal: {ip1} != {ip2}")
@staticmethod
- def setup_network_namespace(
- node, namespace_name, interface_name, ip_addr, prefix):
+ def setup_network_namespace(node, namespace_name, interface_name,
+ ip_addr_list, prefix_length):
"""Setup namespace on given node and attach interface and IP to
this namespace. Applicable also on TG node.
:param node: VPP node.
:param namespace_name: Namespace name.
:param interface_name: Interface name.
- :param ip_addr: IP address of namespace's interface.
- :param prefix: IP address prefix length.
+ :param ip_addr_list: List of IP addresses of namespace's interface.
+ :param prefix_length: IP address prefix length.
:type node: dict
:type namespace_name: str
:type interface_name: str
- :type ip_addr: str
- :type prefix: int
+ :type ip_addr_list: list
+ :type prefix_length: int
"""
- cmd = f"ip netns add {namespace_name}"
- exec_cmd_no_error(node, cmd, sudo=True)
+ Namespaces.create_namespace(node, namespace_name)
- cmd = f"ip link set dev {interface_name} up netns {namespace_name}"
+ cmd = f"ip netns exec {namespace_name} ip link set {interface_name} up"
exec_cmd_no_error(node, cmd, sudo=True)
- cmd = f"ip netns exec {namespace_name} ip addr add {ip_addr}/{prefix}" \
- f" dev {interface_name}"
- exec_cmd_no_error(node, cmd, sudo=True)
+ for ip_addr in ip_addr_list:
+ cmd = f"ip netns exec {namespace_name} ip addr add " \
+ f"{ip_addr}/{prefix_length} dev {interface_name}"
+ exec_cmd_no_error(node, cmd, sudo=True)
@staticmethod
def linux_enable_forwarding(node, ip_ver=u"ipv4"):
@@ -351,6 +351,64 @@ class IPUtil:
exec_cmd_no_error(node, cmd, timeout=5, sudo=True)
@staticmethod
+ def delete_linux_interface_ip(
+ node, interface, ip_addr, prefix_length, namespace=None):
+ """Delete IP address from interface in linux.
+
+ :param node: VPP/TG node.
+ :param interface: Interface in namespace.
+ :param ip_addr: IP to be deleted from interface.
+ :param prefix_length: IP prefix length.
+ :param namespace: Execute command in namespace. Optional
+ :type node: dict
+ :type interface: str
+ :type ip_addr: str
+ :type prefix_length: int
+ :type namespace: str
+ :raises RuntimeError: IP could not be deleted.
+ """
+ # TODO: Refactor command execution in namespaces into central
+ # methods (e.g. Namespace.exec_cmd_in_namespace)
+ if namespace is not None:
+ cmd = f"ip netns exec {namespace} ip addr del " \
+ f"{ip_addr}/{prefix_length} dev {interface}"
+ else:
+ cmd = f"ip addr del {ip_addr}/{prefix_length} dev {interface}"
+
+ exec_cmd_no_error(node, cmd, timeout=5, sudo=True)
+
+ @staticmethod
+ def linux_interface_has_ip(
+ node, interface, ip_addr, prefix_length, namespace=None):
+ """Return True if interface in linux has IP address.
+
+ :param node: VPP/TG node.
+ :param interface: Interface in namespace.
+ :param ip_addr: IP to be queried on interface.
+ :param prefix_length: IP prefix length.
+ :param namespace: Execute command in namespace. Optional
+ :type node: dict
+ :type interface: str
+ :type ip_addr: str
+ :type prefix_length: int
+ :type namespace: str
+ :rtype boolean
+ :raises RuntimeError: Request fails.
+ """
+ ip_addr_with_prefix = f"{ip_addr}/{prefix_length}"
+ if namespace is not None:
+ cmd = f"ip netns exec {namespace} ip addr show dev {interface}"
+ else:
+ cmd = f"ip addr show dev {interface}"
+
+ cmd += u" | grep 'inet ' | awk -e '{print $2}'"
+ cmd += f" | grep '{ip_addr_with_prefix}'"
+ _, stdout, _ = exec_cmd(node, cmd, timeout=5, sudo=True)
+
+ has_ip = stdout.rstrip()
+ return bool(has_ip == ip_addr_with_prefix)
+
+ @staticmethod
def add_linux_route(node, ip_addr, prefix, gateway, namespace=None):
"""Add linux route in namespace.
@@ -406,6 +464,24 @@ class IPUtil:
papi_exec.add(cmd, **args).get_reply(err_msg)
@staticmethod
+ def vpp_interface_set_ip_addresses(node, interface, ip_addr_list,
+ prefix_length=None):
+ """Set IP addresses to VPP interface.
+
+ :param node: VPP node.
+ :param interface: Interface name.
+ :param ip_addr_list: IP addresses.
+ :param prefix_length: Prefix length.
+ :type node: dict
+ :type interface: str
+ :type ip_addr_list: list
+ :type prefix_length: int
+ """
+ for ip_addr in ip_addr_list:
+ IPUtil.vpp_interface_set_ip_address(node, interface, ip_addr,
+ prefix_length)
+
+ @staticmethod
def vpp_add_ip_neighbor(node, iface_key, ip_addr, mac_address):
"""Add IP neighbor on DUT node.
diff --git a/resources/libraries/python/Namespaces.py b/resources/libraries/python/Namespaces.py
index 2618f3d19b..2bdcbcb324 100644
--- a/resources/libraries/python/Namespaces.py
+++ b/resources/libraries/python/Namespaces.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -18,21 +18,52 @@ from resources.libraries.python.ssh import exec_cmd_no_error, exec_cmd
class Namespaces:
"""Linux namespace utilities."""
- def __init__(self):
- self._namespaces = []
+ __namespaces = []
- def create_namespace(self, node, namespace_name):
+ @staticmethod
+ def create_namespace(node, namespace, delete_before_create=True):
"""Create namespace and add the name to the list for later clean-up.
:param node: Where to create namespace.
- :param namespace_name: Name for namespace.
+ :param namespace: Name for namespace.
+ :param delete_before_create: Delete namespace prior to create
:type node: dict
- :type namespace_name: str
+ :type namespace: str
+ :type delete_before_create: bool
"""
- cmd = f"ip netns add {namespace_name}"
+ if delete_before_create:
+ Namespaces.delete_namespace(node, namespace)
+ cmd = f"ip netns add {namespace}"
exec_cmd_no_error(node, cmd, sudo=True)
- self._namespaces.append(namespace_name)
+ Namespaces.__namespaces.append(namespace)
+
+ @staticmethod
+ def delete_namespace(node, namespace):
+ """Delete namespace from the node and list.
+
+ :param node: Where to delete namespace.
+ :param namespace: Name for namespace.
+ :param delete_before_create: Delete namespace prior to create
+ :type node: dict
+ :type namespace: str
+ :type delete_before_create: bool
+ """
+ cmd_timeout = 5
+ cmd = f"ip netns delete {namespace}"
+ (ret_code, _, delete_errmsg) = \
+ exec_cmd(node, cmd, timeout=cmd_timeout, sudo=True)
+ if ret_code != 0:
+ cmd = f"ip netns list {namespace}"
+ (stdout, _) = \
+ exec_cmd_no_error(node, cmd, timeout=cmd_timeout, sudo=True)
+ if stdout == namespace:
+ raise RuntimeError(f"Could not delete namespace "
+ f"({namespace}): {delete_errmsg}")
+ try:
+ Namespaces.__namespaces.remove(namespace)
+ except ValueError:
+ pass
@staticmethod
def attach_interface_to_namespace(node, namespace, interface):
@@ -61,6 +92,21 @@ class Namespaces:
)
@staticmethod
+ def add_default_route_to_namespace(node, namespace, default_route):
+ """Add IPv4 default route to interface in namespace.
+
+ :param node: Node where to execute command.
+ :param namespace: Namespace to execute command on.
+ :param default_route: Default route address.
+ :type node: dict
+ :type namespace: str
+ :type default_route: str
+ """
+ cmd = f"ip netns exec {namespace} ip route add default " \
+ f"via {default_route}"
+ exec_cmd_no_error(node, cmd, sudo=True)
+
+ @staticmethod
def create_bridge_for_int_in_namespace(
node, namespace, bridge_name, *interfaces):
"""Setup bridge domain and add interfaces to it.
@@ -85,16 +131,19 @@ class Namespaces:
cmd = f"ip netns exec {namespace} ip link set dev {bridge_name} up"
exec_cmd_no_error(node, cmd, sudo=True)
- def clean_up_namespaces(self, node):
- """Remove all old namespaces.
+ @staticmethod
+ def clean_up_namespaces(node, namespace=None):
+ """Delete all old namespaces.
:param node: Node where to execute command.
+ :param namespace: Namespace to delete, if None delete all namespaces
:type node: dict
+ :type namespace: str
:raises RuntimeError: Namespaces could not be cleaned properly.
"""
- for namespace in self._namespaces:
- print(f"Cleaning namespace {namespace}")
- cmd = f"ip netns delete {namespace}"
- ret_code, _, _ = exec_cmd(node, cmd, timeout=5, sudo=True)
- if ret_code != 0:
- raise RuntimeError(u"Could not delete namespace")
+ if namespace is not None:
+ Namespaces.delete_namespace(node, namespace)
+ return
+
+ for namespace_name in Namespaces.__namespaces:
+ Namespaces.delete_namespace(node, namespace_name)
diff --git a/resources/libraries/python/VPPUtil.py b/resources/libraries/python/VPPUtil.py
index 865775f995..ca63fa6cea 100644
--- a/resources/libraries/python/VPPUtil.py
+++ b/resources/libraries/python/VPPUtil.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -113,8 +113,7 @@ class VPPUtil:
:param node: Topology node.
:type node: dict
"""
- cmd = u"command -v vpp"
- exec_cmd_no_error(node, cmd, message=u"VPP is not installed!")
+ DUTSetup.verify_program_installed(node, u"vpp")
@staticmethod
def adjust_privileges(node):
@@ -155,7 +154,7 @@ class VPPUtil:
:type node: dict
:raises RuntimeError: If VPP service fails to start.
"""
- VPPUtil.verify_vpp_installed(node)
+ DUTSetup.verify_program_installed(node, 'vpp')
try:
# Verify responsiveness of vppctl.
VPPUtil.verify_vpp_started(node)
diff --git a/resources/libraries/python/VatExecutor.py b/resources/libraries/python/VatExecutor.py
index 19b92a6a1a..1de32a2a21 100644
--- a/resources/libraries/python/VatExecutor.py
+++ b/resources/libraries/python/VatExecutor.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -62,7 +62,7 @@ def get_vpp_pid(node):
running on the DUT node.
:rtype: int or list
"""
- pid = PidLib.DUTSetup.get_vpp_pid(node)
+ pid = PidLib.DUTSetup.get_pid(node, u"vpp")
return pid
diff --git a/resources/libraries/python/VppConfigGenerator.py b/resources/libraries/python/VppConfigGenerator.py
index 02f7cf725d..cd225db896 100644
--- a/resources/libraries/python/VppConfigGenerator.py
+++ b/resources/libraries/python/VppConfigGenerator.py
@@ -202,7 +202,7 @@ class VppConfigGenerator:
def add_socksvr(self, socket=Constants.SOCKSVR_PATH):
"""Add socksvr configuration."""
- path = ['socksvr', u"socket-name"]
+ path = [u"socksvr", u"socket-name"]
self.add_config_item(self._nodeconfig, socket, path)
def add_api_segment_gid(self, value=u"vpp"):
@@ -504,6 +504,16 @@ class VppConfigGenerator:
path = [u"tcp", u"preallocated-half-open-connections"]
self.add_config_item(self._nodeconfig, value, path)
+ def add_session_enable(self):
+ """Add session enable."""
+ path = [u"session", u"enable"]
+ self.add_config_item(self._nodeconfig, u"", path)
+
+ def add_session_event_queues_memfd_segment(self):
+ """Add session event queue memfd segment."""
+ path = [u"session", u"evt_qs_memfd_seg"]
+ self.add_config_item(self._nodeconfig, u"", path)
+
def add_session_event_queue_length(self, value):
"""Add session event queue length.
@@ -513,6 +523,15 @@ class VppConfigGenerator:
path = [u"session", u"event-queue-length"]
self.add_config_item(self._nodeconfig, value, path)
+ def add_session_event_queues_segment_size(self, value):
+ """Add session event queue length.
+
+ :param value: Session event queue segment size.
+ :type value: str
+ """
+ path = [u"session", u"evt_qs_seg_size"]
+ self.add_config_item(self._nodeconfig, value, path)
+
def add_session_preallocated_sessions(self, value):
"""Add the number of pre-allocated sessions.
diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py
index b2d106d3ed..7dec51619c 100644
--- a/resources/libraries/python/topology.py
+++ b/resources/libraries/python/topology.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 Cisco and/or its affiliates.
# 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:
@@ -22,6 +22,8 @@ from yaml import safe_load
from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
+from resources.libraries.python.Constants import Constants
+
__all__ = [
u"DICT__nodes", u"Topology", u"NodeType", u"SocketType", u"NodeSubTypeTG"
]
@@ -705,6 +707,22 @@ class Topology:
return None
@staticmethod
+ def get_interface_ip4_prefix_length(node, iface_key):
+ """Get IP4 address prefix length for the interface.
+
+ :param node: Node to get prefix length on.
+ :param iface_key: Interface key from topology file.
+ :type node: dict
+ :type iface_key: str
+ :returns: Prefix length from topology file or the default
+ IP4 prefix length if not found.
+ :rtype: int
+ :raises: KeyError if iface_key is not found.
+ """
+ return node[u"interfaces"][iface_key].get(u"ip4_prefix_length", \
+ Constants.DEFAULT_IP4_PREFIX_LENGTH)
+
+ @staticmethod
def get_adjacent_node_and_interface(nodes_info, node, iface_key):
"""Get node and interface adjacent to specified interface
on local network.