How to create loop for register?

Hi @mertkanakkoc ,

I second the opinion of Vladimir in the sense that if you explain what you want to do (Vlaidimir’s ZZZ), we might be able to provide a solution that might already be published in some repository… or, at least, just give you some (pseudo) code.

If your control plane is providing the register index (let’s say, as part of a header), you probably do not need a table or an action. This method is an alternative to collect stateful values from register’s. Controller sends a packet with an index and gets a response with the register value. Unless, of course, that the purpose of the packet out is to trigger the execution of a table because that design suits you more.

Check this README and the example in that folder from A. Fingerhut:

The program registeraccess.p4 and the PTF tests in registeraccess.py demonstrate perhaps an unusual way to access a P4 register array from the controller, which is to use PacketOut messages to inject packets from the controller into the data plane, which are then processed by the P4 program. The P4 program is written so that at least some such injected packets from the controller perform read or write operations on a P4 register array, and send a packet back to the controller.

What do you mean by “size of the register”? When you declare one, both index and value size are static before compilation. Let’s imagine the following case: you want to store the last source IPv4 address (the value) for every source TCP port you see (index). If your key size is 16 bits (then you have 2^16 positions in the array) and the value is 32 bits (so the value will be in the range of 0 to 2^32-1), then the size is already predefined. Sometimes, you might have a field (that is supposed to be the value) that is not 32 bits long, but you can always cast the value to 32 bits. Please check this answer about registers. As said before, if you can explain the use case, how and what you want to achieve our answers will be more fulfilling :slight_smile:

Cheers,