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; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 33 | bit<7> _pad; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | header ethernet_t { |
| 37 | mac_addr_t dst_addr; |
| 38 | mac_addr_t src_addr; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 39 | } |
| 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. |
| 43 | header eth_type_t { |
| 44 | bit<16> value; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | header vlan_tag_t { |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 48 | bit<16> eth_type; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 49 | bit<3> pri; |
| 50 | bit<1> cfi; |
| 51 | vlan_id_t vlan_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | header mpls_t { |
| 55 | bit<20> label; |
| 56 | bit<3> tc; |
| 57 | bit<1> bos; |
| 58 | bit<8> ttl; |
| 59 | } |
| 60 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 61 | header 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 Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 70 | header ipv4_t { |
| 71 | bit<4> version; |
| 72 | bit<4> ihl; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 73 | bit<6> dscp; |
| 74 | bit<2> ecn; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 75 | 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 | |
| 86 | header 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 Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 97 | header tcp_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 98 | bit<16> sport; |
| 99 | bit<16> dport; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 100 | 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 | |
| 111 | header udp_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 112 | bit<16> sport; |
| 113 | bit<16> dport; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 114 | bit<16> len; |
| 115 | bit<16> checksum; |
| 116 | } |
| 117 | |
| 118 | header icmp_t { |
| 119 | bit<8> icmp_type; |
| 120 | bit<8> icmp_code; |
| 121 | bit<16> checksum; |
Yi Tseng | f73a553 | 2017-11-17 15:58:57 -0800 | [diff] [blame] | 122 | bit<16> identifier; |
| 123 | bit<16> sequence_number; |
| 124 | bit<64> timestamp; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 127 | #ifdef WITH_SPGW |
| 128 | // GTPU v1 |
| 129 | header 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 */ |
| 138 | bit<32> teid; /* tunnel endpoint id */ |
| 139 | } |
| 140 | |
| 141 | struct spgw_meta_t { |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 142 | direction_t direction; |
Carmelo Cascone | 274daef | 2018-02-14 20:32:49 -0800 | [diff] [blame] | 143 | bit<16> ipv4_len; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 144 | bit<32> teid; |
| 145 | bit<32> s1u_enb_addr; |
| 146 | bit<32> s1u_sgw_addr; |
| 147 | #ifdef WITH_SPGW_PCC_GATING |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 148 | bit<16> l4_sport; |
| 149 | bit<16> l4_dport; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 150 | pcc_gate_status_t pcc_gate_status; |
| 151 | sdf_rule_id_t sdf_rule_id; |
| 152 | pcc_rule_id_t pcc_rule_id; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 153 | #endif // WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 154 | } |
| 155 | #endif // WITH_SPGW |
| 156 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 157 | #ifdef WITH_BNG |
| 158 | |
| 159 | typedef bit<2> bng_type_t; |
| 160 | const bng_type_t BNG_TYPE_INVALID = 2w0x0; |
| 161 | const bng_type_t BNG_TYPE_UPSTREAM = 2w0x1; |
| 162 | const bng_type_t BNG_TYPE_DOWNSTREAM = 2w0x2;; |
| 163 | |
| 164 | struct bng_meta_t { |
Daniele Moro | b3d199b | 2019-11-01 14:01:46 -0700 | [diff] [blame] | 165 | bit<2> type; // upstream or downstream |
| 166 | bit<32> line_id; // subscriber line |
| 167 | bit<16> pppoe_session_id; |
| 168 | bit<32> ds_meter_result; // for downstream metering |
| 169 | vlan_id_t s_tag; |
| 170 | vlan_id_t c_tag; |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 171 | } |
| 172 | #endif // WITH_BNG |
| 173 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 174 | //Custom metadata definition |
| 175 | struct fabric_metadata_t { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 176 | bit<16> ip_eth_type; |
| 177 | vlan_id_t vlan_id; |
| 178 | bit<3> vlan_pri; |
| 179 | bit<1> vlan_cfi; |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 180 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 181 | _BOOL push_double_vlan; |
| 182 | vlan_id_t inner_vlan_id; |
| 183 | bit<3> inner_vlan_pri; |
| 184 | bit<1> inner_vlan_cfi; |
| 185 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 186 | mpls_label_t mpls_label; |
| 187 | bit<8> mpls_ttl; |
| 188 | _BOOL skip_forwarding; |
| 189 | _BOOL skip_next; |
| 190 | fwd_type_t fwd_type; |
| 191 | next_id_t next_id; |
| 192 | _BOOL is_multicast; |
| 193 | _BOOL is_controller_packet_out; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 194 | bit<8> ip_proto; |
| 195 | bit<16> l4_sport; |
| 196 | bit<16> l4_dport; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 197 | #ifdef WITH_SPGW |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 198 | spgw_meta_t spgw; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 199 | #endif // WITH_SPGW |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 200 | #ifdef WITH_BNG |
| 201 | bng_meta_t bng; |
| 202 | #endif // WITH_BNG |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 203 | #ifdef WITH_INT |
| 204 | int_metadata_t int_meta; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 205 | #endif // WITH_INT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | struct parsed_headers_t { |
| 209 | ethernet_t ethernet; |
| 210 | vlan_tag_t vlan_tag; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 211 | #if defined(WITH_XCONNECT) || defined(WITH_DOUBLE_VLAN_TERMINATION) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 212 | vlan_tag_t inner_vlan_tag; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 213 | #endif // WITH_XCONNECT || WITH_DOUBLE_VLAN_TERMINATION |
| 214 | eth_type_t eth_type; |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 215 | #ifdef WITH_BNG |
| 216 | pppoe_t pppoe; |
| 217 | #endif // WITH_BNG |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 218 | mpls_t mpls; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 219 | #ifdef WITH_SPGW |
| 220 | ipv4_t gtpu_ipv4; |
| 221 | udp_t gtpu_udp; |
| 222 | gtpu_t gtpu; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 223 | ipv4_t inner_ipv4; |
| 224 | udp_t inner_udp; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 225 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 226 | ipv4_t ipv4; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 227 | #ifdef WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 228 | ipv6_t ipv6; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 229 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 230 | tcp_t tcp; |
| 231 | udp_t udp; |
| 232 | icmp_t icmp; |
| 233 | packet_out_header_t packet_out; |
| 234 | packet_in_header_t packet_in; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 235 | #ifdef WITH_INT_SINK |
| 236 | // INT Report encap |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 237 | ethernet_t report_ethernet; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 238 | eth_type_t report_eth_type; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 239 | ipv4_t report_ipv4; |
| 240 | udp_t report_udp; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 241 | // INT Report header (support only fixed) |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 242 | report_fixed_header_t report_fixed_header; |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 243 | // local_report_t report_local; |
| 244 | #endif // WITH_INT_SINK |
| 245 | #ifdef WITH_INT |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 246 | // INT specific headers |
| 247 | intl4_shim_t intl4_shim; |
| 248 | int_header_t int_header; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 249 | int_switch_id_t int_switch_id; |
| 250 | int_port_ids_t int_port_ids; |
| 251 | int_hop_latency_t int_hop_latency; |
| 252 | int_q_occupancy_t int_q_occupancy; |
| 253 | int_ingress_tstamp_t int_ingress_tstamp; |
| 254 | int_egress_tstamp_t int_egress_tstamp; |
| 255 | int_q_congestion_t int_q_congestion; |
| 256 | int_egress_port_tx_util_t int_egress_tx_util; |
Carmelo Cascone | 8e5818d | 2018-10-26 11:45:23 -0700 | [diff] [blame] | 257 | #ifdef WITH_INT_SINK |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 258 | int_data_t int_data; |
Carmelo Cascone | 8e5818d | 2018-10-26 11:45:23 -0700 | [diff] [blame] | 259 | #endif // WITH_INT_SINK |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 260 | intl4_tail_t intl4_tail; |
| 261 | #endif //WITH_INT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | #endif |