How to configure mirror direction by using p4runtime protocol?

in p4runtime protocol, message for mirror is like this:
message CloneSessionEntry {
uint32 session_id = 1;
repeated Replica replicas = 2;
uint32 class_of_service = 3;
int32 packet_length_bytes = 4;
message Replica {
oneof port_kind {
// Using uint32 as ports is deprecated, use port field instead.
uint32 egress_port = 1 [deprecated=true];
bytes port = 3;
uint32 instance = 2;

but there is no direction field, you know , for mirror, there are INGRESS, EGRESS and BOTH direction types.
so how to configure mirror direction?

Hi @ychen ,

I think that the mirror direction is defined within your P4 program, indeed in the code you have to specify the direction for the mirror/cloning p4c/p4include/v1model.p4 at main · p4lang/p4c · GitHub and the session and via the CLI you can specify the egress port behavioral-model/targets/simple_switch/ at 7a8843ffb87bab9eb0a44c993ae39a9fefca10cf · p4lang/behavioral-model · GitHub. So I think that the beaviour is the same in P4Runtime.


I did define the direction of the mirror in my code, but it is specified as an input parameter, which means it can be specified by the user. However, in the P4Runtime protocol message definition, there is no way for the user to pass input parameters such as direction. So, I am wondering if I can use the “instance” field in the “Replica” message as the direction. Actually, this parameter only works for multicast, but I want to use it as the direction and then parse it on the receiving end.

In mine previous message I meant to say that the direction of the clone is fixed at compiler level. So, whether or not you use the P4 runtime at control level you cannot change the direction of packet cloning. This also applies to the session id that is associated with that specific “clone function/object” defined in your P4 program.

please lookat this file for tofino:

p4_pd_direction_t dir; /** Mirror direction */
typedef enum {
} p4_pd_direction_t;

and lookat this file in stratum:

and search BfSdeWrapper::WriteCloneSession
// Data: $direction
RETURN_IF_ERROR(SetField(table_data.get(), “$direction”, “BOTH”));

so for tofino based mirror, users can configure mirror session. but p4runtime protocol does not support direction parameter.

Tofino has its own control plane APIs that should support its full range of configuration options.

P4Runtime API configuration for mirroring can cover the options for the v1model architecture and PSA architecture, but not necessarily Tofino’s, which has more options than the others.

P4Runtime API was never designed to cover that full range of options in any architecture other than PSA. There is work going on in the P4 API work group to generalize what P4Runtime API can support, but it is not there yet.

1 Like

ok, thanks! Now I understand.