This repository used to hold two projects: p4cherry and p4-spectec.
p4cherry is an OCaml implementation of the P4 language, while p4-spectec is a formal, mechanized specification for P4 using the SpecTec framework.
We have now split these projects into their own repositories for better organization and clarity.
Now, p4-spectec can be found at: P4-SpecTec.
An OCaml implementation of the P4 language. This reuses parts of the Petr4 codebase, especially the parser and numerics implementation.
-
Install
opamversion 2.0.5 or higher.$ apt-get install opam $ opam init
-
Create OCaml switch for version 5.1.0 Install
duneversion 3.16.1,bignumversion v0.17.0,menhirversion 20240715,coreversion v0.17.1,core_unixversion v0.17.0, andbisect_ppxversion 2.8.3 viaopam.$ opam switch create 5.1.0 $ eval $(opam env) $ opam install dune bignum menhir core core_unix bisect_ppx
-
Install the project.
$ cd p4 $ dune build p4cherry.opam $ opam install . $ cd ..
$ make buildThis creates an executable p4cherry in the project root.
You may also need libgmp-dev and pkg-config, if the error message says so.
$ ./p4cherry parse -i p4/testdata/arch [FILENAME].p4
$ ./p4cherry typecheck -i p4/testdata/arch [FILENAME].p4
$ ./p4cherry instantiate -i p4/testdata/arch [FILENAME].p4
$ ./p4cherry run -a v1model -i p4/testdata/arch [FILENAME].p4 [TESTNAME].stfNote that p4cherry currently only supports the V1Model architecture, and partly the eBPF architecture.
You can run the tests against the p4c compiler test suite and petr4 custom test suite with:
$ make testTo measure the coverage of the tests, run:
$ make coverageThis will generate index.html in p4/_coverage.
Parsing, pretty-printing, and roundtripping (p4c / petr4)
- Positive type checker tests (well-typed programs should be accepted) (p4c / petr4)
- Excluded positive type checker tests (p4c)
- Negative type checker tests (ill-typed programs should be rejected) (p4c / petr4)
- Excluded negative type checker tests (p4c)
Analysis of test failures: p4c-pos / p4c-neg / petr4-pos
Instantiation of stateful objects (p4c / petr4)
Running STF tests against the p4c compiler test suite and petr4 custom test suite (for V1Model) (p4c / petr4)
Analysis of test failures: p4c / petr4
p4cherry is an open-source project. Please feel free to contribute by opening issues or pull requests.
p4cherry is released under the Apache 2.0 license.