Пример #1
0
def api():
    """Demonstrates creating a top level Api instance.
    """
    from .snappiserver import SnappiServer
    pytest.snappiserver = SnappiServer().start()
    import snappi
    yield snappi.api(location='http://127.0.0.1:80')
Пример #2
0
def api():
    """Demonstrates creating a top level Api instance.
    """
    from .snappiserver import SnappiServer
    pytest.snappiserver = SnappiServer().start()
    import snappi
    #yield snappi.api(host='http://10.36.75.151:443',ext='ixnetwork')
    yield snappi.api(host='http://10.36.82.84:443', ext='ixnetwork')
Пример #3
0
 def _wait_until_ready(self):
     api = snappi.api(host='http://127.0.0.1:80')
     while True:
         try:
             api.get_config()
             break
         except Exception:
             pass
         time.sleep(.1)
Пример #4
0
def get_flow_metrics():
    global CONFIG
    api = snappi.api()
    flow_metrics_request = api.flow_metrics_request()
    flow_metrics_request.deserialize(request.data.decode('utf-8'))
    flow_metrics = api.flow_metrics()
    for flow in CONFIG.flows:
        flow_metrics.metric(name=flow.name, frames_tx=10000, frames_rx=10000)
    return Response(flow_metrics.serialize(),
                    mimetype='application/json',
                    status=200)
Пример #5
0
def get_port_metrics():
    global CONFIG
    api = snappi.api()
    port_metrics_request = api.port_metrics_request()
    port_metrics_request.deserialize(request.data.decode('utf-8'))
    port_metrics = api.port_metrics()
    for port in CONFIG.ports:
        port_metrics.metric(name=port.name, frames_tx=10000, frames_rx=10000)
    return Response(port_metrics.serialize(),
                    mimetype='application/json',
                    status=200)
Пример #6
0
def set_config():
    global CONFIG
    config = snappi.api().config()
    config.deserialize(request.data.decode('utf-8'))
    test = config.options.port_options.location_preemption
    if test is not None and isinstance(test, bool) is False:
        return Response(status=590,
                        response=json.dumps({'detail': 'invalid data type'}),
                        headers={'Content-Type': 'application/json'})
    else:
        CONFIG = config
        return Response(status=200)
Пример #7
0
def test_hints():
    """Demonstrate hinting of Snappi objects
    """
    api = snappi.api()
    config = api.config()
    p1, p2, p3 = config.ports.port(name='P1').port(name='P2').port(name='P3')
    p1 = config.ports[0]
    p2 = config.ports[1]
    p1, p2, p3 = config.ports
    config.ports.port().port()
    for port in config.ports:
        print(port)
    print(p1, p2)
Пример #8
0
def snappi_api(snappi_api_serv_ip, snappi_api_serv_port):
    """
    Fixture for session handle,
    for creating snappi objects and making API calls.
    Args:
        snappi_api_serv_ip (pytest fixture): snappi_api_serv_ip fixture
        snappi_api_serv_port (pytest fixture): snappi_api_serv_port fixture.
    """
    location = "https://" + snappi_api_serv_ip + ":" + str(
        snappi_api_serv_port)
    # TODO: Currently extension is defaulted to ixnetwork.
    # Going forward, we should be able to specify extension
    # from command line while running pytest.
    api = snappi.api(location=location, ext="ixnetwork")

    yield api

    if getattr(api, 'assistant', None) is not None:
        api.assistant.Session.remove()
Пример #9
0
def get_metrics():
    global CONFIG
    api = snappi.api()

    metrics_request = api.metrics_request()
    metrics_request.deserialize(request.data.decode('utf-8'))
    metrics_response = api.metrics_response()
    if metrics_request.choice == 'port':
        for port in CONFIG.ports:
            metrics_response.port_metrics.metric(name=port.name,
                                                 frames_tx=10000,
                                                 frames_rx=10000)
    elif metrics_request.choice == 'flow':
        for flow in CONFIG.flows:
            metrics_response.flow_metrics.metric(name=flow.name,
                                                 frames_tx=10000,
                                                 frames_rx=10000)

    return Response(metrics_response.serialize(),
                    mimetype='application/json',
                    status=200)
Пример #10
0
# single import
import snappi
import re


# create the top level api object
api = snappi.api()

# create a top level config object
config = api.config()

# add ports to config ports list using factory method
tx_port = config.ports.port(name='Tx Port', location='10.36.74.26;02;13')
rx_port = config.ports.port(name='Rx Port', location='10.36.74.26;02;14')

# add flow to config flows list using factory method
flow = config.flows.flow(name='Tx -> Rx Flow')

# add a source port and destination port to the flow
flow.tx_rx.port.tx_name = tx_port.name
flow.tx_rx.port.rx_name = rx_port.name

# add flow packet headers to the flow packet using factory methods
pkt = flow.packet.ethernet().vlan().ipv4().tcp()

# different ways to unpack packet headers
eth, _, _, _ = flow.packet
eth = flow.packet[0]
eth = flow.packet[flow.packet.ETHERNET]
ip = pkt[flow.packet.IPV4]
Пример #11
0
import snappiserver
snappiserver.SnappiServer().start()

# # python type hinting
# from scapy.all import *
# pkt = Ether() / IP() / TCP()
# ether = pkt[Ether]  # type: scapy.all.packet
# print(ether.src)
# # alternate separate package called 'hinty'

# TBD: put all classes into one autogenerated file snappi.py
# TBD: import all classes in __init__.py
import snappi

api = snappi.api()  # type: snappi.Api

config = api.config()

tx_port, rx_port = config.ports \
    .port(name='Tx Port', location='10.36.74.26;02;13') \
    .port(name='Rx Port', location='10.36.74.26;02;14')

flow = config.flows.flow(name='Tx -> Rx Flow')[-1]
flow.tx_rx.port.tx_name = tx_port.name
flow.tx_rx.port.rx_name = rx_port.name
flow.size.fixed = 128
flow.rate.pps = 1000
flow.duration.fixed_packets.packets = 10000

# test to demonstrate SnappiList unpacking
flow.packet.ethernet().vlan().ipv4().tcp()