Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 21 | #include "int/int_header.p4" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 22 | |
| 23 | @controller_header("packet_in") |
| 24 | header packet_in_header_t { |
| 25 | port_num_t ingress_port; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 26 | bit<7> _pad; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 29 | _PKT_OUT_HDR_ANNOT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 30 | @controller_header("packet_out") |
| 31 | header packet_out_header_t { |
| 32 | port_num_t egress_port; |
Carmelo Cascone | db34737 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 33 | bit<1> do_forwarding; |
| 34 | bit<6> _pad; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | header ethernet_t { |
| 38 | mac_addr_t dst_addr; |
| 39 | mac_addr_t src_addr; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 40 | } |
| 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. |
| 44 | header eth_type_t { |
| 45 | bit<16> value; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | header vlan_tag_t { |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 49 | bit<16> eth_type; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 50 | bit<3> pri; |
| 51 | bit<1> cfi; |
| 52 | vlan_id_t vlan_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | header mpls_t { |
| 56 | bit<20> label; |
| 57 | bit<3> tc; |
| 58 | bit<1> bos; |
| 59 | bit<8> ttl; |
| 60 | } |
| 61 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 62 | header 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 Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 71 | header ipv4_t { |
| 72 | bit<4> version; |
| 73 | bit<4> ihl; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 74 | bit<6> dscp; |
| 75 | bit<2> ecn; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 76 | 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 | |
| 87 | header 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 Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 98 | header tcp_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 99 | bit<16> sport; |
| 100 | bit<16> dport; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 101 | 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 | |
| 112 | header udp_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 113 | bit<16> sport; |
| 114 | bit<16> dport; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 115 | bit<16> len; |
| 116 | bit<16> checksum; |
| 117 | } |
| 118 | |
| 119 | header icmp_t { |
| 120 | bit<8> icmp_type; |
| 121 | bit<8> icmp_code; |
| 122 | bit<16> checksum; |
Yi Tseng | f73a553 | 2017-11-17 15:58:57 -0800 | [diff] [blame] | 123 | bit<16> identifier; |
| 124 | bit<16> sequence_number; |
| 125 | bit<64> timestamp; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Carmelo Cascone | ffa7fed | 2021-06-01 18:31:57 -0700 | [diff] [blame] | 128 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 129 | // GTPU v1 |
| 130 | header 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 MacDavid | bec6b6a | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 139 | teid_t teid; /* tunnel endpoint id */ |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Carmelo Cascone | ffa7fed | 2021-06-01 18:31:57 -0700 | [diff] [blame] | 142 | #ifdef WITH_SPGW |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 143 | struct spgw_meta_t { |
Carmelo Cascone | 274daef | 2018-02-14 20:32:49 -0800 | [diff] [blame] | 144 | bit<16> ipv4_len; |
Robert MacDavid | bec6b6a | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 145 | teid_t teid; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 146 | bit<16> tunnel_src_port; |
Robert MacDavid | bec6b6a | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 147 | bit<32> tunnel_src_addr; |
| 148 | bit<32> tunnel_dst_addr; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 149 | pdr_ctr_id_t ctr_id; |
Robert MacDavid | bec6b6a | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 150 | far_id_t far_id; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 151 | spgw_interface_t src_iface; |
| 152 | _BOOL skip_spgw; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 153 | _BOOL notify_spgwc; |
| 154 | _BOOL needs_gtpu_encap; |
| 155 | _BOOL needs_gtpu_decap; |
Carmelo Cascone | b1f5cfd | 2020-12-04 16:54:24 -0800 | [diff] [blame] | 156 | _BOOL skip_egress_pdr_ctr; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 157 | } |
| 158 | #endif // WITH_SPGW |
| 159 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 160 | #ifdef WITH_BNG |
| 161 | |
| 162 | typedef bit<2> bng_type_t; |
| 163 | const bng_type_t BNG_TYPE_INVALID = 2w0x0; |
| 164 | const bng_type_t BNG_TYPE_UPSTREAM = 2w0x1; |
| 165 | const bng_type_t BNG_TYPE_DOWNSTREAM = 2w0x2;; |
| 166 | |
| 167 | struct bng_meta_t { |
Daniele Moro | b3d199b | 2019-11-01 14:01:46 -0700 | [diff] [blame] | 168 | 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 Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 174 | } |
| 175 | #endif // WITH_BNG |
| 176 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 177 | //Custom metadata definition |
| 178 | struct fabric_metadata_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 179 | bit<16> ip_eth_type; |
| 180 | vlan_id_t vlan_id; |
| 181 | bit<3> vlan_pri; |
| 182 | bit<1> vlan_cfi; |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 183 | #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 Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 189 | 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 Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 197 | bit<8> ip_proto; |
| 198 | bit<16> l4_sport; |
| 199 | bit<16> l4_dport; |
Robert MacDavid | bec6b6a | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 200 | bit<32> ipv4_src_addr; |
| 201 | bit<32> ipv4_dst_addr; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 202 | #ifdef WITH_SPGW |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 203 | bit<16> inner_l4_sport; |
| 204 | bit<16> inner_l4_dport; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 205 | spgw_meta_t spgw; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 206 | #endif // WITH_SPGW |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 207 | #ifdef WITH_BNG |
| 208 | bng_meta_t bng; |
| 209 | #endif // WITH_BNG |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 210 | #ifdef WITH_INT |
| 211 | int_metadata_t int_meta; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 212 | #endif // WITH_INT |
Wailok Shum | fac26d4 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 213 | port_type_t port_type; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | struct parsed_headers_t { |
| 217 | ethernet_t ethernet; |
| 218 | vlan_tag_t vlan_tag; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 219 | #if defined(WITH_XCONNECT) || defined(WITH_DOUBLE_VLAN_TERMINATION) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 220 | vlan_tag_t inner_vlan_tag; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 221 | #endif // WITH_XCONNECT || WITH_DOUBLE_VLAN_TERMINATION |
| 222 | eth_type_t eth_type; |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 223 | #ifdef WITH_BNG |
| 224 | pppoe_t pppoe; |
| 225 | #endif // WITH_BNG |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 226 | mpls_t mpls; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 227 | #ifdef WITH_SPGW |
| 228 | ipv4_t gtpu_ipv4; |
| 229 | udp_t gtpu_udp; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 230 | gtpu_t outer_gtpu; |
Wailok Shum | 60dfd4a | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 231 | #endif // WITH_SPGW |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 232 | gtpu_t gtpu; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 233 | ipv4_t inner_ipv4; |
| 234 | udp_t inner_udp; |
Robert MacDavid | de12b98 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 235 | tcp_t inner_tcp; |
| 236 | icmp_t inner_icmp; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 237 | ipv4_t ipv4; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 238 | #ifdef WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 239 | ipv6_t ipv6; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 240 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 241 | 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 Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 246 | #ifdef WITH_INT_SINK |
| 247 | // INT Report encap |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 248 | ethernet_t report_ethernet; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 249 | eth_type_t report_eth_type; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 250 | ipv4_t report_ipv4; |
| 251 | udp_t report_udp; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 252 | // INT Report header (support only fixed) |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 253 | report_fixed_header_t report_fixed_header; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 254 | // local_report_t report_local; |
| 255 | #endif // WITH_INT_SINK |
| 256 | #ifdef WITH_INT |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 257 | // INT specific headers |
| 258 | intl4_shim_t intl4_shim; |
| 259 | int_header_t int_header; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 260 | 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 Cascone | 8e5818d | 2018-10-26 11:45:23 -0700 | [diff] [blame] | 268 | #ifdef WITH_INT_SINK |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 269 | int_data_t int_data; |
Carmelo Cascone | 8e5818d | 2018-10-26 11:45:23 -0700 | [diff] [blame] | 270 | #endif // WITH_INT_SINK |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 271 | intl4_tail_t intl4_tail; |
| 272 | #endif //WITH_INT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | #endif |