[P4-dev] varbit

Andy Fingerhut andy.fingerhut at gmail.com
Thu Jun 8 14:13:11 EDT 2017


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170608/d51ec121/attachment-0002.html>


More information about the P4-dev mailing list