-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e477c9
commit a36a279
Showing
2 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,56 @@ | ||
# ![snappi](snappi-logo.png) | ||
|
||
Create test case scripts once using the `snappi` client and run them using a | ||
traffic generator that conforms to the [Open Traffic Generator API](https://github.com/open-traffic-generator/models/releases). | ||
Test scripts written using `snappi` (a python library) can be executed against | ||
any traffic generator conforming to [Open Traffic Generator API](https://github.com/open-traffic-generator/models/releases). | ||
|
||
## Install the client | ||
## Install on a client | ||
|
||
``` | ||
pip install snappi | ||
```sh | ||
python -m pip install --upgrade snappi | ||
# or install along with ixnetwork extension | ||
python -m pip install --upgrade snappi[ixnetwork] | ||
``` | ||
|
||
## Start scripting | ||
|
||
```python | ||
"""A simple test that demonstrates the following: | ||
- A port that transmits an ethernet/vlan/ipv4/tcp flow | ||
for a specified duration and a port that receives the packets. | ||
- While the flow is transmitting the script prints out tx and rx statistics. | ||
- Once all the packets have been transmitted the script will end. | ||
""" | ||
import snappi | ||
Configure a raw TCP flow with, | ||
- tx port as source to rx port as destination | ||
- frame count 10000, each of size 128 bytes | ||
- transmit rate of 1000 packets per second | ||
Validate, | ||
- frames transmitted and received for configured flow is as expected | ||
""" | ||
|
||
api = snappi.api() | ||
import snappi | ||
# when using ixnetwork extension, host is IxNetwork API Server | ||
api = snappi.api(host='https://localhost:443', ext='ixnetwork') | ||
# new config | ||
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.tx_name = rx_port.name | ||
flow.packet.ethernet().vlan().ipv4().tcp() | ||
flow.size.fixed = 128 | ||
flow.rate.pps = 1000 | ||
flow.duration.fixed_packets.packets = 10000 | ||
# when using ixnetwork extension, port location is chassis-ip;card-id;port-id | ||
tx, rx = ( | ||
config.ports | ||
.port(name='tx', location='192.168.0.1;2;1') | ||
.port(name='rx', location='192.168.0.1;2;2') | ||
) | ||
# configure only one flow | ||
flw = config.flows.flow(name='flw')[-1] | ||
# configure rate, size, frame count and endpoints | ||
flw.size.fixed = 128 | ||
flw.rate.pps = 1000 | ||
flw.duration.fixed_packets.packets = 10000 | ||
flw.tx_rx.port.tx_name = tx.name | ||
flw.tx_rx.port.rx_name = rx.name | ||
# configure protocol headers with defaults fields | ||
flw.packet.ethernet().vlan().ipv4().tcp() | ||
# set configuration and start traffic | ||
api.set_config(config) | ||
|
||
tx_state = api.transmit_state(state='start') | ||
api.set_transmit(tx_state) | ||
|
||
while True: | ||
metrics = api.get_port_metrics(api.port_metrics_request()) | ||
tx_frames = sum([metric.frames_tx for metric in metrics]) | ||
if tx_frames >= flow.duration.fixed_packets.packets: | ||
break | ||
ts = api.transmit_state() | ||
ts.state = ts.START | ||
api.set_transmit_state(ts) | ||
# wait for flow metrics to be as expected | ||
metrics = lambda: api.get_flow_metrics(api.flow_metrics_request()) | ||
while not all([m.frames_tx == 10000 == m.frames_rx for m in metrics()]): | ||
continue | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.21 | ||
0.1.22 |