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