p4-spec icon indicating copy to clipboard operation
p4-spec copied to clipboard

Add explanation on passing directionless, extern object argument

Open jaehyun1ee opened this issue 1 year ago • 1 comments

I propose adding some clarifications to the spec, discussing how directionless, extern objects are passed to a control/parser. (#1276)

In the below parser type declaration, the first parameter, packet_in b is an directionless extern object.

parser Top(packet_in b, out Parsed_headers headers) {

Spec section 6.8. Calling convention: call by copy in/copy out discusses the calling convention on directionless parameter as follows:

The meaning of parameters with no direction depends upon the kind of entity the parameter is for: For anything other than an action, e.g. a control, parser, or function, a directionless parameter means that the value supplied as an argument in a call must be a compile-time known value (see Section 18.1). For an action, a directionless parameter indicates that it is “action data”. See Section 14.1 for the meaning of action data, but its meaning includes the following possibilities: The parameter's value is provided in the P4 program. In this case, the parameter behaves as if the direction were in. Such an argument expression need not be a compile-time known value. The parameter's value is provided by the control plane software when an entry is added to a table that uses that action. See Section 14.1.

Yet, it does not discuss how the parameter packet_in b should actually be passed to the parser block.

Given that the packet_in object is stateful (+ instantiated by the target), it seems reasonable to assume that passing it by reference would be the appropriate approach, rather than copying the entire object.

I suggest that the specification clarify this point by providing guidance on how directionless extern parameters should be passed to parsers, controls, or functions.

jaehyun1ee avatar Apr 18 '24 01:04 jaehyun1ee

Hi @jaehyun1ee, this is the ONF bot 🤖 I'm glad you want to contribute to our projects! However, before accepting your contribution, we need to ask you to sign a Contributor License Agreement (CLA). You can do it online, it will take only a few minutes:

✒️ 👉 https://cla.opennetworking.org

After signing, make sure to add your Github user ID jaehyun1ee to the agreement.

For more information or help:" https://wiki.opennetworking.org/x/BgCUI

onf-cla-manager[bot] avatar Apr 18 '24 01:04 onf-cla-manager[bot]