I’ve some questions regarding registers in P4 that I’d appreciate if someone could clarify:
- When I use read in a register am I taking out the stored value or does the value remain stored?
- If a value is stored within a register position, does writing in that position replace the previous content?
- Is there any way to fully erase/reset the content stored within a register?
A P4 register is in some ways better named an “array”, if that makes it more familiar to you. It is an array of values, all with the same type.
A read operation retrieves the value stored in the array at one index, without changing any values stored in the array.
A write operation modifies the value stored in the array at one index, without changing any values stored at other indices.
There is no single operation that changes all array elements.
Understood, thanks for the help.
I guess for completeness I should say “there is no single operation that can be invoked from the data plane, i.e. from inside of your P4 program, that changes all array elements”.
Some P4 implementations provide a control plane API operation that allows the control plane to assign the same value to all array elements.
Whether they can do this while making that change appear to happen “between two consecutive packets processed”, or whether that change might appear to data packet flowing through as one at a time spread out over time, is implementation-specific.
I’ll be looking into that, thanks once again.