[P4-dev] Packet + Header Serialization

Antonin Bas antonin at barefootnetworks.com
Sat Oct 6 19:16:46 EDT 2018

Hi Isaac,

You have access to the p4objects instance when implementing action
primitives. As a result you should be able to write the following in the
functor to access the deparser: get_p4objects()->get_deparser(<deparser
I believe you also have access to the packet through get_packet(). Which
means that you can serialize the packet into one byte array.
There is one caveat, which is that you will need to save the packet buffer
state before deparsing and restore it afterwards:
Otherwise you will screw up the actual deparsing state at the end of packet
If you want you can submit a PR to add a method which gives access to the
vector that defines in which order headers are deparsed (
I wouldn't mind too much :). and it would let you do your own deparsing
without having to worry about checksums and the packet buffer state.

Now if you really want to have access to the packet as it was received,
it's going to be a little tricky and will require some changes (I need to
spend some time thinking about which changes exactly). Feel free to open an
issue on Github if you need this feature.

On Thu, Oct 4, 2018 at 1:56 PM Isaac Pedisich <iped at seas.upenn.edu> wrote:

> Dear All,
> As referenced in a now-closed PR on the behavioral model repo (
> https://github.com/p4lang/behavioral-model/pull/666), we require a way to
> obtain the serialized form of a packet along with its (valid) headers from
> within an extern.
> Either obtaining a copy of the packet as it entered the system before
> parsing, or using a reference to the pipeline's deparser will suit our
> needs. However, neither the original packet nor the deparser seem to be
> accessible from inside of an extern at this time.
> Is there an accepted way of accessing a packet's headers and body as a
> single serialized array of bytes? If not, where is the most appropriate
> location to add such functionality?
> Thank you,
> Isaac
> _______________________________________________
> 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/20181006/2acd6a4a/attachment.html>

More information about the P4-dev mailing list