Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [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 __SPGW__ |
| 18 | #define __SPGW__ |
| 19 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 20 | #define MAX_PDR_COUNTERS 1024 |
| 21 | #define DEFAULT_PDR_CTR_ID 0 |
| 22 | #define DEFAULT_FAR_ID 0 |
| 23 | |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 24 | control spgw_normalizer( |
| 25 | in bool is_gtpu_encapped, |
| 26 | out ipv4_t gtpu_ipv4, |
| 27 | out udp_t gtpu_udp, |
| 28 | inout ipv4_t ipv4, |
| 29 | inout udp_t udp, |
| 30 | in ipv4_t inner_ipv4, |
| 31 | in udp_t inner_udp |
| 32 | ) { |
| 33 | apply { |
| 34 | if (! is_gtpu_encapped) return; |
| 35 | gtpu_ipv4 = ipv4; |
| 36 | ipv4 = inner_ipv4; |
| 37 | gtpu_udp = udp; |
| 38 | if (inner_udp.isValid()) { |
| 39 | udp = inner_udp; |
| 40 | } else { |
| 41 | udp.setInvalid(); |
| 42 | } |
| 43 | } |
| 44 | } |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 45 | |
| 46 | control spgw_ingress( |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 47 | inout ipv4_t gtpu_ipv4, |
| 48 | inout udp_t gtpu_udp, |
| 49 | inout gtpu_t gtpu, |
| 50 | inout ipv4_t ipv4, |
| 51 | inout udp_t udp, |
| 52 | inout fabric_metadata_t fabric_meta, |
| 53 | inout standard_metadata_t standard_metadata |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 54 | ) { |
| 55 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 56 | counter(MAX_PDR_COUNTERS, CounterType.packets_and_bytes) pdr_counter; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 57 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 58 | @hidden |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 59 | action gtpu_decap() { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 60 | // grab information from the tunnel that we'll need later |
| 61 | fabric_meta.spgw.teid = gtpu.teid; |
| 62 | fabric_meta.spgw.tunnel_dst_addr = gtpu_ipv4.dst_addr; |
| 63 | // update metadata src and dst addresses with the inner packet |
| 64 | fabric_meta.ipv4_src_addr = ipv4.src_addr; |
| 65 | fabric_meta.ipv4_dst_addr = ipv4.dst_addr; |
| 66 | // decap |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 67 | gtpu_ipv4.setInvalid(); |
| 68 | gtpu_udp.setInvalid(); |
| 69 | gtpu.setInvalid(); |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 70 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 73 | table downlink_filter_table { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 74 | key = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 75 | // UE addr pool for downlink |
| 76 | ipv4.dst_addr : lpm @name("ipv4_prefix"); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 77 | } |
| 78 | actions = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 79 | nop(); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 80 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 81 | const default_action = nop(); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 84 | table uplink_filter_table { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 85 | key = { |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 86 | // IP addresses of the S1U interfaces of this SPGW-U instance (when uplink) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 87 | gtpu_ipv4.dst_addr : exact @name("gtp_ipv4_dst"); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 88 | } |
| 89 | actions = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 90 | nop(); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 91 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 92 | const default_action = nop(); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 95 | action set_pdr_attributes(ctr_id_t ctr_id, |
| 96 | far_id_t far_id) { |
| 97 | fabric_meta.spgw.pdr_hit = _TRUE; |
| 98 | fabric_meta.spgw.ctr_id = ctr_id; |
| 99 | fabric_meta.spgw.far_id = far_id; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 102 | // These two tables scale well and cover the average case PDR |
| 103 | table downlink_pdr_lookup { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 104 | key = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 105 | ipv4.dst_addr : exact @name("ue_addr"); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 106 | } |
| 107 | actions = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 108 | set_pdr_attributes; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 109 | } |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 110 | } |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 111 | table uplink_pdr_lookup { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 112 | key = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 113 | // tunnel_dst_addr will be static for Q2 target. Can remove if need more scaling |
| 114 | fabric_meta.spgw.tunnel_dst_addr : exact @name("tunnel_ipv4_dst"); |
| 115 | fabric_meta.spgw.teid : exact @name("teid"); |
| 116 | ipv4.src_addr : exact @name("ue_addr"); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 117 | } |
| 118 | actions = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 119 | set_pdr_attributes; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 120 | } |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 121 | } |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 122 | // This table scales poorly and covers uncommon PDRs |
| 123 | table flexible_pdr_lookup { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 124 | key = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 125 | // Direction. Eventually change to interface |
| 126 | fabric_meta.spgw.direction : ternary @name("spgw_direction"); |
| 127 | // F-TEID |
| 128 | fabric_meta.spgw.tunnel_dst_addr : ternary @name("tunnel_ipv4_dst"); |
| 129 | fabric_meta.spgw.teid : ternary @name("teid"); |
| 130 | // SDF (5-tuple) |
| 131 | ipv4.src_addr : ternary @name("ipv4_src"); |
| 132 | ipv4.dst_addr : ternary @name("ipv4_dst"); |
| 133 | ipv4.protocol : ternary @name("ip_proto"); |
| 134 | fabric_meta.l4_sport : ternary @name("l4_sport"); |
| 135 | fabric_meta.l4_dport : ternary @name("l4_dport"); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 136 | } |
| 137 | actions = { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 138 | set_pdr_attributes; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 139 | } |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 140 | const default_action = set_pdr_attributes(DEFAULT_PDR_CTR_ID, DEFAULT_FAR_ID); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 141 | } |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 142 | |
| 143 | action load_normal_far_attributes(bit<1> drop, |
| 144 | bit<1> notify_cp) { |
| 145 | // general far attributes |
| 146 | fabric_meta.spgw.far_dropped = (_BOOL)drop; |
| 147 | fabric_meta.spgw.notify_cp = (_BOOL)notify_cp; |
| 148 | } |
| 149 | action load_tunnel_far_attributes(bit<1> drop, |
| 150 | bit<1> notify_cp, |
| 151 | ipv4_addr_t tunnel_src_addr, |
| 152 | ipv4_addr_t tunnel_dst_addr, |
| 153 | teid_t teid) { |
| 154 | // general far attributes |
| 155 | fabric_meta.spgw.far_dropped = (_BOOL)drop; |
| 156 | fabric_meta.spgw.notify_cp = (_BOOL)notify_cp; |
| 157 | // GTP tunnel attributes |
| 158 | fabric_meta.spgw.outer_header_creation = _TRUE; |
| 159 | fabric_meta.spgw.teid = teid; |
| 160 | fabric_meta.spgw.tunnel_src_addr = tunnel_src_addr; |
| 161 | fabric_meta.spgw.tunnel_dst_addr = tunnel_dst_addr; |
| 162 | // update metadata IP addresses for correct routing/hashing |
| 163 | fabric_meta.ipv4_src_addr = tunnel_src_addr; |
| 164 | fabric_meta.ipv4_dst_addr = tunnel_dst_addr; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | table far_lookup { |
| 169 | key = { |
| 170 | fabric_meta.spgw.far_id : exact @name("far_id"); |
| 171 | } |
| 172 | actions = { |
| 173 | load_normal_far_attributes; |
| 174 | load_tunnel_far_attributes; |
| 175 | } |
| 176 | // default is drop and don't notify CP |
| 177 | const default_action = load_normal_far_attributes(1w1, 1w0); |
| 178 | } |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 179 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 180 | apply { |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 181 | if (gtpu.isValid()) { |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 182 | // If here, pkt has outer IP dst on |
| 183 | // S1U_SGW_PREFIX/S1U_SGW_PREFIX_LEN subnet. |
| 184 | // TODO: check also that gtpu.msgtype == GTP_GPDU |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 185 | if (!uplink_filter_table.apply().hit) { |
| 186 | // Should this be changed to a forwarding/next skip instead of a drop? |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 187 | mark_to_drop(standard_metadata); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 188 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 189 | fabric_meta.spgw.direction = SPGW_DIR_UPLINK; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 190 | gtpu_decap(); |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 191 | } else if (downlink_filter_table.apply().hit) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 192 | fabric_meta.spgw.direction = SPGW_DIR_DOWNLINK; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 193 | } else { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 194 | fabric_meta.spgw.direction = SPGW_DIR_UNKNOWN; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 195 | // No SPGW processing needed. |
| 196 | return; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 199 | // Try the efficient PDR tables first (This PDR partitioning only works |
| 200 | // if the PDRs do not overlap. Will need fixing later.) |
| 201 | if (fabric_meta.spgw.direction == SPGW_DIR_UPLINK) { |
| 202 | uplink_pdr_lookup.apply(); |
| 203 | } else if (fabric_meta.spgw.direction == SPGW_DIR_DOWNLINK) { |
| 204 | downlink_pdr_lookup.apply(); |
| 205 | } else { // SPGW_DIR_UNKNOWN |
| 206 | return; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 207 | } |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 208 | // If those fail to find a match, use the wildcard tables |
| 209 | if (fabric_meta.spgw.pdr_hit == _FALSE) { |
| 210 | flexible_pdr_lookup.apply(); |
| 211 | } |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 212 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 213 | pdr_counter.count(fabric_meta.spgw.ctr_id); |
| 214 | // Load FAR info |
| 215 | far_lookup.apply(); |
| 216 | |
| 217 | if (fabric_meta.spgw.notify_cp == _TRUE) { |
| 218 | // TODO: cpu clone session here |
| 219 | } |
| 220 | if (fabric_meta.spgw.far_dropped == _TRUE) { |
| 221 | // Do dropping in the same way as fabric's filtering.p4, so we can traverse |
| 222 | // the ACL table, which is good for cases like DHCP. |
| 223 | fabric_meta.skip_forwarding = _TRUE; |
| 224 | fabric_meta.skip_next = _TRUE; |
| 225 | } |
| 226 | |
| 227 | // Nothing to be done immediately for forwarding or encapsulation. |
| 228 | // Forwarding is done by other parts of fabric.p4, and |
| 229 | // encapsulation is done in the egress |
| 230 | |
| 231 | // Needed for correct GTPU encapsulation in egress |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 232 | fabric_meta.spgw.ipv4_len = ipv4.total_len; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | control spgw_egress( |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 238 | in ipv4_t ipv4, |
| 239 | inout ipv4_t gtpu_ipv4, |
| 240 | inout udp_t gtpu_udp, |
| 241 | inout gtpu_t gtpu, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 242 | in fabric_metadata_t fabric_meta, |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 243 | in standard_metadata_t std_meta |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 244 | ) { |
| 245 | |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 246 | counter(MAX_PDR_COUNTERS, CounterType.packets_and_bytes) pdr_counter; |
| 247 | |
| 248 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 249 | @hidden |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 250 | action gtpu_encap() { |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 251 | gtpu_ipv4.setValid(); |
| 252 | gtpu_ipv4.version = IP_VERSION_4; |
| 253 | gtpu_ipv4.ihl = IPV4_MIN_IHL; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 254 | gtpu_ipv4.dscp = 0; |
| 255 | gtpu_ipv4.ecn = 0; |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 256 | gtpu_ipv4.total_len = ipv4.total_len |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 257 | + (IPV4_HDR_SIZE + UDP_HDR_SIZE + GTP_HDR_SIZE); |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 258 | gtpu_ipv4.identification = 0x1513; /* From NGIC. TODO: Needs to be dynamic */ |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 259 | gtpu_ipv4.flags = 0; |
| 260 | gtpu_ipv4.frag_offset = 0; |
| 261 | gtpu_ipv4.ttl = DEFAULT_IPV4_TTL; |
| 262 | gtpu_ipv4.protocol = PROTO_UDP; |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 263 | gtpu_ipv4.src_addr = fabric_meta.spgw.tunnel_src_addr; |
| 264 | gtpu_ipv4.dst_addr = fabric_meta.spgw.tunnel_dst_addr; |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 265 | gtpu_ipv4.hdr_checksum = 0; // Updated later |
| 266 | |
| 267 | gtpu_udp.setValid(); |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 268 | gtpu_udp.sport = UDP_PORT_GTPU; // TODO: make this dynamic per 3GPP specs |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 269 | gtpu_udp.dport = UDP_PORT_GTPU; |
| 270 | gtpu_udp.len = fabric_meta.spgw.ipv4_len |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 271 | + (UDP_HDR_SIZE + GTP_HDR_SIZE); |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 272 | gtpu_udp.checksum = 0; // Updated later, if WITH_SPGW_UDP_CSUM_UPDATE |
| 273 | |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 274 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 275 | gtpu.setValid(); |
| 276 | gtpu.version = GTPU_VERSION; |
| 277 | gtpu.pt = GTP_PROTOCOL_TYPE_GTP; |
| 278 | gtpu.spare = 0; |
| 279 | gtpu.ex_flag = 0; |
| 280 | gtpu.seq_flag = 0; |
| 281 | gtpu.npdu_flag = 0; |
| 282 | gtpu.msgtype = GTP_GPDU; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 283 | gtpu.msglen = fabric_meta.spgw.ipv4_len; |
| 284 | gtpu.teid = fabric_meta.spgw.teid; |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | apply { |
Robert MacDavid | 1d47569 | 2020-05-21 21:32:38 -0400 | [diff] [blame] | 288 | pdr_counter.count(fabric_meta.spgw.ctr_id); |
| 289 | |
| 290 | if (fabric_meta.spgw.outer_header_creation == _TRUE) { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 291 | gtpu_encap(); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 297 | control update_gtpu_checksum( |
| 298 | inout ipv4_t gtpu_ipv4, |
| 299 | inout udp_t gtpu_udp, |
| 300 | in gtpu_t gtpu, |
| 301 | in ipv4_t ipv4, |
| 302 | in udp_t udp |
| 303 | ) { |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 304 | apply { |
| 305 | // Compute outer IPv4 checksum. |
| 306 | update_checksum(gtpu_ipv4.isValid(), |
| 307 | { |
| 308 | gtpu_ipv4.version, |
| 309 | gtpu_ipv4.ihl, |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 310 | gtpu_ipv4.dscp, |
| 311 | gtpu_ipv4.ecn, |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 312 | gtpu_ipv4.total_len, |
| 313 | gtpu_ipv4.identification, |
| 314 | gtpu_ipv4.flags, |
| 315 | gtpu_ipv4.frag_offset, |
| 316 | gtpu_ipv4.ttl, |
| 317 | gtpu_ipv4.protocol, |
| 318 | gtpu_ipv4.src_addr, |
| 319 | gtpu_ipv4.dst_addr |
| 320 | }, |
| 321 | gtpu_ipv4.hdr_checksum, |
| 322 | HashAlgorithm.csum16 |
| 323 | ); |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 324 | |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 325 | #ifdef WITH_SPGW_UDP_CSUM_UPDATE |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 326 | // Compute outer UDP checksum. |
| 327 | update_checksum_with_payload(gtpu_udp.isValid(), |
| 328 | { |
| 329 | gtpu_ipv4.src_addr, |
| 330 | gtpu_ipv4.dst_addr, |
| 331 | 8w0, |
| 332 | gtpu_ipv4.protocol, |
| 333 | gtpu_udp.len, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 334 | gtpu_udp.sport, |
| 335 | gtpu_udp.dport, |
Carmelo Cascone | 14cde40 | 2018-01-25 01:57:18 -0800 | [diff] [blame] | 336 | gtpu_udp.len, |
| 337 | gtpu, |
| 338 | ipv4, |
| 339 | // FIXME: we are assuming only UDP for downlink packets |
| 340 | // How to conditionally switch between UDP/TCP/ICMP? |
| 341 | udp |
| 342 | }, |
| 343 | gtpu_udp.checksum, |
| 344 | HashAlgorithm.csum16 |
| 345 | ); |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 346 | #endif // WITH_SPGW_UDP_CSUM_UPDATE |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | #endif |