-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should I2E cloned packets in simple_switch avoid re-parsing? #795
Comments
For the question regarding (3): the ingress pipeline modifies the PHV object (in particular packet header fields are very likely be modified). We don't know whether the packet will be cloned until the pipeline terminates, but by that time it is too late to copy the PHV object, since it has already been modified. We would need to copy it before applying the ingress pipeline, pessimistically, and would only use that copy if I2E cloning was actually requested. Personally, I'm fine with (2). I think it makes the most sense, unless someone thinks the cloned packet should not carry a valid ingress port value. |
OK, adding another quick thought on approach (2), in case that ends up being a change made to behavioral-model. It would be good to scan through all of the v1model standard metadata to see which of them are most likely to be used in P4 parser code, and consider making all of them equal to the values of the packet that caused this I2E clone to be created, so its parsing step ends up with the same results. Here are fields where it seems fairly reasonable that someone might think to write P4 parser code that reads them, at least in some cases:
These fields seem pretty useless or counter-productive to use in a P4 parser, to me. It would seem reasonable to say that for I2E clone packets (and perhaps even packets arriving from ports), these values are all always 0 (or error.NoError for parser_error) when the v1model parser begins:
These fields currently in v1model.p4 are deprecated, and/or may be removed at some point:
|
We are running into this exact issue in the context of implementing P4Runtime packet-IO. We use BMv2's CPU port feature by passing in
Accordingly, our parser looks as follows:
Unfortunately, this breaks when we I2E-clone a packet, since the clone will be re-parsed with I tried working around this by branching on |
I agree with solution (2) proposed above. @jafingerhut @antoninbas is this a thing that can be changed easily, or a deeper issue? |
As far as I know approach (2) should be fairly easy to create a quick experimental implementation of to try out locally on your side, but I have not made such changes myself and tested them. I would try changing this line:
to something like this:
Then test it to see whether it behaves as desired. |
@jafingerhut is describing the correct approach, and IMO it's a very simple change. |
Will give it a try, thank you! |
Works! |
@smolkaj any plan to open a PR? I think it's a change that generally makes sense, not just for your specific use case |
Yes, I am planning to submit a fix for at least the ingress port. I can't promise a more complete solution (#795 (comment)) since there seem to be some open question, AFAICT |
@smolkaj Even if you submit a change that does what you need for now, i.e. only initialize the ingress_port field before re-parsing, that is still useful. It would be good to put a comment in the code to the other issue for anyone that wants more information about additional enhancements they might wish to make in the future. |
This is a partial fix for p4lang#795.
Sounds good! Here is such a patch: #1175. PTAL. |
These lines of code: https://github.com/p4lang/behavioral-model/blob/master/targets/simple_switch/simple_switch.cpp#L551-L554
copied below for convenience:
are part of the code in method
ingress_thread
, inside of anif
statement for handling ingress packets that should be I2E cloned.One minor thing I noticed is that standard_metadata.ingress_port of the cloned packet is 0. If a packet arrived on some non-0 port, and the P4 parser code parsed packets differently for packets arriving on that port vs packets arriving on port 0, then the I2E-cloned packet would have different parsed results than the original packet.
Some possibilities would be:
(1) document this as the expected behavior
(2) change the implementation so that standard_metadata.ingress_port of the cloned packet is copied from the original packet, before the cloned packet is re-parsed.
(3) change the code above so that the packet is not re-parsed, but the PHV of the original packet is copied.
Now the current comment implies to me that approach (3) was avoided intentionally, by design. However, the comment text confuses me. Wouldn't it be possible to pay the (huge) price of PHV copy only for packets that had an I2E clone operation performed, and not for all ingress packets?
The text was updated successfully, but these errors were encountered: