P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
psa.h
1/*
2Copyright 2022-present Orange
3Copyright 2022-present Open Networking Foundation
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17#ifndef P4C_PSA_H
18#define P4C_PSA_H
19
20#include <stdbool.h>
21
22typedef __u32 PortId_t;
23typedef __u64 Timestamp_t;
24typedef __u8 ClassOfService_t;
25typedef __u16 CloneSessionId_t;
26typedef __u32 MulticastGroup_t;
27typedef __u16 EgressInstance_t;
28
29// Instead of using enum we define PSA_PacketPath_t as __u8 to save memory.
30typedef __u8 PSA_PacketPath_t;
31
32static const PSA_PacketPath_t NORMAL = 0;
33static const PSA_PacketPath_t NORMAL_UNICAST = 1;
34static const PSA_PacketPath_t NORMAL_MULTICAST = 2;
35static const PSA_PacketPath_t CLONE_I2E = 3;
36static const PSA_PacketPath_t CLONE_E2E = 4;
37static const PSA_PacketPath_t RESUBMIT = 5;
38static const PSA_PacketPath_t RECIRCULATE = 6;
39
40// Instead of using enum we define ParserError_t as __u8 to save memory.
41typedef __u8 ParserError_t;
42static const ParserError_t NoError = 0;
43static const ParserError_t PacketTooShort = 1;
44static const ParserError_t NoMatch = 2;
45static const ParserError_t StackOutOfBounds = 3;
46static const ParserError_t HeaderTooShort = 4;
47static const ParserError_t ParserTimeout = 5;
48static const ParserError_t ParserInvalidArgument = 6;
50
51enum PSA_MeterColor_t { RED, GREEN, YELLOW };
52
53/*
54 * INGRESS data types
55 */
57 PortId_t ingress_port; // taken from xdp_md or __sk_buff
58 PSA_PacketPath_t packet_path; // taken from psa_global_metadata
59} __attribute__((aligned(4)));
60
62 // All of these values are initialized by the architecture before
63 // the Ingress control block begins executing.
64 PortId_t ingress_port; // taken from xdp_md or __sk_buff
65 PSA_PacketPath_t packet_path; // taken from psa_global_metadata
66 Timestamp_t ingress_timestamp; // taken from bpf helper
67 ParserError_t parser_error; // local to ingress parser
68} __attribute__((aligned(4)));;
69
71 // The comment after each field specifies its initial value when the
72 // Ingress control block begins executing.
73 MulticastGroup_t multicast_group; // 0, set in ingress as global metadata
74 PortId_t egress_port; // initial value is undefined, set in ingress as global metadata
75 ClassOfService_t class_of_service; // 0, set in ingress as global metadata
76 bool clone; // false, set in ingress/egress as global metadata
77 CloneSessionId_t clone_session_id; // initial value is undefined, set in ingress/egress as global metadata
78 bool drop; // true, set in ingress/egress as global metadata
79 bool resubmit; // false, local to ingress?
80} __attribute__((aligned(4)));
81
82/*
83 * EGRESS data types
84 */
85
87 PortId_t egress_port; // taken from xdp_md or __sk_buff
88 PSA_PacketPath_t packet_path; // taken from psa_global_metadata
89} __attribute__((aligned(4)));
90
92 ClassOfService_t class_of_service; // taken from global metadata
93 PortId_t egress_port; // taken taken from xdp_md or __sk_buff
94 PSA_PacketPath_t packet_path; // taken from global metadata
95 EgressInstance_t instance; // instance comes from the PacketReplicationEngine
96 // set by PRE as global metadata,
97 // in Egress taken from global metadata
98 Timestamp_t egress_timestamp; // taken from bpf_helper
99 ParserError_t parser_error; // local to egress pipeline
100} __attribute__((aligned(4)));
101
103 // The comment after each field specifies its initial value when the
104 // Egress control block begins executing.
105 bool clone; // false, set in egress as global metadata
106 CloneSessionId_t clone_session_id; // initial value is undefined, set in egress as global metadata
107 bool drop; // false, set in egress as global metadata
108} __attribute__((aligned(4)));
109
111 PortId_t egress_port; // local to egress pipeline, set by in egress
112} __attribute__((aligned(4)));
113
114/*
115 * Opaque struct to be used to share global PSA metadata fields between eBPF program attached to Ingress and Egress.
116 * The size of this struct must be less than 32 bytes.
117 */
119 PSA_PacketPath_t packet_path;
120 EgressInstance_t instance;
121 __u8 mark;
123} __attribute__((aligned(4)));
124
126 __u32 egress_port;
127 __u16 instance;
128 __u8 class_of_service;
129 __u8 truncate;
130 __u16 packet_length_bytes;
131} __attribute__((aligned(4)));
132
133#endif //P4C_PSA_H
Definition psa.h:125
Definition psa.h:91
Definition psa.h:102
Definition psa.h:118
bool pass_to_kernel
packet mark set by PSA/eBPF programs. Used to differentiate between packets processed by PSA/eBPF fro...
Definition psa.h:122
EgressInstance_t instance
set by eBPF program as helper variable, read by ingress/egress
Definition psa.h:120
__u8 mark
set by PRE, read by Egress
Definition psa.h:121
Definition psa.h:61