I am using on V1 model and trying to store a selected feature value(e.g., packet length) for each packet or upto a certain number of packets (e.g., let’s say first 100 packets). In a normal programming language we can easily do this by creating 2D array where rows for flows and columns for each packet. But I am not sure whether this can be done in P4 using V1 model. Any suggestion will be highly appreciated.
There is no direct way to declare and use a 2-dimensional array that I am aware of.
There is a fairly straightforward workaround. Suppose you wish you had a 2-dimensional array my_reg[A][B]. Instead declare a 1-dimensional array my_reg[A*B], and whenever you wish to access element my_reg[i][j], you instead access element my_reg[i*B+j]. If one of the array dimensions A or B is a power of 2, then multiplying by that value is equivalent to a left shift by the proper number of bit positions.