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

Antonin Bas antonin at barefootnetworks.com
Tue Jul 17 13:22:31 EDT 2018


Yes, unless I'm missing something any of the hash algorithms supported by
bmv2/simple_switch should work there.

On Tue, Jul 17, 2018 at 10:19 AM, Mihai Budiu <mbudiu at vmware.com> wrote:

> So can we just remove that particular check from the compiler and
> everything should just work?
>
>
> ------------------------------
> *From:* P4-dev <p4-dev-bounces at lists.p4.org> on behalf of Antonin Bas via
> P4-dev <p4-dev at lists.p4.org>
> *Sent:* Tuesday, July 17, 2018 10:16:06 AM
> *To:* cristina.dominicini at aluno.ufes.br
> *Cc:* p4-dev
> *Subject:* Re: [P4-dev] Behavioral model implementation of Hash extern
> with CRC32
>
>
> On Mon, Jul 16, 2018 at 4:13 PM, <cristina.dominicini at aluno.ufes.br>
> wrote:
>
>> 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.
>>
>
> I don't believe it is a limitation of the simple_switch implementation,
> I'm pretty sure it is a compiler limitation here.
>
>
>>
>> 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.
>>
>
> Your usage is correct, but it is much easier to debug the issue with the
> actual P4 and generated JSON file.
>
>
>>
>> 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/sim
>> ple_switch/simpleSwitch.cpp#L801
>> <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4c%2Fblob%2Fmaster%2Fbackends%2Fbmv2%2Fsimple_switch%2FsimpleSwitch.cpp%23L801&data=02%7C01%7Cmbudiu%40vmware.com%7C9b9f77f919b947efea0808d5ec091537%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636674446135736464&sdata=%2Byxnfb4myFJ9bmd0cvBJvdvZ16VxEQqTULZBlxsSvxc%3D&reserved=0>)
>> 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
>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcrcmod.sourceforge.net%2Fcrcmod.predefined.html%23predefined-crc-algorithms&data=02%7C01%7Cmbudiu%40vmware.com%7C9b9f77f919b947efea0808d5ec091537%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636674446135746469&sdata=E9ojN4G%2BvRk5tRmhn3fk2cHZNQIl2dHOC%2FUiDL535H4%3D&reserved=0>
>>>
>>> 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
>>> <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fbehavioral-model%2Fblob%2Fmaster%2Fsrc%2Fbm_sim%2Fcalculations.cpp%23L285&data=02%7C01%7Cmbudiu%40vmware.com%7C9b9f77f919b947efea0808d5ec091537%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636674446135746469&sdata=eRZBx88sPjahP2KuwqGRuDzze6rJWGzBKyoJWS3iO0A%3D&reserved=0>
>>>
>>> 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
>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.p4.org%2Fmailman%2Flistinfo%2Fp4-dev_lists.p4.org&data=02%7C01%7Cmbudiu%40vmware.com%7C9b9f77f919b947efea0808d5ec091537%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636674446135756478&sdata=8%2Fvcj8zt0h4DPfBxu%2FEUYTHAkv8%2B23XdSB%2FXTGoEAJo%3D&reserved=0>
>>>
>>>
>>
>>
>> --
>> Antonin
>>
>>
>
>
> --
> Antonin
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20180717/6c783d41/attachment-0001.html>


More information about the P4-dev mailing list