[P4-dev] add a persistent Header

Antonin Bas antonin at barefootnetworks.com
Thu May 19 17:28:18 EDT 2016


The copy_to_cpu example which I pointed you to in the previous thread also
covers add_header:

1) You should not use add_header on a metadata header, so it should be a
"real" header

2) Your custom header needs to be part of the parse graph, so that the
switch knows where to place it in the packet. If you look at the
copy_to_cpu example, you will see that the cpu_header header instance is
placed at the very beginning of the packet, before the ethernet header.
More precisely, the P4 compiler uses the parse graph (the P4 parser) to
generate a topological sorting of the header instances (
https://en.wikipedia.org/wiki/Topological_sorting). Note that this excludes
metadata instances, which by definition are not part of the parse graph.
You have to be careful when you write the parser code, because a
topological sorting is not always unique, so you may have to add some extra
edges to make it unique.
It is very easy to transform the P4 parser object to a parse graph: each
header instance becomes a node in the graph and each transition becomes an
edge. If a parse state includes 2 successive extract operations on 2
distinct header instances, there exists an edge from the first header to
the second one.

3) Yes, it is your job to adjust the value of relevant fields in all
previous headers.


On Thu, May 19, 2016 at 2:13 PM, Halouoi HAMZA <halouoi.hamza at utt.fr> wrote:

> Hi,
> I want to add my own custom header to the packet, and I want that header
> to be persistent : it remains attached to the packet as it get sent over
> the network; making the packet permanently modified.
> 1)      Can I use the primitive action add_header ? It takes a header as
> parameter, but can it be a real header, or only metadata header ?
> 2)      If that’s a real header, where is my header actually located in
> the packet ? Is it appended at the end of the packet ? At the very
> beginning ? After the IP header ? Where is it ? The primitive only takes
> one argument, and I cannot specify the header location.
> 3)      If that’s a real header that I can add after the IP header, do I
> need to modify the IP field “total length” to accurately match the new
> packet size, or is it done automatically ?
> Thanks,
> Halouoi
> _______________________________________________
> 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/20160519/851dda0d/attachment.html>

More information about the P4-dev mailing list