[P4-dev] varbit

Rui Miguel rmiguel at lasige.di.fc.ul.pt
Thu Jun 8 07:01:03 EDT 2017


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






More information about the P4-dev mailing list