Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2017 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 <vnet/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/session/application.h> |
| 19 | #include <vnet/session/application_interface.h> |
| 20 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 21 | /* define message IDs */ |
| 22 | #include <vpp/api/vpe_msg_enum.h> |
| 23 | |
| 24 | /* define message structures */ |
| 25 | #define vl_typedefs |
| 26 | #include <vpp/api/vpe_all_api_h.h> |
| 27 | #undef vl_typedefs |
| 28 | |
| 29 | /* define generated endian-swappers */ |
| 30 | #define vl_endianfun |
| 31 | #include <vpp/api/vpe_all_api_h.h> |
| 32 | #undef vl_endianfun |
| 33 | |
| 34 | /* instantiate all the print functions we know about */ |
| 35 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 36 | #define vl_printfun |
| 37 | #include <vpp/api/vpe_all_api_h.h> |
| 38 | #undef vl_printfun |
| 39 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 40 | typedef struct |
| 41 | { |
| 42 | u8 *rx_buf; |
| 43 | unix_shared_memory_queue_t **vpp_queue; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 44 | u64 byte_index; |
| 45 | |
| 46 | /* Sever's event queue */ |
| 47 | unix_shared_memory_queue_t *vl_input_queue; |
| 48 | |
| 49 | /* API client handle */ |
| 50 | u32 my_client_index; |
| 51 | |
| 52 | u32 app_index; |
| 53 | |
| 54 | /* process node index for evnt scheduling */ |
| 55 | u32 node_index; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 56 | vlib_main_t *vlib_main; |
| 57 | } builtin_server_main_t; |
| 58 | |
| 59 | builtin_server_main_t builtin_server_main; |
| 60 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 61 | int |
| 62 | builtin_session_accept_callback (stream_session_t * s) |
| 63 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 64 | builtin_server_main_t *bsm = &builtin_server_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 65 | clib_warning ("called..."); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 66 | |
| 67 | bsm->vpp_queue[s->thread_index] = |
| 68 | session_manager_get_vpp_event_queue (s->thread_index); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 69 | s->session_state = SESSION_STATE_READY; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 70 | bsm->byte_index = 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | builtin_session_disconnect_callback (stream_session_t * s) |
| 76 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 77 | builtin_server_main_t *bsm = &builtin_server_main; |
| 78 | vnet_disconnect_args_t _a, *a = &_a; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 79 | clib_warning ("called..."); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 80 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 81 | a->handle = stream_session_handle (s); |
| 82 | a->app_index = bsm->app_index; |
| 83 | vnet_disconnect_session (a); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 86 | void |
| 87 | builtin_session_reset_callback (stream_session_t * s) |
| 88 | { |
| 89 | clib_warning ("called.. "); |
| 90 | |
| 91 | stream_session_cleanup (s); |
| 92 | } |
| 93 | |
| 94 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 95 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 96 | builtin_session_connected_callback (u32 app_index, u32 api_context, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 97 | stream_session_t * s, u8 is_fail) |
| 98 | { |
| 99 | clib_warning ("called..."); |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | int |
| 104 | builtin_add_segment_callback (u32 client_index, |
| 105 | const u8 * seg_name, u32 seg_size) |
| 106 | { |
| 107 | clib_warning ("called..."); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | int |
| 112 | builtin_redirect_connect_callback (u32 client_index, void *mp) |
| 113 | { |
| 114 | clib_warning ("called..."); |
| 115 | return -1; |
| 116 | } |
| 117 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 118 | void |
| 119 | test_bytes (builtin_server_main_t * bsm, int actual_transfer) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 120 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < actual_transfer; i++) |
| 124 | { |
| 125 | if (bsm->rx_buf[i] != ((bsm->byte_index + i) & 0xff)) |
| 126 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 127 | clib_warning ("at %lld expected %d got %d", bsm->byte_index + i, |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 128 | (bsm->byte_index + i) & 0xff, bsm->rx_buf[i]); |
| 129 | } |
| 130 | } |
| 131 | bsm->byte_index += actual_transfer; |
| 132 | } |
| 133 | |
| 134 | int |
| 135 | builtin_server_rx_callback (stream_session_t * s) |
| 136 | { |
| 137 | u32 n_written, max_dequeue, max_enqueue, max_transfer; |
| 138 | int actual_transfer; |
| 139 | svm_fifo_t *tx_fifo, *rx_fifo; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 140 | builtin_server_main_t *bsm = &builtin_server_main; |
| 141 | session_fifo_event_t evt; |
| 142 | static int serial_number = 0; |
| 143 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 144 | max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo); |
| 145 | max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo); |
| 146 | |
| 147 | if (PREDICT_FALSE (max_dequeue == 0)) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 148 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | tx_fifo = s->server_tx_fifo; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 153 | rx_fifo = s->server_rx_fifo; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 154 | |
| 155 | /* Number of bytes we're going to copy */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 156 | max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 157 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 158 | /* No space in tx fifo */ |
| 159 | if (PREDICT_FALSE (max_transfer == 0)) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 160 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 161 | /* XXX timeout for session that are stuck */ |
| 162 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 163 | rx_event: |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 164 | /* Program self-tap to retry */ |
| 165 | if (svm_fifo_set_event (rx_fifo)) |
| 166 | { |
| 167 | evt.fifo = rx_fifo; |
| 168 | evt.event_type = FIFO_EVENT_BUILTIN_RX; |
| 169 | evt.event_id = 0; |
| 170 | unix_shared_memory_queue_add (bsm->vpp_queue[s->thread_index], |
| 171 | (u8 *) & evt, |
| 172 | 0 /* do wait for mutex */ ); |
| 173 | } |
| 174 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 178 | svm_fifo_unset_event (rx_fifo); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 179 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 180 | vec_validate (bsm->rx_buf, max_transfer - 1); |
| 181 | _vec_len (bsm->rx_buf) = max_transfer; |
| 182 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 183 | actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer, |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 184 | bsm->rx_buf); |
| 185 | ASSERT (actual_transfer == max_transfer); |
| 186 | |
| 187 | // test_bytes (bsm, actual_transfer); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Echo back |
| 191 | */ |
| 192 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 193 | n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer, bsm->rx_buf); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 194 | |
| 195 | if (n_written != max_transfer) |
| 196 | clib_warning ("short trout!"); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 197 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 198 | if (svm_fifo_set_event (tx_fifo)) |
| 199 | { |
| 200 | /* Fabricate TX event, send to vpp */ |
| 201 | evt.fifo = tx_fifo; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 202 | evt.event_type = FIFO_EVENT_APP_TX; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 203 | evt.event_id = serial_number++; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 204 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 205 | unix_shared_memory_queue_add (bsm->vpp_queue[s->thread_index], |
| 206 | (u8 *) & evt, 0 /* do wait for mutex */ ); |
| 207 | } |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 208 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 209 | if (PREDICT_FALSE (max_enqueue < max_dequeue)) |
| 210 | goto rx_event; |
| 211 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static session_cb_vft_t builtin_session_cb_vft = { |
| 216 | .session_accept_callback = builtin_session_accept_callback, |
| 217 | .session_disconnect_callback = builtin_session_disconnect_callback, |
| 218 | .session_connected_callback = builtin_session_connected_callback, |
| 219 | .add_segment_callback = builtin_add_segment_callback, |
| 220 | .redirect_connect_callback = builtin_redirect_connect_callback, |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 221 | .builtin_server_rx_callback = builtin_server_rx_callback, |
| 222 | .session_reset_callback = builtin_session_reset_callback |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 223 | }; |
| 224 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 225 | /* Abuse VPP's input queue */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 226 | static int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 227 | create_api_loopback (vlib_main_t * vm) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 228 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 229 | builtin_server_main_t *bsm = &builtin_server_main; |
| 230 | vl_api_memclnt_create_t _m, *mp = &_m; |
| 231 | extern void vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t *); |
| 232 | api_main_t *am = &api_main; |
| 233 | vl_shmem_hdr_t *shmem_hdr; |
| 234 | uword *event_data = 0, event_type; |
| 235 | int resolved = 0; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 236 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 237 | /* |
| 238 | * Create a "loopback" API client connection |
| 239 | * Don't do things like this unless you know what you're doing... |
| 240 | */ |
| 241 | |
| 242 | shmem_hdr = am->shmem_hdr; |
| 243 | bsm->vl_input_queue = shmem_hdr->vl_input_queue; |
| 244 | memset (mp, 0, sizeof (*mp)); |
| 245 | mp->_vl_msg_id = VL_API_MEMCLNT_CREATE; |
| 246 | mp->context = 0xFEEDFACE; |
| 247 | mp->input_queue = (u64) bsm->vl_input_queue; |
| 248 | strncpy ((char *) mp->name, "tcp_test_server", sizeof (mp->name) - 1); |
| 249 | |
| 250 | vl_api_memclnt_create_t_handler (mp); |
| 251 | |
| 252 | /* Wait for reply */ |
| 253 | bsm->node_index = vlib_get_current_process (vm)->node_runtime.node_index; |
| 254 | vlib_process_wait_for_event_or_clock (vm, 1.0); |
| 255 | event_type = vlib_process_get_events (vm, &event_data); |
| 256 | switch (event_type) |
| 257 | { |
| 258 | case 1: |
| 259 | resolved = 1; |
| 260 | break; |
| 261 | case ~0: |
| 262 | /* timed out */ |
| 263 | break; |
| 264 | default: |
| 265 | clib_warning ("unknown event_type %d", event_type); |
| 266 | } |
| 267 | if (!resolved) |
| 268 | return -1; |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int |
| 274 | server_attach () |
| 275 | { |
| 276 | builtin_server_main_t *bsm = &builtin_server_main; |
| 277 | u8 segment_name[128]; |
| 278 | u64 options[SESSION_OPTIONS_N_OPTIONS]; |
| 279 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 280 | |
| 281 | memset (a, 0, sizeof (*a)); |
| 282 | memset (options, 0, sizeof (options)); |
| 283 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 284 | a->api_client_index = bsm->my_client_index; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 285 | a->session_cb_vft = &builtin_session_cb_vft; |
| 286 | a->options = options; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 287 | a->options[SESSION_OPTIONS_SEGMENT_SIZE] = 128 << 20; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 288 | a->options[SESSION_OPTIONS_RX_FIFO_SIZE] = 1 << 16; |
| 289 | a->options[SESSION_OPTIONS_TX_FIFO_SIZE] = 1 << 16; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 290 | a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_BUILTIN_APP; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 291 | a->segment_name = segment_name; |
| 292 | a->segment_name_length = ARRAY_LEN (segment_name); |
| 293 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 294 | if (vnet_application_attach (a)) |
| 295 | { |
| 296 | clib_warning ("failed to attach server"); |
| 297 | return -1; |
| 298 | } |
| 299 | bsm->app_index = a->app_index; |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static int |
| 304 | server_listen () |
| 305 | { |
| 306 | builtin_server_main_t *bsm = &builtin_server_main; |
| 307 | vnet_bind_args_t _a, *a = &_a; |
| 308 | memset (a, 0, sizeof (*a)); |
| 309 | a->app_index = bsm->app_index; |
| 310 | a->uri = "tcp://0.0.0.0/1234"; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 311 | return vnet_bind_uri (a); |
| 312 | } |
| 313 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 314 | static int |
| 315 | server_create (vlib_main_t * vm) |
| 316 | { |
| 317 | builtin_server_main_t *bsm = &builtin_server_main; |
| 318 | u32 num_threads; |
| 319 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 320 | |
| 321 | if (bsm->my_client_index == (u32) ~ 0) |
| 322 | { |
| 323 | if (create_api_loopback (vm)) |
| 324 | return -1; |
| 325 | } |
| 326 | |
| 327 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 328 | vec_validate (builtin_server_main.vpp_queue, num_threads - 1); |
| 329 | |
| 330 | if (server_attach ()) |
| 331 | { |
| 332 | clib_warning ("failed to attach server"); |
| 333 | return -1; |
| 334 | } |
| 335 | if (server_listen ()) |
| 336 | { |
| 337 | clib_warning ("failed to start listening"); |
| 338 | return -1; |
| 339 | } |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /* Get our api client index */ |
| 344 | static void |
| 345 | vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp) |
| 346 | { |
| 347 | vlib_main_t *vm = vlib_get_main (); |
| 348 | builtin_server_main_t *bsm = &builtin_server_main; |
| 349 | bsm->my_client_index = mp->index; |
| 350 | vlib_process_signal_event (vm, bsm->node_index, 1 /* evt */ , |
| 351 | 0 /* data */ ); |
| 352 | } |
| 353 | |
| 354 | #define foreach_tcp_builtin_server_api_msg \ |
| 355 | _(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \ |
| 356 | |
| 357 | static clib_error_t * |
| 358 | tcp_builtin_server_api_hookup (vlib_main_t * vm) |
| 359 | { |
| 360 | vl_msg_api_msg_config_t _c, *c = &_c; |
| 361 | |
| 362 | /* Hook up client-side static APIs to our handlers */ |
| 363 | #define _(N,n) do { \ |
| 364 | c->id = VL_API_##N; \ |
| 365 | c->name = #n; \ |
| 366 | c->handler = vl_api_##n##_t_handler; \ |
| 367 | c->cleanup = vl_noop_handler; \ |
| 368 | c->endian = vl_api_##n##_t_endian; \ |
| 369 | c->print = vl_api_##n##_t_print; \ |
| 370 | c->size = sizeof(vl_api_##n##_t); \ |
| 371 | c->traced = 1; /* trace, so these msgs print */ \ |
| 372 | c->replay = 0; /* don't replay client create/delete msgs */ \ |
| 373 | c->message_bounce = 0; /* don't bounce this message */ \ |
| 374 | vl_msg_api_config(c);} while (0); |
| 375 | |
| 376 | foreach_tcp_builtin_server_api_msg; |
| 377 | #undef _ |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 382 | static clib_error_t * |
| 383 | server_create_command_fn (vlib_main_t * vm, |
| 384 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 385 | { |
| 386 | int rv; |
| 387 | #if 0 |
| 388 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 389 | { |
| 390 | if (unformat (input, "whatever %d", &whatever)) |
| 391 | ; |
| 392 | else |
| 393 | return clib_error_return (0, "unknown input `%U'", |
| 394 | format_unformat_error, input); |
| 395 | } |
| 396 | #endif |
| 397 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 398 | tcp_builtin_server_api_hookup (vm); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 399 | vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ ); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 400 | rv = server_create (vm); |
| 401 | switch (rv) |
| 402 | { |
| 403 | case 0: |
| 404 | break; |
| 405 | default: |
| 406 | return clib_error_return (0, "server_create returned %d", rv); |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 411 | /* *INDENT-OFF* */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 412 | VLIB_CLI_COMMAND (server_create_command, static) = |
| 413 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 414 | .path = "test tcp server", |
| 415 | .short_help = "test tcp server", |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 416 | .function = server_create_command_fn, |
| 417 | }; |
| 418 | /* *INDENT-ON* */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 419 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 420 | clib_error_t * |
| 421 | builtin_tcp_server_main_init (vlib_main_t * vm) |
| 422 | { |
| 423 | builtin_server_main_t *bsm = &builtin_server_main; |
| 424 | bsm->my_client_index = ~0; |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | VLIB_INIT_FUNCTION (builtin_tcp_server_main_init); |
| 429 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 430 | /* |
| 431 | * fd.io coding-style-patch-verification: ON |
| 432 | * |
| 433 | * Local Variables: |
| 434 | * eval: (c-set-style "gnu") |
| 435 | * End: |
| 436 | */ |