Exemplo n.º 1
0

def analyzer_models(api_client, protocol_counters=None, flow_counters=None):
    ana1 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2.source_id = get_second_port_id(api_client)
    return [ana1, ana2]


with description('Packet Analyzer,', 'packet_analyzer') as self:
    with description('REST API,'):

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

        with description('invalid HTTP methods,'):
            with description('/packet/analyzers,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/analyzers', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/analyzer-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/analyzer-results', 'PUT')).to(
Exemplo n.º 2
0
                           ipv6_interface,
                           make_interface_protocols)
from common.matcher import be_valid_interface, raise_api_exception


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


with description('Interfaces,', 'interfaces') as self:
    with description ('REST API,'):

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

        with description('list,'):
            with description('Eth,'):
                with before.each:
                    intf = self.api.create_interface(example_ipv4_interface(self.api.api_client))
                    expect(intf).to(be_valid_interface)
                    self.intf, self.cleanup = intf, intf

                with description('unfiltered,'):
                    with it('succeeds'):
                        intfs = self.api.list_interfaces()
                        expect(intfs).not_to(be_empty)
                        for intf in intfs:
                            expect(intf).to(be_valid_interface)
                            expect([ i for i in intfs if i.id == self.intf.id ]).not_to(be_empty)
Exemplo n.º 3
0
                            be_valid_dynamic_results)


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


def approximately_equal(a, b):
    return abs(a - b) < 0.01


with description('CPU Generator Module', 'cpu') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.CpuGeneratorApi(service.client())
        if not check_modules_exists(service.client(), 'cpu'):
            self.skip()

    with after.all:
        try:
            for gen in self._api.list_cpu_generators():
                if gen.running:
                    self._api.stop_cpu_generator(gen.id)
                self._api.delete_cpu_generator(gen.id)

            self._process.terminate()
            self._process.wait()
        except AttributeError:
            pass
Exemplo n.º 4
0
def pcap_icmp_echo_request_lengths(pcap_file):
    lengths = []
    icmp_type = scapy.all.ICMP(type='echo-request').type
    for packet in scapy.all.rdpcap(pcap_file):
        if 'ICMP' in packet and packet['ICMP'].type == icmp_type:
            lengths.append(len(packet))
    return lengths


with description('Packet Capture,', 'packet_capture') as self:
    with description('REST API,'):

        with before.all:
            service = Service(CONFIG.service('dataplane'))
            self.process = service.start()
            self.api = client.api.PacketCapturesApi(service.client())
            self.intf_api = client.api.InterfacesApi(self.api.api_client)

            # 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))

        with description('invalid HTTP methods,'):
            with description('/packet/captures,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/captures', 'PUT')).to(
Exemplo n.º 5
0
    gen1 = generator_model(api_client)
    gen1.target_id = ports[0].id
    gen2 = generator_model(api_client)
    gen2.target_id = ports[1].id

    return [gen1, gen2]


with description('Packet Generator,', 'packet_generator') as self:
    with description('REST API'):

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

        with description('invalid HTTP methods,'):
            with description('/packet/generators,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/generators', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/generator-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/generator-results', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET"}))

            with description('/packet/tx-flows,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/tx-flows', 'PUT')).to(
Exemplo n.º 6
0
                           bulk_stop_model, wait_for_file_initialization_done)
from common.matcher import (be_valid_block_device, be_valid_block_file,
                            be_valid_block_generator,
                            be_valid_block_generator_result, has_location,
                            raise_api_exception, be_valid_dynamic_results)

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

with description('Block,', 'block') as self:
    with description('REST API,'):
        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.BlockGeneratorApi(service.client())
            if not check_modules_exists(service.client(), 'block'):
                self.skip()

        with description('invalid HTTP methods,'):
            with description('/block-devices,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-devices', 'PUT')).to(
                            raise_api_exception(405, headers={'Allow': "GET"}))

            with description('/block-files,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-files', 'PUT')).to(
                            raise_api_exception(405,
Exemplo n.º 7
0
    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))

            with description('client interface,'):
                with it('succeeds'):
Exemplo n.º 8
0

def analyzer_models(api_client, protocol_counters=None, flow_counters=None):
    ana1 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2.source_id = get_second_port_id(api_client)
    return [ana1, ana2]


with description('Packet Analyzer,', 'packet_analyzer') as self:
    with description('REST API,'):

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

        with description('invalid HTTP methods,'):
            with description('/packet/analyzers,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/analyzers', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/analyzer-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/analyzer-results', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET"}))
Exemplo n.º 9
0
        flow = gen_api.get_tx_flow(flow_id)
        expect(flow).to(be_valid_transmit_flow)

    expect([f.id for f in gen_api.list_tx_flows() if f.id in gen_result.flows]).not_to(be_empty)


###
# Begin test proper
###
with description('Packet back to back', 'packet_b2b') as self:
    with description('generation and analysis,'):

        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.client = service.client()
            self.analyzer_api = client.api.PacketAnalyzersApi(service.client())
            self.generator_api = client.api.PacketGeneratorsApi(service.client())

        with description('with single traffic definition,'):
            with description('without signatures,'):
                with it('succeeds'):
                    ana_result, gen_result = configure_and_run_test(self.client,
                                                                    ANALYZER_CONFIG_NO_SIGS,
                                                                    GENERATOR_CONFIG_NO_SIGS)

                    # Validate results
                    exp_flow_count = 1
                    expect(len(ana_result.flows)).to(equal(exp_flow_count))
                    expect(len(gen_result.flows)).to(equal(exp_flow_count))
Exemplo n.º 10
0
import os

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

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

with description('Stacks,', 'stacks') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.StacksApi(service.client())

    with description('list,'):
        with it('returns valid stacks'):
            stacks = self.api.list_stacks()
            expect(stacks).not_to(be_empty)
            for stack in stacks:
                expect(stack).to(be_valid_stack)

        with description('unsupported method'):
            with it('returns 405'):
                expect(
                    lambda: self.api.api_client.call_api('/stacks', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

    with description('get,'):
Exemplo n.º 11
0
import client.models
from common import Config, Service
from common.matcher import be_valid_port, raise_api_exception
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('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())
            if not check_modules_exists(service.client(), 'packetio'):
                self.skip()

        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.º 12
0
class has_location(Matcher):
    def __init__(self, expected):
        self._expected = expected

    def _match(self, subject):
        expect(subject).to(have_key('Location'))
        return subject['Location'] == self._expected, []


has_json_content_type = _has_json_content_type()

with description('Memory Generator Module', 'memory') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.MemoryGeneratorApi(service.client())

    with after.all:
        try:
            self._process.terminate()
            self._process.wait()
        except AttributeError:
            pass

    with description('/memory-info'):
        with context('GET'):
            with before.all:
                self._result = self._api.memory_info_with_http_info(
                    _return_http_data_only=False)

            with it('succeeded'):
Exemplo n.º 13
0
class has_location(Matcher):
    def __init__(self, expected):
        self._expected = expected

    def _match(self, subject):
        expect(subject).to(have_key('Location'))
        return subject['Location'] == self._expected, []


has_json_content_type = _has_json_content_type()

with description('CPU Generator Module', 'cpu') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.CpuGeneratorApi(service.client())

    with after.all:
        try:
            for gen in self._api.list_cpu_generators():
                if gen.running:
                    self._api.stop_cpu_generator(gen.id)
                self._api.delete_cpu_generator(gen.id)

            self._process.terminate()
            self._process.wait()
        except AttributeError:
            pass

    with description('/cpu-info'):
        with context('GET'):
Exemplo n.º 14
0
class has_location(Matcher):
    def __init__(self, expected):
        self._expected = CONFIG.service().base_url + expected

    def _match(self, subject):
        expect(subject).to(have_key('Location'))
        return subject['Location'] == self._expected, []


with description('Block,', 'block') as self:
    with description('REST API,'):
        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.BlockGeneratorApi(service.client())

        with description('invalid HTTP methods,'):
            with description('/block-devices,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-devices', 'PUT')).to(
                            raise_api_exception(405, headers={'Allow': "GET"}))

            with description('/block-files,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-files', 'PUT')).to(
                            raise_api_exception(405,
                                                headers={'Allow':
                                                         "GET, POST"}))
Exemplo n.º 15
0
    return s


def get_system_timesource(id=None):
    s = client.models.TimeSource()
    s.kind = 'system'
    s.id = 'test-source-' + str(id)

    return s


with description('Timesync,', 'timesync') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.TimeSyncApi(service.client())

    with description('counters,'):
        with description('unsupported method,'):
            with it('returns 405'):
                expect(lambda: self.api.api_client.call_api(
                    '/time-counters', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

        with description('GET,'):
            with description('list,'):
                with it('succeeds'):
                    counters = self.api.list_time_counters()
                    expect(counters).not_to(be_empty)
                    for counter in counters:
                        expect(counter).to(be_valid_counter)
Exemplo n.º 16
0
    timestamps = pcap_packet_timestamps(pacp_file)
    prev_ts = None
    for ts in timestamps:
        expect(ts).to(be_above(0))
        if (prev_ts):
            expect(ts).to(be_above_or_equal(prev_ts))
        prev_ts = ts


with description('Packet Capture,', 'packet_capture') as self:
    with description('REST API,'):

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

            # 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))

        with description('invalid HTTP methods,'):
            with description('/packet/captures,'):
Exemplo n.º 17
0
    gen1 = generator_model(api_client)
    gen1.target_id = ports[0].id
    gen2 = generator_model(api_client)
    gen2.target_id = ports[1].id

    return [gen1, gen2]


with description('Packet Generator,', 'packet_generator') as self:
    with description('REST API'):

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

        with description('invalid HTTP methods,'):
            with description('/packet/generators,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/generators', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/generator-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/generator-results', 'PUT')).to(
Exemplo n.º 18
0
                           wait_for_buffer_initialization_done)
from common.matcher import (has_location, has_json_content_type,
                            raise_api_exception, be_valid_memory_info,
                            be_valid_memory_generator,
                            be_valid_memory_generator_result,
                            be_valid_dynamic_results)

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

with description('Memory Generator Module', 'memory') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.MemoryGeneratorApi(service.client())
        if not check_modules_exists(service.client(), 'memory'):
            self.skip()

    with after.all:
        try:
            for gen in self.api.list_memory_generators():
                if gen.running:
                    self.api.stop_memory_generator(gen.id)
                self.api.delete_memory_generator(gen.id)
        except AttributeError:
            pass

        try:
            self._process.terminate()
            self._process.wait()
Exemplo n.º 19
0
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(
                            raise_api_exception(405, headers={'Allow': "GET"}))
Exemplo n.º 20
0
import client.api
import client.models
from common import Config, Service
from common.matcher import be_valid_stack, raise_api_exception
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('Stacks,', 'stacks') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.StacksApi(service.client())
        if not check_modules_exists(service.client(), 'packet-stack'):
            self.skip()

    with description('list,'):
        with it('returns valid stacks'):
            stacks = self.api.list_stacks()
            expect(stacks).not_to(be_empty)
            for stack in stacks:
                expect(stack).to(be_valid_stack)

        with description('unsupported method'):
            with it('returns 405'):
                expect(
                    lambda: self.api.api_client.call_api('/stacks', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))
Exemplo n.º 21
0
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')
                        expect(ports).not_to(be_empty)
                        for port in ports:
Exemplo n.º 22
0
    expect(ana).to(be_valid_packet_analyzer)

    return ana


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

with description('MAC Learning,', 'learning') as self:
    with description('REST API'):

        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.ana_api = client.api.PacketAnalyzersApi(service.client())
            self.gen_api = client.api.PacketGeneratorsApi(service.client())
            self.intf_api = client.api.InterfacesApi(service.client())
            if not check_modules_exists(service.client(), 'packet-generator',
                                        'packet-analyzer'):
                self.skip()

        with description('packet-generator, '):
            with description('IPv4, '):
                with before.each:
                    self.source_ip = "192.168.22.10"
                    self.source_mac = "aa:bb:cc:dd:ee:01"
                    self.target_ip = "192.168.22.1"
                    self.intf1 = ipv4_interface(self.intf_api.api_client,
                                                method="static",
                                                ipv4_address=self.source_ip,