How do I access the data of ingress in egress?

I calculate a data in ingress and I want to obtain this data in egree. Is there any way?

You can write it to metadata or a transient header.

The implementation of the v1model architecture in the behavioral-model simple_switch / simple_switch_grpc process enables the feature that any assignments made to user-defined metadata fields in ingress are preserved with the packet and readable (and assignable) in egress processing.

There are other P4 architectures, e.g. Tofino’s Native Architecture (TNA) where making a field calculated in ingress to be readable in egress, requires copying the field into a “bridge” metadata header that is prepended to the packet during ingress processing, and parsed in the egress parser.

So there are variations here that may require different approaches, but if you are asking about the v1model architecture implementation in open source, it is quite easy to achieve.

Thank you for your advice. I am studying P4 in TNA,‘bridge’ is exactly what I want.