P4runtime-go-controller: Go SDK and CLI for P4Runtime controllers

Hi everyone,

I’d like to share p4runtime-go-controller, an open-source Go SDK and CLI for building P4Runtime controllers. The latest release is v2.0.1, licensed under Apache 2.0.

The SDK provides helpers for looking up resources in P4Info, building table entries, and handling controller connections and stream messages. It may be useful if you’re writing a control plane in Go or putting together a P4 experiment.

It currently includes:

  • Controller arbitration, pipeline configuration, automatic reconnection, TLS and mutual TLS.
  • Table entry builders supporting exact, LPM, ternary, range and optional matches, with value and bit-width validation.
  • PacketIn and PacketOut handling, metadata encoding and decoding, and digest subscriptions with acknowledgements.
  • Counters, meters, typed registers, multicast groups and clone sessions.
  • A p4ctl CLI for common control-plane operations, with text, JSON and YAML output.

My testing so far has focused on BMv2, including control-plane operations and packet forwarding. The repository includes an L2 forwarding example, Packet I/O and counter examples, and scripts for starting BMv2 locally or through Docker.

The SDK requires Go 1.26 or newer. From your application’s Go module:

go get github.com/zhh2001/p4runtime-go-controller/v2@v2.0.1

To install the CLI:

go install github.com/zhh2001/p4runtime-go-controller/v2/cmd/p4ctl@v2.0.1

A few community users and research colleagues have already tried it. I’d welcome feedback from others working with P4Runtime, especially on the API, examples and behavior with different targets.

If you find it useful, a GitHub star would help others discover the project. Issues and contributions are welcome.