[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 19:13:14 EDT 2018


Hi Antonin,

Thank you for your feedback. 

For the checksum extern, I understand there is a limitation in the
current simple switch implementation, which only implements csum16. 

As it is not possible to get the CRC32 output directly using the
checksum extern, I assumed that it is possible to get this information
using the hash extern in the way explained in my last e-mail. However, I
get an output from the hash extern that is different from the expected
result. I can see two possibilities:  
(1) The way I am using the hash extern is not correct. This was my first
guess and the motivation to send this e-mail. Do you think the usage I
described seems ok? 
(2) The bmv2 implementation of the hash extern is not following the
expected behavior. This may not be noticed by applications that only use
the output for hashing purposes, and do not need the exact value from
the CRC32 output. From your response, I understood that my issue might
be related to the bmv2 implementation. So, I will follow your advice and
open an issue on behavioral-model github. 

Thank you, 
Cristina 

Em 16.07.2018 15:16, Antonin Bas escreveu:

> Hi Cristina, 
> 
> The first issue seems to be a limitation of the p4c compiler (https://github.com/p4lang/p4c/blob/master/backends/bmv2/simple_switch/simpleSwitch.cpp#L801 [4]) and so I would recommend opening an issue on the p4c Github, unless there is already one for this. 
> 
> For the second issue, I would recommend opening an issue on the behavioral-model Github with your P4 program + the generated JSON. If this is an issue with bmv2 I will fix it. If this is an issue with the compiler, I can open the appropriate issue on the p4c Github. 
> 
> Thanks, 
> 
> Antonin 
> 
> On Mon, Jul 16, 2018 at 7:19 AM, <cristina.dominicini at aluno.ufes.br> wrote:
> 
>> 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: http://crcmod.sourceforge.net/crcmod.predefined.html#predefined-crc-algorithms [1] 
>> 
>> To that end, I executed the C++ code provided below. For input "123456789", I got 3421780262 (int) or 0xcbf43926 (hex). 
>> https://github.com/p4lang/behavioral-model/blob/master/src/bm_sim/calculations.cpp#L285 [2] 
>> 
>> 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 output. 
>> 
>> 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 
>> 
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org [3]
> 
> -- 
> 
> Antonin
 

Links:
------
[1]
http://crcmod.sourceforge.net/crcmod.predefined.html#predefined-crc-algorithms
[2]
https://github.com/p4lang/behavioral-model/blob/master/src/bm_sim/calculations.cpp#L285
[3] http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
[4]
https://github.com/p4lang/p4c/blob/master/backends/bmv2/simple_switch/simpleSwitch.cpp#L801
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20180716/22c0fcc2/attachment-0001.html>


More information about the P4-dev mailing list