Are registers in BMv2 initialized to zero?

Hi everyone,

I was wondering if registers are guaranteed to be initialized to 0 when using BMv2 (specifically simple_switch_grpc) and, if so, whether this is also common on other targets.

I looked through the P4 language specification and the v1model specification, but I couldn’t find anything about this, so I thought it was a target-dependent behavior. Correct me if I’m wrong.

I couldn’t find a complete Behavioral Model specification anyway: is there one?

Thank you in advance for your help!

Dear @a_mora,

The behavior of any architecture-specific extern in P4 (including in this case register initialization) is defined by the architecture, not by the language itself. In your case, registers are v1model-specific externs and it is v1model specification that should be defining their behavior, including initialization.

Practically speaking, I believe that they are initialized to 0 at BMv2 startup.

By the way, other architectures do it differently – for example TNA allows the user to specify the initialization value in the program and so on.

Happy hacking,
Vladimir

I would not call it a complete Behavioral Model specification, but a lot of details about how the v1model architecture works when run in the simple_switch or simple_switch_grpc executables compiled from the source code in repository GitHub - p4lang/behavioral-model: The reference P4 software switch can be found here: behavioral-model/docs/simple_switch.md at main · p4lang/behavioral-model · GitHub

It does not have an answer to your particular question. In general, if the initial values of the contents of P4 register arrays matters to you for your application, it is best to ensure that you initialize them to known values.

Unfortunately BMv2 does not support writing to registers via P4Runtime API messages at this time. You can do it either via the Thrift API, or by writing your P4 program in such a way that selected PacketOut messages from the controller cause the register entries to be written with a value you want. An example of the latter approach can be found in this test program: p4-guide/ptf-tests/registeraccess at master · jafingerhut/p4-guide · GitHub