nsg-ethz/p4-learning

Question about hash function

ls760008979 opened this issue · 3 comments

Is there any detail descriptions about the hash function in p4switch,for i am confuse about the exercise"https://github.com/nsg-ethz/p4-learning/tree/master/exercises/11-Packet-Loss-Detection" in compute hash indexes for stream meter.
hash.
I think the base value may bigger than the max value,so i want to how this hash function compute?Thanks in advance.

You can find the description of hash here: https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4#L453

The important part:

The value written to the out parameter named result: will always be in the range [base, base+max-1] inclusive, if max >=1. If max=0, the value written to result will always be base.

That means if base is 0, and max is 100, it will be from 0 to 100. If base is 100 and range 100, it will be from 100 to 200.

Hope that answers your question

Oh,thanks! I got it,and one more question about register.In the same exercise,for example:
register
does it means the 'um_ip_src' register have index from 0 to 'REGISTER_SIZE_TOTAL',and every index has a value in type 'REGISTER_CELL_WIDTH'.Excuse me for taking your time,thanks in advance.

Yes it means that!