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 | b531b68 | 2018-01-30 17:55:56 -0800 | [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; |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [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 | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame^] | 135 | bit<1> do_spgw; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 136 | direction_t direction; |
Carmelo Cascone | 274daef | 2018-02-14 20:32:49 -0800 | [diff] [blame] | 137 | bit<16> ipv4_len; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 138 | bit<32> teid; |
| 139 | bit<32> s1u_enb_addr; |
| 140 | bit<32> s1u_sgw_addr; |
| 141 | #ifdef WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 142 | bit<16> l4_src_port; |
| 143 | bit<16> l4_dst_port; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 144 | pcc_gate_status_t pcc_gate_status; |
| 145 | sdf_rule_id_t sdf_rule_id; |
| 146 | pcc_rule_id_t pcc_rule_id; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 147 | #endif // WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 148 | } |
| 149 | #endif // WITH_SPGW |
| 150 | |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame^] | 151 | #ifdef WITH_INT_TRANSIT |
| 152 | |
| 153 | header intl4_shim_t { |
| 154 | bit<8> int_type; |
| 155 | bit<8> rsvd1; |
| 156 | bit<8> len; |
| 157 | bit<8> rsvd2; |
| 158 | } |
| 159 | |
| 160 | // INT headers |
| 161 | header int_header_t { |
| 162 | bit<4> ver; |
| 163 | bit<2> rep; |
| 164 | bit<1> c; |
| 165 | bit<1> e; |
| 166 | bit<3> rsvd1; |
| 167 | bit<5> ins_cnt; |
| 168 | bit<8> max_hop_cnt; |
| 169 | bit<8> total_hop_cnt; |
| 170 | bit<4> instruction_mask_0003; // split the bits for lookup |
| 171 | bit<4> instruction_mask_0407; |
| 172 | bit<4> instruction_mask_0811; |
| 173 | bit<4> instruction_mask_1215; |
| 174 | bit<16> rsvd2; |
| 175 | } |
| 176 | |
| 177 | // INT meta-value headers - different header for each value type |
| 178 | header int_switch_id_t { |
| 179 | bit<32> switch_id; |
| 180 | } |
| 181 | |
| 182 | header int_port_ids_t { |
| 183 | bit<16> ingress_port_id; |
| 184 | bit<16> egress_port_id; |
| 185 | } |
| 186 | |
| 187 | header int_hop_latency_t { |
| 188 | bit<32> hop_latency; |
| 189 | } |
| 190 | |
| 191 | header int_q_occupancy_t { |
| 192 | bit<8> q_id; |
| 193 | bit<24> q_occupancy; |
| 194 | } |
| 195 | |
| 196 | header int_ingress_tstamp_t { |
| 197 | bit<32> ingress_tstamp; |
| 198 | } |
| 199 | |
| 200 | header int_egress_tstamp_t { |
| 201 | bit<32> egress_tstamp; |
| 202 | } |
| 203 | |
| 204 | header int_q_congestion_t { |
| 205 | bit<8> q_id; |
| 206 | bit<24> q_congestion; |
| 207 | } |
| 208 | |
| 209 | header int_egress_port_tx_util_t { |
| 210 | bit<32> egress_port_tx_util; |
| 211 | } |
| 212 | |
| 213 | // switch internal variables for INT logic implementation |
| 214 | struct int_metadata_t { |
| 215 | bit<16> insert_byte_cnt; |
| 216 | bit<8> int_hdr_word_len; |
| 217 | bit<32> switch_id; |
| 218 | bit<5> ins_cnt_tmp; |
| 219 | } |
| 220 | |
| 221 | #endif // WITH_INT_TRANSIT |
| 222 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 223 | //Custom metadata definition |
| 224 | struct fabric_metadata_t { |
| 225 | fwd_type_t fwd_type; |
| 226 | next_id_t next_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 227 | bool pop_vlan_at_egress; |
| 228 | bit<8> ip_proto; |
| 229 | bit<16> l4_src_port; |
| 230 | bit<16> l4_dst_port; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 231 | bit<16> original_ether_type; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 232 | #ifdef WITH_SPGW |
| 233 | spgw_meta_t spgw; |
| 234 | #endif // WITH_SPGW |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame^] | 235 | #ifdef WITH_INT_TRANSIT |
| 236 | int_metadata_t int_metadata; |
| 237 | #endif // WITH_INT_TRANSIT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | struct parsed_headers_t { |
| 241 | ethernet_t ethernet; |
| 242 | vlan_tag_t vlan_tag; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 243 | mpls_t mpls; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 244 | #ifdef WITH_SPGW |
| 245 | ipv4_t gtpu_ipv4; |
| 246 | udp_t gtpu_udp; |
| 247 | gtpu_t gtpu; |
| 248 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 249 | ipv4_t ipv4; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 250 | #ifdef WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 251 | ipv6_t ipv6; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 252 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 253 | arp_t arp; |
| 254 | tcp_t tcp; |
| 255 | udp_t udp; |
| 256 | icmp_t icmp; |
| 257 | packet_out_header_t packet_out; |
| 258 | packet_in_header_t packet_in; |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame^] | 259 | #ifdef WITH_INT_TRANSIT |
| 260 | intl4_shim_t intl4_shim; |
| 261 | int_header_t int_header; |
| 262 | int_switch_id_t int_switch_id; |
| 263 | int_port_ids_t int_port_ids; |
| 264 | int_hop_latency_t int_hop_latency; |
| 265 | int_q_occupancy_t int_q_occupancy; |
| 266 | int_ingress_tstamp_t int_ingress_tstamp; |
| 267 | int_egress_tstamp_t int_egress_tstamp; |
| 268 | int_q_congestion_t int_q_congestion; |
| 269 | int_egress_port_tx_util_t int_egress_port_tx_util; |
| 270 | #endif // WITH_INT_TRANSIT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | #endif |