Test scripts written in snappi
, an auto-generated python SDK, can be executed against any traffic generator conforming to Open Traffic Generator API.
Ixia-c is one such reference implementation of Open Traffic Generator API.
The repository is under active development and is subject to updates. All efforts will be made to keep the updates backwards compatible.
Setup Client
python -m pip install --upgrade snappi
Start Testing
import datetime
import time
import snappi
import pytest
@pytest.mark.example
def test_quickstart():
api = snappi.api(location="https://localhost:8443")
config = api.config()
ptx = config.ports.add(name="ptx", location="veth-a")
flow = config.flows.add(name="flow")
flow.tx_rx.port.tx_name = ptx.name
flow.metrics.enable = True
flow.duration.fixed_packets.packets = 100
flow.size.fixed = 128
eth, ip, udp, cus = flow.packet.ethernet().ipv4().udp().custom()
eth.src.value = "00:11:22:33:44:55"
eth.dst.value = "00:11:22:33:44:66"
ip.src.value = "10.1.1.1"
ip.dst.value = "20.1.1.1"
udp.src_port.values = [5010, 5015, 5020, 5025, 5030]
udp.dst_port.increment.start = 6010
udp.dst_port.increment.step = 5
udp.dst_port.increment.count = 5
cus.bytes = "".join([hex(c)[2:] for c in b"..QUICKSTART SNAPPI.."])
print("Configuration: ", config.serialize(encoding=config.JSON))
api.set_config(config)
ts = api.transmit_state()
ts.state = ts.START
api.set_transmit_state(ts)
req = api.metrics_request()
req.flow.flow_names = [flow.name]
start = datetime.datetime.now()
while True:
metrics = api.get_metrics(req)
if (datetime.datetime.now() - start).seconds > 10:
raise Exception("deadline exceeded")
print(metrics)
if metrics.flow_metrics[0].transmit == metrics.flow_metrics[0].STOPPED:
break
time.sleep(0.1)