blob: b76ea01f0a6ae43958961a9c0b23b14ce7556367 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __HEADER__
18#define __HEADER__
19
20#include "define.p4"
Carmelo Cascone79a3a312018-08-16 17:14:43 -070021#include "int/int_header.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070022
23@controller_header("packet_in")
24header packet_in_header_t {
25 port_num_t ingress_port;
Yi Tseng1d842672017-11-28 16:06:52 -080026 bit<7> _pad;
Yi Tsengbe342052017-11-03 10:21:23 -070027}
28
Carmelo Cascone35d9b332018-06-15 16:27:22 +020029_PKT_OUT_HDR_ANNOT
Yi Tsengbe342052017-11-03 10:21:23 -070030@controller_header("packet_out")
31header packet_out_header_t {
32 port_num_t egress_port;
Carmelo Casconedb347372021-05-26 19:30:30 +020033 bit<1> do_forwarding;
34 bit<6> _pad;
Yi Tsengbe342052017-11-03 10:21:23 -070035}
36
37header ethernet_t {
38 mac_addr_t dst_addr;
39 mac_addr_t src_addr;
Daniele Moro5a2de712019-09-24 14:34:07 -070040}
41
42// NOTE: splitting the eth_type from the ethernet header helps to match on
43// the actual eth_type without checking validity bit of the VLAN tags.
44header eth_type_t {
45 bit<16> value;
Yi Tsengbe342052017-11-03 10:21:23 -070046}
47
48header vlan_tag_t {
Daniele Moro5a2de712019-09-24 14:34:07 -070049 bit<16> eth_type;
Yi Tsengbe342052017-11-03 10:21:23 -070050 bit<3> pri;
51 bit<1> cfi;
52 vlan_id_t vlan_id;
Yi Tsengbe342052017-11-03 10:21:23 -070053}
54
55header mpls_t {
56 bit<20> label;
57 bit<3> tc;
58 bit<1> bos;
59 bit<8> ttl;
60}
61
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070062header pppoe_t {
63 bit<4> version;
64 bit<4> type_id;
65 bit<8> code;
66 bit<16> session_id;
67 bit<16> length;
68 bit<16> protocol;
69}
70
Yi Tsengbe342052017-11-03 10:21:23 -070071header ipv4_t {
72 bit<4> version;
73 bit<4> ihl;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090074 bit<6> dscp;
75 bit<2> ecn;
Yi Tsengbe342052017-11-03 10:21:23 -070076 bit<16> total_len;
77 bit<16> identification;
78 bit<3> flags;
79 bit<13> frag_offset;
80 bit<8> ttl;
81 bit<8> protocol;
82 bit<16> hdr_checksum;
83 bit<32> src_addr;
84 bit<32> dst_addr;
85}
86
87header ipv6_t {
88 bit<4> version;
89 bit<8> traffic_class;
90 bit<20> flow_label;
91 bit<16> payload_len;
92 bit<8> next_hdr;
93 bit<8> hop_limit;
94 bit<128> src_addr;
95 bit<128> dst_addr;
96}
97
Yi Tsengbe342052017-11-03 10:21:23 -070098header tcp_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080099 bit<16> sport;
100 bit<16> dport;
Yi Tsengbe342052017-11-03 10:21:23 -0700101 bit<32> seq_no;
102 bit<32> ack_no;
103 bit<4> data_offset;
104 bit<3> res;
105 bit<3> ecn;
106 bit<6> ctrl;
107 bit<16> window;
108 bit<16> checksum;
109 bit<16> urgent_ptr;
110}
111
112header udp_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800113 bit<16> sport;
114 bit<16> dport;
Yi Tsengbe342052017-11-03 10:21:23 -0700115 bit<16> len;
116 bit<16> checksum;
117}
118
119header icmp_t {
120 bit<8> icmp_type;
121 bit<8> icmp_code;
122 bit<16> checksum;
Yi Tsengf73a5532017-11-17 15:58:57 -0800123 bit<16> identifier;
124 bit<16> sequence_number;
125 bit<64> timestamp;
Yi Tsengbe342052017-11-03 10:21:23 -0700126}
127
Carmelo Casconeffa7fed2021-06-01 18:31:57 -0700128
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800129// GTPU v1
130header gtpu_t {
131 bit<3> version; /* version */
132 bit<1> pt; /* protocol type */
133 bit<1> spare; /* reserved */
134 bit<1> ex_flag; /* next extension hdr present? */
135 bit<1> seq_flag; /* sequence no. */
136 bit<1> npdu_flag; /* n-pdn number present ? */
137 bit<8> msgtype; /* message type */
138 bit<16> msglen; /* message length */
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400139 teid_t teid; /* tunnel endpoint id */
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800140}
141
Carmelo Casconeffa7fed2021-06-01 18:31:57 -0700142#ifdef WITH_SPGW
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800143struct spgw_meta_t {
Carmelo Cascone274daef2018-02-14 20:32:49 -0800144 bit<16> ipv4_len;
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400145 teid_t teid;
Robert MacDavidde12b982020-07-15 18:38:59 -0700146 bit<16> tunnel_src_port;
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400147 bit<32> tunnel_src_addr;
148 bit<32> tunnel_dst_addr;
Robert MacDavidde12b982020-07-15 18:38:59 -0700149 pdr_ctr_id_t ctr_id;
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400150 far_id_t far_id;
Robert MacDavidde12b982020-07-15 18:38:59 -0700151 spgw_interface_t src_iface;
152 _BOOL skip_spgw;
Robert MacDavidde12b982020-07-15 18:38:59 -0700153 _BOOL notify_spgwc;
154 _BOOL needs_gtpu_encap;
155 _BOOL needs_gtpu_decap;
Carmelo Casconeb1f5cfd2020-12-04 16:54:24 -0800156 _BOOL skip_egress_pdr_ctr;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800157}
158#endif // WITH_SPGW
159
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700160#ifdef WITH_BNG
161
162typedef bit<2> bng_type_t;
163const bng_type_t BNG_TYPE_INVALID = 2w0x0;
164const bng_type_t BNG_TYPE_UPSTREAM = 2w0x1;
165const bng_type_t BNG_TYPE_DOWNSTREAM = 2w0x2;;
166
167struct bng_meta_t {
Daniele Morob3d199b2019-11-01 14:01:46 -0700168 bit<2> type; // upstream or downstream
169 bit<32> line_id; // subscriber line
170 bit<16> pppoe_session_id;
171 bit<32> ds_meter_result; // for downstream metering
172 vlan_id_t s_tag;
173 vlan_id_t c_tag;
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700174}
175#endif // WITH_BNG
176
Yi Tsengbe342052017-11-03 10:21:23 -0700177//Custom metadata definition
178struct fabric_metadata_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800179 bit<16> ip_eth_type;
180 vlan_id_t vlan_id;
181 bit<3> vlan_pri;
182 bit<1> vlan_cfi;
Daniele Moro7c3a0022019-07-12 13:38:34 -0700183#ifdef WITH_DOUBLE_VLAN_TERMINATION
184 _BOOL push_double_vlan;
185 vlan_id_t inner_vlan_id;
186 bit<3> inner_vlan_pri;
187 bit<1> inner_vlan_cfi;
188#endif // WITH_DOUBLE_VLAN_TERMINATION
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800189 mpls_label_t mpls_label;
190 bit<8> mpls_ttl;
191 _BOOL skip_forwarding;
192 _BOOL skip_next;
193 fwd_type_t fwd_type;
194 next_id_t next_id;
195 _BOOL is_multicast;
196 _BOOL is_controller_packet_out;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800197 bit<8> ip_proto;
198 bit<16> l4_sport;
199 bit<16> l4_dport;
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400200 bit<32> ipv4_src_addr;
201 bit<32> ipv4_dst_addr;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800202#ifdef WITH_SPGW
Robert MacDavidde12b982020-07-15 18:38:59 -0700203 bit<16> inner_l4_sport;
204 bit<16> inner_l4_dport;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800205 spgw_meta_t spgw;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800206#endif // WITH_SPGW
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700207#ifdef WITH_BNG
208 bng_meta_t bng;
209#endif // WITH_BNG
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900210#ifdef WITH_INT
211 int_metadata_t int_meta;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900212#endif // WITH_INT
Wailok Shumfac26d42021-06-18 17:30:08 +0800213 port_type_t port_type;
Yi Tsengbe342052017-11-03 10:21:23 -0700214}
215
216struct parsed_headers_t {
217 ethernet_t ethernet;
218 vlan_tag_t vlan_tag;
Daniele Moro5a2de712019-09-24 14:34:07 -0700219#if defined(WITH_XCONNECT) || defined(WITH_DOUBLE_VLAN_TERMINATION)
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800220 vlan_tag_t inner_vlan_tag;
Daniele Moro5a2de712019-09-24 14:34:07 -0700221#endif // WITH_XCONNECT || WITH_DOUBLE_VLAN_TERMINATION
222 eth_type_t eth_type;
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700223#ifdef WITH_BNG
224 pppoe_t pppoe;
225#endif // WITH_BNG
Yi Tsengbe342052017-11-03 10:21:23 -0700226 mpls_t mpls;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800227#ifdef WITH_SPGW
228 ipv4_t gtpu_ipv4;
229 udp_t gtpu_udp;
Robert MacDavidde12b982020-07-15 18:38:59 -0700230 gtpu_t outer_gtpu;
Wailok Shum60dfd4a2021-06-11 22:48:41 +0800231#endif // WITH_SPGW
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800232 gtpu_t gtpu;
Carmelo Cascone9b0171b2018-08-14 01:43:57 -0700233 ipv4_t inner_ipv4;
234 udp_t inner_udp;
Robert MacDavidde12b982020-07-15 18:38:59 -0700235 tcp_t inner_tcp;
236 icmp_t inner_icmp;
Yi Tsengbe342052017-11-03 10:21:23 -0700237 ipv4_t ipv4;
Carmelo Casconeb757dbc2018-01-25 17:53:17 -0800238#ifdef WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700239 ipv6_t ipv6;
Carmelo Casconeb757dbc2018-01-25 17:53:17 -0800240#endif // WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700241 tcp_t tcp;
242 udp_t udp;
243 icmp_t icmp;
244 packet_out_header_t packet_out;
245 packet_in_header_t packet_in;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700246#ifdef WITH_INT_SINK
247 // INT Report encap
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900248 ethernet_t report_ethernet;
Daniele Moro5a2de712019-09-24 14:34:07 -0700249 eth_type_t report_eth_type;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900250 ipv4_t report_ipv4;
251 udp_t report_udp;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700252 // INT Report header (support only fixed)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900253 report_fixed_header_t report_fixed_header;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700254 // local_report_t report_local;
255#endif // WITH_INT_SINK
256#ifdef WITH_INT
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900257 // INT specific headers
258 intl4_shim_t intl4_shim;
259 int_header_t int_header;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900260 int_switch_id_t int_switch_id;
261 int_port_ids_t int_port_ids;
262 int_hop_latency_t int_hop_latency;
263 int_q_occupancy_t int_q_occupancy;
264 int_ingress_tstamp_t int_ingress_tstamp;
265 int_egress_tstamp_t int_egress_tstamp;
266 int_q_congestion_t int_q_congestion;
267 int_egress_port_tx_util_t int_egress_tx_util;
Carmelo Cascone8e5818d2018-10-26 11:45:23 -0700268#ifdef WITH_INT_SINK
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700269 int_data_t int_data;
Carmelo Cascone8e5818d2018-10-26 11:45:23 -0700270#endif // WITH_INT_SINK
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900271 intl4_tail_t intl4_tail;
272#endif //WITH_INT
Yi Tsengbe342052017-11-03 10:21:23 -0700273}
274
275#endif