Hi everyone,
I maintain p4runtime-go-controller, a Go library for P4Runtime. Here is the table-write step from its BMv2 L2 forwarding example.
The controller loads the P4Info and matching BMv2 configuration, becomes primary, and installs the pipeline. It then writes a static forwarding entry:
entry, err := tableentry.NewBuilder(p, "MyIngress.t_l2").
Match("hdr.eth.dst", tableentry.Exact(codec.MustMAC("00:11:22:33:44:55"))).
Action("MyIngress.forward", tableentry.Param("port", codec.MustEncodeUint(1, 9))).
Build()
if err != nil {
return fmt.Errorf("build entry: %w", err)
}
if err := c.WriteTableEntry(setupCtx, client.UpdateInsert, entry); err != nil {
return fmt.Errorf("insert entry: %w", err)
}
The table, match field and action are looked up by name in P4Info. The 9 is the width of the port parameter in the bundled P4 program.
With data interfaces bound to BMv2, this entry forwards frames addressed to 00:11:22:33:44:55 to port 1. The P4 program sends table misses to CPU port 255, and the controller receives them as PacketIn messages containing the Ethernet frame and ingress-port metadata.
The complete example and BMv2 setup instructions include the controller source and links to the P4 program and interface setup. The Go code requires Go 1.26 or newer.
I’d welcome feedback on the table-entry API and example from others writing P4Runtime controllers in Go.