snappi


Namesnappi JSON
Version 1.19.1 PyPI version JSON
download
home_pagehttps://github.com/open-traffic-generator/snappi
SummaryThe Snappi Open Traffic Generator Python Package
upload_time2024-12-19 13:57:24
maintainerNone
docs_urlNone
authorajbalogh
requires_python<4,>=2.7
licenseMIT
keywords snappi testing open traffic generator automation
VCS
bugtrack_url
requirements grpcio grpcio-tools grpcio grpcio-tools PyYAML protobuf protobuf requests urllib3 semantic_version
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ![snappi](snappi-logo.png)

[![license](https://img.shields.io/badge/license-MIT-green.svg)](https://en.wikipedia.org/wiki/MIT_License)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Build](https://github.com/open-traffic-generator/snappi/workflows/Build/badge.svg)](https://github.com/open-traffic-generator/snappi/actions)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/open-traffic-generator/snappi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/open-traffic-generator/snappi/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/open-traffic-generator/snappi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/open-traffic-generator/snappi/context:python)
[![pypi](https://img.shields.io/pypi/v/snappi.svg)](https://pypi.org/project/snappi)
[![python](https://img.shields.io/pypi/pyversions/snappi.svg)](https://pypi.python.org/pypi/snappi)

Test scripts written in `snappi`, an auto-generated python SDK, can be executed against any traffic generator conforming to [Open Traffic Generator API](https://github.com/open-traffic-generator/models).

[Ixia-c](https://github.com/open-traffic-generator/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 
 
```sh
python -m pip install --upgrade snappi 
```

## Start Testing 

```python
import datetime
import time
import snappi
import pytest


@pytest.mark.example
def test_quickstart():
    # Create a new API handle to make API calls against OTG
    # with HTTP as default transport protocol
    api = snappi.api(location="https://localhost:8443")

    # Create a new traffic configuration that will be set on OTG
    config = api.config()

    # Add a test port to the configuration
    ptx = config.ports.add(name="ptx", location="veth-a")

    # Configure a flow and set previously created test port as one of endpoints
    flow = config.flows.add(name="flow")
    flow.tx_rx.port.tx_name = ptx.name
    # and enable tracking flow metrics
    flow.metrics.enable = True

    # Configure number of packets to transmit for previously configured flow
    flow.duration.fixed_packets.packets = 100
    # and fixed byte size of all packets in the flow
    flow.size.fixed = 128

    # Configure protocol headers for all packets in the flow
    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"

    # Configure repeating patterns for source and destination UDP ports
    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

    # Configure custom bytes (hex string) in payload
    cus.bytes = "".join([hex(c)[2:] for c in b"..QUICKSTART SNAPPI.."])

    # Optionally, print JSON representation of config
    print("Configuration: ", config.serialize(encoding=config.JSON))

    # Push traffic configuration constructed so far to OTG
    api.set_config(config)

    # Start transmitting the packets from configured flow
    ts = api.transmit_state()
    ts.state = ts.START
    api.set_transmit_state(ts)

    # Fetch metrics for configured flow
    req = api.metrics_request()
    req.flow.flow_names = [flow.name]
    # and keep polling until either expectation is met or deadline exceeds
    start = datetime.datetime.now()
    while True:
        metrics = api.get_metrics(req)
        if (datetime.datetime.now() - start).seconds > 10:
            raise Exception("deadline exceeded")
        # print YAML representation of flow metrics
        print(metrics)
        if metrics.flow_metrics[0].transmit == metrics.flow_metrics[0].STOPPED:
            break
        time.sleep(0.1)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/open-traffic-generator/snappi",
    "name": "snappi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=2.7",
    "maintainer_email": null,
    "keywords": "snappi testing open traffic generator automation",
    "author": "ajbalogh",
    "author_email": "andy.balogh@keysight.com",
    "download_url": "https://files.pythonhosted.org/packages/02/d2/a2d315f8bf7093d142c2bd54ea773038b8a6d1ac26bf285ba16919702b78/snappi-1.19.1.tar.gz",
    "platform": null,
    "description": "# ![snappi](snappi-logo.png)\n\n[![license](https://img.shields.io/badge/license-MIT-green.svg)](https://en.wikipedia.org/wiki/MIT_License)\n[![Project Status: Active \u2013 The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![Build](https://github.com/open-traffic-generator/snappi/workflows/Build/badge.svg)](https://github.com/open-traffic-generator/snappi/actions)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/open-traffic-generator/snappi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/open-traffic-generator/snappi/alerts/)\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/open-traffic-generator/snappi.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/open-traffic-generator/snappi/context:python)\n[![pypi](https://img.shields.io/pypi/v/snappi.svg)](https://pypi.org/project/snappi)\n[![python](https://img.shields.io/pypi/pyversions/snappi.svg)](https://pypi.python.org/pypi/snappi)\n\nTest scripts written in `snappi`, an auto-generated python SDK, can be executed against any traffic generator conforming to [Open Traffic Generator API](https://github.com/open-traffic-generator/models).\n\n[Ixia-c](https://github.com/open-traffic-generator/ixia-c) is one such reference implementation of Open Traffic Generator API.\n\n> The repository is under active development and is subject to updates. All efforts will be made to keep the updates backwards compatible.\n\n## Setup Client \n \n```sh\npython -m pip install --upgrade snappi \n```\n\n## Start Testing \n\n```python\nimport datetime\nimport time\nimport snappi\nimport pytest\n\n\n@pytest.mark.example\ndef test_quickstart():\n    # Create a new API handle to make API calls against OTG\n    # with HTTP as default transport protocol\n    api = snappi.api(location=\"https://localhost:8443\")\n\n    # Create a new traffic configuration that will be set on OTG\n    config = api.config()\n\n    # Add a test port to the configuration\n    ptx = config.ports.add(name=\"ptx\", location=\"veth-a\")\n\n    # Configure a flow and set previously created test port as one of endpoints\n    flow = config.flows.add(name=\"flow\")\n    flow.tx_rx.port.tx_name = ptx.name\n    # and enable tracking flow metrics\n    flow.metrics.enable = True\n\n    # Configure number of packets to transmit for previously configured flow\n    flow.duration.fixed_packets.packets = 100\n    # and fixed byte size of all packets in the flow\n    flow.size.fixed = 128\n\n    # Configure protocol headers for all packets in the flow\n    eth, ip, udp, cus = flow.packet.ethernet().ipv4().udp().custom()\n\n    eth.src.value = \"00:11:22:33:44:55\"\n    eth.dst.value = \"00:11:22:33:44:66\"\n\n    ip.src.value = \"10.1.1.1\"\n    ip.dst.value = \"20.1.1.1\"\n\n    # Configure repeating patterns for source and destination UDP ports\n    udp.src_port.values = [5010, 5015, 5020, 5025, 5030]\n    udp.dst_port.increment.start = 6010\n    udp.dst_port.increment.step = 5\n    udp.dst_port.increment.count = 5\n\n    # Configure custom bytes (hex string) in payload\n    cus.bytes = \"\".join([hex(c)[2:] for c in b\"..QUICKSTART SNAPPI..\"])\n\n    # Optionally, print JSON representation of config\n    print(\"Configuration: \", config.serialize(encoding=config.JSON))\n\n    # Push traffic configuration constructed so far to OTG\n    api.set_config(config)\n\n    # Start transmitting the packets from configured flow\n    ts = api.transmit_state()\n    ts.state = ts.START\n    api.set_transmit_state(ts)\n\n    # Fetch metrics for configured flow\n    req = api.metrics_request()\n    req.flow.flow_names = [flow.name]\n    # and keep polling until either expectation is met or deadline exceeds\n    start = datetime.datetime.now()\n    while True:\n        metrics = api.get_metrics(req)\n        if (datetime.datetime.now() - start).seconds > 10:\n            raise Exception(\"deadline exceeded\")\n        # print YAML representation of flow metrics\n        print(metrics)\n        if metrics.flow_metrics[0].transmit == metrics.flow_metrics[0].STOPPED:\n            break\n        time.sleep(0.1)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The Snappi Open Traffic Generator Python Package",
    "version": "1.19.1",
    "project_urls": {
        "Homepage": "https://github.com/open-traffic-generator/snappi"
    },
    "split_keywords": [
        "snappi",
        "testing",
        "open",
        "traffic",
        "generator",
        "automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf1d9d44824424e4093340fcdf61680e5dff7ddec42dd915aaec82d96aaf9353",
                "md5": "ee3c5864a77a40dcf527cd50b674973c",
                "sha256": "cdd7b3cd6b83c07f5ef832fde2c0c64590c7cc5b45918bda59a5b944755020bb"
            },
            "downloads": -1,
            "filename": "snappi-1.19.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ee3c5864a77a40dcf527cd50b674973c",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "<4,>=2.7",
            "size": 421499,
            "upload_time": "2024-12-19T13:57:21",
            "upload_time_iso_8601": "2024-12-19T13:57:21.363090Z",
            "url": "https://files.pythonhosted.org/packages/bf/1d/9d44824424e4093340fcdf61680e5dff7ddec42dd915aaec82d96aaf9353/snappi-1.19.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02d2a2d315f8bf7093d142c2bd54ea773038b8a6d1ac26bf285ba16919702b78",
                "md5": "401bb9d18d9bc30261e2ca2e1942f83a",
                "sha256": "8a723fcd9318481689f697eed5775e01a4725ed8f7632bc9cb249fdd92c91b1c"
            },
            "downloads": -1,
            "filename": "snappi-1.19.1.tar.gz",
            "has_sig": false,
            "md5_digest": "401bb9d18d9bc30261e2ca2e1942f83a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=2.7",
            "size": 418082,
            "upload_time": "2024-12-19T13:57:24",
            "upload_time_iso_8601": "2024-12-19T13:57:24.615456Z",
            "url": "https://files.pythonhosted.org/packages/02/d2/a2d315f8bf7093d142c2bd54ea773038b8a6d1ac26bf285ba16919702b78/snappi-1.19.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-19 13:57:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "open-traffic-generator",
    "github_project": "snappi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "grpcio",
            "specs": [
                [
                    "~=",
                    "1.44.0"
                ]
            ]
        },
        {
            "name": "grpcio-tools",
            "specs": [
                [
                    "~=",
                    "1.59.0"
                ]
            ]
        },
        {
            "name": "grpcio",
            "specs": [
                [
                    "~=",
                    "1.59.0"
                ]
            ]
        },
        {
            "name": "grpcio-tools",
            "specs": [
                [
                    "~=",
                    "1.44.0"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": []
        },
        {
            "name": "protobuf",
            "specs": [
                [
                    "~=",
                    "4.24.4"
                ]
            ]
        },
        {
            "name": "protobuf",
            "specs": [
                [
                    "~=",
                    "3.15.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "urllib3",
            "specs": []
        },
        {
            "name": "semantic_version",
            "specs": []
        }
    ],
    "lcname": "snappi"
}
        
Elapsed time: 0.42699s