Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 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 | |
| 16 | #include <stdio.h> |
| 17 | #include <setjmp.h> |
| 18 | #include <signal.h> |
| 19 | #include <vppinfra/clib.h> |
| 20 | #include <vppinfra/format.h> |
| 21 | #include <vppinfra/error.h> |
| 22 | #include <vppinfra/time.h> |
| 23 | #include <vppinfra/macros.h> |
| 24 | #include <vnet/vnet.h> |
| 25 | #include <vlib/vlib.h> |
| 26 | #include <vlib/unix/unix.h> |
| 27 | #include <vlibapi/api.h> |
| 28 | #include <vlibmemory/api.h> |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 29 | #include <vpp/api/vpe_msg_enum.h> |
| 30 | #include <svm/svm_fifo_segment.h> |
| 31 | #include <pthread.h> |
| 32 | #include <vnet/session/application_interface.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 33 | |
| 34 | #define vl_typedefs /* define message structures */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 35 | #include <vpp/api/vpe_all_api_h.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 36 | #undef vl_typedefs |
| 37 | |
| 38 | /* declare message handlers for each api */ |
| 39 | |
| 40 | #define vl_endianfun /* define message structures */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 41 | #include <vpp/api/vpe_all_api_h.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 42 | #undef vl_endianfun |
| 43 | |
| 44 | /* instantiate all the print functions we know about */ |
| 45 | #define vl_print(handle, ...) |
| 46 | #define vl_printfun |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 47 | #include <vpp/api/vpe_all_api_h.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 48 | #undef vl_printfun |
| 49 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 50 | typedef enum |
| 51 | { |
| 52 | STATE_START, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 53 | STATE_BOUND, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 54 | STATE_READY, |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 55 | STATE_FAILED, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 56 | STATE_DISCONNECTING, |
| 57 | } connection_state_t; |
| 58 | |
| 59 | typedef struct |
| 60 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 61 | /* vpe input queue */ |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 62 | svm_queue_t *vl_input_queue; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 63 | |
| 64 | /* API client handle */ |
| 65 | u32 my_client_index; |
| 66 | |
| 67 | /* The URI we're playing with */ |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 68 | u8 *listen_uri; |
| 69 | |
| 70 | /* URI for connect */ |
| 71 | u8 *connect_uri; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 72 | |
| 73 | /* Session pool */ |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 74 | app_session_t *sessions; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 75 | |
| 76 | /* Hash table for disconnect processing */ |
| 77 | uword *session_index_by_vpp_handles; |
| 78 | |
| 79 | /* fifo segment */ |
| 80 | svm_fifo_segment_private_t *seg; |
| 81 | |
| 82 | /* intermediate rx buffer */ |
| 83 | u8 *rx_buf; |
| 84 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 85 | u32 fifo_size; |
| 86 | int i_am_server; |
| 87 | u8 is_connected; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 88 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 89 | /* Our event queue */ |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 90 | svm_queue_t *our_event_queue; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 91 | |
| 92 | /* $$$ single thread only for the moment */ |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 93 | svm_queue_t *vpp_event_queue; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 94 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 95 | /* $$$$ hack: cut-through session index */ |
| 96 | volatile u32 cut_through_session_index; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 97 | volatile u32 connected_session; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 98 | |
| 99 | /* unique segment name counter */ |
| 100 | u32 unique_segment_index; |
| 101 | |
| 102 | pid_t my_pid; |
| 103 | |
| 104 | /* pthread handle */ |
| 105 | pthread_t cut_through_thread_handle; |
| 106 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 107 | /* For deadman timers */ |
| 108 | clib_time_t clib_time; |
| 109 | |
| 110 | /* State of the connection, shared between msg RX thread and main thread */ |
| 111 | volatile connection_state_t state; |
| 112 | |
| 113 | volatile int time_to_stop; |
| 114 | volatile int time_to_print_stats; |
| 115 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 116 | u32 configured_segment_size; |
| 117 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 118 | /* VNET_API_ERROR_FOO -> "Foo" hash table */ |
| 119 | uword *error_string_by_error_number; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 120 | |
| 121 | /* convenience */ |
| 122 | svm_fifo_segment_main_t *segment_main; |
| 123 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 124 | u8 *connect_test_data; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 125 | |
| 126 | uword *segments_table; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 127 | u8 do_echo; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 128 | u8 have_return; |
| 129 | u64 bytes_to_send; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 130 | } udp_echo_main_t; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 131 | |
| 132 | #if CLIB_DEBUG > 0 |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 133 | #define NITER 10000 |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 134 | #else |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 135 | #define NITER 4000000 |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 136 | #endif |
| 137 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 138 | udp_echo_main_t udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 139 | |
| 140 | static void |
| 141 | stop_signal (int signum) |
| 142 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 143 | udp_echo_main_t *um = &udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 144 | |
| 145 | um->time_to_stop = 1; |
| 146 | } |
| 147 | |
| 148 | static void |
| 149 | stats_signal (int signum) |
| 150 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 151 | udp_echo_main_t *um = &udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 152 | um->time_to_print_stats = 1; |
| 153 | } |
| 154 | |
| 155 | static clib_error_t * |
| 156 | setup_signal_handlers (void) |
| 157 | { |
| 158 | signal (SIGINT, stats_signal); |
| 159 | signal (SIGQUIT, stop_signal); |
| 160 | signal (SIGTERM, stop_signal); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 165 | uword |
| 166 | unformat_ip4_address (unformat_input_t * input, va_list * args) |
| 167 | { |
| 168 | u8 *result = va_arg (*args, u8 *); |
| 169 | unsigned a[4]; |
| 170 | |
| 171 | if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3])) |
| 172 | return 0; |
| 173 | |
| 174 | if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256) |
| 175 | return 0; |
| 176 | |
| 177 | result[0] = a[0]; |
| 178 | result[1] = a[1]; |
| 179 | result[2] = a[2]; |
| 180 | result[3] = a[3]; |
| 181 | |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | uword |
| 186 | unformat_ip6_address (unformat_input_t * input, va_list * args) |
| 187 | { |
| 188 | ip6_address_t *result = va_arg (*args, ip6_address_t *); |
| 189 | u16 hex_quads[8]; |
| 190 | uword hex_quad, n_hex_quads, hex_digit, n_hex_digits; |
| 191 | uword c, n_colon, double_colon_index; |
| 192 | |
| 193 | n_hex_quads = hex_quad = n_hex_digits = n_colon = 0; |
| 194 | double_colon_index = ARRAY_LEN (hex_quads); |
| 195 | while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT) |
| 196 | { |
| 197 | hex_digit = 16; |
| 198 | if (c >= '0' && c <= '9') |
| 199 | hex_digit = c - '0'; |
| 200 | else if (c >= 'a' && c <= 'f') |
| 201 | hex_digit = c + 10 - 'a'; |
| 202 | else if (c >= 'A' && c <= 'F') |
| 203 | hex_digit = c + 10 - 'A'; |
| 204 | else if (c == ':' && n_colon < 2) |
| 205 | n_colon++; |
| 206 | else |
| 207 | { |
| 208 | unformat_put_input (input); |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | /* Too many hex quads. */ |
| 213 | if (n_hex_quads >= ARRAY_LEN (hex_quads)) |
| 214 | return 0; |
| 215 | |
| 216 | if (hex_digit < 16) |
| 217 | { |
| 218 | hex_quad = (hex_quad << 4) | hex_digit; |
| 219 | |
| 220 | /* Hex quad must fit in 16 bits. */ |
| 221 | if (n_hex_digits >= 4) |
| 222 | return 0; |
| 223 | |
| 224 | n_colon = 0; |
| 225 | n_hex_digits++; |
| 226 | } |
| 227 | |
| 228 | /* Save position of :: */ |
| 229 | if (n_colon == 2) |
| 230 | { |
| 231 | /* More than one :: ? */ |
| 232 | if (double_colon_index < ARRAY_LEN (hex_quads)) |
| 233 | return 0; |
| 234 | double_colon_index = n_hex_quads; |
| 235 | } |
| 236 | |
| 237 | if (n_colon > 0 && n_hex_digits > 0) |
| 238 | { |
| 239 | hex_quads[n_hex_quads++] = hex_quad; |
| 240 | hex_quad = 0; |
| 241 | n_hex_digits = 0; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | if (n_hex_digits > 0) |
| 246 | hex_quads[n_hex_quads++] = hex_quad; |
| 247 | |
| 248 | { |
| 249 | word i; |
| 250 | |
| 251 | /* Expand :: to appropriate number of zero hex quads. */ |
| 252 | if (double_colon_index < ARRAY_LEN (hex_quads)) |
| 253 | { |
| 254 | word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads; |
| 255 | |
| 256 | for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--) |
| 257 | hex_quads[n_zero + i] = hex_quads[i]; |
| 258 | |
| 259 | for (i = 0; i < n_zero; i++) |
| 260 | hex_quads[double_colon_index + i] = 0; |
| 261 | |
| 262 | n_hex_quads = ARRAY_LEN (hex_quads); |
| 263 | } |
| 264 | |
| 265 | /* Too few hex quads given. */ |
| 266 | if (n_hex_quads < ARRAY_LEN (hex_quads)) |
| 267 | return 0; |
| 268 | |
| 269 | for (i = 0; i < ARRAY_LEN (hex_quads); i++) |
| 270 | result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]); |
| 271 | |
| 272 | return 1; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | uword |
| 277 | unformat_uri (unformat_input_t * input, va_list * args) |
| 278 | { |
| 279 | session_endpoint_extended_t *sep = va_arg (*args, |
| 280 | session_endpoint_extended_t *); |
| 281 | u32 port; |
| 282 | char *tmp; |
| 283 | |
| 284 | if (unformat (input, "%s://%U/%d", &tmp, unformat_ip4_address, &sep->ip.ip4, |
| 285 | &port)) |
| 286 | { |
| 287 | sep->port = clib_host_to_net_u16 (port); |
| 288 | sep->is_ip4 = 1; |
| 289 | return 1; |
| 290 | } |
| 291 | else if (unformat (input, "%s://%U/%d", &tmp, unformat_ip6_address, |
| 292 | &sep->ip.ip6, &port)) |
| 293 | { |
| 294 | sep->port = clib_host_to_net_u16 (port); |
| 295 | sep->is_ip4 = 0; |
| 296 | return 1; |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 301 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 302 | application_send_attach (udp_echo_main_t * utm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 303 | { |
| 304 | vl_api_application_attach_t *bmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 305 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 306 | memset (bmp, 0, sizeof (*bmp)); |
| 307 | |
| 308 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH); |
| 309 | bmp->client_index = utm->my_client_index; |
| 310 | bmp->context = ntohl (0xfeedface); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 311 | bmp->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_ADD_SEGMENT; |
| 312 | bmp->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; |
| 313 | bmp->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 314 | bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 2; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 315 | bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = utm->fifo_size; |
| 316 | bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = utm->fifo_size; |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 317 | bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20; |
| 318 | bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20; |
| 319 | bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = 16768; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 320 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp); |
| 321 | } |
| 322 | |
| 323 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 324 | application_detach (udp_echo_main_t * utm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 325 | { |
| 326 | vl_api_application_detach_t *bmp; |
| 327 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 328 | memset (bmp, 0, sizeof (*bmp)); |
| 329 | |
| 330 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH); |
| 331 | bmp->client_index = utm->my_client_index; |
| 332 | bmp->context = ntohl (0xfeedface); |
| 333 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp); |
| 334 | } |
| 335 | |
| 336 | static void |
| 337 | vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t * |
| 338 | mp) |
| 339 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 340 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | 84a30ef | 2018-01-24 10:49:23 -0800 | [diff] [blame] | 341 | svm_fifo_segment_create_args_t _a = { 0 }, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 342 | int rv; |
| 343 | |
| 344 | if (mp->retval) |
| 345 | { |
| 346 | clib_warning ("attach failed: %d", mp->retval); |
| 347 | utm->state = STATE_FAILED; |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | if (mp->segment_name_length == 0) |
| 352 | { |
| 353 | clib_warning ("segment_name_length zero"); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | a->segment_name = (char *) mp->segment_name; |
| 358 | a->segment_size = mp->segment_size; |
| 359 | |
| 360 | ASSERT (mp->app_event_queue_address); |
| 361 | |
| 362 | /* Attach to the segment vpp created */ |
| 363 | rv = svm_fifo_segment_attach (a); |
| 364 | if (rv) |
| 365 | { |
| 366 | clib_warning ("svm_fifo_segment_attach ('%s') failed", |
| 367 | mp->segment_name); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | utm->our_event_queue = |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 372 | uword_to_pointer (mp->app_event_queue_address, svm_queue_t *); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static void |
| 376 | vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t * |
| 377 | mp) |
| 378 | { |
| 379 | if (mp->retval) |
| 380 | clib_warning ("detach returned with err: %d", mp->retval); |
| 381 | } |
| 382 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 383 | u8 * |
| 384 | format_api_error (u8 * s, va_list * args) |
| 385 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 386 | udp_echo_main_t *utm = va_arg (*args, udp_echo_main_t *); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 387 | i32 error = va_arg (*args, u32); |
| 388 | uword *p; |
| 389 | |
| 390 | p = hash_get (utm->error_string_by_error_number, -error); |
| 391 | |
| 392 | if (p) |
| 393 | s = format (s, "%s", p[0]); |
| 394 | else |
| 395 | s = format (s, "%d", error); |
| 396 | return s; |
| 397 | } |
| 398 | |
| 399 | int |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 400 | wait_for_state_change (udp_echo_main_t * utm, connection_state_t state) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 401 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 402 | #if CLIB_DEBUG > 0 |
| 403 | #define TIMEOUT 600.0 |
| 404 | #else |
| 405 | #define TIMEOUT 600.0 |
| 406 | #endif |
| 407 | |
| 408 | f64 timeout = clib_time_now (&utm->clib_time) + TIMEOUT; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 409 | |
| 410 | while (clib_time_now (&utm->clib_time) < timeout) |
| 411 | { |
| 412 | if (utm->state == state) |
| 413 | return 0; |
| 414 | } |
| 415 | return -1; |
| 416 | } |
| 417 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 418 | u64 server_bytes_received, server_bytes_sent; |
| 419 | |
| 420 | static void * |
| 421 | cut_through_thread_fn (void *arg) |
| 422 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 423 | app_session_t *s; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 424 | svm_fifo_t *rx_fifo; |
| 425 | svm_fifo_t *tx_fifo; |
| 426 | u8 *my_copy_buffer = 0; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 427 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 428 | i32 actual_transfer; |
| 429 | int rv; |
| 430 | u32 buffer_offset; |
| 431 | |
| 432 | while (utm->cut_through_session_index == ~0) |
| 433 | ; |
| 434 | |
| 435 | s = pool_elt_at_index (utm->sessions, utm->cut_through_session_index); |
| 436 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 437 | rx_fifo = s->rx_fifo; |
| 438 | tx_fifo = s->tx_fifo; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 439 | |
| 440 | vec_validate (my_copy_buffer, 64 * 1024 - 1); |
| 441 | |
| 442 | while (true) |
| 443 | { |
| 444 | /* We read from the tx fifo and write to the rx fifo */ |
| 445 | do |
| 446 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 447 | actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 448 | vec_len (my_copy_buffer), |
| 449 | my_copy_buffer); |
| 450 | } |
| 451 | while (actual_transfer <= 0); |
| 452 | |
| 453 | server_bytes_received += actual_transfer; |
| 454 | |
| 455 | buffer_offset = 0; |
| 456 | while (actual_transfer > 0) |
| 457 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 458 | rv = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 459 | my_copy_buffer + buffer_offset); |
| 460 | if (rv > 0) |
| 461 | { |
| 462 | actual_transfer -= rv; |
| 463 | buffer_offset += rv; |
| 464 | server_bytes_sent += rv; |
| 465 | } |
| 466 | |
| 467 | } |
| 468 | if (PREDICT_FALSE (utm->time_to_stop)) |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | pthread_exit (0); |
| 473 | } |
| 474 | |
| 475 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 476 | udp_client_connect (udp_echo_main_t * utm) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 477 | { |
| 478 | vl_api_connect_uri_t *cmp; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 479 | cmp = vl_msg_api_alloc (sizeof (*cmp)); |
| 480 | memset (cmp, 0, sizeof (*cmp)); |
| 481 | |
| 482 | cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI); |
| 483 | cmp->client_index = utm->my_client_index; |
| 484 | cmp->context = ntohl (0xfeedface); |
| 485 | memcpy (cmp->uri, utm->connect_uri, vec_len (utm->connect_uri)); |
| 486 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 487 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 488 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 489 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 490 | client_send_cut_through (udp_echo_main_t * utm, app_session_t * session) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 491 | { |
| 492 | int i; |
| 493 | u8 *test_data = 0; |
| 494 | u64 bytes_received = 0, bytes_sent = 0; |
| 495 | i32 bytes_to_read; |
| 496 | int rv; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 497 | f64 before, after, delta, bytes_per_second; |
| 498 | svm_fifo_t *rx_fifo, *tx_fifo; |
| 499 | int buffer_offset, bytes_to_send = 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 500 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 501 | /* |
| 502 | * Prepare test data |
| 503 | */ |
| 504 | vec_validate (test_data, 64 * 1024 - 1); |
| 505 | for (i = 0; i < vec_len (test_data); i++) |
| 506 | test_data[i] = i & 0xff; |
| 507 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 508 | rx_fifo = session->rx_fifo; |
| 509 | tx_fifo = session->tx_fifo; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 510 | |
| 511 | before = clib_time_now (&utm->clib_time); |
| 512 | |
| 513 | vec_validate (utm->rx_buf, vec_len (test_data) - 1); |
| 514 | |
| 515 | for (i = 0; i < NITER; i++) |
| 516 | { |
| 517 | bytes_to_send = vec_len (test_data); |
| 518 | buffer_offset = 0; |
| 519 | while (bytes_to_send > 0) |
| 520 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 521 | rv = svm_fifo_enqueue_nowait (tx_fifo, bytes_to_send, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 522 | test_data + buffer_offset); |
| 523 | |
| 524 | if (rv > 0) |
| 525 | { |
| 526 | bytes_to_send -= rv; |
| 527 | buffer_offset += rv; |
| 528 | bytes_sent += rv; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | bytes_to_read = svm_fifo_max_dequeue (rx_fifo); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 533 | bytes_to_read = vec_len (utm->rx_buf) > bytes_to_read ? |
| 534 | bytes_to_read : vec_len (utm->rx_buf); |
| 535 | |
| 536 | buffer_offset = 0; |
| 537 | while (bytes_to_read > 0) |
| 538 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 539 | rv = svm_fifo_dequeue_nowait (rx_fifo, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 540 | bytes_to_read, |
| 541 | utm->rx_buf + buffer_offset); |
| 542 | if (rv > 0) |
| 543 | { |
| 544 | bytes_to_read -= rv; |
| 545 | buffer_offset += rv; |
| 546 | bytes_received += rv; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | while (bytes_received < bytes_sent) |
| 551 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 552 | rv = |
| 553 | svm_fifo_dequeue_nowait (rx_fifo, vec_len (utm->rx_buf), utm->rx_buf); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 554 | if (rv > 0) |
| 555 | { |
| 556 | #if CLIB_DEBUG > 0 |
| 557 | int j; |
| 558 | for (j = 0; j < rv; j++) |
| 559 | { |
| 560 | if (utm->rx_buf[j] != ((bytes_received + j) & 0xff)) |
| 561 | { |
| 562 | clib_warning ("error at byte %lld, 0x%x not 0x%x", |
| 563 | bytes_received + j, |
| 564 | utm->rx_buf[j], |
| 565 | ((bytes_received + j) & 0xff)); |
| 566 | } |
| 567 | } |
| 568 | #endif |
| 569 | bytes_received += (u64) rv; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | after = clib_time_now (&utm->clib_time); |
| 574 | delta = after - before; |
| 575 | bytes_per_second = 0.0; |
| 576 | |
| 577 | if (delta > 0.0) |
| 578 | bytes_per_second = (f64) bytes_received / delta; |
| 579 | |
| 580 | fformat (stdout, |
| 581 | "Done: %lld recv bytes in %.2f seconds, %.2f bytes/sec...\n\n", |
| 582 | bytes_received, delta, bytes_per_second); |
| 583 | fformat (stdout, |
| 584 | "Done: %lld sent bytes in %.2f seconds, %.2f bytes/sec...\n\n", |
| 585 | bytes_sent, delta, bytes_per_second); |
| 586 | fformat (stdout, |
| 587 | "client -> server -> client round trip: %.2f Gbit/sec \n\n", |
| 588 | (bytes_per_second * 8.0) / 1e9); |
| 589 | } |
| 590 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 591 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 592 | send_test_chunk (udp_echo_main_t * utm, app_session_t * s, u32 bytes) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 593 | { |
| 594 | u8 *test_data = utm->connect_test_data; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 595 | int test_buf_offset = 0; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 596 | u64 bytes_sent = 0; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 597 | u32 bytes_to_snd, enq_space, min_chunk; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 598 | int rv; |
| 599 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 600 | min_chunk = clib_min (65536, s->tx_fifo->nitems); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 601 | bytes_to_snd = (bytes == 0) ? vec_len (test_data) : bytes; |
| 602 | if (bytes_to_snd > vec_len (test_data)) |
| 603 | bytes_to_snd = vec_len (test_data); |
| 604 | |
| 605 | while (bytes_to_snd > 0 && !utm->time_to_stop) |
| 606 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 607 | enq_space = svm_fifo_max_enqueue (s->tx_fifo); |
| 608 | if (enq_space < clib_min (bytes_to_snd, min_chunk)) |
| 609 | continue; |
| 610 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 611 | rv = app_send (s, test_data + test_buf_offset, bytes_to_snd, 0); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 612 | if (rv > 0) |
| 613 | { |
| 614 | bytes_to_snd -= rv; |
| 615 | test_buf_offset += rv; |
| 616 | bytes_sent += rv; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 622 | recv_test_chunk (udp_echo_main_t * utm, app_session_t * s) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 623 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 624 | app_recv (s, utm->rx_buf, vec_len (utm->rx_buf)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 628 | client_send_data (udp_echo_main_t * utm) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 629 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 630 | f64 start_time, end_time, delta; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 631 | app_session_t *session; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 632 | char *transfer_type; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 633 | u32 n_iterations; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 634 | u8 *test_data; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 635 | int i; |
| 636 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 637 | vec_validate (utm->connect_test_data, 1024 * 1024 - 1); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 638 | for (i = 0; i < vec_len (utm->connect_test_data); i++) |
| 639 | utm->connect_test_data[i] = i & 0xff; |
| 640 | |
| 641 | test_data = utm->connect_test_data; |
| 642 | session = pool_elt_at_index (utm->sessions, utm->connected_session); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 643 | ASSERT (vec_len (test_data) > 0); |
| 644 | |
| 645 | vec_validate (utm->rx_buf, vec_len (test_data) - 1); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 646 | n_iterations = utm->bytes_to_send / vec_len (test_data); |
| 647 | if (!n_iterations) |
| 648 | n_iterations = 1; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 649 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 650 | start_time = clib_time_now (&utm->clib_time); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 651 | for (i = 0; i < n_iterations; i++) |
| 652 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 653 | send_test_chunk (utm, session, 0); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 654 | if (utm->have_return) |
| 655 | recv_test_chunk (utm, session); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 656 | if (utm->time_to_stop) |
| 657 | break; |
| 658 | } |
| 659 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 660 | if (utm->have_return) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 661 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 662 | f64 timeout = clib_time_now (&utm->clib_time) + 5; |
| 663 | while (clib_time_now (&utm->clib_time) < timeout) |
| 664 | recv_test_chunk (utm, session); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 667 | end_time = clib_time_now (&utm->clib_time); |
| 668 | delta = end_time - start_time; |
| 669 | transfer_type = utm->have_return ? "full-duplex" : "half-duplex"; |
| 670 | clib_warning ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds", |
| 671 | utm->bytes_to_send, utm->bytes_to_send / (1ULL << 20), |
| 672 | utm->bytes_to_send / (1ULL << 30), delta); |
| 673 | clib_warning ("%.2f bytes/second %s", ((f64) utm->bytes_to_send) / (delta), |
| 674 | transfer_type); |
| 675 | clib_warning ("%.4f gbit/second %s", |
| 676 | (((f64) utm->bytes_to_send * 8.0) / delta / 1e9), |
| 677 | transfer_type); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 681 | client_test (udp_echo_main_t * utm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 682 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 683 | app_session_t *session; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 684 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 685 | application_send_attach (utm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 686 | udp_client_connect (utm); |
| 687 | |
| 688 | if (wait_for_state_change (utm, STATE_READY)) |
| 689 | { |
| 690 | clib_warning ("timeout waiting for STATE_READY"); |
| 691 | return; |
| 692 | } |
| 693 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 694 | if (utm->cut_through_session_index != ~0) |
| 695 | { |
| 696 | session = pool_elt_at_index (utm->sessions, |
| 697 | utm->cut_through_session_index); |
| 698 | client_send_cut_through (utm, session); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | session = pool_elt_at_index (utm->sessions, utm->connected_session); |
| 703 | client_send_data (utm); |
| 704 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 705 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 706 | application_detach (utm); |
| 707 | } |
| 708 | |
| 709 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 710 | vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp) |
| 711 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 712 | udp_echo_main_t *utm = &udp_echo_main; |
| 713 | svm_fifo_t *rx_fifo, *tx_fifo; |
| 714 | app_session_t *session; |
| 715 | u32 session_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 716 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 717 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 718 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 719 | clib_warning ("bind failed: %d", mp->retval); |
| 720 | utm->state = STATE_FAILED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 721 | return; |
| 722 | } |
| 723 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 724 | rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *); |
| 725 | tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *); |
| 726 | |
| 727 | pool_get (utm->sessions, session); |
| 728 | memset (session, 0, sizeof (*session)); |
| 729 | session_index = session - utm->sessions; |
| 730 | |
| 731 | rx_fifo->client_session_index = session_index; |
| 732 | tx_fifo->client_session_index = session_index; |
| 733 | session->rx_fifo = rx_fifo; |
| 734 | session->tx_fifo = tx_fifo; |
| 735 | clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip, |
| 736 | sizeof (ip46_address_t)); |
| 737 | session->transport.is_ip4 = mp->lcl_is_ip4; |
| 738 | session->transport.lcl_port = mp->lcl_port; |
| 739 | session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_queue_t *); |
| 740 | |
| 741 | utm->state = utm->is_connected ? STATE_BOUND : STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 745 | vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp) |
| 746 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 747 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 748 | svm_fifo_segment_create_args_t _a, *a = &_a; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 749 | svm_fifo_segment_private_t *seg; |
| 750 | u8 *seg_name; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 751 | int rv; |
| 752 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 753 | memset (a, 0, sizeof (*a)); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 754 | a->segment_name = (char *) mp->segment_name; |
| 755 | a->segment_size = mp->segment_size; |
| 756 | /* Attach to the segment vpp created */ |
| 757 | rv = svm_fifo_segment_attach (a); |
| 758 | if (rv) |
| 759 | { |
| 760 | clib_warning ("svm_fifo_segment_attach ('%s') failed", |
| 761 | mp->segment_name); |
| 762 | return; |
| 763 | } |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 764 | seg = svm_fifo_segment_get_segment (a->new_segment_indices[0]); |
| 765 | clib_warning ("Mapped new segment '%s' size %d", seg->ssvm.name, |
| 766 | seg->ssvm.ssvm_size); |
| 767 | seg_name = format (0, "%s", (char *) mp->segment_name); |
| 768 | hash_set_mem (utm->segments_table, seg_name, a->new_segment_indices[0]); |
| 769 | vec_free (seg_name); |
| 770 | } |
| 771 | |
| 772 | static void |
| 773 | vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp) |
| 774 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 775 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 776 | svm_fifo_segment_private_t *seg; |
| 777 | u64 *seg_indexp; |
| 778 | u8 *seg_name; |
| 779 | |
| 780 | |
| 781 | seg_name = format (0, "%s", mp->segment_name); |
| 782 | seg_indexp = hash_get_mem (utm->segments_table, seg_name); |
| 783 | if (!seg_indexp) |
| 784 | { |
| 785 | clib_warning ("segment not mapped: %s", seg_name); |
| 786 | return; |
| 787 | } |
| 788 | hash_unset_mem (utm->segments_table, seg_name); |
| 789 | seg = svm_fifo_segment_get_segment ((u32) seg_indexp[0]); |
| 790 | svm_fifo_segment_delete (seg); |
| 791 | clib_warning ("Unmapped segment '%s'", seg_name); |
| 792 | vec_free (seg_name); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 795 | /** |
| 796 | * Acting as server for redirected connect requests |
| 797 | */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 798 | static void |
| 799 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 800 | { |
| 801 | u32 segment_index; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 802 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 803 | svm_fifo_segment_main_t *sm = &svm_fifo_segment_main; |
| 804 | svm_fifo_segment_create_args_t _a, *a = &_a; |
| 805 | svm_fifo_segment_private_t *seg; |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 806 | svm_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 807 | vl_api_connect_session_reply_t *rmp; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 808 | app_session_t *session = 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 809 | int rv = 0; |
| 810 | |
| 811 | /* Create the segment */ |
| 812 | a->segment_name = (char *) format (0, "%d:segment%d%c", utm->my_pid, |
| 813 | utm->unique_segment_index++, 0); |
| 814 | a->segment_size = utm->configured_segment_size; |
| 815 | |
| 816 | rv = svm_fifo_segment_create (a); |
| 817 | if (rv) |
| 818 | { |
| 819 | clib_warning ("sm_fifo_segment_create ('%s') failed", a->segment_name); |
| 820 | rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED; |
| 821 | goto send_reply; |
| 822 | } |
| 823 | |
| 824 | vec_add2 (utm->seg, seg, 1); |
| 825 | |
| 826 | segment_index = vec_len (sm->segments) - 1; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 827 | memcpy (seg, sm->segments + segment_index, sizeof (utm->seg[0])); |
| 828 | |
| 829 | pool_get (utm->sessions, session); |
| 830 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 831 | session->rx_fifo = svm_fifo_segment_alloc_fifo |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 832 | (utm->seg, 128 * 1024, FIFO_SEGMENT_RX_FREELIST); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 833 | ASSERT (session->rx_fifo); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 834 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 835 | session->tx_fifo = svm_fifo_segment_alloc_fifo |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 836 | (utm->seg, 128 * 1024, FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 837 | ASSERT (session->tx_fifo); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 838 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 839 | session->rx_fifo->master_session_index = session - utm->sessions; |
| 840 | session->tx_fifo->master_session_index = session - utm->sessions; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 841 | utm->cut_through_session_index = session - utm->sessions; |
| 842 | |
| 843 | rv = pthread_create (&utm->cut_through_thread_handle, |
| 844 | NULL /*attr */ , cut_through_thread_fn, 0); |
| 845 | if (rv) |
| 846 | { |
| 847 | clib_warning ("pthread_create returned %d", rv); |
| 848 | rv = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 849 | } |
| 850 | |
| 851 | send_reply: |
| 852 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 853 | memset (rmp, 0, sizeof (*rmp)); |
| 854 | |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 855 | rmp->_vl_msg_id = ntohs (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 856 | rmp->context = mp->context; |
| 857 | rmp->retval = ntohl (rv); |
| 858 | rmp->segment_name_length = vec_len (a->segment_name); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 859 | if (session) |
| 860 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 861 | rmp->server_rx_fifo = pointer_to_uword (session->rx_fifo); |
| 862 | rmp->server_tx_fifo = pointer_to_uword (session->tx_fifo); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 865 | memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name)); |
| 866 | |
| 867 | vec_free (a->segment_name); |
| 868 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 869 | client_q = uword_to_pointer (mp->client_queue_address, svm_queue_t *); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 870 | vl_msg_api_send_shmem (client_q, (u8 *) & rmp); |
| 871 | } |
| 872 | |
| 873 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 874 | vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp) |
| 875 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 876 | udp_echo_main_t *utm = &udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 877 | |
| 878 | if (mp->retval != 0) |
| 879 | clib_warning ("returned %d", ntohl (mp->retval)); |
| 880 | |
| 881 | utm->state = STATE_START; |
| 882 | } |
| 883 | |
| 884 | static void |
| 885 | vl_api_accept_session_t_handler (vl_api_accept_session_t * mp) |
| 886 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 887 | udp_echo_main_t *utm = &udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 888 | vl_api_accept_session_reply_t *rmp; |
| 889 | svm_fifo_t *rx_fifo, *tx_fifo; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 890 | app_session_t *session; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 891 | static f64 start_time; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 892 | u32 session_index; |
| 893 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 894 | |
| 895 | if (start_time == 0.0) |
| 896 | start_time = clib_time_now (&utm->clib_time); |
| 897 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 898 | utm->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address, |
| 899 | svm_queue_t *); |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 900 | rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 901 | tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 902 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 903 | pool_get (utm->sessions, session); |
| 904 | memset (session, 0, sizeof (*session)); |
| 905 | session_index = session - utm->sessions; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 906 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 907 | /* Cut-through case */ |
| 908 | if (mp->server_event_queue_address) |
| 909 | { |
| 910 | clib_warning ("cut-through session"); |
| 911 | utm->our_event_queue = uword_to_pointer (mp->server_event_queue_address, |
| 912 | svm_queue_t *); |
| 913 | rx_fifo->master_session_index = session_index; |
| 914 | tx_fifo->master_session_index = session_index; |
| 915 | utm->cut_through_session_index = session_index; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 916 | session->rx_fifo = rx_fifo; |
| 917 | session->tx_fifo = tx_fifo; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 918 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 919 | rv = pthread_create (&utm->cut_through_thread_handle, |
| 920 | NULL /*attr */ , cut_through_thread_fn, 0); |
| 921 | if (rv) |
| 922 | { |
| 923 | clib_warning ("pthread_create returned %d", rv); |
| 924 | rv = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 925 | } |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 926 | utm->do_echo = 1; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 927 | } |
| 928 | else |
| 929 | { |
| 930 | rx_fifo->client_session_index = session_index; |
| 931 | tx_fifo->client_session_index = session_index; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 932 | session->rx_fifo = rx_fifo; |
| 933 | session->tx_fifo = tx_fifo; |
| 934 | clib_memcpy (&session->transport.rmt_ip, mp->ip, |
| 935 | sizeof (ip46_address_t)); |
| 936 | session->transport.is_ip4 = mp->is_ip4; |
| 937 | session->transport.rmt_port = mp->port; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | hash_set (utm->session_index_by_vpp_handles, mp->handle, session_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 941 | if (pool_elts (utm->sessions) && (pool_elts (utm->sessions) % 20000) == 0) |
| 942 | { |
| 943 | f64 now = clib_time_now (&utm->clib_time); |
| 944 | fformat (stdout, "%d active sessions in %.2f seconds, %.2f/sec...\n", |
| 945 | pool_elts (utm->sessions), now - start_time, |
| 946 | (f64) pool_elts (utm->sessions) / (now - start_time)); |
| 947 | } |
| 948 | |
| 949 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 950 | memset (rmp, 0, sizeof (*rmp)); |
| 951 | rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 952 | rmp->handle = mp->handle; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 953 | rmp->context = mp->context; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 954 | rmp->retval = rv; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 955 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 956 | |
| 957 | CLIB_MEMORY_BARRIER (); |
| 958 | utm->state = STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
| 962 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 963 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 964 | udp_echo_main_t *utm = &udp_echo_main; |
| 965 | app_session_t *session; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 966 | vl_api_disconnect_session_reply_t *rmp; |
| 967 | uword *p; |
| 968 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 969 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 970 | p = hash_get (utm->session_index_by_vpp_handles, mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 971 | |
| 972 | if (p) |
| 973 | { |
| 974 | session = pool_elt_at_index (utm->sessions, p[0]); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 975 | hash_unset (utm->session_index_by_vpp_handles, mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 976 | pool_put (utm->sessions, session); |
| 977 | } |
| 978 | else |
| 979 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 980 | clib_warning ("couldn't find session key %llx", mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 981 | rv = -11; |
| 982 | } |
| 983 | |
| 984 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 985 | memset (rmp, 0, sizeof (*rmp)); |
| 986 | rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY); |
| 987 | rmp->retval = rv; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 988 | rmp->handle = mp->handle; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 989 | rmp->context = mp->context; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 990 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp); |
| 991 | } |
| 992 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 993 | static void |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 994 | vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 995 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 996 | udp_echo_main_t *utm = &udp_echo_main; |
| 997 | unformat_input_t _input, *input = &_input; |
| 998 | session_endpoint_extended_t _sep, *sep = &_sep; |
| 999 | app_session_t *session; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1000 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1001 | ASSERT (utm->i_am_server == 0); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1002 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1003 | if (mp->retval) |
| 1004 | { |
| 1005 | clib_warning ("failed connect"); |
| 1006 | return; |
| 1007 | } |
| 1008 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1009 | ASSERT (mp->server_rx_fifo && mp->server_tx_fifo); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1010 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1011 | pool_get (utm->sessions, session); |
| 1012 | session->rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
| 1013 | session->tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
| 1014 | session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address, |
| 1015 | svm_queue_t *); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1016 | /* Cut-through case */ |
| 1017 | if (mp->client_event_queue_address) |
| 1018 | { |
| 1019 | clib_warning ("cut-through session"); |
| 1020 | utm->cut_through_session_index = session - utm->sessions; |
| 1021 | utm->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address, |
| 1022 | svm_queue_t *); |
| 1023 | utm->our_event_queue = uword_to_pointer (mp->client_event_queue_address, |
| 1024 | svm_queue_t *); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1025 | utm->do_echo = 1; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1026 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1027 | else |
| 1028 | { |
| 1029 | utm->connected_session = session - utm->sessions; |
| 1030 | utm->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address, |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1031 | svm_queue_t *); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1032 | |
| 1033 | clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip, |
| 1034 | sizeof (ip46_address_t)); |
| 1035 | session->transport.is_ip4 = mp->is_ip4; |
| 1036 | session->transport.lcl_port = mp->lcl_port; |
| 1037 | |
| 1038 | unformat_init_vector (input, utm->connect_uri); |
| 1039 | if (!unformat (input, "%U", unformat_uri, sep)) |
| 1040 | { |
| 1041 | clib_warning ("can't figure out remote ip and port"); |
| 1042 | utm->state = STATE_FAILED; |
| 1043 | unformat_free (input); |
| 1044 | return; |
| 1045 | } |
| 1046 | unformat_free (input); |
| 1047 | clib_memcpy (&session->transport.rmt_ip, &sep->ip, |
| 1048 | sizeof (ip46_address_t)); |
| 1049 | session->transport.rmt_port = sep->port; |
| 1050 | session->is_dgram = !utm->is_connected; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1051 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1052 | utm->state = STATE_READY; |
| 1053 | } |
| 1054 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1055 | #define foreach_tcp_echo_msg \ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1056 | _(BIND_URI_REPLY, bind_uri_reply) \ |
| 1057 | _(CONNECT_URI, connect_uri) \ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1058 | _(CONNECT_SESSION_REPLY, connect_session_reply) \ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1059 | _(UNBIND_URI_REPLY, unbind_uri_reply) \ |
| 1060 | _(ACCEPT_SESSION, accept_session) \ |
| 1061 | _(DISCONNECT_SESSION, disconnect_session) \ |
| 1062 | _(MAP_ANOTHER_SEGMENT, map_another_segment) \ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1063 | _(UNMAP_SEGMENT, unmap_segment) \ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1064 | _(APPLICATION_ATTACH_REPLY, application_attach_reply) \ |
| 1065 | _(APPLICATION_DETACH_REPLY, application_detach_reply) \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1066 | |
| 1067 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1068 | tcp_echo_api_hookup (udp_echo_main_t * utm) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1069 | { |
| 1070 | #define _(N,n) \ |
| 1071 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1072 | vl_api_##n##_t_handler, \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1073 | vl_noop_handler, \ |
| 1074 | vl_api_##n##_t_endian, \ |
| 1075 | vl_api_##n##_t_print, \ |
| 1076 | sizeof(vl_api_##n##_t), 1); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1077 | foreach_tcp_echo_msg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1078 | #undef _ |
| 1079 | |
| 1080 | } |
| 1081 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1082 | int |
| 1083 | connect_to_vpp (char *name) |
| 1084 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1085 | udp_echo_main_t *utm = &udp_echo_main; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1086 | api_main_t *am = &api_main; |
| 1087 | |
| 1088 | if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0) |
| 1089 | return -1; |
| 1090 | |
| 1091 | utm->vl_input_queue = am->shmem_hdr->vl_input_queue; |
| 1092 | utm->my_client_index = am->my_client_index; |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | void |
| 1098 | vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...) |
| 1099 | { |
| 1100 | clib_warning ("BUG"); |
| 1101 | } |
| 1102 | |
| 1103 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1104 | init_error_string_table (udp_echo_main_t * utm) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1105 | { |
| 1106 | utm->error_string_by_error_number = hash_create (0, sizeof (uword)); |
| 1107 | |
| 1108 | #define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s); |
| 1109 | foreach_vnet_api_error; |
| 1110 | #undef _ |
| 1111 | |
| 1112 | hash_set (utm->error_string_by_error_number, 99, "Misc"); |
| 1113 | } |
| 1114 | |
| 1115 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1116 | server_handle_fifo_event_rx (udp_echo_main_t * utm, session_fifo_event_t * e) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1117 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1118 | app_session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1119 | int rv; |
| 1120 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1121 | s = pool_elt_at_index (utm->sessions, e->fifo->client_session_index); |
| 1122 | app_recv (s, utm->rx_buf, vec_len (utm->rx_buf)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1123 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1124 | if (utm->do_echo) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1125 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1126 | do |
| 1127 | { |
| 1128 | rv = app_send_stream (s, utm->rx_buf, vec_len (utm->rx_buf), 0); |
| 1129 | } |
| 1130 | while (rv == SVM_FIFO_FULL); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1131 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1135 | server_handle_event_queue (udp_echo_main_t * utm) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1136 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 1137 | session_fifo_event_t _e, *e = &_e; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1138 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1139 | while (utm->state != STATE_READY) |
| 1140 | sleep (5); |
| 1141 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1142 | while (1) |
| 1143 | { |
Mohsin Kazmi | 3fca567 | 2018-01-04 18:57:26 +0100 | [diff] [blame] | 1144 | svm_queue_sub (utm->our_event_queue, (u8 *) e, SVM_Q_WAIT, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1145 | switch (e->event_type) |
| 1146 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1147 | case FIFO_EVENT_APP_RX: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1148 | server_handle_fifo_event_rx (utm, e); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1149 | break; |
| 1150 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1151 | case FIFO_EVENT_DISCONNECT: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1152 | return; |
| 1153 | |
| 1154 | default: |
| 1155 | clib_warning ("unknown event type %d", e->event_type); |
| 1156 | break; |
| 1157 | } |
| 1158 | if (PREDICT_FALSE (utm->time_to_stop == 1)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1159 | return; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1160 | if (PREDICT_FALSE (utm->time_to_print_stats == 1)) |
| 1161 | { |
| 1162 | utm->time_to_print_stats = 0; |
| 1163 | fformat (stdout, "%d connections\n", pool_elts (utm->sessions)); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1168 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1169 | server_unbind (udp_echo_main_t * utm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1170 | { |
| 1171 | vl_api_unbind_uri_t *ump; |
| 1172 | |
| 1173 | ump = vl_msg_api_alloc (sizeof (*ump)); |
| 1174 | memset (ump, 0, sizeof (*ump)); |
| 1175 | |
| 1176 | ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI); |
| 1177 | ump->client_index = utm->my_client_index; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1178 | memcpy (ump->uri, utm->listen_uri, vec_len (utm->listen_uri)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1179 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump); |
| 1180 | } |
| 1181 | |
| 1182 | static void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1183 | server_bind (udp_echo_main_t * utm) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1184 | { |
| 1185 | vl_api_bind_uri_t *bmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1186 | |
| 1187 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 1188 | memset (bmp, 0, sizeof (*bmp)); |
| 1189 | |
| 1190 | bmp->_vl_msg_id = ntohs (VL_API_BIND_URI); |
| 1191 | bmp->client_index = utm->my_client_index; |
| 1192 | bmp->context = ntohl (0xfeedface); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1193 | memcpy (bmp->uri, utm->listen_uri, vec_len (utm->listen_uri)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1194 | vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | void |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1198 | udp_server_test (udp_echo_main_t * utm) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1199 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1200 | u8 wait_for_state = utm->is_connected ? STATE_BOUND : STATE_READY; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1201 | application_send_attach (utm); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1202 | |
| 1203 | /* Bind to uri */ |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1204 | server_bind (utm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1205 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1206 | if (wait_for_state_change (utm, wait_for_state)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1207 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1208 | clib_warning ("timeout waiting for state change"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1209 | return; |
| 1210 | } |
| 1211 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1212 | server_handle_event_queue (utm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1213 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1214 | /* Cleanup */ |
| 1215 | server_unbind (utm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1216 | |
| 1217 | if (wait_for_state_change (utm, STATE_START)) |
| 1218 | { |
| 1219 | clib_warning ("timeout waiting for STATE_START"); |
| 1220 | return; |
| 1221 | } |
| 1222 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1223 | application_detach (utm); |
| 1224 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1225 | fformat (stdout, "Test complete...\n"); |
| 1226 | } |
| 1227 | |
| 1228 | int |
| 1229 | main (int argc, char **argv) |
| 1230 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1231 | udp_echo_main_t *utm = &udp_echo_main; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1232 | u8 *uri = (u8 *) "udp://6.0.1.1/1234"; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1233 | unformat_input_t _argv, *a = &_argv; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1234 | int i_am_server = 1; |
| 1235 | app_session_t *session; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1236 | u8 *chroot_prefix; |
| 1237 | char *app_name; |
| 1238 | mheap_t *h; |
| 1239 | u8 *heap; |
| 1240 | u32 tmp; |
| 1241 | int i; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1242 | |
| 1243 | clib_mem_init (0, 256 << 20); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1244 | heap = clib_mem_get_per_cpu_heap (); |
| 1245 | h = mheap_header (heap); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1246 | /* make the main heap thread-safe */ |
| 1247 | h->flags |= MHEAP_FLAG_THREAD_SAFE; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1248 | svm_fifo_segment_main_init (0x200000000ULL, 20); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1249 | |
| 1250 | vec_validate (utm->rx_buf, 8192); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1251 | utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword)); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1252 | utm->my_pid = getpid (); |
| 1253 | utm->configured_segment_size = 1 << 20; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1254 | utm->segments_table = hash_create_vec (0, sizeof (u8), sizeof (u64)); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1255 | utm->have_return = 1; |
| 1256 | utm->bytes_to_send = 1024; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1257 | utm->fifo_size = 128 << 10; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1258 | utm->segment_main = &svm_fifo_segment_main; |
| 1259 | utm->cut_through_session_index = ~0; |
| 1260 | clib_time_init (&utm->clib_time); |
| 1261 | |
| 1262 | init_error_string_table (utm); |
| 1263 | unformat_init_command_line (a, argv); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1264 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1265 | while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT) |
| 1266 | { |
| 1267 | if (unformat (a, "chroot prefix %s", &chroot_prefix)) |
| 1268 | { |
| 1269 | vl_set_memory_root_path ((char *) chroot_prefix); |
| 1270 | } |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1271 | else if (unformat (a, "uri %s", &uri)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1272 | ; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1273 | else if (unformat (a, "segment-size %dM", &tmp)) |
| 1274 | utm->configured_segment_size = tmp << 20; |
| 1275 | else if (unformat (a, "segment-size %dG", &tmp)) |
| 1276 | utm->configured_segment_size = tmp << 30; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1277 | else if (unformat (a, "server")) |
| 1278 | i_am_server = 1; |
| 1279 | else if (unformat (a, "client")) |
| 1280 | i_am_server = 0; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1281 | else if (unformat (a, "no-return")) |
| 1282 | utm->have_return = 0; |
| 1283 | else if (unformat (a, "mbytes %d", &tmp)) |
| 1284 | utm->bytes_to_send = (u64) tmp << 20; |
| 1285 | else if (unformat (a, "fifo-size %d", &tmp)) |
| 1286 | utm->fifo_size = tmp << 10; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1287 | else |
| 1288 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1289 | fformat (stderr, "%s: usage [server|client]\n"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1290 | exit (1); |
| 1291 | } |
| 1292 | } |
| 1293 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1294 | utm->i_am_server = i_am_server; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1295 | |
| 1296 | setup_signal_handlers (); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1297 | tcp_echo_api_hookup (utm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1298 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1299 | if (i_am_server) |
| 1300 | { |
| 1301 | utm->listen_uri = format (0, "%s%c", uri, 0); |
| 1302 | utm->is_connected = (utm->listen_uri[4] == 'c'); |
| 1303 | app_name = "udp_echo_server"; |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | app_name = "udp_echo_client"; |
| 1308 | utm->connect_uri = format (0, "%s%c", uri, 0); |
| 1309 | utm->is_connected = (utm->connect_uri[4] == 'c'); |
| 1310 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1311 | if (connect_to_vpp (app_name) < 0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1312 | { |
| 1313 | svm_region_exit (); |
| 1314 | fformat (stderr, "Couldn't connect to vpe, exiting...\n"); |
| 1315 | exit (1); |
| 1316 | } |
| 1317 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1318 | if (i_am_server == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1319 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1320 | client_test (utm); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1321 | goto done; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1324 | /* $$$$ hack preallocation */ |
| 1325 | for (i = 0; i < 200000; i++) |
| 1326 | { |
| 1327 | pool_get (utm->sessions, session); |
| 1328 | memset (session, 0, sizeof (*session)); |
| 1329 | } |
| 1330 | for (i = 0; i < 200000; i++) |
| 1331 | pool_put_index (utm->sessions, i); |
| 1332 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1333 | udp_server_test (utm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1334 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 1335 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1336 | vl_client_disconnect_from_vlib (); |
| 1337 | exit (0); |
| 1338 | } |
| 1339 | |
| 1340 | #undef vl_api_version |
| 1341 | #define vl_api_version(n,v) static u32 vpe_api_version = v; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1342 | #include <vpp/api/vpe.api.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1343 | #undef vl_api_version |
| 1344 | |
| 1345 | void |
| 1346 | vl_client_add_api_signatures (vl_api_memclnt_create_t * mp) |
| 1347 | { |
| 1348 | /* |
| 1349 | * Send the main API signature in slot 0. This bit of code must |
| 1350 | * match the checks in ../vpe/api/api.c: vl_msg_api_version_check(). |
| 1351 | */ |
| 1352 | mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version); |
| 1353 | } |
| 1354 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1355 | u32 |
| 1356 | vl (void *p) |
| 1357 | { |
| 1358 | return vec_len (p); |
| 1359 | } |
| 1360 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1361 | /* |
| 1362 | * fd.io coding-style-patch-verification: ON |
| 1363 | * |
| 1364 | * Local Variables: |
| 1365 | * eval: (c-set-style "gnu") |
| 1366 | * End: |
| 1367 | */ |