p4lang / p4-spec

Apache License 2.0
177 stars 80 forks source link

for p4-14, Is it possible to add header at the end of the whole packet? #776

Closed wangsingx closed 5 years ago

wangsingx commented 5 years ago

for p4-14, Is it possible to add header at the end of the whole packet? the packet might be L2/L3/L4 or tunnel packet(vxlan or other). I mean that we don't know the pakcet's whole length and protocol, it might be any packets. what I want to do is add a header at the end of the whole packet to mark the ingress port and egress port.

I have confirmed that we can add header at the head of the whole packet, but the output packet can't be parsed by next device. I also have confirmed that it is possible to add header after the udp, tcp or other header. but this will damage the original packet's integrity

jafingerhut commented 5 years ago

The P4_14 and P4_16 language specifications provide no standard way to do this.

Individual P4 implementations are free to add whatever extensions they wish. In general, the cheaper the implementation is in $ per "terabit-per-second", the less likely it is to have such an extension, but check with a particular device vendor if it is really important to you.

The Inband Network Telemetry group (INT) has wrestled with many possibilities of adding INT headers to packets in multiple possible places near the beginning of the packet -- you may want to read over its specification [1] for what the group has come up with. The primary difficulties there are thinking through cases of which devices will ignore such inserted headers, vs. which ones will allow them through. A lot of high speed switches would be unlikely to do anything with extra headers inserted after TCP or UDP, treating them as part of the packet payload to be carried along -- it is impractically expensive in such devices to check the full packet payload's TCP or UDP checksum, and as long as the end system does so, those checksums have served their purpose.

With INT, the plan is that some INT-aware network device will remove those inserted INT headers before the packet reaches a device (e.g. the target device's TCP/IP network software) that would misbehave because of their presence.

[1] https://p4.org/specs/

wangsingx commented 5 years ago

I agree that it is impractically expensive in such devices to check the full packet. I can't find a switch chip implement this function so far. Maybe the Tofino chip produced by Barefoot can achieve it. Only pure software can do it.

I think the problem is we can't bypass the payload, so we can't add the header end of the payload. From the spec, payload is only used to calculate checksum, and it can't be add to the topological sorting of the header instance as we can't extract payload.

@jafingerhut > The P4_14 and P4_16 language specifications provide no standard way to do this. as you said p4 spec provide no standard way to do this, so you mean it is possible? or there may be some work-around to bypass or extract payload that could be of any length?

jafingerhut commented 5 years ago

Is it possible to create a device that can append data at the end of a packet payload? Of course. Software running on a general purpose CPU can trivially do this. Can a device that is 3 orders of magnitude less $ per terabit-per-second do it? I don't know. It isn't a cheap thing to do, and there isn't a lot of need to do it that cannot be done in other ways, as I mentioned by suggesting looking at the INT specification.

jafingerhut commented 5 years ago

And sorry, to answer your question more directly, when I said that there is no standard way in the P4 language specifications, I meant that if a P4 programmable device implemented exactly what was in the language specifications, and no more, then that implementation could not append headers to the end of the packet.