[P4-dev] Behavioral model implementation of Hash extern with CRC32

cristina.dominicini at aluno.ufes.br cristina.dominicini at aluno.ufes.br
Mon Jul 16 10:19:09 EDT 2018

Hi All, 

For my application, I need to calculate the output value of CRC32 in a
P4 program using a arbitrary input data. I am running the simple switch
of BMv2 behavioral model using v1model. 

Firstly, I checked if the behavioral model implementation was producing
the same results described here:

To that end, I executed the C++ code provided below. For input
"123456789", I got 3421780262 (int) or 0xcbf43926 (hex). 

So, the behavioral model implementation of CRC32 was working as
expected. Then, I tried to use the checksum extern with CRC32 in my P4
program, but I discovery the only supported algorithm is csum16 :
"error: HashAlgorithm.crc32: the only supported algorithm is csum16" 

My next try was to use the hash extern: 
extern void hash<O, T, D, M>(out O result, in HashAlgorithm algo, in T
base, in D data, in M max); 

My test P4 code: 
        bit<32> nbase=0;
        bit<64> nmax=4294967296*2;
        bit<32> nselect;
        bit<32> operand_x = 123456789;
        hash(nselect, HashAlgorithm.crc32, nbase, {operand_x},nmax); 


As the result is (nbase + (hash_value % nmax)), I used base as 0 and
nmax as a value greater than the maximum possible value for nselect (32
bits). In this way, I expect to get the CRC32 output from input
123456789 without any modification. Is this assumption right? 

But, when I run this P4 code, I get the result 3488836380 (int). I have
already tried different format conversions (Big Endian, Little Endian,
Unsigned Int, ASCII, Hex, ...), but I was not able to understand this

I would be grateful if somebody could give a help on this issue. My
questions are: 

- Am I using the hash extern correctly? 
- Does the hash function execute any additional operation apart from the
normal CRC calculation? 
- Is there another way to compute the CRC32 output in P4? 
Thank you, 
Cristina Klippel Dominicini 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20180716/613d874a/attachment.html>

More information about the P4-dev mailing list