{"id":25495980,"url":"https://github.com/opennetworkinglab/fabric-p4test","last_synced_at":"2025-11-09T22:30:14.308Z","repository":{"id":48106909,"uuid":"133090773","full_name":"opennetworkinglab/fabric-p4test","owner":"opennetworkinglab","description":"PTF-based data plane tests for ONOS fabric.p4","archived":false,"fork":false,"pushed_at":"2021-08-06T09:40:31.000Z","size":248,"stargazers_count":15,"open_issues_count":1,"forks_count":12,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-03-26T18:02:32.461Z","etag":null,"topics":["onos","p4","p4runtime","ptf"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opennetworkinglab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-11T21:35:33.000Z","updated_at":"2022-08-18T08:41:08.000Z","dependencies_parsed_at":"2022-08-12T18:40:58.434Z","dependency_job_id":null,"html_url":"https://github.com/opennetworkinglab/fabric-p4test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opennetworkinglab%2Ffabric-p4test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opennetworkinglab%2Ffabric-p4test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opennetworkinglab%2Ffabric-p4test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opennetworkinglab%2Ffabric-p4test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opennetworkinglab","download_url":"https://codeload.github.com/opennetworkinglab/fabric-p4test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239576796,"owners_count":19662113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["onos","p4","p4runtime","ptf"],"created_at":"2025-02-19T00:52:57.175Z","updated_at":"2025-11-09T22:30:13.943Z","avatar_url":"https://github.com/opennetworkinglab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PTF tests for ONOS fabric.p4\n\nThis project contains PTF-based tests for [fabric.p4][fabric.p4 code], a P4\nprogram distributed as part of ONOS, designed to work with\n[Trellis](https://www.opennetworking.org/trellis/), a set of SDN applications\nrunning on top of ONOS to provide the control plane for an IP fabric based on\nMPLS segment-routing.\n\nPTF is a framework for data plane testing:\n\u003chttps://github.com/p4lang/PTF\u003e\n\nThis project maintains the test case definition (written in Python), as well as\nthe scripts to run them on different targets. Test cases are defined inside the\ndirectory `tests/ptf/fabric.ptf` Run scripts can be found in `run/`.\n\nCurrently, we provide scripts to test the following targets: \n* `stratum_bmv2` (`run/bmv2/`)\n* `tofino-model` with `stratum_bf` (`run/tm/`)\n\nTo learn more about Stratum:\n\u003chttps://github.com/stratum/stratum\u003e\n\n## Requirements\n\nAll scripts are based on a containerized version of the required tools and can\nbe executed by installing the following dependencies:\n\n* Docker (tested with v19.03, but it should work with older versions as well)\n* make\n* Bash-like Unix shell\n\n## Steps to run tests on stratum_bmv2\n\n`stratum_bmv2` is a version of [BMv2's simple_switch][bmv2] (the reference P4\nsoftware switch) built with Stratum support to expose a P4Runtime interface that\nis used by the test cases to populate tables and other P4 objects.\n\n1. Obtain the `fabric.p4` pre-compiled artifacts for BMv2 (`bmv2.json` and\n   `p4info.txt`). These files are distributed with ONOS:\n\n    ```\n    git clone https://github.com/opennetworkinglab/onos\n    ```\n\n2. Set the `ONOS_ROOT` environment variable to the location where you just\n   cloned the ONOS repo:\n\n    ```\n    export ONOS_ROOT=\u003cpath-to-onos\u003e\n    ```\n\n3. Run PTF tests:\n\n    ```\n    ./run/bmv2/run \u003cprofile\u003e [test-case]\n    ```\n\n    To learn more about fabric.p4 \"profiles\" check\n    [these instructions][fabric profiles].\n    \n    For example, to run all test cases for all profiles:\n\n    ```\n    ./run/bmv2/run all\n    ```\n\n    To run all test cases for the `fabric-spgw` profile:\n\n    ```\n    ./run/bmv2/run fabric-spgw\n    ```\n\n    To run a specific test case against a specific fabric profile (or `all`),\n    for example `test.FabricBridgingTest` for the basic `fabric` profile:\n\n    ```\n    ./run/bmv2/run fabric TEST=test.FabricBridgingTest\n    ```\n\n4. If tests fail, check logs in:\n\n   * `run/bmv2/log` for stratum_bmv2 logs\n   * `tests/ptf/` for PTF-related logs and PCAP traces (`ptf.log` and\n     `ptf.pcap`)\n\n## Steps to run tests on tofino-model with stratum_bf\n\n### Requirements\n\nSteps are similar to the previous case with a few differences:\n\n* You will need to compile fabric.p4 for Tofino;\n* You will need to create or obtain a containerized version of `tofino-model`;\n* `stratum_bf` is used to provide a P4Runtime server to control\n  `tofino-model` (a Docker image for it will be downloaded automatically.)\n\nThe run scripts assume that you have access to a containerized version of the\nIntel/Barefoot SDE that includes `tofino-model`. We do not provide such Docker\nimage, but one can be easily generated by executing the SDE install instructions\ninside a Dockerfile.\n\nThe run script will use `docker run` to invoke the `tofino-model` command inside\nthe container. For this reason, the script expects a Docker image that has the\nwhole Barefoot SDE installed in it or just the `tofino-model` package. In both\ncases, the `tofino-model` executable should be on `PATH`.\n\n**IMPORTANT: make sure to reserve at least 8GB of RAM** for your Docker host\nsystem (or VM if running Docker Desktop for Mac), otherwise `tofino-model` might\nfail to start or affect test results negatively.\n\n### Steps\n\n1. Clone `fabric-tofino` repo and follow instructions to compile fabric.p4 for\n   Tofino:\n\n   ```\n   https://github.com/opencord/fabric-tofino.git\n   cd fabric-tofino\n   \u003copen README and follow instructions\u003e\n   ```\n\n2. Set the `FABRIC_TOFINO` environment variable to the location where you cloned\n   `fabric-tofino`:\n\n   ```\n   export FABRIC_TOFINO=\u003cpath-to-fabric-tofino\u003e\n   ```\n\n3. Set the `SDE_DOCKER_IMG` environment variable to the location of a Docker\n   image that can be downloaded via `docker pull` and that contains a Barefoot\n   SDE installation, including `tofino-model`:\n\n   ```\n   export SDE_DOCKER_IMG=my-docker-repo/bf-sde:9.0.0\n   ```\n\n4. Run PTF tests using the `run/tm/run` script:\n\n    ```\n    ./run/tm/run \u003cprofile\u003e [test-case]\n    ```\n\n    **NOTE:** Testing `all` profiles is not supported on this target. You must\n    execute the run command for each profile.\n\n    To run all test cases for the basic `fabric` profile:\n\n    ```\n    ./run/tm/run fabric\n    ```\n\n    To run a specific test case against a specific fabric profile,\n    for example `test.FabricBridgingTest` for the `fabric-spgw` profile:\n\n    ```\n    ./run/tm/run fabric-spgw TEST=test.FabricBridgingTest\n    ```\n\n5. If tests fail, check logs in:\n\n   * `run/tm/log` for `tofino-model` and `stratum_bf` logs\n   * `tests/ptf/` for PTF-related logs and PCAP traces (`ptf.log` and\n     `ptf.pcap`)\n\n## Run tests on other targets\n\nTo run tests on targets other than BMv2 (e.g. a real Tofino-based switch), check\nthe instructions available inside the `tests/ptf` directory.\n\n## Status\n\nAll test cases are executed daily against the ONOS 2.5 LTS branch (`onos-2.5`) using Travis CI.\nThe current status is:\n\n[![Build Status](https://travis-ci.org/opennetworkinglab/fabric-p4test.svg?branch=master)](https://travis-ci.org/opennetworkinglab/fabric-p4test)\n\n## Migrating to Stratum Test Vectors\n\nWe are currently in the process of migrating the test runner framework from PTF\nto Stratum's [testvectors-runner].\n\nFor this reason, some PTF-based test case definitions are currently instrumented\nto generate protobuf-based [TestVectors] (TVs) (under `tests/ptf/testvectors`).\nThe long-term goal is to remove all PTF references from the codebase, but\ncontinue using Python as a convenient way to generate TVs. For now, we use a\nPython library (`tvutils`) to wrap PTF and P4Runtime calls in methods that\ngenerate TV's actions, stimuli and expectations instead of calling the\ncorresponding PTF or P4Runtime gRPC methods.\n\n### Steps to generate TestVectors\n\nTestVectors can be generated for bmv2 and tofino targets. The instructions are similar to running ptf tests on bmv2 and tofino model.\n\n1. Obtain the `fabric.p4` pre-compiled artifacts for BMv2 (`bmv2.json` and\n   `p4info.txt`). These files are distributed with ONOS:\n\n    ```\n    git clone https://github.com/opennetworkinglab/onos\n    ```\n\n2. Set the `ONOS_ROOT` environment variable to the location where you just\n   cloned the ONOS repo:\n\n    ```\n    export ONOS_ROOT=\u003cpath-to-onos\u003e\n    ```\n\n3. Clone `fabric-tofino` repo and follow instructions to compile fabric.p4 for\n   Tofino:\n\n   ```\n   https://github.com/opencord/fabric-tofino.git\n   cd fabric-tofino\n   \u003copen README and follow instructions\u003e\n   ```\n\n4. Set the `FABRIC_TOFINO` environment variable to the location where you cloned\n   `fabric-tofino`:\n\n   ```\n   export FABRIC_TOFINO=\u003cpath-to-fabric-tofino\u003e\n   ```\n\n5. Set the optional `SDE_VERSION` environment variable. Default value is `9.0.0`\n   \n   ```\n   export SDE_VERSION=9.0.0\n   ```\n\n6. Generate TestVectors using the `run/tv/run` script:\n\n    ```\n    ./run/tv/run \u003cprofile\u003e [device] [portmap] [grpcaddr] [cpuport] [test-case]\n    ```\n   Default values for optional arguments are:\n   1. `device`: `tofino`\n   2. `portmap`: `portmap.veth.json`\n   3. `grpcaddr`: `127.0.0.1:28000`\n   4. `cpuport`: `320` for tofino and `255` for bmv2\n   \n   Example command with all the optional arguments set:\n\n   ```\n   ./run/tv/run fabric DEVICE=tofino PORTMAP=port_map.hw.json GRPCADDR=10.128.13.111:28000 CPUPORT=320 TEST=test.FabricBridgingTest\n   ```\n\n    **NOTE:** Testing `all` profiles is not supported on this target. You must\n    execute the run command for each profile.\n\n    To generate TestVectors for the basic `fabric` profile:\n\n    ```\n    ./run/tv/run fabric\n    ```\n\n    To generate a specific test case for a specific fabric profile,\n    for example `test.FabricBridgingTest` for the `fabric-spgw` profile:\n\n    ```\n    ./run/tv/run fabric-spgw TEST=test.FabricBridgingTest\n    ```\n  \n## Support\n\nFor help running the tests please write to the P4 Brigade\nmailing list:\n\n\u003chttps://groups.google.com/a/onosproject.org/forum/#!forum/brigade-p4\u003e\n\n\n[fabric.p4 code]: https://github.com/opennetworkinglab/onos/tree/master/pipelines/fabric/impl/src/main/resources\n[fabric profiles]: tests/ptf/README.md#fabric-profiles\n[bmv2]: https://github.com/p4lang/behavioral-model\n[testvectors-runner]: https://github.com/stratum/testvectors-runner\n[TestVectors]: https://github.com/stratum/testvectors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopennetworkinglab%2Ffabric-p4test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopennetworkinglab%2Ffabric-p4test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopennetworkinglab%2Ffabric-p4test/lists"}