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" |
| 21 | |
| 22 | @controller_header("packet_in") |
| 23 | header packet_in_header_t { |
| 24 | port_num_t ingress_port; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 25 | bit<7> _pad; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 28 | _PKT_OUT_HDR_ANNOT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 29 | @controller_header("packet_out") |
| 30 | header packet_out_header_t { |
| 31 | port_num_t egress_port; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 32 | bit<7> _pad; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | header ethernet_t { |
| 36 | mac_addr_t dst_addr; |
| 37 | mac_addr_t src_addr; |
| 38 | bit<16> ether_type; |
| 39 | } |
| 40 | |
| 41 | header vlan_tag_t { |
| 42 | bit<3> pri; |
| 43 | bit<1> cfi; |
| 44 | vlan_id_t vlan_id; |
| 45 | bit<16> ether_type; |
| 46 | } |
| 47 | |
| 48 | header mpls_t { |
| 49 | bit<20> label; |
| 50 | bit<3> tc; |
| 51 | bit<1> bos; |
| 52 | bit<8> ttl; |
| 53 | } |
| 54 | |
| 55 | header ipv4_t { |
| 56 | bit<4> version; |
| 57 | bit<4> ihl; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 58 | bit<6> dscp; |
| 59 | bit<2> ecn; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 60 | bit<16> total_len; |
| 61 | bit<16> identification; |
| 62 | bit<3> flags; |
| 63 | bit<13> frag_offset; |
| 64 | bit<8> ttl; |
| 65 | bit<8> protocol; |
| 66 | bit<16> hdr_checksum; |
| 67 | bit<32> src_addr; |
| 68 | bit<32> dst_addr; |
| 69 | } |
| 70 | |
| 71 | header ipv6_t { |
| 72 | bit<4> version; |
| 73 | bit<8> traffic_class; |
| 74 | bit<20> flow_label; |
| 75 | bit<16> payload_len; |
| 76 | bit<8> next_hdr; |
| 77 | bit<8> hop_limit; |
| 78 | bit<128> src_addr; |
| 79 | bit<128> dst_addr; |
| 80 | } |
| 81 | |
| 82 | header arp_t { |
| 83 | bit<16> hw_type; |
| 84 | bit<16> proto_type; |
| 85 | bit<8> hw_addr_len; |
| 86 | bit<8> proto_addr_len; |
| 87 | bit<16> opcode; |
| 88 | } |
| 89 | |
| 90 | header tcp_t { |
| 91 | bit<16> src_port; |
| 92 | bit<16> dst_port; |
| 93 | bit<32> seq_no; |
| 94 | bit<32> ack_no; |
| 95 | bit<4> data_offset; |
| 96 | bit<3> res; |
| 97 | bit<3> ecn; |
| 98 | bit<6> ctrl; |
| 99 | bit<16> window; |
| 100 | bit<16> checksum; |
| 101 | bit<16> urgent_ptr; |
| 102 | } |
| 103 | |
| 104 | header udp_t { |
| 105 | bit<16> src_port; |
| 106 | bit<16> dst_port; |
| 107 | bit<16> len; |
| 108 | bit<16> checksum; |
| 109 | } |
| 110 | |
| 111 | header icmp_t { |
| 112 | bit<8> icmp_type; |
| 113 | bit<8> icmp_code; |
| 114 | bit<16> checksum; |
Yi Tseng | f73a553 | 2017-11-17 15:58:57 -0800 | [diff] [blame] | 115 | bit<16> identifier; |
| 116 | bit<16> sequence_number; |
| 117 | bit<64> timestamp; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 120 | #ifdef WITH_SPGW |
| 121 | // GTPU v1 |
| 122 | header gtpu_t { |
| 123 | bit<3> version; /* version */ |
| 124 | bit<1> pt; /* protocol type */ |
| 125 | bit<1> spare; /* reserved */ |
| 126 | bit<1> ex_flag; /* next extension hdr present? */ |
| 127 | bit<1> seq_flag; /* sequence no. */ |
| 128 | bit<1> npdu_flag; /* n-pdn number present ? */ |
| 129 | bit<8> msgtype; /* message type */ |
| 130 | bit<16> msglen; /* message length */ |
| 131 | bit<32> teid; /* tunnel endpoint id */ |
| 132 | } |
| 133 | |
| 134 | struct spgw_meta_t { |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 135 | direction_t direction; |
Carmelo Cascone | 274daef | 2018-02-14 20:32:49 -0800 | [diff] [blame] | 136 | bit<16> ipv4_len; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 137 | bit<32> teid; |
| 138 | bit<32> s1u_enb_addr; |
| 139 | bit<32> s1u_sgw_addr; |
| 140 | #ifdef WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 141 | bit<16> l4_src_port; |
| 142 | bit<16> l4_dst_port; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 143 | pcc_gate_status_t pcc_gate_status; |
| 144 | sdf_rule_id_t sdf_rule_id; |
| 145 | pcc_rule_id_t pcc_rule_id; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 146 | #endif // WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 147 | } |
| 148 | #endif // WITH_SPGW |
| 149 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 150 | #ifdef WITH_INT |
| 151 | // Report Telemetry Headers |
| 152 | header report_fixed_header_t { |
| 153 | bit<4> ver; |
| 154 | bit<4> nproto; |
| 155 | bit<1> d; |
| 156 | bit<1> q; |
| 157 | bit<1> f; |
| 158 | bit<15> rsvd; |
| 159 | bit<6> hw_id; |
| 160 | bit<32> seq_no; |
| 161 | bit<32> ingress_tstamp; |
| 162 | } |
| 163 | |
| 164 | // Telemetry drop report header |
| 165 | header drop_report_header_t { |
| 166 | bit<32> switch_id; |
| 167 | bit<16> ingress_port_id; |
| 168 | bit<16> egress_port_id; |
| 169 | bit<8> queue_id; |
| 170 | bit<8> drop_reason; |
| 171 | bit<16> pad; |
| 172 | } |
| 173 | |
| 174 | // Switch Local Report Header |
| 175 | header local_report_header_t { |
| 176 | bit<32> switch_id; |
| 177 | bit<16> ingress_port_id; |
| 178 | bit<16> egress_port_id; |
| 179 | bit<8> queue_id; |
| 180 | bit<24> queue_occupancy; |
| 181 | bit<32> egress_tstamp; |
| 182 | } |
| 183 | |
| 184 | header_union local_report_t { |
| 185 | drop_report_header_t drop_report_header; |
| 186 | local_report_header_t local_report_header; |
| 187 | } |
| 188 | |
| 189 | // INT headers |
| 190 | header int_header_t { |
| 191 | bit<2> ver; |
| 192 | bit<2> rep; |
| 193 | bit<1> c; |
| 194 | bit<1> e; |
| 195 | bit<5> rsvd1; |
| 196 | bit<5> ins_cnt; |
| 197 | bit<8> max_hop_cnt; |
| 198 | bit<8> total_hop_cnt; |
| 199 | bit<4> instruction_mask_0003; /* split the bits for lookup */ |
| 200 | bit<4> instruction_mask_0407; |
| 201 | bit<4> instruction_mask_0811; |
| 202 | bit<4> instruction_mask_1215; |
| 203 | bit<16> rsvd2; |
| 204 | } |
| 205 | |
| 206 | // INT meta-value headers - different header for each value type |
| 207 | header int_switch_id_t { |
| 208 | bit<32> switch_id; |
| 209 | } |
| 210 | header int_port_ids_t { |
| 211 | bit<16> ingress_port_id; |
| 212 | bit<16> egress_port_id; |
| 213 | } |
| 214 | header int_hop_latency_t { |
| 215 | bit<32> hop_latency; |
| 216 | } |
| 217 | header int_q_occupancy_t { |
| 218 | bit<8> q_id; |
| 219 | bit<24> q_occupancy; |
| 220 | } |
| 221 | header int_ingress_tstamp_t { |
| 222 | bit<32> ingress_tstamp; |
| 223 | } |
| 224 | header int_egress_tstamp_t { |
| 225 | bit<32> egress_tstamp; |
| 226 | } |
| 227 | header int_q_congestion_t { |
| 228 | bit<8> q_id; |
| 229 | bit<24> q_congestion; |
| 230 | } |
| 231 | header int_egress_port_tx_util_t { |
| 232 | bit<32> egress_port_tx_util; |
| 233 | } |
| 234 | |
| 235 | header int_data_t { |
| 236 | // Maximum int metadata stack size in bits: |
| 237 | // (0xFF -4) * 32 (excluding INT shim header, tail header and INT header) |
| 238 | varbit<8032> data; |
| 239 | } |
| 240 | |
| 241 | /* INT shim header for TCP/UDP */ |
| 242 | header intl4_shim_t { |
| 243 | bit<8> int_type; |
| 244 | bit<8> rsvd1; |
| 245 | bit<8> len; |
| 246 | bit<8> rsvd2; |
| 247 | } |
| 248 | /* INT tail header for TCP/UDP */ |
| 249 | header intl4_tail_t { |
| 250 | bit<8> next_proto; |
| 251 | bit<16> dest_port; |
| 252 | bit<8> dscp; |
| 253 | } |
| 254 | |
| 255 | struct int_metadata_t { |
| 256 | switch_id_t switch_id; |
| 257 | bit<16> insert_byte_cnt; |
| 258 | bit<1> source; |
| 259 | bit<1> sink; |
| 260 | bit<8> mirror_id; |
| 261 | bit<16> flow_id; |
| 262 | bit<8> metadata_len; |
| 263 | } |
| 264 | #endif // WITH_INT |
| 265 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 266 | //Custom metadata definition |
| 267 | struct fabric_metadata_t { |
| 268 | fwd_type_t fwd_type; |
| 269 | next_id_t next_id; |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 270 | _BOOL pop_vlan_when_packet_in; |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 271 | _BOOL is_multicast; |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 272 | _BOOL is_controller_packet_out; |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 273 | _BOOL clone_to_cpu; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 274 | bit<8> ip_proto; |
| 275 | bit<16> l4_src_port; |
| 276 | bit<16> l4_dst_port; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 277 | #ifdef WITH_SPGW |
| 278 | spgw_meta_t spgw; |
| 279 | #endif // WITH_SPGW |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 280 | #ifdef WITH_INT |
| 281 | int_metadata_t int_meta; |
| 282 | bool compute_checksum; |
| 283 | #endif // WITH_INT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | struct parsed_headers_t { |
| 287 | ethernet_t ethernet; |
| 288 | vlan_tag_t vlan_tag; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 289 | mpls_t mpls; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 290 | #ifdef WITH_SPGW |
| 291 | ipv4_t gtpu_ipv4; |
| 292 | udp_t gtpu_udp; |
| 293 | gtpu_t gtpu; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 294 | ipv4_t inner_ipv4; |
| 295 | udp_t inner_udp; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 296 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 297 | ipv4_t ipv4; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 298 | #ifdef WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 299 | ipv6_t ipv6; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 300 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 301 | arp_t arp; |
| 302 | tcp_t tcp; |
| 303 | udp_t udp; |
| 304 | icmp_t icmp; |
| 305 | packet_out_header_t packet_out; |
| 306 | packet_in_header_t packet_in; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 307 | #ifdef WITH_INT |
| 308 | // INT Report Encapsulation |
| 309 | ethernet_t report_ethernet; |
| 310 | ipv4_t report_ipv4; |
| 311 | udp_t report_udp; |
| 312 | // INT Report Headers |
| 313 | report_fixed_header_t report_fixed_header; |
| 314 | local_report_t report_local; |
| 315 | // INT specific headers |
| 316 | intl4_shim_t intl4_shim; |
| 317 | int_header_t int_header; |
| 318 | int_data_t int_data; |
| 319 | int_switch_id_t int_switch_id; |
| 320 | int_port_ids_t int_port_ids; |
| 321 | int_hop_latency_t int_hop_latency; |
| 322 | int_q_occupancy_t int_q_occupancy; |
| 323 | int_ingress_tstamp_t int_ingress_tstamp; |
| 324 | int_egress_tstamp_t int_egress_tstamp; |
| 325 | int_q_congestion_t int_q_congestion; |
| 326 | int_egress_port_tx_util_t int_egress_tx_util; |
| 327 | intl4_tail_t intl4_tail; |
| 328 | #endif //WITH_INT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | #endif |