[P4-dev] varbit

Wallas Fróes wallasync at gmail.com
Thu Jun 8 16:25:45 EDT 2017


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
>>
>>
>>
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>
>
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>



-- 
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/cb374669/attachment-0002.html>


More information about the P4-dev mailing list