p4lang / p4runtime

Specification documents for the P4Runtime control-plane API
Apache License 2.0
142 stars 88 forks source link

Do "Read" requests allow filtering on non-key fields? #385

Closed blp closed 2 years ago

blp commented 2 years ago

In implementing a P4Runtime server, I'm trying to understand the intended behavior of the Read request when a Entity includes a value for a non-key field. For example, suppose that an Entity in the request is a TableEntry whose metadata member is nonempty. Does this select only the table entries whose metadata is equal to the one in the Entity? I think this is the intention based on https://github.com/p4lang/p4runtime/issues/229#issuecomment-517868612, but I could not find good support for this in the text.

This would lead to some odd corner cases, for example it would be possible to filter for table entries with a particular nonzero idle_timeout_ns, but not those with a zero idle_timeout_ns.

(I read P4Runtime 1.3.0 for this purpose.)

Guidance or textual clarification is appreciated.

antoninbas commented 2 years ago

This section describes the filtering mechanism supported for wildcard reads on table entries. Not all fields are supported, e.g. idle_timeout_ns.

For the metadata field:

metadata: If default (empty byte string), all entries from the specified table will be considered. Otherwise, results will be filtered based on the provided metadata value.

Because of Protobuf 3 semantics, it is not possible to request all entries for which metadata is unset / empty. In a lot of cases, the zero-value for a field is reserved and is not a valid value. For example, a priority of 0 for a ternary entry is not valid, so there is no ambiguity for the priority field. When we have a field for which we clearly need to distinguish between unset and the zero-value, we usually wrap the individual field in its own Protobuf message (and example would be the index field for indirect counters & meters). However, in the case of metadata, we did not deem it necessary at the time.

antoninbas commented 2 years ago

Note that other Entities (besides TableEntry) do not support filtering on non-key fields, unless I am misremembering.

blp commented 2 years ago

OK, thanks! The explanation was there, I just did not read carefully enough.

I don't think anything is needed here, so I'll close this.