Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 16 | #include <vnet/session/transport.h> |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 17 | #include <vnet/session/session.h> |
| 18 | #include <vnet/fib/fib.h> |
| 19 | |
| 20 | /** |
| 21 | * Per-type vector of transport protocol virtual function tables |
| 22 | */ |
| 23 | transport_proto_vft_t *tp_vfts; |
| 24 | |
| 25 | /* |
| 26 | * Port allocator seed |
| 27 | */ |
| 28 | static u32 port_allocator_seed; |
| 29 | |
| 30 | /* |
| 31 | * Local endpoints table |
| 32 | */ |
| 33 | static transport_endpoint_table_t local_endpoints_table; |
| 34 | |
| 35 | /* |
| 36 | * Pool of local endpoints |
| 37 | */ |
| 38 | static transport_endpoint_t *local_endpoints; |
| 39 | |
| 40 | /* |
| 41 | * Local endpoints pool lock |
| 42 | */ |
| 43 | static clib_spinlock_t local_endpoints_lock; |
| 44 | |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 45 | /* |
| 46 | * Period used by transport pacers. Initialized by session layer |
| 47 | */ |
| 48 | static double transport_pacer_period; |
| 49 | |
Florin Coras | 7ac053b | 2018-11-05 15:57:21 -0800 | [diff] [blame] | 50 | #define TRANSPORT_PACER_MIN_MSS 1460 |
| 51 | #define TRANSPORT_PACER_MIN_BURST TRANSPORT_PACER_MIN_MSS |
Simon Zhang | 1146ff4 | 2019-09-02 22:54:00 +0800 | [diff] [blame] | 52 | #define TRANSPORT_PACER_MAX_BURST (43 * TRANSPORT_PACER_MIN_MSS) |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 53 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 54 | u8 * |
| 55 | format_transport_proto (u8 * s, va_list * args) |
| 56 | { |
| 57 | u32 transport_proto = va_arg (*args, u32); |
| 58 | switch (transport_proto) |
| 59 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 60 | #define _(sym, str, sstr) \ |
| 61 | case TRANSPORT_PROTO_ ## sym: \ |
| 62 | s = format (s, str); \ |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 63 | break; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 64 | foreach_transport_proto |
| 65 | #undef _ |
Nathan Skrzypczak | ba65ca4 | 2019-05-16 16:35:40 +0200 | [diff] [blame] | 66 | default: |
| 67 | s = format (s, "UNKNOWN"); |
| 68 | break; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 69 | } |
| 70 | return s; |
| 71 | } |
| 72 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 73 | u8 * |
| 74 | format_transport_proto_short (u8 * s, va_list * args) |
| 75 | { |
| 76 | u32 transport_proto = va_arg (*args, u32); |
| 77 | switch (transport_proto) |
| 78 | { |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 79 | #define _(sym, str, sstr) \ |
| 80 | case TRANSPORT_PROTO_ ## sym: \ |
| 81 | s = format (s, sstr); \ |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 82 | break; |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 83 | foreach_transport_proto |
| 84 | #undef _ |
Nathan Skrzypczak | ba65ca4 | 2019-05-16 16:35:40 +0200 | [diff] [blame] | 85 | default: |
| 86 | s = format (s, "?"); |
| 87 | break; |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 88 | } |
| 89 | return s; |
| 90 | } |
| 91 | |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 92 | u8 * |
| 93 | format_transport_connection (u8 * s, va_list * args) |
| 94 | { |
| 95 | u32 transport_proto = va_arg (*args, u32); |
| 96 | u32 conn_index = va_arg (*args, u32); |
| 97 | u32 thread_index = va_arg (*args, u32); |
| 98 | u32 verbose = va_arg (*args, u32); |
| 99 | transport_proto_vft_t *tp_vft; |
| 100 | transport_connection_t *tc; |
| 101 | u32 indent; |
| 102 | |
| 103 | tp_vft = transport_protocol_get_vft (transport_proto); |
| 104 | if (!tp_vft) |
| 105 | return s; |
| 106 | |
| 107 | s = format (s, "%U", tp_vft->format_connection, conn_index, thread_index, |
| 108 | verbose); |
| 109 | tc = tp_vft->get_connection (conn_index, thread_index); |
| 110 | if (tc && transport_connection_is_tx_paced (tc) && verbose > 1) |
| 111 | { |
| 112 | indent = format_get_indent (s) + 1; |
| 113 | s = format (s, "%Upacer: %U\n", format_white_space, indent, |
| 114 | format_transport_pacer, &tc->pacer); |
| 115 | } |
| 116 | return s; |
| 117 | } |
| 118 | |
| 119 | u8 * |
| 120 | format_transport_listen_connection (u8 * s, va_list * args) |
| 121 | { |
| 122 | u32 transport_proto = va_arg (*args, u32); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 123 | transport_proto_vft_t *tp_vft; |
| 124 | |
| 125 | tp_vft = transport_protocol_get_vft (transport_proto); |
| 126 | if (!tp_vft) |
| 127 | return s; |
| 128 | |
Florin Coras | 3389dd2 | 2019-02-01 18:00:05 -0800 | [diff] [blame] | 129 | s = (tp_vft->format_listener) (s, args); |
Florin Coras | de9a849 | 2018-10-24 22:18:58 -0700 | [diff] [blame] | 130 | return s; |
| 131 | } |
| 132 | |
| 133 | u8 * |
| 134 | format_transport_half_open_connection (u8 * s, va_list * args) |
| 135 | { |
| 136 | u32 transport_proto = va_arg (*args, u32); |
| 137 | u32 listen_index = va_arg (*args, u32); |
| 138 | transport_proto_vft_t *tp_vft; |
| 139 | |
| 140 | tp_vft = transport_protocol_get_vft (transport_proto); |
| 141 | if (!tp_vft) |
| 142 | return s; |
| 143 | |
| 144 | s = format (s, "%U", tp_vft->format_half_open, listen_index); |
| 145 | return s; |
| 146 | } |
| 147 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 148 | uword |
| 149 | unformat_transport_proto (unformat_input_t * input, va_list * args) |
| 150 | { |
| 151 | u32 *proto = va_arg (*args, u32 *); |
Florin Coras | 5bb23ec | 2019-08-31 09:45:13 -0700 | [diff] [blame] | 152 | |
| 153 | #define _(sym, str, sstr) \ |
| 154 | if (unformat (input, str)) \ |
| 155 | { \ |
| 156 | *proto = TRANSPORT_PROTO_ ## sym; \ |
| 157 | return 1; \ |
| 158 | } |
| 159 | foreach_transport_proto |
| 160 | #undef _ |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 161 | return 0; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 162 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 163 | |
| 164 | u32 |
| 165 | transport_endpoint_lookup (transport_endpoint_table_t * ht, u8 proto, |
| 166 | ip46_address_t * ip, u16 port) |
| 167 | { |
| 168 | clib_bihash_kv_24_8_t kv; |
| 169 | int rv; |
| 170 | |
| 171 | kv.key[0] = ip->as_u64[0]; |
| 172 | kv.key[1] = ip->as_u64[1]; |
| 173 | kv.key[2] = (u64) port << 8 | (u64) proto; |
| 174 | |
| 175 | rv = clib_bihash_search_inline_24_8 (ht, &kv); |
| 176 | if (rv == 0) |
| 177 | return kv.value; |
| 178 | |
| 179 | return ENDPOINT_INVALID_INDEX; |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | transport_endpoint_table_add (transport_endpoint_table_t * ht, u8 proto, |
| 184 | transport_endpoint_t * te, u32 value) |
| 185 | { |
| 186 | clib_bihash_kv_24_8_t kv; |
| 187 | |
| 188 | kv.key[0] = te->ip.as_u64[0]; |
| 189 | kv.key[1] = te->ip.as_u64[1]; |
| 190 | kv.key[2] = (u64) te->port << 8 | (u64) proto; |
| 191 | kv.value = value; |
| 192 | |
| 193 | clib_bihash_add_del_24_8 (ht, &kv, 1); |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | transport_endpoint_table_del (transport_endpoint_table_t * ht, u8 proto, |
| 198 | transport_endpoint_t * te) |
| 199 | { |
| 200 | clib_bihash_kv_24_8_t kv; |
| 201 | |
| 202 | kv.key[0] = te->ip.as_u64[0]; |
| 203 | kv.key[1] = te->ip.as_u64[1]; |
| 204 | kv.key[2] = (u64) te->port << 8 | (u64) proto; |
| 205 | |
| 206 | clib_bihash_add_del_24_8 (ht, &kv, 0); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Register transport virtual function table. |
| 211 | * |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 212 | * @param transport_proto - transport protocol type (i.e., TCP, UDP ..) |
| 213 | * @param vft - virtual function table for transport proto |
| 214 | * @param fib_proto - network layer protocol |
| 215 | * @param output_node - output node index that session layer will hand off |
| 216 | * buffers to, for requested fib proto |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 217 | */ |
| 218 | void |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 219 | transport_register_protocol (transport_proto_t transport_proto, |
| 220 | const transport_proto_vft_t * vft, |
| 221 | fib_protocol_t fib_proto, u32 output_node) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 222 | { |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 223 | u8 is_ip4 = fib_proto == FIB_PROTOCOL_IP4; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 224 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 225 | vec_validate (tp_vfts, transport_proto); |
| 226 | tp_vfts[transport_proto] = *vft; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 227 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 228 | session_register_transport (transport_proto, vft, is_ip4, output_node); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Get transport virtual function table |
| 233 | * |
| 234 | * @param type - session type (not protocol type) |
| 235 | */ |
| 236 | transport_proto_vft_t * |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 237 | transport_protocol_get_vft (transport_proto_t transport_proto) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 238 | { |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 239 | if (transport_proto >= vec_len (tp_vfts)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 240 | return 0; |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 241 | return &tp_vfts[transport_proto]; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Nathan Skrzypczak | a26349d | 2019-06-26 13:53:08 +0200 | [diff] [blame] | 244 | u8 |
| 245 | transport_half_open_has_fifos (transport_proto_t tp) |
| 246 | { |
| 247 | return tp_vfts[tp].transport_options.half_open_has_fifos; |
| 248 | } |
| 249 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 250 | transport_service_type_t |
| 251 | transport_protocol_service_type (transport_proto_t tp) |
| 252 | { |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 253 | return tp_vfts[tp].transport_options.service_type; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 256 | transport_tx_fn_type_t |
| 257 | transport_protocol_tx_fn_type (transport_proto_t tp) |
| 258 | { |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 259 | return tp_vfts[tp].transport_options.tx_type; |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 262 | void |
| 263 | transport_cleanup (transport_proto_t tp, u32 conn_index, u8 thread_index) |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 264 | { |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 265 | tp_vfts[tp].cleanup (conn_index, thread_index); |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 268 | int |
| 269 | transport_connect (transport_proto_t tp, transport_endpoint_cfg_t * tep) |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 270 | { |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 271 | return tp_vfts[tp].connect (tep); |
| 272 | } |
| 273 | |
| 274 | void |
| 275 | transport_close (transport_proto_t tp, u32 conn_index, u8 thread_index) |
| 276 | { |
| 277 | tp_vfts[tp].close (conn_index, thread_index); |
| 278 | } |
| 279 | |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 280 | void |
| 281 | transport_reset (transport_proto_t tp, u32 conn_index, u8 thread_index) |
| 282 | { |
| 283 | if (tp_vfts[tp].reset) |
| 284 | tp_vfts[tp].reset (conn_index, thread_index); |
| 285 | else |
| 286 | tp_vfts[tp].close (conn_index, thread_index); |
| 287 | } |
| 288 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 289 | u32 |
| 290 | transport_start_listen (transport_proto_t tp, u32 session_index, |
| 291 | transport_endpoint_t * tep) |
| 292 | { |
| 293 | return tp_vfts[tp].start_listen (session_index, tep); |
| 294 | } |
| 295 | |
| 296 | u32 |
| 297 | transport_stop_listen (transport_proto_t tp, u32 conn_index) |
| 298 | { |
| 299 | return tp_vfts[tp].stop_listen (conn_index); |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 302 | u8 |
| 303 | transport_protocol_is_cl (transport_proto_t tp) |
| 304 | { |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 305 | return (tp_vfts[tp].transport_options.service_type == TRANSPORT_SERVICE_CL); |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 308 | always_inline void |
| 309 | default_get_transport_endpoint (transport_connection_t * tc, |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 310 | transport_endpoint_t * tep, u8 is_lcl) |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 311 | { |
| 312 | if (is_lcl) |
| 313 | { |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 314 | tep->port = tc->lcl_port; |
| 315 | tep->is_ip4 = tc->is_ip4; |
| 316 | clib_memcpy_fast (&tep->ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 317 | } |
| 318 | else |
| 319 | { |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 320 | tep->port = tc->rmt_port; |
| 321 | tep->is_ip4 = tc->is_ip4; |
| 322 | clib_memcpy_fast (&tep->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | void |
| 327 | transport_get_endpoint (transport_proto_t tp, u32 conn_index, |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 328 | u32 thread_index, transport_endpoint_t * tep, |
| 329 | u8 is_lcl) |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 330 | { |
| 331 | if (tp_vfts[tp].get_transport_endpoint) |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 332 | tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, tep, |
| 333 | is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 334 | else |
| 335 | { |
| 336 | transport_connection_t *tc; |
| 337 | tc = transport_get_connection (tp, conn_index, thread_index); |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 338 | default_get_transport_endpoint (tc, tep, is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
| 342 | void |
| 343 | transport_get_listener_endpoint (transport_proto_t tp, u32 conn_index, |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 344 | transport_endpoint_t * tep, u8 is_lcl) |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 345 | { |
| 346 | if (tp_vfts[tp].get_transport_listener_endpoint) |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 347 | tp_vfts[tp].get_transport_listener_endpoint (conn_index, tep, is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 348 | else |
| 349 | { |
| 350 | transport_connection_t *tc; |
| 351 | tc = transport_get_listener (tp, conn_index); |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 352 | default_get_transport_endpoint (tc, tep, is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 356 | #define PORT_MASK ((1 << 16)- 1) |
| 357 | |
| 358 | void |
| 359 | transport_endpoint_del (u32 tepi) |
| 360 | { |
| 361 | clib_spinlock_lock_if_init (&local_endpoints_lock); |
| 362 | pool_put_index (local_endpoints, tepi); |
| 363 | clib_spinlock_unlock_if_init (&local_endpoints_lock); |
| 364 | } |
| 365 | |
| 366 | always_inline transport_endpoint_t * |
| 367 | transport_endpoint_new (void) |
| 368 | { |
| 369 | transport_endpoint_t *tep; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 370 | pool_get_zero (local_endpoints, tep); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 371 | return tep; |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port) |
| 376 | { |
| 377 | u32 tepi; |
| 378 | transport_endpoint_t *tep; |
| 379 | |
| 380 | /* Cleanup local endpoint if this was an active connect */ |
| 381 | tepi = transport_endpoint_lookup (&local_endpoints_table, proto, lcl_ip, |
| 382 | clib_net_to_host_u16 (port)); |
| 383 | if (tepi != ENDPOINT_INVALID_INDEX) |
| 384 | { |
| 385 | tep = pool_elt_at_index (local_endpoints, tepi); |
| 386 | transport_endpoint_table_del (&local_endpoints_table, proto, tep); |
| 387 | transport_endpoint_del (tepi); |
| 388 | } |
| 389 | } |
| 390 | |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 391 | static void |
| 392 | transport_endpoint_mark_used (u8 proto, ip46_address_t * ip, u16 port) |
| 393 | { |
| 394 | transport_endpoint_t *tep; |
| 395 | clib_spinlock_lock_if_init (&local_endpoints_lock); |
| 396 | tep = transport_endpoint_new (); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 397 | clib_memcpy_fast (&tep->ip, ip, sizeof (*ip)); |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 398 | tep->port = port; |
| 399 | transport_endpoint_table_add (&local_endpoints_table, proto, tep, |
| 400 | tep - local_endpoints); |
| 401 | clib_spinlock_unlock_if_init (&local_endpoints_lock); |
| 402 | } |
| 403 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 404 | /** |
| 405 | * Allocate local port and add if successful add entry to local endpoint |
| 406 | * table to mark the pair as used. |
| 407 | */ |
| 408 | int |
| 409 | transport_alloc_local_port (u8 proto, ip46_address_t * ip) |
| 410 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 411 | u16 min = 1024, max = 65535; /* XXX configurable ? */ |
| 412 | int tries, limit; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 413 | u32 tei; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 414 | |
| 415 | limit = max - min; |
| 416 | |
| 417 | /* Only support active opens from thread 0 */ |
| 418 | ASSERT (vlib_get_thread_index () == 0); |
| 419 | |
| 420 | /* Search for first free slot */ |
| 421 | for (tries = 0; tries < limit; tries++) |
| 422 | { |
| 423 | u16 port = 0; |
| 424 | |
| 425 | /* Find a port in the specified range */ |
| 426 | while (1) |
| 427 | { |
| 428 | port = random_u32 (&port_allocator_seed) & PORT_MASK; |
| 429 | if (PREDICT_TRUE (port >= min && port < max)) |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | /* Look it up. If not found, we're done */ |
| 434 | tei = transport_endpoint_lookup (&local_endpoints_table, proto, ip, |
| 435 | port); |
| 436 | if (tei == ENDPOINT_INVALID_INDEX) |
| 437 | { |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 438 | transport_endpoint_mark_used (proto, ip, port); |
| 439 | return port; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | return -1; |
| 443 | } |
| 444 | |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 445 | static clib_error_t * |
| 446 | transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 447 | { |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 448 | if (is_ip4) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 449 | { |
| 450 | ip4_address_t *ip4; |
| 451 | ip4 = ip_interface_get_first_ip (sw_if_index, 1); |
Florin Coras | fc804d9 | 2018-01-26 01:27:01 -0800 | [diff] [blame] | 452 | if (!ip4) |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 453 | return clib_error_return (0, "no routable ip4 address on %U", |
| 454 | format_vnet_sw_if_index_name, |
| 455 | vnet_get_main (), sw_if_index); |
| 456 | addr->ip4.as_u32 = ip4->as_u32; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 457 | } |
| 458 | else |
| 459 | { |
| 460 | ip6_address_t *ip6; |
| 461 | ip6 = ip_interface_get_first_ip (sw_if_index, 0); |
| 462 | if (ip6 == 0) |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 463 | return clib_error_return (0, "no routable ip6 addresses on %U", |
| 464 | format_vnet_sw_if_index_name, |
| 465 | vnet_get_main (), sw_if_index); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 466 | clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6)); |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static clib_error_t * |
| 472 | transport_find_local_ip_for_remote (u32 sw_if_index, |
| 473 | transport_endpoint_t * rmt, |
| 474 | ip46_address_t * lcl_addr) |
| 475 | { |
| 476 | fib_node_index_t fei; |
| 477 | fib_prefix_t prefix; |
| 478 | |
| 479 | if (sw_if_index == ENDPOINT_INVALID_INDEX) |
| 480 | { |
| 481 | /* Find a FIB path to the destination */ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 482 | clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip)); |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 483 | prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 484 | prefix.fp_len = rmt->is_ip4 ? 32 : 128; |
| 485 | |
| 486 | ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX); |
| 487 | fei = fib_table_lookup (rmt->fib_index, &prefix); |
| 488 | |
| 489 | /* Couldn't find route to destination. Bail out. */ |
| 490 | if (fei == FIB_NODE_INDEX_INVALID) |
| 491 | return clib_error_return (0, "no route to %U", format_ip46_address, |
| 492 | &rmt->ip, (rmt->is_ip4 == 0) + 1); |
| 493 | |
| 494 | sw_if_index = fib_entry_get_resolving_interface (fei); |
| 495 | if (sw_if_index == ENDPOINT_INVALID_INDEX) |
| 496 | return clib_error_return (0, "no resolving interface for %U", |
| 497 | format_ip46_address, &rmt->ip, |
| 498 | (rmt->is_ip4 == 0) + 1); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 501 | clib_memset (lcl_addr, 0, sizeof (*lcl_addr)); |
| 502 | return transport_get_interface_ip (sw_if_index, rmt->is_ip4, lcl_addr); |
| 503 | } |
| 504 | |
| 505 | int |
| 506 | transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt_cfg, |
| 507 | ip46_address_t * lcl_addr, u16 * lcl_port) |
| 508 | { |
| 509 | transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg; |
| 510 | clib_error_t *error; |
| 511 | int port; |
| 512 | u32 tei; |
| 513 | |
| 514 | /* |
| 515 | * Find the local address |
| 516 | */ |
| 517 | if (ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 518 | { |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 519 | error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index, |
| 520 | rmt, lcl_addr); |
| 521 | if (error) |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 522 | { |
| 523 | clib_error_report (error); |
| 524 | return -1; |
| 525 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 526 | } |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 527 | else |
| 528 | { |
| 529 | /* Assume session layer vetted this address */ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 530 | clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip, |
| 531 | sizeof (rmt_cfg->peer.ip)); |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Allocate source port |
| 536 | */ |
| 537 | if (rmt_cfg->peer.port == 0) |
| 538 | { |
| 539 | port = transport_alloc_local_port (proto, lcl_addr); |
| 540 | if (port < 1) |
| 541 | { |
| 542 | clib_warning ("Failed to allocate src port"); |
| 543 | return -1; |
| 544 | } |
| 545 | *lcl_port = port; |
| 546 | } |
| 547 | else |
| 548 | { |
| 549 | port = clib_net_to_host_u16 (rmt_cfg->peer.port); |
| 550 | tei = transport_endpoint_lookup (&local_endpoints_table, proto, |
| 551 | lcl_addr, port); |
| 552 | if (tei != ENDPOINT_INVALID_INDEX) |
| 553 | return -1; |
| 554 | |
| 555 | transport_endpoint_mark_used (proto, lcl_addr, port); |
| 556 | *lcl_port = port; |
| 557 | } |
| 558 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 562 | #define SPACER_CPU_TICKS_PER_PERIOD_SHIFT 10 |
| 563 | #define SPACER_CPU_TICKS_PER_PERIOD (1 << SPACER_CPU_TICKS_PER_PERIOD_SHIFT) |
| 564 | |
| 565 | u8 * |
| 566 | format_transport_pacer (u8 * s, va_list * args) |
| 567 | { |
| 568 | spacer_t *pacer = va_arg (*args, spacer_t *); |
Florin Coras | be237bf | 2019-09-27 08:16:40 -0700 | [diff] [blame^] | 569 | vlib_main_t *vm = vlib_get_main (); |
| 570 | u64 now, diff; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 571 | |
Florin Coras | be237bf | 2019-09-27 08:16:40 -0700 | [diff] [blame^] | 572 | now = vm->clib_time.last_cpu_time; |
| 573 | diff = now - (pacer->last_update << SPACER_CPU_TICKS_PER_PERIOD_SHIFT); |
| 574 | s = format (s, "rate %u bucket %u t/p %.3f last_update %.3f", |
| 575 | pacer->bytes_per_sec, pacer->bucket, pacer->tokens_per_period, |
| 576 | diff * vm->clib_time.seconds_per_clock); |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 577 | return s; |
| 578 | } |
| 579 | |
| 580 | static inline u32 |
| 581 | spacer_max_burst (spacer_t * pacer, u64 norm_time_now) |
| 582 | { |
| 583 | u64 n_periods = norm_time_now - pacer->last_update; |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 584 | u64 inc; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 585 | |
Florin Coras | 36ebcff | 2019-09-12 18:36:44 -0700 | [diff] [blame] | 586 | if (n_periods > 0 |
| 587 | && (inc = (f32) n_periods * pacer->tokens_per_period) > 10) |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 588 | { |
| 589 | pacer->last_update = norm_time_now; |
Florin Coras | 7c8f828 | 2019-09-15 16:28:45 -0700 | [diff] [blame] | 590 | pacer->bucket = clib_min (pacer->bucket + inc, pacer->bytes_per_sec); |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Florin Coras | 6bc6fd0 | 2019-03-27 18:55:11 -0700 | [diff] [blame] | 593 | return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST); |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static inline void |
| 597 | spacer_update_bucket (spacer_t * pacer, u32 bytes) |
| 598 | { |
| 599 | ASSERT (pacer->bucket >= bytes); |
| 600 | pacer->bucket -= bytes; |
| 601 | } |
| 602 | |
| 603 | static inline void |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 604 | spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec) |
| 605 | { |
| 606 | ASSERT (rate_bytes_per_sec != 0); |
Florin Coras | 7c8f828 | 2019-09-15 16:28:45 -0700 | [diff] [blame] | 607 | pacer->bytes_per_sec = rate_bytes_per_sec; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 608 | pacer->tokens_per_period = rate_bytes_per_sec / transport_pacer_period; |
| 609 | } |
| 610 | |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame] | 611 | static inline u64 |
| 612 | spacer_pace_rate (spacer_t * pacer) |
| 613 | { |
Florin Coras | 7c8f828 | 2019-09-15 16:28:45 -0700 | [diff] [blame] | 614 | return pacer->bytes_per_sec; |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Florin Coras | 36ebcff | 2019-09-12 18:36:44 -0700 | [diff] [blame] | 617 | static inline void |
| 618 | spacer_reset_bucket (spacer_t * pacer, u64 norm_time_now) |
| 619 | { |
| 620 | pacer->last_update = norm_time_now; |
| 621 | pacer->bucket = 0; |
| 622 | } |
| 623 | |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 624 | void |
Florin Coras | c44a558 | 2018-11-01 16:30:54 -0700 | [diff] [blame] | 625 | transport_connection_tx_pacer_reset (transport_connection_t * tc, |
| 626 | u32 rate_bytes_per_sec, |
| 627 | u32 start_bucket, u64 time_now) |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 628 | { |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 629 | spacer_t *pacer = &tc->pacer; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 630 | spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec); |
| 631 | pacer->last_update = time_now >> SPACER_CPU_TICKS_PER_PERIOD_SHIFT; |
Florin Coras | c44a558 | 2018-11-01 16:30:54 -0700 | [diff] [blame] | 632 | pacer->bucket = start_bucket; |
| 633 | } |
| 634 | |
| 635 | void |
| 636 | transport_connection_tx_pacer_init (transport_connection_t * tc, |
| 637 | u32 rate_bytes_per_sec, |
| 638 | u32 initial_bucket) |
| 639 | { |
| 640 | vlib_main_t *vm = vlib_get_main (); |
| 641 | tc->flags |= TRANSPORT_CONNECTION_F_IS_TX_PACED; |
| 642 | transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec, |
| 643 | initial_bucket, |
| 644 | vm->clib_time.last_cpu_time); |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void |
| 648 | transport_connection_tx_pacer_update (transport_connection_t * tc, |
| 649 | u64 bytes_per_sec) |
| 650 | { |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 651 | spacer_set_pace_rate (&tc->pacer, bytes_per_sec); |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | u32 |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 655 | transport_connection_tx_pacer_burst (transport_connection_t * tc, |
| 656 | u64 time_now) |
| 657 | { |
| 658 | time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT; |
| 659 | return spacer_max_burst (&tc->pacer, time_now); |
| 660 | } |
| 661 | |
Florin Coras | 36ebcff | 2019-09-12 18:36:44 -0700 | [diff] [blame] | 662 | void |
| 663 | transport_connection_tx_pacer_reset_bucket (transport_connection_t * tc, |
| 664 | u64 time_now) |
| 665 | { |
| 666 | time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT; |
| 667 | spacer_reset_bucket (&tc->pacer, time_now); |
| 668 | } |
| 669 | |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 670 | u32 |
| 671 | transport_connection_snd_space (transport_connection_t * tc, u64 time_now, |
| 672 | u16 mss) |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 673 | { |
| 674 | u32 snd_space, max_paced_burst; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 675 | |
| 676 | snd_space = tp_vfts[tc->proto].send_space (tc); |
| 677 | if (transport_connection_is_tx_paced (tc)) |
| 678 | { |
| 679 | time_now >>= SPACER_CPU_TICKS_PER_PERIOD_SHIFT; |
| 680 | max_paced_burst = spacer_max_burst (&tc->pacer, time_now); |
Simon Zhang | 1146ff4 | 2019-09-02 22:54:00 +0800 | [diff] [blame] | 681 | max_paced_burst = |
| 682 | (max_paced_burst < TRANSPORT_PACER_MIN_BURST) ? 0 : max_paced_burst; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 683 | snd_space = clib_min (snd_space, max_paced_burst); |
Simon Zhang | 1146ff4 | 2019-09-02 22:54:00 +0800 | [diff] [blame] | 684 | return snd_space >= mss ? snd_space - snd_space % mss : snd_space; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 685 | } |
| 686 | return snd_space; |
| 687 | } |
| 688 | |
Florin Coras | 5281473 | 2019-06-12 15:38:19 -0700 | [diff] [blame] | 689 | u64 |
| 690 | transport_connection_tx_pacer_rate (transport_connection_t * tc) |
| 691 | { |
| 692 | return spacer_pace_rate (&tc->pacer); |
| 693 | } |
| 694 | |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 695 | void |
Florin Coras | 0048223 | 2019-08-02 12:52:00 -0700 | [diff] [blame] | 696 | transport_connection_update_tx_bytes (transport_connection_t * tc, u32 bytes) |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 697 | { |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 698 | if (transport_connection_is_tx_paced (tc)) |
| 699 | spacer_update_bucket (&tc->pacer, bytes); |
| 700 | } |
| 701 | |
| 702 | void |
Florin Coras | e55a6d7 | 2018-10-31 23:09:22 -0700 | [diff] [blame] | 703 | transport_connection_tx_pacer_update_bytes (transport_connection_t * tc, |
| 704 | u32 bytes) |
| 705 | { |
| 706 | spacer_update_bucket (&tc->pacer, bytes); |
| 707 | } |
| 708 | |
| 709 | void |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 710 | transport_init_tx_pacers_period (void) |
| 711 | { |
| 712 | f64 cpu_freq = os_cpu_clock_frequency (); |
| 713 | transport_pacer_period = cpu_freq / SPACER_CPU_TICKS_PER_PERIOD; |
| 714 | } |
| 715 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 716 | void |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 717 | transport_update_time (f64 time_now, u8 thread_index) |
| 718 | { |
| 719 | transport_proto_vft_t *vft; |
| 720 | vec_foreach (vft, tp_vfts) |
| 721 | { |
| 722 | if (vft->update_time) |
| 723 | (vft->update_time) (time_now, thread_index); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | void |
| 728 | transport_enable_disable (vlib_main_t * vm, u8 is_en) |
| 729 | { |
| 730 | transport_proto_vft_t *vft; |
| 731 | vec_foreach (vft, tp_vfts) |
| 732 | { |
| 733 | if (vft->enable) |
| 734 | (vft->enable) (vm, is_en); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | void |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 739 | transport_init (void) |
| 740 | { |
| 741 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 742 | session_main_t *smm = vnet_get_session_main (); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 743 | u32 num_threads; |
| 744 | |
Florin Coras | 93e6580 | 2017-11-29 00:07:11 -0500 | [diff] [blame] | 745 | if (smm->local_endpoints_table_buckets == 0) |
| 746 | smm->local_endpoints_table_buckets = 250000; |
| 747 | if (smm->local_endpoints_table_memory == 0) |
| 748 | smm->local_endpoints_table_memory = 512 << 20; |
| 749 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 750 | /* Initialize [port-allocator] random number seed */ |
| 751 | port_allocator_seed = (u32) clib_cpu_time_now (); |
| 752 | |
| 753 | clib_bihash_init_24_8 (&local_endpoints_table, "local endpoints table", |
Florin Coras | 93e6580 | 2017-11-29 00:07:11 -0500 | [diff] [blame] | 754 | smm->local_endpoints_table_buckets, |
| 755 | smm->local_endpoints_table_memory); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 756 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 757 | if (num_threads > 1) |
| 758 | clib_spinlock_init (&local_endpoints_lock); |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * fd.io coding-style-patch-verification: ON |
| 763 | * |
| 764 | * Local Variables: |
| 765 | * eval: (c-set-style "gnu") |
| 766 | * End: |
| 767 | */ |