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 __DEFINE__ |
| 18 | #define __DEFINE__ |
| 19 | |
| 20 | #define MAX_PORTS 511 |
| 21 | |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 22 | #if defined(WITH_INT_SOURCE) || defined(WITH_INT_TRANSIT) || defined(WITH_INT_SINK) |
| 23 | #define WITH_INT |
| 24 | #endif |
| 25 | |
Daniele Moro | 693d76f | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 26 | #if defined(WITH_BNG) |
| 27 | #define WITH_DOUBLE_VLAN_TERMINATION |
| 28 | #endif |
| 29 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 30 | #ifndef WITHOUT_XCONNECT |
| 31 | #define WITH_XCONNECT |
| 32 | #endif |
| 33 | |
| 34 | #if ! defined(WITH_SIMPLE_NEXT) |
| 35 | #define WITH_HASHED_NEXT |
| 36 | #endif |
| 37 | |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 38 | #ifndef _BOOL |
| 39 | #define _BOOL bool |
| 40 | #endif |
| 41 | #ifndef _TRUE |
| 42 | #define _TRUE true |
| 43 | #endif |
| 44 | #ifndef _FALSE |
Yi Tseng | 34af316 | 2018-06-17 18:02:21 +0800 | [diff] [blame] | 45 | #define _FALSE false |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | #ifndef _PKT_OUT_HDR_ANNOT |
| 49 | #define _PKT_OUT_HDR_ANNOT |
| 50 | #endif |
| 51 | |
Carmelo Cascone | fa42158 | 2018-09-13 10:05:57 -0700 | [diff] [blame] | 52 | #ifndef _PRE_INGRESS |
| 53 | #define _PRE_INGRESS |
| 54 | #endif |
| 55 | |
| 56 | #ifndef _PRE_EGRESS |
| 57 | #define _PRE_EGRESS |
| 58 | #endif |
| 59 | |
Carmelo Cascone | 35d9b33 | 2018-06-15 16:27:22 +0200 | [diff] [blame] | 60 | #ifndef IP_VER_LENGTH |
| 61 | #define IP_VER_LENGTH 4 |
| 62 | #endif |
| 63 | #ifndef IP_VERSION_4 |
| 64 | #define IP_VERSION_4 4 |
| 65 | #endif |
| 66 | #ifndef IP_VERSION_6 |
| 67 | #define IP_VERSION_6 6 |
| 68 | #endif |
| 69 | |
| 70 | #define ETH_HDR_SIZE 14 |
| 71 | #define IPV4_HDR_SIZE 20 |
| 72 | #define UDP_HDR_SIZE 8 |
| 73 | #define GTP_HDR_SIZE 8 |
| 74 | |
| 75 | #define UDP_PORT_GTPU 2152 |
| 76 | #define GTP_GPDU 0xff |
| 77 | #define GTPU_VERSION 0x01 |
| 78 | #define GTP_PROTOCOL_TYPE_GTP 0x01 |
| 79 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 80 | #define PKT_INSTANCE_TYPE_NORMAL 0 |
| 81 | #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1 |
| 82 | #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2 |
| 83 | #define PKT_INSTANCE_TYPE_COALESCED 3 |
| 84 | #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4 |
| 85 | #define PKT_INSTANCE_TYPE_REPLICATION 5 |
| 86 | #define PKT_INSTANCE_TYPE_RESUBMIT 6 |
| 87 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 88 | typedef bit<3> fwd_type_t; |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 89 | typedef bit<32> next_id_t; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 90 | typedef bit<20> mpls_label_t; |
| 91 | typedef bit<9> port_num_t; |
| 92 | typedef bit<48> mac_addr_t; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 93 | typedef bit<16> mcast_group_id_t; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 94 | typedef bit<12> vlan_id_t; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 95 | typedef bit<32> ipv4_addr_t; |
| 96 | typedef bit<16> l4_port_t; |
| 97 | |
| 98 | // SPGW types |
| 99 | typedef bit<2> direction_t; |
Robert MacDavid | c9fce63 | 2020-07-28 22:17:07 -0400 | [diff] [blame] | 100 | typedef bit<8> spgw_interface_t; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 101 | typedef bit pcc_gate_status_t; |
| 102 | typedef bit<32> sdf_rule_id_t; |
| 103 | typedef bit<32> pcc_rule_id_t; |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 104 | typedef bit<32> far_id_t; |
Robert MacDavid | c9fce63 | 2020-07-28 22:17:07 -0400 | [diff] [blame] | 105 | typedef bit<32> pdr_ctr_id_t; |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 106 | typedef bit<32> teid_t; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 107 | |
Robert MacDavid | c9fce63 | 2020-07-28 22:17:07 -0400 | [diff] [blame] | 108 | const spgw_interface_t SPGW_IFACE_UNKNOWN = 8w0; |
| 109 | const spgw_interface_t SPGW_IFACE_ACCESS = 8w1; |
| 110 | const spgw_interface_t SPGW_IFACE_CORE = 8w2; |
| 111 | const direction_t SPGW_DIR_UNKNOWN = 2w0; |
| 112 | const direction_t SPGW_DIR_UPLINK = 2w1; |
| 113 | const direction_t SPGW_DIR_DOWNLINK = 2w2; |
| 114 | |
Carmelo Cascone | d35e8a6 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 115 | #ifndef S1U_SGW_PREFIX |
| 116 | // By default spgw.p4 expects uplink packets with IP dst matching 140.0.0.0/8 |
| 117 | // FIXME: refactor pipeline to remove dependency on this value or allow setting it at runtime |
| 118 | // (e.g. via parser value sets) |
| 119 | #define S1U_SGW_PREFIX (8w140++8w0++8w0++8w0) |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 120 | #define S1U_SGW_PREFIX_LEN 8 |
Carmelo Cascone | d35e8a6 | 2020-07-15 18:38:59 -0700 | [diff] [blame] | 121 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 122 | |
| 123 | const bit<16> ETHERTYPE_QINQ = 0x88A8; |
| 124 | const bit<16> ETHERTYPE_QINQ_NON_STD = 0x9100; |
| 125 | const bit<16> ETHERTYPE_VLAN = 0x8100; |
| 126 | const bit<16> ETHERTYPE_MPLS = 0x8847; |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 127 | const bit<16> ETHERTYPE_MPLS_MULTICAST = 0x8848; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 128 | const bit<16> ETHERTYPE_IPV4 = 0x0800; |
| 129 | const bit<16> ETHERTYPE_IPV6 = 0x86dd; |
| 130 | const bit<16> ETHERTYPE_ARP = 0x0806; |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 131 | const bit<16> ETHERTYPE_PPPOED = 0x8863; |
| 132 | const bit<16> ETHERTYPE_PPPOES = 0x8864; |
| 133 | |
| 134 | const bit<16> PPPOE_PROTOCOL_IP4 = 0x0021; |
| 135 | const bit<16> PPPOE_PROTOCOL_IP6 = 0x0057; |
Daniele Moro | e22b574 | 2019-06-28 15:32:37 -0700 | [diff] [blame] | 136 | const bit<16> PPPOE_PROTOCOL_MPLS = 0x0281; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 137 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 138 | const bit<8> PROTO_ICMP = 1; |
| 139 | const bit<8> PROTO_TCP = 6; |
| 140 | const bit<8> PROTO_UDP = 17; |
| 141 | const bit<8> PROTO_ICMPV6 = 58; |
| 142 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 143 | const bit<4> IPV4_MIN_IHL = 5; |
| 144 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 145 | const fwd_type_t FWD_BRIDGING = 0; |
| 146 | const fwd_type_t FWD_MPLS = 1; |
| 147 | const fwd_type_t FWD_IPV4_UNICAST = 2; |
| 148 | const fwd_type_t FWD_IPV4_MULTICAST = 3; |
| 149 | const fwd_type_t FWD_IPV6_UNICAST = 4; |
| 150 | const fwd_type_t FWD_IPV6_MULTICAST = 5; |
Carmelo Cascone | 8a715f8 | 2018-08-20 23:16:27 -0700 | [diff] [blame] | 151 | const fwd_type_t FWD_UNKNOWN = 7; |
| 152 | |
| 153 | const vlan_id_t DEFAULT_VLAN_ID = 12w4094; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 154 | |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 155 | const bit<8> DEFAULT_MPLS_TTL = 64; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 156 | const bit<8> DEFAULT_IPV4_TTL = 64; |
| 157 | |
Robert MacDavid | c9fce63 | 2020-07-28 22:17:07 -0400 | [diff] [blame] | 158 | |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 159 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 160 | /* indicate INT at LSB of DSCP */ |
| 161 | const bit<6> INT_DSCP = 0x1; |
| 162 | |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 163 | // Length of the whole INT header, |
| 164 | // including shim and tail, excluding metadata stack. |
| 165 | const bit<8> INT_HEADER_LEN_WORDS = 4; |
| 166 | const bit<16> INT_HEADER_LEN_BYTES = 16; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 167 | |
| 168 | const bit<8> CPU_MIRROR_SESSION_ID = 250; |
| 169 | const bit<32> REPORT_MIRROR_SESSION_ID = 500; |
| 170 | |
| 171 | const bit<4> NPROTO_ETHERNET = 0; |
| 172 | const bit<4> NPROTO_TELEMETRY_DROP_HEADER = 1; |
| 173 | const bit<4> NPROTO_TELEMETRY_SWITCH_LOCAL_HEADER = 2; |
| 174 | |
| 175 | const bit<6> HW_ID = 1; |
| 176 | const bit<8> REPORT_FIXED_HEADER_LEN = 12; |
| 177 | const bit<8> DROP_REPORT_HEADER_LEN = 12; |
| 178 | const bit<8> LOCAL_REPORT_HEADER_LEN = 16; |
| 179 | const bit<8> ETH_HEADER_LEN = 14; |
| 180 | const bit<8> IPV4_MIN_HEAD_LEN = 20; |
| 181 | const bit<8> UDP_HEADER_LEN = 8; |
| 182 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 183 | action nop() { |
| 184 | NoAction(); |
| 185 | } |
| 186 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 187 | #endif |