[P4-dev] varbit

Mihai Budiu mbudiu at vmware.com
Thu Jun 8 16:36:47 EDT 2017


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<mailto:wallasync at gmail.com>
Sent: Thursday, June 8, 2017 1:26 PM
To: Andy Fingerhut<mailto:andy.fingerhut at gmail.com>
Cc: p4-dev lists.p4.org<mailto: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<mailto: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<mailto: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<mailto:wallasync at gmail.com>
To: p4-dev at lists.p4.org<mailto: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<tel:%2877%29%208841-0762>
>

__________________________________________________
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org<mailto: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<mailto: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<mailto: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/ef122854/attachment-0002.html>


More information about the P4-dev mailing list