blob: decad94a5ac2fa1983d3d538c01a3c217adfc080 [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;
Yi Tseng1d842672017-11-28 16:06:52 -080033 bit<7> _pad;
Yi Tsengbe342052017-11-03 10:21:23 -070034}
35
36header ethernet_t {
37 mac_addr_t dst_addr;
38 mac_addr_t src_addr;
Daniele Moro693d76f2019-09-24 14:34:07 -070039}
40
41// NOTE: splitting the eth_type from the ethernet header helps to match on
42// the actual eth_type without checking validity bit of the VLAN tags.
43header eth_type_t {
44 bit<16> value;
Yi Tsengbe342052017-11-03 10:21:23 -070045}
46
47header vlan_tag_t {
Daniele Moro693d76f2019-09-24 14:34:07 -070048 bit<16> eth_type;
Yi Tsengbe342052017-11-03 10:21:23 -070049 bit<3> pri;
50 bit<1> cfi;
51 vlan_id_t vlan_id;
Yi Tsengbe342052017-11-03 10:21:23 -070052}
53
54header mpls_t {
55 bit<20> label;
56 bit<3> tc;
57 bit<1> bos;
58 bit<8> ttl;
59}
60
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070061header pppoe_t {
62 bit<4> version;
63 bit<4> type_id;
64 bit<8> code;
65 bit<16> session_id;
66 bit<16> length;
67 bit<16> protocol;
68}
69
Yi Tsengbe342052017-11-03 10:21:23 -070070header ipv4_t {
71 bit<4> version;
72 bit<4> ihl;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090073 bit<6> dscp;
74 bit<2> ecn;
Yi Tsengbe342052017-11-03 10:21:23 -070075 bit<16> total_len;
76 bit<16> identification;
77 bit<3> flags;
78 bit<13> frag_offset;
79 bit<8> ttl;
80 bit<8> protocol;
81 bit<16> hdr_checksum;
82 bit<32> src_addr;
83 bit<32> dst_addr;
84}
85
86header ipv6_t {
87 bit<4> version;
88 bit<8> traffic_class;
89 bit<20> flow_label;
90 bit<16> payload_len;
91 bit<8> next_hdr;
92 bit<8> hop_limit;
93 bit<128> src_addr;
94 bit<128> dst_addr;
95}
96
Yi Tsengbe342052017-11-03 10:21:23 -070097header tcp_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080098 bit<16> sport;
99 bit<16> dport;
Yi Tsengbe342052017-11-03 10:21:23 -0700100 bit<32> seq_no;
101 bit<32> ack_no;
102 bit<4> data_offset;
103 bit<3> res;
104 bit<3> ecn;
105 bit<6> ctrl;
106 bit<16> window;
107 bit<16> checksum;
108 bit<16> urgent_ptr;
109}
110
111header udp_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800112 bit<16> sport;
113 bit<16> dport;
Yi Tsengbe342052017-11-03 10:21:23 -0700114 bit<16> len;
115 bit<16> checksum;
116}
117
118header icmp_t {
119 bit<8> icmp_type;
120 bit<8> icmp_code;
121 bit<16> checksum;
Yi Tsengf73a5532017-11-17 15:58:57 -0800122 bit<16> identifier;
123 bit<16> sequence_number;
124 bit<64> timestamp;
Yi Tsengbe342052017-11-03 10:21:23 -0700125}
126
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800127#ifdef WITH_SPGW
128// GTPU v1
129header gtpu_t {
130 bit<3> version; /* version */
131 bit<1> pt; /* protocol type */
132 bit<1> spare; /* reserved */
133 bit<1> ex_flag; /* next extension hdr present? */
134 bit<1> seq_flag; /* sequence no. */
135 bit<1> npdu_flag; /* n-pdn number present ? */
136 bit<8> msgtype; /* message type */
137 bit<16> msglen; /* message length */
Robert MacDavid1d475692020-05-21 21:32:38 -0400138 teid_t teid; /* tunnel endpoint id */
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800139}
140
141struct spgw_meta_t {
Carmelo Casconeb757dbc2018-01-25 17:53:17 -0800142 direction_t direction;
Carmelo Cascone274daef2018-02-14 20:32:49 -0800143 bit<16> ipv4_len;
Robert MacDavid1d475692020-05-21 21:32:38 -0400144 teid_t teid;
145 bit<32> tunnel_src_addr;
146 bit<32> tunnel_dst_addr;
147 ctr_id_t ctr_id;
148 far_id_t far_id;
149 _BOOL pdr_hit;
150 _BOOL far_dropped;
151 _BOOL notify_cp;
152 _BOOL outer_header_creation;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800153}
154#endif // WITH_SPGW
155
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700156#ifdef WITH_BNG
157
158typedef bit<2> bng_type_t;
159const bng_type_t BNG_TYPE_INVALID = 2w0x0;
160const bng_type_t BNG_TYPE_UPSTREAM = 2w0x1;
161const bng_type_t BNG_TYPE_DOWNSTREAM = 2w0x2;;
162
163struct bng_meta_t {
Daniele Morodd0568b2019-11-01 14:01:46 -0700164 bit<2> type; // upstream or downstream
165 bit<32> line_id; // subscriber line
166 bit<16> pppoe_session_id;
167 bit<32> ds_meter_result; // for downstream metering
168 vlan_id_t s_tag;
169 vlan_id_t c_tag;
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700170}
171#endif // WITH_BNG
172
Yi Tsengbe342052017-11-03 10:21:23 -0700173//Custom metadata definition
174struct fabric_metadata_t {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800175 bit<16> ip_eth_type;
176 vlan_id_t vlan_id;
177 bit<3> vlan_pri;
178 bit<1> vlan_cfi;
Daniele Moro7c3a0022019-07-12 13:38:34 -0700179#ifdef WITH_DOUBLE_VLAN_TERMINATION
180 _BOOL push_double_vlan;
181 vlan_id_t inner_vlan_id;
182 bit<3> inner_vlan_pri;
183 bit<1> inner_vlan_cfi;
184#endif // WITH_DOUBLE_VLAN_TERMINATION
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800185 mpls_label_t mpls_label;
186 bit<8> mpls_ttl;
187 _BOOL skip_forwarding;
188 _BOOL skip_next;
189 fwd_type_t fwd_type;
190 next_id_t next_id;
191 _BOOL is_multicast;
192 _BOOL is_controller_packet_out;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800193 bit<8> ip_proto;
194 bit<16> l4_sport;
195 bit<16> l4_dport;
Robert MacDavid1d475692020-05-21 21:32:38 -0400196 bit<32> ipv4_src_addr;
197 bit<32> ipv4_dst_addr;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800198#ifdef WITH_SPGW
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800199 spgw_meta_t spgw;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800200#endif // WITH_SPGW
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700201#ifdef WITH_BNG
202 bng_meta_t bng;
203#endif // WITH_BNG
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900204#ifdef WITH_INT
205 int_metadata_t int_meta;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900206#endif // WITH_INT
Yi Tsengbe342052017-11-03 10:21:23 -0700207}
208
209struct parsed_headers_t {
210 ethernet_t ethernet;
211 vlan_tag_t vlan_tag;
Daniele Moro693d76f2019-09-24 14:34:07 -0700212#if defined(WITH_XCONNECT) || defined(WITH_DOUBLE_VLAN_TERMINATION)
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800213 vlan_tag_t inner_vlan_tag;
Daniele Moro693d76f2019-09-24 14:34:07 -0700214#endif // WITH_XCONNECT || WITH_DOUBLE_VLAN_TERMINATION
215 eth_type_t eth_type;
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700216#ifdef WITH_BNG
217 pppoe_t pppoe;
218#endif // WITH_BNG
Yi Tsengbe342052017-11-03 10:21:23 -0700219 mpls_t mpls;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800220#ifdef WITH_SPGW
221 ipv4_t gtpu_ipv4;
222 udp_t gtpu_udp;
223 gtpu_t gtpu;
Carmelo Cascone9b0171b2018-08-14 01:43:57 -0700224 ipv4_t inner_ipv4;
225 udp_t inner_udp;
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800226#endif // WITH_SPGW
Yi Tsengbe342052017-11-03 10:21:23 -0700227 ipv4_t ipv4;
Carmelo Casconeb757dbc2018-01-25 17:53:17 -0800228#ifdef WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700229 ipv6_t ipv6;
Carmelo Casconeb757dbc2018-01-25 17:53:17 -0800230#endif // WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700231 tcp_t tcp;
232 udp_t udp;
233 icmp_t icmp;
234 packet_out_header_t packet_out;
235 packet_in_header_t packet_in;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700236#ifdef WITH_INT_SINK
237 // INT Report encap
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900238 ethernet_t report_ethernet;
Daniele Moro693d76f2019-09-24 14:34:07 -0700239 eth_type_t report_eth_type;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900240 ipv4_t report_ipv4;
241 udp_t report_udp;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700242 // INT Report header (support only fixed)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900243 report_fixed_header_t report_fixed_header;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700244 // local_report_t report_local;
245#endif // WITH_INT_SINK
246#ifdef WITH_INT
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900247 // INT specific headers
248 intl4_shim_t intl4_shim;
249 int_header_t int_header;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900250 int_switch_id_t int_switch_id;
251 int_port_ids_t int_port_ids;
252 int_hop_latency_t int_hop_latency;
253 int_q_occupancy_t int_q_occupancy;
254 int_ingress_tstamp_t int_ingress_tstamp;
255 int_egress_tstamp_t int_egress_tstamp;
256 int_q_congestion_t int_q_congestion;
257 int_egress_port_tx_util_t int_egress_tx_util;
Carmelo Cascone8e5818d2018-10-26 11:45:23 -0700258#ifdef WITH_INT_SINK
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700259 int_data_t int_data;
Carmelo Cascone8e5818d2018-10-26 11:45:23 -0700260#endif // WITH_INT_SINK
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900261 intl4_tail_t intl4_tail;
262#endif //WITH_INT
Yi Tsengbe342052017-11-03 10:21:23 -0700263}
264
265#endif