Exemplo n.º 1
0
def do_packet_ping(api_client, src_id, dst_id, socket_type):
    """Perform a packet ping from src to dst using the specified binary"""
    shim = Service(CONFIG.shim())

    with open(os.devnull, 'w') as null:
        p = subprocess.Popen(packet_ping_command(api_client, src_id, dst_id, socket_type),
                             stdout=null, stderr=null,
                             env={'LD_PRELOAD': shim.config.path,
                                  'OP_BINDTODEVICE': src_id})
        p.wait()
        expect(p.returncode).to(equal(0))
Exemplo n.º 2
0
def do_ping(api_client, ping_binary, src_id, dst_id, domain):
    """Perform a ping from src to dst using the specified binary"""
    shim = Service(CONFIG.shim())
    dst_ip = get_interface_address(api_client, dst_id, domain)

    with open(os.devnull, 'w') as null:
        p = subprocess.Popen(ping_command(ping_binary, dst_ip, domain),
                             stdout=null, stderr=null,
                             env={'LD_PRELOAD': shim.config.path,
                                  'OP_BINDTODEVICE': src_id})
        p.wait()
        expect(p.returncode).to(equal(0))
Exemplo n.º 3
0
import os

import client.api
import client.models
from common import Config, Service
from common.matcher import be_valid_port, raise_api_exception


CONFIG = Config(os.path.join(os.path.dirname(__file__), os.environ.get('MAMBA_CONFIG', 'config.yaml')))


with description('Ports,', 'ports') as self:
    with description('REST API,'):

        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.PortsApi(service.client())

        with description('list,'):
            with description('unfiltered,'):
                with it('returns valid ports'):
                    ports = self.api.list_ports()
                    expect(ports).not_to(be_empty)
                    for port in ports:
                        expect(port).to(be_valid_port)

            with description('filtered,'):
                with description('known existing kind,'):
                    with it('returns valid ports of that kind'):
                        ports = self.api.list_ports(kind='dpdk')
Exemplo n.º 4
0
def create_connected_endpoints(api_client, reader_id, writer_id, domain, protocol, null):
    """
    We need to create the server endpoint before the client endpoint, otherwise we
    run the risk of the client failing to connect before the server is started
    This function juggles the order as appropriate and returns the reader/writer
    subprocesses running the nc instances.  It also waits for verification that
    the client process has connected before returning.
    """

    shim = Service(CONFIG.shim())
    reader = None
    writer = None

    server_id = reader_id if is_server_interface(reader_id) else writer_id
    server_ip_addr = get_interface_address(api_client, server_id, domain)

    server_input = None
    if is_server_interface(writer_id):
        writer = subprocess.Popen(nc_command(server_ip_addr, version=domain, protocol=protocol, listen=True),
                                  stdin=subprocess.PIPE,
                                  stdout=null,
                                  stderr=subprocess.PIPE,
                                  close_fds=True,
                                  env={'LD_PRELOAD': shim.config.path,
                                       'OP_BINDTODEVICE': writer_id})
        server_input = writer.stdin

    if is_server_interface(reader_id):
        reader = subprocess.Popen(nc_command(server_ip_addr, version=domain, protocol=protocol, listen=True),
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  close_fds=True,
                                  env={'LD_PRELOAD': shim.config.path,
                                       'OP_BINDTODEVICE': reader_id})
        server_input = reader.stdin

    try:
        # Use a writable stdin as a proxy for a listening server.  Using
        # the verbose option to nc can trigger a getnameinfo() call, which
        # can fail inside a container.
        wait_until_writable(server_input)
    except Exception as e:
        if reader: reader.kill()
        if writer: writer.kill()
        raise e

    client_output = None
    if not is_server_interface(writer_id):
        writer = subprocess.Popen(nc_command(server_ip_addr, version=domain, protocol=protocol, verbose=True),
                                  stdin=subprocess.PIPE,
                                  stdout=null,
                                  stderr=subprocess.PIPE,
                                  close_fds=True,
                                  env={'LD_PRELOAD': shim.config.path,
                                       'OP_BINDTODEVICE': writer_id})
        client_output = writer.stderr

    if not is_server_interface(reader_id):
        reader = subprocess.Popen(nc_command(server_ip_addr, version=domain, protocol=protocol, verbose=True),
                                  stdin=null,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  close_fds=True,
                                  env={'LD_PRELOAD': shim.config.path,
                                       'OP_BINDTODEVICE': reader_id})
        client_output = reader.stderr

    try:
        wait_for_keyword(client_output, "succeeded")
    except Exception as e:
        reader.kill()
        writer.kill()
        raise e

    return reader, writer
Exemplo n.º 5
0
    shim = Service(CONFIG.shim())
    dst_ip = get_interface_address(api_client, dst_id, domain)

    with open(os.devnull, 'w') as null:
        p = subprocess.Popen(ping_command(ping_binary, dst_ip, domain),
                             stdout=null, stderr=null,
                             env={'LD_PRELOAD': shim.config.path,
                                  'OP_BINDTODEVICE': src_id})
        p.wait()
        expect(p.returncode).to(equal(0))


with description('Dataplane,', 'dataplane') as self:

    with before.all:
        service = Service(CONFIG.service('dataplane'))
        self.process = service.start()
        self.api = client.api.InterfacesApi(service.client())
        if not check_modules_exists(service.client(), 'packetio'):
            self.skip()

    with description('ipv4,', 'dataplane:ipv4'):
        with description('ping,', 'dataplane:ipv4:ping'):
            with before.all:
                # By default, ping is a privileged process.  We need it unprivileged
                # to use LD_PRELOAD, so just make a copy as a regular user.
                self.temp_dir = tempfile.mkdtemp()
                shutil.copy(PING, self.temp_dir)
                self.temp_ping = os.path.join(self.temp_dir, os.path.basename(PING))
                expect(os.path.isfile(self.temp_ping))
Exemplo n.º 6
0
from mamba import description, before, after, it
from expects import *
import os

import client.api
import client.models
from common import Config, Service
from common.matcher import be_valid_module, raise_api_exception

CONFIG = Config(
    os.path.join(os.path.dirname(__file__),
                 os.environ.get('MAMBA_CONFIG', 'config.yaml')))

with description('Modules, ', 'modules') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.ModulesApi(service.client())

    with description('list, '):
        with description('all, '):
            with it('returns list of modules'):
                modules = self.api.list_modules()
                expect(modules).not_to(be_empty)
                for module in modules:
                    expect(module).to(be_valid_module)

            with description('unsupported method, '):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/modules', 'PUT')).to(
Exemplo n.º 7
0
from mamba import description, before, after, it
from expects import expect
import os

import client.api
from common import Config, Service
from common.helper import check_modules_exists

CONFIG = Config(
    os.path.join(os.path.dirname(__file__),
                 os.environ.get('MAMBA_CONFIG', 'config.yaml')))

with description('PacketIO arguments,', 'packetio_args'):
    with description('Empty core mask,'):
        with before.all:
            service = Service(CONFIG.service('packetio-args-1'))
            self.process = service.start()
            self.api = client.api.PortsApi(service.client())
            if not check_modules_exists(service.client(), 'packetio'):
                self.skip()

        with description('binary started,'):
            with it('has no port handlers'):
                expect(
                    lambda: self.api.list_ports().to(raise_api_exception(405)))

        with after.all:
            try:
                self.process.terminate()
                self.process.wait()
            except AttributeError:
        time.sleep(initial_sleep)

    while True:
        result = gen_client.get_packet_generator_result(result_id)
        expect(result).to(be_valid_packet_generator_result)
        if result.flow_counters.packets_actual > 0 and not result.active:
            break
        time.sleep(POLL_INTERVAL)


with description('Packet Generator Drop Mode,',
                 'packet_generator_drop') as self:
    with description('Drops and Stops'):

        with before.all:
            service = Service(CONFIG.service('packet-generator-drop'))
            self.process = service.start()
            self.api = client.api.PacketGeneratorsApi(service.client())
            if not check_modules_exists(service.client(), 'packet-generator'):
                self.skip()

        with description('overload transmit path,'):
            with it('stops on-time and drops packets'):
                time = client.models.TrafficDurationTime()
                time.value = 100
                time.units = "milliseconds"
                duration = client.models.TrafficDuration()
                duration.time = time
                gen = packet_generator_model(self.api.api_client)
                gen.config.duration = duration