FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
echo_server.c
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2017-2019 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>
20 #include <vnet/session/session.h>
21 
22 #define ECHO_SERVER_DBG (0)
23 #define DBG(_fmt, _args...) \
24  if (ECHO_SERVER_DBG) \
25  clib_warning (_fmt, ##_args)
26 
27 typedef struct
28 {
29  /*
30  * Server app parameters
31  */
33  svm_queue_t *vl_input_queue; /**< Sever's event queue */
34 
35  u32 app_index; /**< Server app index */
36  u32 my_client_index; /**< API client handle */
37  u32 node_index; /**< process node index for event scheduling */
38 
39  /*
40  * Config params
41  */
42  u8 no_echo; /**< Don't echo traffic */
43  u32 fifo_size; /**< Fifo size */
44  u32 rcv_buffer_size; /**< Rcv buffer size */
45  u32 prealloc_fifos; /**< Preallocate fifos */
46  u32 private_segment_count; /**< Number of private segments */
47  u32 private_segment_size; /**< Size of private segments */
48  char *server_uri; /**< Server URI */
49  u32 tls_engine; /**< TLS engine: mbedtls/openssl */
50  u32 ckpair_index; /**< Cert and key for tls/quic */
51  u8 is_dgram; /**< set if transport is dgram */
52 
53  /*
54  * Test state
55  */
56  u8 **rx_buf; /**< Per-thread RX buffer */
60  u64 listener_handle; /**< Session handle of the root listener */
61 
64 
66 
67 int
69 {
70  DBG ("QSession %u accept w/opaque %d", s->session_index, s->opaque);
71  return 0;
72 }
73 
74 int
76 {
78  if (s->listener_handle == esm->listener_handle)
80  DBG ("SSESSION %u accept w/opaque %d", s->session_index, s->opaque);
81 
82  esm->vpp_queue[s->thread_index] =
84  s->session_state = SESSION_STATE_READY;
85  esm->byte_index = 0;
86  ASSERT (vec_len (esm->rx_retries) > s->thread_index);
88  esm->rx_retries[s->thread_index][s->session_index] = 0;
89  return 0;
90 }
91 
92 int
94 {
96  esm->vpp_queue[s->thread_index] =
98  s->session_state = SESSION_STATE_READY;
99  esm->byte_index = 0;
100  ASSERT (vec_len (esm->rx_retries) > s->thread_index);
102  esm->rx_retries[s->thread_index][s->session_index] = 0;
103  return 0;
104 }
105 
106 void
108 {
110  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
111 
112  a->handle = session_handle (s);
113  a->app_index = esm->app_index;
115 }
116 
117 void
119 {
121  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
122  clib_warning ("Reset session %U", format_session, s, 2);
123  a->handle = session_handle (s);
124  a->app_index = esm->app_index;
126 }
127 
128 int
130  session_t * s, session_error_t err)
131 {
132  clib_warning ("called...");
133  return -1;
134 }
135 
136 int
137 echo_server_add_segment_callback (u32 client_index, u64 segment_handle)
138 {
139  /* New heaps may be added */
140  return 0;
141 }
142 
143 int
145 {
146  clib_warning ("called...");
147  return -1;
148 }
149 
150 void
151 test_bytes (echo_server_main_t * esm, int actual_transfer)
152 {
153  int i;
154  u32 my_thread_id = vlib_get_thread_index ();
155 
156  for (i = 0; i < actual_transfer; i++)
157  {
158  if (esm->rx_buf[my_thread_id][i] != ((esm->byte_index + i) & 0xff))
159  {
160  clib_warning ("at %lld expected %d got %d", esm->byte_index + i,
161  (esm->byte_index + i) & 0xff,
162  esm->rx_buf[my_thread_id][i]);
163  }
164  }
165  esm->byte_index += actual_transfer;
166 }
167 
168 /*
169  * If no-echo, just drop the data and be done with it.
170  */
171 int
173 {
174  svm_fifo_t *rx_fifo = s->rx_fifo;
176  return 0;
177 }
178 
179 int
181 {
182  u32 n_written, max_dequeue, max_enqueue, max_transfer;
183  int actual_transfer;
184  svm_fifo_t *tx_fifo, *rx_fifo;
188 
190 
191  rx_fifo = s->rx_fifo;
192  tx_fifo = s->tx_fifo;
193 
194  ASSERT (rx_fifo->master_thread_index == thread_index);
195  ASSERT (tx_fifo->master_thread_index == thread_index);
196 
197  max_enqueue = svm_fifo_max_enqueue_prod (tx_fifo);
198  if (!esm->is_dgram)
199  {
200  max_dequeue = svm_fifo_max_dequeue_cons (rx_fifo);
201  }
202  else
203  {
205  svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) & ph);
206  max_dequeue = ph.data_length - ph.data_offset;
207  if (!esm->vpp_queue[s->thread_index])
208  {
209  svm_msg_q_t *mq;
211  esm->vpp_queue[s->thread_index] = mq;
212  }
213  max_enqueue -= sizeof (session_dgram_hdr_t);
214  }
215 
216  if (PREDICT_FALSE (max_dequeue == 0))
217  return 0;
218 
219  /* Number of bytes we're going to copy */
220  max_transfer = clib_min (max_dequeue, max_enqueue);
221 
222  /* No space in tx fifo */
223  if (PREDICT_FALSE (max_transfer == 0))
224  {
225  /* XXX timeout for session that are stuck */
226 
227  rx_event:
228  /* Program self-tap to retry */
229  if (svm_fifo_set_event (rx_fifo))
230  {
231  if (session_send_io_evt_to_thread (rx_fifo,
233  clib_warning ("failed to enqueue self-tap");
234 
236  if (esm->rx_retries[thread_index][s->session_index] == 500000)
237  {
238  clib_warning ("session stuck: %U", format_session, s, 2);
239  }
240  if (esm->rx_retries[thread_index][s->session_index] < 500001)
242  }
243 
244  return 0;
245  }
246 
247  vec_validate (esm->rx_buf[thread_index], max_transfer);
248  if (!esm->is_dgram)
249  {
250  actual_transfer = app_recv_stream_raw (rx_fifo,
251  esm->rx_buf[thread_index],
252  max_transfer,
253  0 /* don't clear event */ ,
254  0 /* peek */ );
255  }
256  else
257  {
258  actual_transfer = app_recv_dgram_raw (rx_fifo,
259  esm->rx_buf[thread_index],
260  max_transfer, &at,
261  0 /* don't clear event */ ,
262  0 /* peek */ );
263  }
264  ASSERT (actual_transfer == max_transfer);
265  /* test_bytes (esm, actual_transfer); */
266 
267  /*
268  * Echo back
269  */
270 
271  if (!esm->is_dgram)
272  {
273  n_written = app_send_stream_raw (tx_fifo,
274  esm->vpp_queue[thread_index],
275  esm->rx_buf[thread_index],
276  actual_transfer, SESSION_IO_EVT_TX,
277  1 /* do_evt */ , 0);
278  }
279  else
280  {
281  n_written = app_send_dgram_raw (tx_fifo, &at,
282  esm->vpp_queue[s->thread_index],
283  esm->rx_buf[thread_index],
284  actual_transfer, SESSION_IO_EVT_TX,
285  1 /* do_evt */ , 0);
286  }
287 
288  if (n_written != max_transfer)
289  clib_warning ("short trout! written %u read %u", n_written, max_transfer);
290 
292  goto rx_event;
293 
294  return 0;
295 }
296 
299  .session_disconnect_callback = echo_server_session_disconnect_callback,
300  .session_connected_callback = echo_server_session_connected_callback,
301  .add_segment_callback = echo_server_add_segment_callback,
302  .builtin_app_rx_callback = echo_server_rx_callback,
303  .session_reset_callback = echo_server_session_reset_callback
304 };
305 
306 static int
307 echo_server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
308 {
309  vnet_app_add_cert_key_pair_args_t _ck_pair, *ck_pair = &_ck_pair;
311  vnet_app_attach_args_t _a, *a = &_a;
313  u32 segment_size = 512 << 20;
314 
315  clib_memset (a, 0, sizeof (*a));
316  clib_memset (options, 0, sizeof (options));
317 
318  if (esm->no_echo)
321  else
324  if (esm->transport_proto == TRANSPORT_PROTO_QUIC)
327 
328  if (esm->private_segment_size)
329  segment_size = esm->private_segment_size;
330 
331  a->api_client_index = ~0;
332  a->name = format (0, "echo_server");
333  a->session_cb_vft = &echo_server_session_cb_vft;
334  a->options = options;
335  a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
336  a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
337  a->options[APP_OPTIONS_RX_FIFO_SIZE] = esm->fifo_size;
338  a->options[APP_OPTIONS_TX_FIFO_SIZE] = esm->fifo_size;
340  a->options[APP_OPTIONS_TLS_ENGINE] = esm->tls_engine;
341  a->options[APP_OPTIONS_PCT_FIRST_ALLOC] = 100;
343  esm->prealloc_fifos ? esm->prealloc_fifos : 1;
344 
345  a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
346  if (appns_id)
347  {
348  a->namespace_id = appns_id;
349  a->options[APP_OPTIONS_FLAGS] |= appns_flags;
350  a->options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
351  }
352 
354  {
355  clib_warning ("failed to attach server");
356  return -1;
357  }
358  esm->app_index = a->app_index;
359  vec_free (a->name);
360 
361  clib_memset (ck_pair, 0, sizeof (*ck_pair));
362  ck_pair->cert = (u8 *) test_srv_crt_rsa;
363  ck_pair->key = (u8 *) test_srv_key_rsa;
364  ck_pair->cert_len = test_srv_crt_rsa_len;
365  ck_pair->key_len = test_srv_key_rsa_len;
366  vnet_app_add_cert_key_pair (ck_pair);
367  esm->ckpair_index = ck_pair->index;
368 
369  return 0;
370 }
371 
372 static int
374 {
376  vnet_app_detach_args_t _da, *da = &_da;
377  int rv;
378 
379  da->app_index = esm->app_index;
380  da->api_client_index = ~0;
382  esm->app_index = ~0;
384  return rv;
385 }
386 
387 static int
389 {
390  return proto == TRANSPORT_PROTO_TLS || proto == TRANSPORT_PROTO_DTLS ||
391  proto == TRANSPORT_PROTO_QUIC;
392 }
393 
394 static int
396 {
397  i32 rv;
399  vnet_listen_args_t _args = { 0 }, *args = &_args;
400 
401  args->sep_ext.app_wrk_index = 0;
402 
403  if ((rv = parse_uri (esm->server_uri, &args->sep_ext)))
404  {
405  return -1;
406  }
407  args->app_index = esm->app_index;
408  if (echo_client_transport_needs_crypto (args->sep_ext.transport_proto))
409  {
410  session_endpoint_alloc_ext_cfg (&args->sep_ext,
412  args->sep_ext.ext_cfg->crypto.ckpair_index = esm->ckpair_index;
413  }
414 
415  if (args->sep_ext.transport_proto == TRANSPORT_PROTO_UDP)
416  {
417  args->sep_ext.transport_flags = TRANSPORT_CFG_F_CONNECTED;
418  }
419 
420  rv = vnet_listen (args);
421  esm->listener_handle = args->handle;
422  if (args->sep_ext.ext_cfg)
423  clib_mem_free (args->sep_ext.ext_cfg);
424  return rv;
425 }
426 
427 static int
428 echo_server_create (vlib_main_t * vm, u8 * appns_id, u64 appns_flags,
429  u64 appns_secret)
430 {
433  u32 num_threads;
434  int i;
435 
436  num_threads = 1 /* main thread */ + vtm->n_threads;
437  vec_validate (echo_server_main.vpp_queue, num_threads - 1);
438  vec_validate (esm->rx_buf, num_threads - 1);
439  vec_validate (esm->rx_retries, num_threads - 1);
440  for (i = 0; i < vec_len (esm->rx_retries); i++)
441  vec_validate (esm->rx_retries[i],
444  for (i = 0; i < num_threads; i++)
445  vec_validate (esm->rx_buf[i], esm->rcv_buffer_size);
446 
447  if (echo_server_attach (appns_id, appns_flags, appns_secret))
448  {
449  clib_warning ("failed to attach server");
450  return -1;
451  }
452  if (echo_server_listen ())
453  {
454  clib_warning ("failed to start listening");
455  if (echo_server_detach ())
456  clib_warning ("failed to detach");
457  return -1;
458  }
459  return 0;
460 }
461 
462 static clib_error_t *
464  vlib_cli_command_t * cmd)
465 {
468  u8 server_uri_set = 0, *appns_id = 0;
469  u64 tmp, appns_flags = 0, appns_secret = 0;
470  char *default_uri = "tcp://0.0.0.0/1234";
471  int rv, is_stop = 0, barrier_acq_needed = 0;
472  clib_error_t *error = 0;
473 
474  /* The request came over the binary api and the inband cli handler
475  * is not mp_safe. Drop the barrier to make sure the workers are not
476  * blocked.
477  */
479  {
480  barrier_acq_needed = 1;
482  }
483 
484  esm->no_echo = 0;
485  esm->fifo_size = 64 << 10;
486  esm->rcv_buffer_size = 128 << 10;
487  esm->prealloc_fifos = 0;
488  esm->private_segment_count = 0;
489  esm->private_segment_size = 0;
491  vec_free (esm->server_uri);
492 
494  {
495  if (unformat (input, "uri %s", &esm->server_uri))
496  server_uri_set = 1;
497  else if (unformat (input, "no-echo"))
498  esm->no_echo = 1;
499  else if (unformat (input, "fifo-size %d", &esm->fifo_size))
500  esm->fifo_size <<= 10;
501  else if (unformat (input, "rcv-buf-size %d", &esm->rcv_buffer_size))
502  ;
503  else if (unformat (input, "prealloc-fifos %d", &esm->prealloc_fifos))
504  ;
505  else if (unformat (input, "private-segment-count %d",
506  &esm->private_segment_count))
507  ;
508  else if (unformat (input, "private-segment-size %U",
510  {
511  if (tmp >= 0x100000000ULL)
512  {
514  0, "private segment size %lld (%llu) too large", tmp, tmp);
515  goto cleanup;
516  }
517  esm->private_segment_size = tmp;
518  }
519  else if (unformat (input, "appns %_%v%_", &appns_id))
520  ;
521  else if (unformat (input, "all-scope"))
522  appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
523  | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
524  else if (unformat (input, "local-scope"))
525  appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
526  else if (unformat (input, "global-scope"))
527  appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
528  else if (unformat (input, "secret %lu", &appns_secret))
529  ;
530  else if (unformat (input, "stop"))
531  is_stop = 1;
532  else if (unformat (input, "tls-engine %d", &esm->tls_engine))
533  ;
534  else
535  {
536  error = clib_error_return (0, "failed: unknown input `%U'",
537  format_unformat_error, input);
538  goto cleanup;
539  }
540  }
541 
542  if (is_stop)
543  {
544  if (esm->app_index == (u32) ~ 0)
545  {
546  clib_warning ("server not running");
547  error = clib_error_return (0, "failed: server not running");
548  goto cleanup;
549  }
550  rv = echo_server_detach ();
551  if (rv)
552  {
553  clib_warning ("failed: detach");
554  error = clib_error_return (0, "failed: server detach %d", rv);
555  goto cleanup;
556  }
557  goto cleanup;
558  }
559 
560  vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
561 
562  if (!server_uri_set)
563  {
564  clib_warning ("No uri provided! Using default: %s", default_uri);
565  esm->server_uri = (char *) format (0, "%s%c", default_uri, 0);
566  }
567 
568  if ((rv = parse_uri ((char *) esm->server_uri, &sep)))
569  {
570  error = clib_error_return (0, "Uri parse error: %d", rv);
571  goto cleanup;
572  }
573  esm->transport_proto = sep.transport_proto;
574  esm->is_dgram = (sep.transport_proto == TRANSPORT_PROTO_UDP);
575 
576  rv = echo_server_create (vm, appns_id, appns_flags, appns_secret);
577  if (rv)
578  {
579  vec_free (esm->server_uri);
580  error = clib_error_return (0, "failed: server_create returned %d", rv);
581  goto cleanup;
582  }
583 
584 cleanup:
585  vec_free (appns_id);
586 
587  if (barrier_acq_needed)
589 
590  return error;
591 }
592 
593 /* *INDENT-OFF* */
595 {
596  .path = "test echo server",
597  .short_help = "test echo server proto <proto> [no echo][fifo-size <mbytes>]"
598  "[rcv-buf-size <bytes>][prealloc-fifos <count>]"
599  "[private-segment-count <count>][private-segment-size <bytes[m|g]>]"
600  "[uri <tcp://ip/port>]",
601  .function = echo_server_create_command_fn,
602 };
603 /* *INDENT-ON* */
604 
605 clib_error_t *
607 {
609  esm->my_client_index = ~0;
610  return 0;
611 }
612 
614 
615 /*
616 * fd.io coding-style-patch-verification: ON
617 *
618 * Local Variables:
619 * eval: (c-set-style "gnu")
620 * End:
621 */
echo_server_main_t::my_client_index
u32 my_client_index
API client handle.
Definition: echo_server.c:36
vnet_listen
int vnet_listen(vnet_listen_args_t *a)
Definition: application.c:1294
tmp
u32 * tmp
Definition: interface_output.c:1096
svm_fifo_set_event
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:733
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
api.h
vlib_worker_thread_barrier_release
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1375
session_error_t
enum session_error_ session_error_t
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
echo_server_session_accept_callback
int echo_server_session_accept_callback(session_t *s)
Definition: echo_server.c:93
APP_OPTIONS_RX_FIFO_SIZE
@ APP_OPTIONS_RX_FIFO_SIZE
Definition: application_interface.h:210
app_send_stream_raw
static int app_send_stream_raw(svm_fifo_t *f, svm_msg_q_t *vpp_evt_q, u8 *data, u32 len, u8 evt_type, u8 do_evt, u8 noblock)
Definition: application_interface.h:689
session_::session_index
u32 session_index
Index in thread pool where session was allocated.
Definition: session_types.h:188
echo_server_attach
static int echo_server_attach(u8 *appns_id, u64 appns_flags, u64 appns_secret)
Definition: echo_server.c:307
clib_max
#define clib_max(x, y)
Definition: clib.h:335
echo_server_main
echo_server_main_t echo_server_main
Definition: echo_server.c:65
app_session_transport_
Definition: application_interface.h:290
echo_server_main_t::byte_index
u64 byte_index
Definition: echo_server.c:57
session_dgram_hdr_t
struct session_dgram_header_ session_dgram_hdr_t
echo_server_main_t::is_dgram
u8 is_dgram
set if transport is dgram
Definition: echo_server.c:51
session_::tx_fifo
svm_fifo_t * tx_fifo
Definition: session_types.h:179
svm_fifo_peek
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1141
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
echo_server_main_t::app_index
u32 app_index
Server app index.
Definition: echo_server.c:35
test_bytes
void test_bytes(echo_server_main_t *esm, int actual_transfer)
Definition: echo_server.c:151
session_cb_vft_::builtin_app_rx_callback
int(* builtin_app_rx_callback)(session_t *session)
Direct RX callback for built-in application.
Definition: application_interface.h:66
session_
Definition: session_types.h:175
CRYPTO_ENGINE_OPENSSL
@ CRYPTO_ENGINE_OPENSSL
Definition: application_interface.h:177
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
session_endpoint_cfg_t
struct _session_endpoint_cfg session_endpoint_cfg_t
echo_server_session_connected_callback
int echo_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
Definition: echo_server.c:129
echo_server_detach
static int echo_server_detach(void)
Definition: echo_server.c:373
app_recv_stream_raw
static int app_recv_stream_raw(svm_fifo_t *f, u8 *buf, u32 len, u8 clear_evt, u8 peek)
Definition: application_interface.h:765
vlib_cli_command_t::path
char * path
Definition: cli.h:96
svm_queue_t
struct _svm_queue svm_queue_t
echo_server_main_t::private_segment_count
u32 private_segment_count
Number of private segments
Definition: echo_server.c:46
vnet_application_detach
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
Definition: application.c:1216
session_::thread_index
u8 thread_index
Index of the thread that allocated the session.
Definition: session_types.h:194
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
app_recv_dgram_raw
static int app_recv_dgram_raw(svm_fifo_t *f, u8 *buf, u32 len, app_session_transport_t *at, u8 clear_evt, u8 peek)
Definition: application_interface.h:720
echo_server_session_cb_vft
static session_cb_vft_t echo_server_session_cb_vft
Definition: echo_server.c:297
echo_server_main_t::rcv_buffer_size
u32 rcv_buffer_size
Rcv buffer size.
Definition: echo_server.c:44
APP_OPTIONS_SEGMENT_SIZE
@ APP_OPTIONS_SEGMENT_SIZE
Definition: application_interface.h:207
vnet_app_detach_args_t
struct _vnet_app_detach_args_t vnet_app_detach_args_t
unformat_input_t
struct _unformat_input_t unformat_input_t
echo_server_session_disconnect_callback
void echo_server_session_disconnect_callback(session_t *s)
Definition: echo_server.c:107
APP_OPTIONS_NAMESPACE_SECRET
@ APP_OPTIONS_NAMESPACE_SECRET
Definition: application_interface.h:215
APP_OPTIONS_N_OPTIONS
@ APP_OPTIONS_N_OPTIONS
Definition: application_interface.h:223
error
Definition: cJSON.c:88
echo_server_create
static int echo_server_create(vlib_main_t *vm, u8 *appns_id, u64 appns_flags, u64 appns_secret)
Definition: echo_server.c:428
session_main_::wrk
session_worker_t * wrk
Worker contexts.
Definition: session.h:176
ph
pool_header_t * ph(void *p)
GDB callable function: ph - call pool_header - get pool header.
Definition: gdb_funcs.c:78
i32
signed int i32
Definition: types.h:77
session_cb_vft_::session_accept_callback
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
Definition: application_interface.h:41
svm_fifo_t
struct _svm_fifo svm_fifo_t
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
SESSION_ENDPOINT_CFG_NULL
#define SESSION_ENDPOINT_CFG_NULL
Definition: session_types.h:77
session_cb_vft_
Definition: application_interface.h:32
echo_server_redirect_connect_callback
int echo_server_redirect_connect_callback(u32 client_index, void *mp)
Definition: echo_server.c:144
session_::rx_fifo
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
Definition: session_types.h:178
unformat_memory_size
unformat_function_t unformat_memory_size
Definition: format.h:288
echo_server_main_t::no_echo
u8 no_echo
Don't echo traffic.
Definition: echo_server.c:42
SESSION_IO_EVT_BUILTIN_RX
@ SESSION_IO_EVT_BUILTIN_RX
Definition: session_types.h:331
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
session_endpoint_alloc_ext_cfg
static void session_endpoint_alloc_ext_cfg(session_endpoint_cfg_t *sep_ext, transport_endpt_ext_cfg_type_t type)
Definition: application_interface.h:898
vnet_disconnect_args_t
struct _vnet_disconnect_args_t vnet_disconnect_args_t
test_srv_key_rsa
static const char test_srv_key_rsa[]
Definition: tls_test.h:49
session_main_get_vpp_event_queue
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
Definition: session.h:717
vnet_app_del_cert_key_pair
int vnet_app_del_cert_key_pair(u32 index)
Definition: application.c:2060
vlib_worker_thread_barrier_sync
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:173
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
echo_server_add_segment_callback
int echo_server_add_segment_callback(u32 client_index, u64 segment_handle)
Definition: echo_server.c:137
echo_server_main_t::rx_retries
u32 ** rx_retries
Definition: echo_server.c:58
vnet_listen_args_t
struct _vnet_bind_args_t vnet_listen_args_t
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
APP_OPTIONS_TLS_ENGINE
@ APP_OPTIONS_TLS_ENGINE
Definition: application_interface.h:218
vlib_thread_is_main_w_barrier
static u8 vlib_thread_is_main_w_barrier(void)
Definition: threads.h:485
session_main
session_main_t session_main
Definition: session.c:25
echo_server_main_t::private_segment_size
u32 private_segment_size
Size of private segments
Definition: echo_server.c:47
svm_fifo_dequeue_drop
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:1168
session_handle
static session_handle_t session_handle(session_t *s)
Definition: session_types.h:283
TRANSPORT_CFG_F_CONNECTED
@ TRANSPORT_CFG_F_CONNECTED
Definition: transport_types.h:202
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
echo_server_main_t
Definition: echo_server.c:27
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
echo_server_main_t::vpp_queue
svm_msg_q_t ** vpp_queue
Definition: echo_server.c:32
SESSION_IO_EVT_TX
@ SESSION_IO_EVT_TX
Definition: session_types.h:329
echo_server_create_command_fn
static clib_error_t * echo_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: echo_server.c:463
app_send_dgram_raw
static int app_send_dgram_raw(svm_fifo_t *f, app_session_transport_t *at, svm_msg_q_t *vpp_evt_q, u8 *data, u32 len, u8 evt_type, u8 do_evt, u8 noblock)
Definition: application_interface.h:645
echo_server_main_t::rx_buf
u8 ** rx_buf
Per-thread RX buffer.
Definition: echo_server.c:56
clib_min
#define clib_min(x, y)
Definition: clib.h:342
vnet_app_add_cert_key_pair
int vnet_app_add_cert_key_pair(vnet_app_add_cert_key_pair_args_t *a)
Definition: application.c:2037
echo_server_main_t::prealloc_fifos
u32 prealloc_fifos
Preallocate fifos.
Definition: echo_server.c:45
vnet_disconnect_session
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1439
echo_server_main_t::server_uri
char * server_uri
Server URI.
Definition: echo_server.c:48
svm_msg_q_
Definition: message_queue.h:72
echo_server_main_t::listener_handle
u64 listener_handle
Session handle of the root listener.
Definition: echo_server.c:60
format_session
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:101
vnet_app_add_cert_key_pair_args_t
struct _vnet_app_add_cert_key_pair_args_ vnet_app_add_cert_key_pair_args_t
APP_OPTIONS_PREALLOC_FIFO_PAIRS
@ APP_OPTIONS_PREALLOC_FIFO_PAIRS
Definition: application_interface.h:212
session_::listener_handle
session_handle_t listener_handle
Parent listener session index if the result of an accept.
Definition: session_types.h:208
echo_client_transport_needs_crypto
static int echo_client_transport_needs_crypto(transport_proto_t proto)
Definition: echo_server.c:388
vnet_application_attach
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
Definition: application.c:1142
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
echo_server_main_t::ckpair_index
u32 ckpair_index
Cert and key for tls/quic.
Definition: echo_server.c:50
APP_OPTIONS_TX_FIFO_SIZE
@ APP_OPTIONS_TX_FIFO_SIZE
Definition: application_interface.h:211
svm_fifo_max_enqueue_prod
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
Definition: svm_fifo.h:607
test_srv_crt_rsa
static const char test_srv_crt_rsa[]
Definition: tls_test.h:23
APP_OPTIONS_ADD_SEGMENT_SIZE
@ APP_OPTIONS_ADD_SEGMENT_SIZE
Definition: application_interface.h:208
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_thread_main_t::n_threads
u32 n_threads
Definition: threads.h:271
session_::opaque
u32 opaque
Opaque, for general use.
Definition: session_types.h:218
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
options
static struct option options[]
Definition: main.c:52
echo_server_main_t::transport_proto
u8 transport_proto
Definition: echo_server.c:59
vlib_thread_main_t
Definition: threads.h:243
transport_proto_t
enum _transport_proto transport_proto_t
quic_echo_server_qsession_accept_callback
int quic_echo_server_qsession_accept_callback(session_t *s)
Definition: echo_server.c:68
echo_server_main_t::vlib_main
vlib_main_t * vlib_main
Definition: echo_server.c:62
test_srv_crt_rsa_len
static const u32 test_srv_crt_rsa_len
Definition: tls_test.h:47
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
echo_server_session_reset_callback
void echo_server_session_reset_callback(session_t *s)
Definition: echo_server.c:118
parse_uri
int parse_uri(char *uri, session_endpoint_cfg_t *sep)
Definition: application_interface.c:77
APP_OPTIONS_FLAGS
@ APP_OPTIONS_FLAGS
Definition: application_interface.h:205
session_worker_::sessions
session_t * sessions
Worker session pool.
Definition: session.h:92
echo_server_main_t::fifo_size
u32 fifo_size
Fifo size.
Definition: echo_server.c:43
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
application_interface.h
DBG
#define DBG(_fmt, _args...)
Definition: echo_server.c:23
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
echo_server_create_command
static vlib_cli_command_t echo_server_create_command
(constructor) VLIB_CLI_COMMAND (echo_server_create_command)
Definition: echo_server.c:594
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
echo_server_builtin_server_rx_callback_no_echo
int echo_server_builtin_server_rx_callback_no_echo(session_t *s)
Definition: echo_server.c:172
session.h
i
int i
Definition: flowhash_template.h:376
echo_server_main_init
clib_error_t * echo_server_main_init(vlib_main_t *vm)
Definition: echo_server.c:606
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
rv
int __clib_unused rv
Definition: application.c:491
cleanup
static void cleanup(void)
Definition: client.c:98
echo_server_main_t::tls_engine
u32 tls_engine
TLS engine: mbedtls/openssl.
Definition: echo_server.c:49
vnet.h
vnet_app_attach_args_t
struct _vnet_app_attach_args_t vnet_app_attach_args_t
APP_OPTIONS_PCT_FIRST_ALLOC
@ APP_OPTIONS_PCT_FIRST_ALLOC
Definition: application_interface.h:222
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
vlib_cli_command_t
Definition: cli.h:92
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
svm_fifo_max_dequeue_cons
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:487
session_dgram_pre_hdr_
Definition: session_types.h:431
session_send_io_evt_to_thread
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:84
session_::session_state
volatile u8 session_state
State in session layer state machine.
Definition: session_types.h:185
TRANSPORT_ENDPT_EXT_CFG_CRYPTO
@ TRANSPORT_ENDPT_EXT_CFG_CRYPTO
Definition: transport_types.h:270
echo_server_main_t::vl_input_queue
svm_queue_t * vl_input_queue
Sever's event queue.
Definition: echo_server.c:33
quic_echo_server_session_accept_callback
int quic_echo_server_session_accept_callback(session_t *s)
Definition: echo_server.c:75
APP_OPTIONS_PRIVATE_SEGMENT_COUNT
@ APP_OPTIONS_PRIVATE_SEGMENT_COUNT
Definition: application_interface.h:209
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
vnet_session_enable_disable
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1925
echo_server_listen
static int echo_server_listen()
Definition: echo_server.c:395
application.h
test_srv_key_rsa_len
static const u32 test_srv_key_rsa_len
Definition: tls_test.h:77
echo_server_rx_callback
int echo_server_rx_callback(session_t *s)
Definition: echo_server.c:180
echo_server_main_t::node_index
u32 node_index
process node index for event scheduling
Definition: echo_server.c:37