[P4-dev] varbit

Andy Fingerhut andy.fingerhut at gmail.com
Thu Jun 8 20:57:20 EDT 2017


Yes, it is a limitation in the P4 language as specified today that you can
copy varbit fields from input packets to output packets, or remove them,
but there is no way to assign values to the bits of a varbit field if the
input packet has no varbit fields.

The best way I know to create headers of varying lengths that did not
arrive in the input packet is to create multiple fixed-length header types,
and create separate table actions for each different length for filling
them in.

There is an open issue for the P4-16 language specification proposing
additional operations on varbit fields to be supported, but it isn't clear
yet whether that will garner enough interest for inclusion:
https://github.com/p4lang/p4-spec/issues/264

Andy

On Thu, Jun 8, 2017 at 1:36 PM, Mihai Budiu <mbudiu at vmware.com> wrote:

> The only thing you can assign to a varbit is another varbit. If you want
> to emit some sequence of fixed-width fields, just declare a new header type
> containing these fields, allocate it, make it valid, populate it and emit
> it.
>
>
>
> Mihai
>
> *From: *Wallas Fróes <wallasync at gmail.com>
> *Sent: *Thursday, June 8, 2017 1:26 PM
> *To: *Andy Fingerhut <andy.fingerhut at gmail.com>
> *Cc: *p4-dev lists.p4.org <p4-dev at lists.p4.org>
> *Subject: *Re: [P4-dev] varbit
>
>
> i'll try too explain better my problem. I need to build a header based on
> table infos at the switch pipeline and emmit that header with the packet_in
> and it's easy to do on the fixed length fields, but one field at my header
> is a varbit field and i don't know how to attach some value to the varbit
> field...
>
> 2017-06-08 15:13 GMT-03:00 Andy Fingerhut <andy.fingerhut at gmail.com>:
>
>> Minor note: the 2nd argument to the 2-argument version of extract() is in
>> units of bits, not bytes, so you will often need to multiply by 8, and
>> maybe add or subtract a constant depending upon which part of the header is
>> included or excluded in the protocol's length field.
>>
>> Andy
>>
>> On Thu, Jun 8, 2017 at 4:01 AM, Rui Miguel <rmiguel at lasige.di.fc.ul.pt>
>> wrote:
>>
>>> Hi!
>>> Two options:
>>>
>>> 1. You can use the lookahead<T>() method from packet_in. For example,
>>> assuming your header is composed of a fixed length field (8 bits) and the
>>> variable length field, you can write:
>>>
>>>  bit<8> length = b.lookahead<bit<8>>();
>>>  b.extract(p.yourVariableLengthHeader, (bit<32>) length);
>>>
>>> NOTE: You'll have to make sure the packet isn't at its end. If you
>>> invoke lookahead() when there's no more data to be read, the packet is
>>> rejected by the parser.
>>>
>>>
>>> 2. As the specification suggests, you can split it into various headers.
>>>
>>> header fixedLenHeader_h {
>>>  bit<8> length;
>>> }
>>>
>>> header varLenHeader_h {
>>>  varbit<255> varField;
>>> }
>>>
>>> struct Parsed_packet {
>>>  fixedLenHeader_h preamble;
>>>  varLenHeader_h data;
>>> }
>>>
>>> Then, in the parser, write:
>>>
>>>  b.extract(p.preamble);
>>>  b.extract(p.data, (bit<32>) p.preamble.length);
>>>
>>>
>>> ~ Rui Miguel
>>>
>>> ----------------original message-----------------
>>> From: "Wallas Fróes" wallasync at gmail.com
>>> To: p4-dev at lists.p4.org
>>> Date: Wed, 7 Jun 2017 23:07:58 -0300
>>> -------------------------------------------------
>>>
>>>
>>> > Hello,
>>> >
>>> > I am with a doubt. I am creating a header within of the switch and in
>>> this
>>> > header I create a variable field using the "varbit".
>>> > So I create a field that will receive a value to will define the fixed
>>> > lenght for the variable field.
>>> >
>>> > The issue is, how do I do to atribute the value of the fixed field to
>>> the
>>> > variable field? and how build this header, and put it into the package
>>> > and, lastly, forward the package to the out port.
>>> >
>>> > --
>>> > Att,
>>> >
>>> > Wallas Fróes
>>> > Information Security in Computer Networks
>>> > Computer Engineer
>>> > Cel: (77) 8841-0762
>>> >
>>>
>>> __________________________________________________
>>> > _______________________________________________
>>> > P4-dev mailing list
>>> > P4-dev at lists.p4.org
>>> > http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.p4.org_mailman_listinfo_p4-2Ddev-5Flists.p4.org&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=tGW6TKXajnoXSyy1S1P4DHGPe8sj54GGvw-b21n7aWg&m=nZ1-0r3KxaCJae5G5zNHV9ljqQAsNIYQI8OhgHv1Qf4&s=BD7tsuxreplEW-Qm8qKt6w9XejY0imlOMKhqxHIUX_c&e=>
>>>
>>>
>>>
>>> _______________________________________________
>>> P4-dev mailing list
>>> P4-dev at lists.p4.org
>>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.p4.org_mailman_listinfo_p4-2Ddev-5Flists.p4.org&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=tGW6TKXajnoXSyy1S1P4DHGPe8sj54GGvw-b21n7aWg&m=nZ1-0r3KxaCJae5G5zNHV9ljqQAsNIYQI8OhgHv1Qf4&s=BD7tsuxreplEW-Qm8qKt6w9XejY0imlOMKhqxHIUX_c&e=>
>>
>>
>>
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.p4.org_mailman_listinfo_p4-2Ddev-5Flists.p4.org&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=tGW6TKXajnoXSyy1S1P4DHGPe8sj54GGvw-b21n7aWg&m=nZ1-0r3KxaCJae5G5zNHV9ljqQAsNIYQI8OhgHv1Qf4&s=BD7tsuxreplEW-Qm8qKt6w9XejY0imlOMKhqxHIUX_c&e=>
>>
>
>
>
> --
> Att,
>
> Wallas Fróes
> Information Security in Computer Networks
> Computer Engineer
> Cel: (77) 8841-0762
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170608/7fe9f864/attachment-0002.html>


More information about the P4-dev mailing list