I defined a global register as follows:
register<bit<32>>(MAX_PORTS) byte_cnt_reg;
Then, in the apply
method in MyIngress
, I want to increment the value of the register using the following code:
bit<32> byte_cnt;
byte_cnt_reg.read(byte_cnt, 1);
byte_cnt = byte_cnt + 1;
byte_cnt_reg.write(1, byte_cnt);
It works as it should without any problem.
However, if I put the above code in an if
condition like:
if (hdr.ipv4.isValid()) {
bit<32> byte_cnt;
byte_cnt_reg.read(byte_cnt, 1);
byte_cnt = byte_cnt + 1;
byte_cnt_reg.write(1, byte_cnt);
....
Two problems happen! First, the value of the register is a strange large integer instead of zero. Second, at some points in my code, some commands will not be executed. Also, in the log file of the respective switch for those codes, I see: “Primitive (no source info)”.
Please help me with this strange behaviour!