aboutsummaryrefslogtreecommitdiffstats
path: root/samples/ha-baremetal.yaml
AgeCommit message (Collapse)AuthorFilesLines
2017-02-17Update missing license headersDeepak S1-0/+8
Change-Id: I063fd37fe25754c94d164ae5a209d15b69322093 Signed-off-by: Deepak S <deepak.s@linux.intel.com>
2016-01-10The secondi HA test case-shutdown controllerwym_libra1-0/+45
1) add "attacker_baremetal.py" for fault injection 2) modify the monitor to excute on remote node after ssh connection 3) move all shell scripts together JIRA: YARDSTICK-182 Change-Id: Ibb9dc908224ddb8b99a0140b75c1a046503f6dfb Signed-off-by: wym_libra <yimin.wang@huawei.com>
'n101' href='#n101'>101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
# Copyright 2017-2018 Intel Corporation., Tieto
#
# 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.

"""VSPERF VPP implementation using DPDK and vhostuser vports
"""

import os
import copy
import re
import pexpect

from src.dpdk import dpdk
from conf import settings as S
from vswitches.vswitch import IVSwitch
from tools import tasks
from tools.version import Version

# pylint: disable=too-many-public-methods
class VppDpdkVhost(IVSwitch, tasks.Process):
    """ VPP with DPDK support
    """
    _proc_name = 'vpp'
    _bridge_idx_counter = 100

    def __init__(self):
        """See IVswitch for general description
        """
        super().__init__()
        name, ext = os.path.splitext(S.getValue('LOG_FILE_VPP'))
        rename_vpplf = "{name}_{uid}{ex}".format(name=name,
                                                 uid=S.getValue(
                                                     'LOG_TIMESTAMP'),
                                                 ex=ext)
        self._logfile = os.path.join(S.getValue('RESULTS_PATH'), rename_vpplf)
        self._expect = r'vpp#'
        self._cmd_template = ['sudo', '-E', S.getValue('TOOLS')['vpp']]
        self._phy_ports = []
        self._virt_ports = []
        self._vpp_ctl = ['sudo', S.getValue('TOOLS')['vppctl']]

        # configure DPDK NICs
        tmp_args = copy.deepcopy(S.getValue('VSWITCH_VPP_ARGS'))
        if 'dpdk' not in tmp_args:
            tmp_args['dpdk'] = []

        # override socket-mem settings
        for tmp_arg in tmp_args['dpdk']:
            if tmp_arg.startswith('socket-mem'):
                tmp_args['dpdk'].remove(tmp_arg)
        tmp_args['dpdk'].append('socket-mem ' +
                                ','.join(S.getValue('DPDK_SOCKET_MEM')))

        # create directory for vhostuser sockets if needed
        if not os.path.exists(S.getValue('TOOLS')['ovs_var_tmp']):
            tasks.run_task(['sudo', 'mkdir', '-p',
                            S.getValue('TOOLS')['ovs_var_tmp']], self._logger)

        # configure path to the plugins
        tmp_args['plugin_path'] = S.getValue('TOOLS')['vpp_plugin_path']

        # cli sock file must be used for VPP 17.10 and newer
        if S.getValue('VSWITCH_VPP_CLI_SOCK'):
            self._vpp_ctl += ['-s', S.getValue('VSWITCH_VPP_CLI_SOCK')]
            tmp_args['unix'].append('cli-listen {}'.format(
                S.getValue('VSWITCH_VPP_CLI_SOCK')))

        mqs = int(S.getValue('VSWITCH_DPDK_MULTI_QUEUES'))
        tmp_rxqs = ''
        if mqs:
            tmp_rxqs = " {{ num-rx-queues {} }}".format(mqs)

        # configure physical ports
        for nic in S.getValue('NICS'):
            tmp_args['dpdk'].append("dev {}{}".format(nic['pci'], tmp_rxqs))
        self._vswitch_args = self._process_vpp_args(tmp_args)

    def _get_nic_info(self, key='Name'):
        """Read NIC info from VPP and return NIC details in a dictionary
           indexed by given ``key``

        :param key: Name of the key to be used for indexing result dictionary

        :returns: Dictionary with NIC infos including their PCI addresses
        """
        result = {}
        output = self.run_vppctl(['show', 'hardware', 'brief'])
        # parse output and store basic info about NICS
        ifaces = output[0].split('\n')
        keys = ifaces[0].split()
        keys.append('Pci')
        keyidx = keys.index(key)
        for iface in ifaces[1:]:
            tmpif = iface.split()
            if not tmpif:
                continue
            # get PCI address of given interface
            output = self.run_vppctl(['show', 'hardware', tmpif[1], 'detail'])
            match = re.search(r'pci address:\s*([\d:\.]+)', output[0])
            if match:
                # normalize PCI address, e.g. 0000:05:10.01 => 0000:05:10.1
                tmp_pci = match.group(1).split('.')
                tmp_pci[1] = str(int(tmp_pci[1]))
                tmpif.append('.'.join(tmp_pci))
            else:
                tmpif.append(None)
            # store only NICs with reasonable index
            if tmpif[keyidx] is not None:
                result[tmpif[keyidx]] = dict(zip(keys, tmpif))

        return result

    def _process_vpp_args(self, args):
        """Produce VPP CLI args from input dictionary ``args``
        """
        cli_args = []
        for cfg_key in args:
            cli_args.append(cfg_key)
            if isinstance(args[cfg_key], str):
                cli_args.append(args[cfg_key])
            else:
                cli_args.append("{{ {} }}".format(' '.join(args[cfg_key])))

        self._logger.debug("VPP CLI args: %s", cli_args)
        return cli_args

    def start(self):
        """Activates DPDK kernel modules and starts VPP

        :raises: pexpect.EOF, pexpect.TIMEOUT
        """
        dpdk.init()
        self._logger.info("Starting VPP...")

        self._cmd = self._cmd_template + self._vswitch_args

        try:
            tasks.Process.start(self)
            self.relinquish()
        except (pexpect.EOF, pexpect.TIMEOUT) as exc:
            self._logger.error("Exception during VPP start.")
            raise exc

        self._logger.info("VPP...Started.")

    def stop(self):
        """See IVswitch for general description

        Kills VPP and removes DPDK kernel modules.
        """
        self._logger.info("Terminating VPP...")
        self.kill()
        self._logger.info("VPP...Terminated.")
        dpdk.cleanup()

    def kill(self, signal='-15', sleep=10):
        """See IVswitch for general description

        Kills ``vpp``
        """
        if self.is_running():
            # try to get VPP pid
            output = self.run_vppctl(['show', 'version', 'verbose'])
            match = re.search(r'Current PID:\s*([0-9]+)', output[0])
            if match:
                vpp_pid = match.group(1)
                tasks.terminate_task(vpp_pid, logger=self._logger)

            # in case, that pid was not detected or sudo envelope
            # has not been terminated yet
            tasks.Process.kill(self, signal, sleep)

    def get_version(self):
        """See IVswitch for general description
        """
        versions = []
        output = self.run_vppctl(['show', 'version', 'verbose'])
        if output[1]:
            self._logger.warning("VPP version can not be read!")
            return versions

        match = re.search(r'Version:\s*(.+)', output[0])
        if match:
            versions.append(Version(S.getValue('VSWITCH'), match.group(1)))

        match = re.search(r'DPDK Version:\s*DPDK (.+)', output[0])
        if match:
            versions.append(Version('dpdk', match.group(1)))

        return versions

    def add_switch(self, switch_name, dummy_params=None):
        """See IVswitch for general description
        """
        # pylint: disable=unused-argument
        if switch_name in self._switches:
            self._logger.warning("switch %s already exists...", switch_name)
        else:
            self._switches[switch_name] = self._bridge_idx_counter
            self._bridge_idx_counter += 1

    def del_switch(self, switch_name):
        """See IVswitch for general description
        """
        if switch_name in self._switches:
            del self._switches[switch_name]

    def add_phy_port(self, dummy_switch_name):
        """See IVswitch for general description
        :raises: RuntimeError
        """
        # pylint: disable=unused-argument
        # get list of physical interfaces with PCI addresses
        vpp_nics = self._get_nic_info(key='Pci')
        # check if there are any NICs left
        if len(self._phy_ports) >= len(S.getValue('NICS')):
            raise RuntimeError("Can't add phy port! There are only {} ports defined "
                               "by WHITELIST_NICS parameter!".format(len(S.getValue('NICS'))))

        nic = S.getValue('NICS')[len(self._phy_ports)]
        if not nic['pci'] in vpp_nics:
            raise RuntimeError('VPP cannot access nic with PCI address: {}'.format(nic['pci']))
        nic_name = vpp_nics[nic['pci']]['Name']
        self._phy_ports.append(nic_name)
        self.run_vppctl(['set', 'int', 'state', nic_name, 'up'])
        return (nic_name, vpp_nics[nic['pci']]['Idx'])

    def add_vport(self, dummy_switch_name):
        """See IVswitch for general description
        """
        # pylint: disable=unused-argument
        socket_name = S.getValue('TOOLS')['ovs_var_tmp'] + 'dpdkvhostuser' + str(len(self._virt_ports))
        if S.getValue('VSWITCH_VHOSTUSER_SERVER_MODE'):
            mode = ['server']
        else:
            mode = []
        output = self.run_vppctl(['create', 'vhost-user', 'socket', socket_name] + mode +
                                 S.getValue('VSWITCH_VPP_VHOSTUSER_ARGS'))
        if output[0].find('returned') >= 0:
            raise RuntimeError('VPP VhostUser interface cannot be created.')
        nic_name = output[0].strip()
        self._virt_ports.append(nic_name)
        self.run_vppctl(['set', 'int', 'state', nic_name, 'up'])
        return (nic_name, None)

    def del_port(self, switch_name, port_name):
        """See IVswitch for general description
        """
        if port_name in self._phy_ports:
            self.run_vppctl(['set', 'int', 'state', port_name, 'down'])
            self._phy_ports.remove(port_name)
        elif port_name in self._virt_ports:
            self.run_vppctl(['set', 'int', 'state', port_name, 'down'])
            self.run_vppctl(['delete', 'vhost-user', port_name])
            self._virt_ports.remove(port_name)
        else:
            self._logger.warning("Port %s is not configured.", port_name)

    def add_l2patch(self, port1, port2):
        """Create l2patch connection between given ports
        """
        self.run_vppctl(['test', 'l2patch', 'rx', port1, 'tx', port2])

    def add_xconnect(self, port1, port2):
        """Create l2patch connection between given ports
        """
        self.run_vppctl(['set', 'interface', 'l2', 'xconnect', port1, port2])

    def add_bridge(self, switch_name, port1, port2):
        """Add given ports to bridge ``switch_name``
        """
        self.run_vppctl(['set', 'interface', 'l2', 'bridge', port1,
                         str(self._switches[switch_name])])
        self.run_vppctl(['set', 'interface', 'l2', 'bridge', port2,
                         str(self._switches[switch_name])])

    def add_connection(self, switch_name, port1, port2, traffic=None):
        """See IVswitch for general description

        :raises: RuntimeError
        """
        if traffic:
            self._logger.warning("VPP add_connection() does not support 'traffic' options.")

        mode = S.getValue('VSWITCH_VPP_L2_CONNECT_MODE')
        if mode == 'l2patch':
            self.add_l2patch(port1, port2)
        elif mode == 'xconnect':
            self.add_xconnect(port1, port2)
        elif mode == 'bridge':
            self.add_bridge(switch_name, port1, port2)
        else:
            raise RuntimeError('VPP: Unsupported l2 connection mode detected %s' % mode)

    def del_l2patch(self, port1, port2):
        """Remove l2patch connection between given ports

        :param port1: port to be used in connection
        :param port2: port to be used in connection
        """
        self.run_vppctl(['test', 'l2patch', 'rx', port1, 'tx', port2, 'del'])

    def del_xconnect(self, port1, port2):
        """Remove xconnect connection between given ports
        """
        self.run_vppctl(['set', 'interface', 'l3', port1])
        self.run_vppctl(['set', 'interface', 'l3', port2])

    def del_bridge(self, _dummy_switch_name, port1, port2):
        """Remove given ports from the bridge
        """
        self.run_vppctl(['set', 'interface', 'l3', port1])
        self.run_vppctl(['set', 'interface', 'l3', port2])

    def del_connection(self, switch_name, port1=None, port2=None):
        """See IVswitch for general description

        :raises: RuntimeError
        """
        if port1 and port2:
            mode = S.getValue('VSWITCH_VPP_L2_CONNECT_MODE')
            if mode == 'l2patch':
                self.del_l2patch(port1, port2)
            elif mode == 'xconnect':
                self.del_xconnect(port1, port2)
            elif mode == 'bridge':
                self.del_bridge(switch_name, port1, port2)
            else:
                raise RuntimeError('VPP: Unsupported l2 connection mode detected %s' % mode)

    def dump_l2patch(self):
        """Dump l2patch connections
        """
        self.run_vppctl(['show', 'l2patch'])

    def dump_xconnect(self):
        """Dump l2 xconnect connections
        """
        self.run_vppctl(['show', 'mode'] + self._phy_ports + self._virt_ports)

    def dump_bridge(self, switch_name):
        """Show bridge details

        :param switch_name: switch on which to operate
        """
        self.run_vppctl(['show', 'bridge-domain', str(self._switches[switch_name]), 'int'])

    def dump_connections(self, switch_name):
        """See IVswitch for general description

        :raises: RuntimeError
        """
        mode = S.getValue('VSWITCH_VPP_L2_CONNECT_MODE')
        if mode == 'l2patch':
            self.dump_l2patch()
        elif mode == 'xconnect':
            self.dump_xconnect()
        elif mode == 'bridge':
            self.dump_bridge(switch_name)
        else:
            raise RuntimeError('VPP: Unsupported l2 connection mode detected %s' % mode)

    def run_vppctl(self, args, check_error=False):
        """Run ``vppctl`` with supplied arguments.

        :param args: Arguments to pass to ``vppctl``
        :param check_error: Throw exception on error

        :return: None
        """
        cmd = self._vpp_ctl + args
        return tasks.run_task(cmd, self._logger, 'Running vppctl...', check_error)

    #
    # Validate methods
    #
    def validate_add_switch(self, _dummy_result, switch_name, _dummy_params=None):
        """Validate - Create a new logical switch with no ports
        """
        return switch_name in self._switches

    def validate_del_switch(self, _dummy_result, switch_name):
        """Validate removal of switch
        """
        return not self.validate_add_switch(_dummy_result, switch_name)

    def validate_add_phy_port(self, result, _dummy_switch_name):
        """ Validate that physical port was added to bridge.
        """
        return result[0] in self._phy_ports

    def validate_add_vport(self, result, _dummy_switch_name):
        """ Validate that virtual port was added to bridge.
        """
        return result[0] in self._virt_ports

    def validate_del_port(self, _dummy_result, _dummy_switch_name, port_name):
        """ Validate that port_name was removed from bridge.
        """
        return not (port_name in self._phy_ports or port_name in self._virt_ports)

    # pylint: disable=no-self-use
    def validate_add_connection(self, _dummy_result, _dummy_switch_name, _dummy_port1,
                                _dummy_port2, _dummy_traffic=None):
        """ Validate that connection was added
        """
        return True

    def validate_del_connection(self, _dummy_result, _dummy_switch_name, _dummy_port1,
                                _dummy_port2):
        """ Validate that connection was deleted
        """
        return True

    def validate_dump_connections(self, _dummy_result, _dummy_switch_name):
        """ Validate dump connections call
        """
        return True

    def validate_run_vppctl(self, result, _dummy_args, _dummy_check_error=False):
        """validate execution of ``vppctl`` with supplied arguments.
        """
        # there shouldn't be any stderr
        return not result[1]

    #
    # Non implemented methods
    #
    def add_route(self, switch_name, network, destination):
        """See IVswitch for general description
        """
        raise NotImplementedError()

    def set_tunnel_arp(self, ip_addr, mac_addr, switch_name):
        """See IVswitch for general description
        """
        raise NotImplementedError()

    def add_tunnel_port(self, switch_name, remote_ip, tunnel_type='vxlan', params=None):
        """See IVswitch for general description
        """
        raise NotImplementedError()

    def get_ports(self, switch_name):
        """See IVswitch for general description
        """
        raise NotImplementedError()