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

Antonin Bas antonin at barefootnetworks.com
Mon Jul 16 14:16:13 EDT 2018


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) 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
>
> 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/b
> m_sim/calculations.cpp#L285
>
> 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
>
>


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


More information about the P4-dev mailing list