FD.io VPP  v21.01.1
Vector Packet Processing
proxy.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 <hs_apps/proxy.h>
21 #include <vnet/tcp/tcp.h>
22 
24 
25 #define TCP_MSS 1460
26 
27 typedef struct
28 {
29  char uri[128];
33 
34 static void
36 {
39 
40  memset (&a, 0, sizeof (a));
41  a.api_context = pa->api_context;
42  a.app_index = pa->app_index;
43  a.uri = pa->uri;
44  vnet_connect_uri (&a);
45 }
46 
47 static void
49 {
50  if (vlib_get_thread_index () == 0)
51  {
52  vnet_connect_uri (a);
53  }
54  else
55  {
57  args.api_context = a->api_context;
58  args.app_index = a->app_index;
59  clib_memcpy (args.uri, a->uri, vec_len (a->uri));
60  vl_api_rpc_call_main_thread (proxy_cb_fn, (u8 *) & args, sizeof (args));
61  }
62 }
63 
64 static proxy_session_t *
66 {
67  proxy_session_t *ps = 0;
68  uword *p;
69 
71  if (p)
72  ps = pool_elt_at_index (pm->sessions, p[0]);
73  return ps;
74 }
75 
76 static proxy_session_t *
78 {
79  proxy_session_t *ps = 0;
80  uword *p;
81 
82  p = hash_get (pm->proxy_session_by_server_handle, handle);
83  if (p)
84  ps = pool_elt_at_index (pm->sessions, p[0]);
85  return ps;
86 }
87 
88 static void
89 proxy_try_close_session (session_t * s, int is_active_open)
90 {
91  proxy_main_t *pm = &proxy_main;
92  proxy_session_t *ps = 0;
93  vnet_disconnect_args_t _a, *a = &_a;
94  session_handle_t handle;
95 
96  handle = session_handle (s);
97 
99 
100  if (is_active_open)
101  {
102  ps = proxy_get_active_open (pm, handle);
103  ASSERT (ps != 0);
104 
105  a->handle = ps->vpp_active_open_handle;
106  a->app_index = pm->active_open_app_index;
108  ps->ao_disconnected = 1;
109 
110  if (!ps->po_disconnected)
111  {
113  a->handle = ps->vpp_server_handle;
114  a->app_index = pm->server_app_index;
116  ps->po_disconnected = 1;
117  }
118  }
119  else
120  {
121  ps = proxy_get_passive_open (pm, handle);
122  ASSERT (ps != 0);
123 
124  a->handle = ps->vpp_server_handle;
125  a->app_index = pm->server_app_index;
127  ps->po_disconnected = 1;
128 
129  if (!ps->ao_disconnected && !ps->active_open_establishing)
130  {
131  /* Proxy session closed before active open */
133  {
134  a->handle = ps->vpp_active_open_handle;
135  a->app_index = pm->active_open_app_index;
137  }
138  ps->ao_disconnected = 1;
139  }
140  }
142 }
143 
144 static void
146 {
147  proxy_main_t *pm = &proxy_main;
148  if (CLIB_DEBUG > 0)
149  clib_memset (ps, 0xFE, sizeof (*ps));
150  pool_put (pm->sessions, ps);
151 }
152 
153 static void
154 proxy_try_delete_session (session_t * s, u8 is_active_open)
155 {
156  proxy_main_t *pm = &proxy_main;
157  proxy_session_t *ps = 0;
158  session_handle_t handle;
159 
160  handle = session_handle (s);
161 
163 
164  if (is_active_open)
165  {
166  ps = proxy_get_active_open (pm, handle);
167  ASSERT (ps != 0);
168 
171 
173  proxy_session_free (ps);
174  }
175  else
176  {
177  ps = proxy_get_passive_open (pm, handle);
178  ASSERT (ps != 0);
179 
182 
184  {
185  if (!ps->active_open_establishing)
186  proxy_session_free (ps);
187  }
188  }
190 }
191 
192 static int
194  session_ft_action_t act, u32 bytes)
195 {
196  proxy_main_t *pm = &proxy_main;
197 
198  segment_manager_t *sm = segment_manager_get (f->segment_manager);
199  fifo_segment_t *fs = segment_manager_get_segment (sm, f->segment_index);
200 
201  u8 seg_usage = fifo_segment_get_mem_usage (fs);
202  u32 fifo_in_use = svm_fifo_max_dequeue_prod (f);
203  u32 fifo_size = svm_fifo_size (f);
204  u8 fifo_usage = fifo_in_use * 100 / fifo_size;
205  u8 update_size = 0;
206 
208 
209  if (act == SESSION_FT_ACTION_ENQUEUED)
210  {
211  if (seg_usage < pm->low_watermark && fifo_usage > 50)
212  update_size = fifo_in_use;
213  else if (seg_usage < pm->high_watermark && fifo_usage > 80)
214  update_size = fifo_in_use;
215 
216  update_size = clib_min (update_size, sm->max_fifo_size - fifo_size);
217  if (update_size)
218  svm_fifo_set_size (f, fifo_size + update_size);
219  }
220  else /* dequeued */
221  {
222  if (seg_usage > pm->high_watermark || fifo_usage < 20)
223  update_size = bytes;
224  else if (seg_usage > pm->low_watermark && fifo_usage < 50)
225  update_size = (bytes / 2);
226 
227  ASSERT (fifo_size >= 4096);
228  update_size = clib_min (update_size, fifo_size - 4096);
229  if (update_size)
230  svm_fifo_set_size (f, fifo_size - update_size);
231  }
232 
233  return 0;
234 }
235 
236 static int
238 {
239  proxy_main_t *pm = &proxy_main;
240  proxy_session_t *ps;
241 
243 
244  pool_get_zero (pm->sessions, ps);
247 
249  ps - pm->sessions);
250 
252 
253  s->session_state = SESSION_STATE_READY;
254 
255  return 0;
256 }
257 
258 static void
260 {
261  proxy_try_close_session (s, 0 /* is_active_open */ );
262 }
263 
264 static void
266 {
267  proxy_try_close_session (s, 0 /* is_active_open */ );
268 }
269 
270 static int
271 proxy_connected_callback (u32 app_index, u32 api_context,
272  session_t * s, session_error_t err)
273 {
274  clib_warning ("called...");
275  return -1;
276 }
277 
278 static int
279 proxy_add_segment_callback (u32 client_index, u64 segment_handle)
280 {
281  clib_warning ("called...");
282  return -1;
283 }
284 
285 static int
287 {
288  proxy_main_t *pm = &proxy_main;
289  u32 thread_index = vlib_get_thread_index ();
290  svm_fifo_t *ao_tx_fifo;
291  proxy_session_t *ps;
292 
293  ASSERT (s->thread_index == thread_index);
294 
296 
297  ps = proxy_get_passive_open (pm, session_handle (s));
298  ASSERT (ps != 0);
299 
301  {
303 
304  ao_tx_fifo = s->rx_fifo;
305 
306  /*
307  * Send event for active open tx fifo
308  */
309  if (svm_fifo_set_event (ao_tx_fifo))
310  {
311  u32 ao_thread_index = ao_tx_fifo->master_thread_index;
312  u32 ao_session_index = ao_tx_fifo->master_session_index;
313  if (session_send_io_evt_to_thread_custom (&ao_session_index,
314  ao_thread_index,
316  clib_warning ("failed to enqueue tx evt");
317  }
318 
319  if (svm_fifo_max_enqueue (ao_tx_fifo) <= TCP_MSS)
321  }
322  else
323  {
324  vnet_connect_args_t _a, *a = &_a;
325  svm_fifo_t *tx_fifo, *rx_fifo;
326  u32 max_dequeue, proxy_index;
327  int actual_transfer __attribute__ ((unused));
328 
329  rx_fifo = s->rx_fifo;
330  tx_fifo = s->tx_fifo;
331 
332  ASSERT (rx_fifo->master_thread_index == thread_index);
333  ASSERT (tx_fifo->master_thread_index == thread_index);
334 
335  max_dequeue = svm_fifo_max_dequeue_cons (s->rx_fifo);
336 
337  if (PREDICT_FALSE (max_dequeue == 0))
338  return 0;
339 
340  max_dequeue = clib_min (pm->rcv_buffer_size, max_dequeue);
341  actual_transfer = svm_fifo_peek (rx_fifo, 0 /* relative_offset */ ,
342  max_dequeue, pm->rx_buf[thread_index]);
343 
344  /* $$$ your message in this space: parse url, etc. */
345 
346  clib_memset (a, 0, sizeof (*a));
347 
348  ps->server_rx_fifo = rx_fifo;
349  ps->server_tx_fifo = tx_fifo;
350  ps->active_open_establishing = 1;
351  proxy_index = ps - pm->sessions;
352 
354 
355  a->uri = (char *) pm->client_uri;
356  a->api_context = proxy_index;
357  a->app_index = pm->active_open_app_index;
359  }
360 
361  return 0;
362 }
363 
364 static void
365 proxy_force_ack (void *handlep)
366 {
368  session_t *ao_s;
369 
370  ao_s = session_get_from_handle (pointer_to_uword (handlep));
371  tc = session_get_transport (ao_s);
373 }
374 
375 static int
377 {
378  proxy_main_t *pm = &proxy_main;
379  proxy_session_t *ps;
380  u32 min_free;
381 
382  min_free = clib_min (svm_fifo_size (proxy_s->tx_fifo) >> 3, 128 << 10);
383  if (svm_fifo_max_enqueue (proxy_s->tx_fifo) < min_free)
384  {
386  return 0;
387  }
388 
390 
391  ps = proxy_get_passive_open (pm, session_handle (proxy_s));
392  ASSERT (ps != 0);
393 
395  return 0;
396 
397  /* Force ack on active open side to update rcv wnd. Make sure it's done on
398  * the right thread */
399  void *arg = uword_to_pointer (ps->vpp_active_open_handle, void *);
400  session_send_rpc_evt_to_thread (ps->server_rx_fifo->master_thread_index,
401  proxy_force_ack, arg);
402 
404 
405  return 0;
406 }
407 
408 static void
410 {
411  if (ntf == SESSION_CLEANUP_TRANSPORT)
412  return;
413 
414  proxy_try_delete_session (s, 0 /* is_active_open */ );
415 }
416 
417 static session_cb_vft_t proxy_session_cb_vft = {
419  .session_disconnect_callback = proxy_disconnect_callback,
420  .session_connected_callback = proxy_connected_callback,
421  .add_segment_callback = proxy_add_segment_callback,
422  .builtin_app_rx_callback = proxy_rx_callback,
423  .builtin_app_tx_callback = proxy_tx_callback,
424  .session_reset_callback = proxy_reset_callback,
425  .session_cleanup_callback = proxy_cleanup_callback,
426  .fifo_tuning_callback = common_fifo_tuning_callback
427 };
428 
429 static int
431  session_t * s, session_error_t err)
432 {
433  proxy_main_t *pm = &proxy_main;
434  proxy_session_t *ps;
435  u8 thread_index = vlib_get_thread_index ();
436 
437  /*
438  * Setup proxy session handle.
439  */
441 
442  ps = pool_elt_at_index (pm->sessions, opaque);
443 
444  /* Connection failed */
445  if (err)
446  {
447  vnet_disconnect_args_t _a, *a = &_a;
448 
449  a->handle = ps->vpp_server_handle;
450  a->app_index = pm->server_app_index;
452  ps->po_disconnected = 1;
453  }
454  else
455  {
457  ps->active_open_establishing = 0;
458  }
459 
460  /* Passive open session was already closed! */
461  if (ps->po_disconnected)
462  {
463  /* Setup everything for the cleanup notification */
465  ps->vpp_active_open_handle, opaque);
466  ps->ao_disconnected = 1;
468  return -1;
469  }
470 
471  s->tx_fifo = ps->server_rx_fifo;
472  s->rx_fifo = ps->server_tx_fifo;
473 
474  /*
475  * Reset the active-open tx-fifo master indices so the active-open session
476  * will receive data, etc.
477  */
478  s->tx_fifo->master_session_index = s->session_index;
479  s->tx_fifo->master_thread_index = s->thread_index;
480 
481  /*
482  * Account for the active-open session's use of the fifos
483  * so they won't disappear until the last session which uses
484  * them disappears
485  */
486  s->tx_fifo->refcnt++;
487  s->rx_fifo->refcnt++;
488 
490  ps->vpp_active_open_handle, opaque);
491 
493 
494  /*
495  * Send event for active open tx fifo
496  */
497  ASSERT (s->thread_index == thread_index);
498  if (svm_fifo_set_event (s->tx_fifo))
500 
501  return 0;
502 }
503 
504 static void
506 {
507  proxy_try_close_session (s, 1 /* is_active_open */ );
508 }
509 
510 static int
512 {
513  return 0;
514 }
515 
516 static void
518 {
519  proxy_try_close_session (s, 1 /* is_active_open */ );
520 }
521 
522 static int
524 {
525  svm_fifo_t *proxy_tx_fifo;
526 
527  proxy_tx_fifo = s->rx_fifo;
528 
529  /*
530  * Send event for server tx fifo
531  */
532  if (svm_fifo_set_event (proxy_tx_fifo))
533  {
534  u8 thread_index = proxy_tx_fifo->master_thread_index;
535  u32 session_index = proxy_tx_fifo->master_session_index;
536  return session_send_io_evt_to_thread_custom (&session_index,
537  thread_index,
539  }
540 
541  if (svm_fifo_max_enqueue (proxy_tx_fifo) <= TCP_MSS)
543 
544  return 0;
545 }
546 
547 static int
549 {
550  proxy_main_t *pm = &proxy_main;
552  session_handle_t handle;
553  proxy_session_t *ps;
554  session_t *proxy_s;
555  u32 min_free;
556  uword *p;
557 
558  min_free = clib_min (svm_fifo_size (ao_s->tx_fifo) >> 3, 128 << 10);
559  if (svm_fifo_max_enqueue (ao_s->tx_fifo) < min_free)
560  {
562  return 0;
563  }
564 
566 
567  handle = session_handle (ao_s);
569  if (!p)
570  return 0;
571 
572  if (pool_is_free_index (pm->sessions, p[0]))
573  return 0;
574 
575  ps = pool_elt_at_index (pm->sessions, p[0]);
576  if (ps->vpp_server_handle == ~0)
577  return 0;
578 
580 
581  /* Force ack on proxy side to update rcv wnd */
582  tc = session_get_transport (proxy_s);
584 
586 
587  return 0;
588 }
589 
590 static void
592 {
593  if (ntf == SESSION_CLEANUP_TRANSPORT)
594  return;
595 
596  proxy_try_delete_session (s, 1 /* is_active_open */ );
597 }
598 
599 /* *INDENT-OFF* */
600 static session_cb_vft_t active_open_clients = {
602  .session_connected_callback = active_open_connected_callback,
603  .session_accept_callback = active_open_create_callback,
604  .session_disconnect_callback = active_open_disconnect_callback,
605  .session_cleanup_callback = active_open_cleanup_callback,
606  .builtin_app_rx_callback = active_open_rx_callback,
607  .builtin_app_tx_callback = active_open_tx_callback,
608  .fifo_tuning_callback = common_fifo_tuning_callback
609 };
610 /* *INDENT-ON* */
611 
612 static int
614 {
615  proxy_main_t *pm = &proxy_main;
617  vnet_app_attach_args_t _a, *a = &_a;
618  u32 segment_size = 512 << 20;
619 
620  clib_memset (a, 0, sizeof (*a));
621  clib_memset (options, 0, sizeof (options));
622 
623  if (pm->private_segment_size)
624  segment_size = pm->private_segment_size;
625  a->name = format (0, "proxy-server");
626  a->api_client_index = pm->server_client_index;
627  a->session_cb_vft = &proxy_session_cb_vft;
628  a->options = options;
629  a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
630  a->options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size;
631  a->options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
632  a->options[APP_OPTIONS_MAX_FIFO_SIZE] = pm->max_fifo_size;
633  a->options[APP_OPTIONS_HIGH_WATERMARK] = (u64) pm->high_watermark;
634  a->options[APP_OPTIONS_LOW_WATERMARK] = (u64) pm->low_watermark;
636  a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
637  pm->prealloc_fifos ? pm->prealloc_fifos : 0;
638 
639  a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
640 
641  if (vnet_application_attach (a))
642  {
643  clib_warning ("failed to attach server");
644  return -1;
645  }
646  pm->server_app_index = a->app_index;
647 
648  vec_free (a->name);
649  return 0;
650 }
651 
652 static int
654 {
655  proxy_main_t *pm = &proxy_main;
656  vnet_app_attach_args_t _a, *a = &_a;
658 
659  clib_memset (a, 0, sizeof (*a));
660  clib_memset (options, 0, sizeof (options));
661 
662  a->api_client_index = pm->active_open_client_index;
663  a->session_cb_vft = &active_open_clients;
664  a->name = format (0, "proxy-active-open");
665 
666  options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
667  options[APP_OPTIONS_SEGMENT_SIZE] = 512 << 20;
668  options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size;
669  options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
675  pm->prealloc_fifos ? pm->prealloc_fifos : 0;
676 
677  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN
678  | APP_OPTIONS_FLAGS_IS_PROXY;
679 
680  a->options = options;
681 
682  if (vnet_application_attach (a))
683  return -1;
684 
685  pm->active_open_app_index = a->app_index;
686 
687  vec_free (a->name);
688 
689  return 0;
690 }
691 
692 static int
694 {
695  proxy_main_t *pm = &proxy_main;
696  vnet_listen_args_t _a, *a = &_a;
697  clib_memset (a, 0, sizeof (*a));
698  a->app_index = pm->server_app_index;
699  a->uri = (char *) pm->server_uri;
700  return vnet_bind_uri (a);
701 }
702 
703 static int
705 {
706  proxy_main_t *pm = &proxy_main;
708  u32 num_threads;
709  int i;
710 
711  num_threads = 1 /* main thread */ + vtm->n_threads;
712  vec_validate (proxy_main.server_event_queue, num_threads - 1);
713  vec_validate (proxy_main.active_open_event_queue, num_threads - 1);
714  vec_validate (pm->rx_buf, num_threads - 1);
715 
716  for (i = 0; i < num_threads; i++)
717  vec_validate (pm->rx_buf[i], pm->rcv_buffer_size);
718 
719  if (proxy_server_attach ())
720  {
721  clib_warning ("failed to attach server app");
722  return -1;
723  }
724  if (proxy_server_listen ())
725  {
726  clib_warning ("failed to start listening");
727  return -1;
728  }
729  if (active_open_attach ())
730  {
731  clib_warning ("failed to attach active open app");
732  return -1;
733  }
734 
735  for (i = 0; i < num_threads; i++)
736  {
738 
740 
742  }
743 
744  return 0;
745 }
746 
747 static clib_error_t *
749  vlib_cli_command_t * cmd)
750 {
751  proxy_main_t *pm = &proxy_main;
752  char *default_server_uri = "tcp://0.0.0.0/23";
753  char *default_client_uri = "tcp://6.0.2.2/23";
754  int rv, tmp32;
755  u64 tmp64;
756 
757  pm->fifo_size = 64 << 10;
758  pm->max_fifo_size = 128 << 20;
759  pm->high_watermark = 80;
760  pm->low_watermark = 50;
761  pm->rcv_buffer_size = 1024;
762  pm->prealloc_fifos = 0;
763  pm->private_segment_count = 0;
764  pm->private_segment_size = 0;
765  pm->server_uri = 0;
766  pm->client_uri = 0;
767  if (vlib_num_workers ())
769 
771  {
772  if (unformat (input, "fifo-size %U",
774  ;
775  else if (unformat (input, "max-fifo-size %U",
777  ;
778  else if (unformat (input, "high-watermark %d", &tmp32))
779  pm->high_watermark = (u8) tmp32;
780  else if (unformat (input, "low-watermark %d", &tmp32))
781  pm->low_watermark = (u8) tmp32;
782  else if (unformat (input, "rcv-buf-size %d", &pm->rcv_buffer_size))
783  ;
784  else if (unformat (input, "prealloc-fifos %d", &pm->prealloc_fifos))
785  ;
786  else if (unformat (input, "private-segment-count %d",
787  &pm->private_segment_count))
788  ;
789  else if (unformat (input, "private-segment-size %U",
790  unformat_memory_size, &tmp64))
791  {
792  if (tmp64 >= 0x100000000ULL)
793  return clib_error_return
794  (0, "private segment size %lld (%llu) too large", tmp64, tmp64);
795  pm->private_segment_size = tmp64;
796  }
797  else if (unformat (input, "server-uri %s", &pm->server_uri))
798  vec_add1 (pm->server_uri, 0);
799  else if (unformat (input, "client-uri %s", &pm->client_uri))
800  vec_add1 (pm->client_uri, 0);
801  else
802  return clib_error_return (0, "unknown input `%U'",
803  format_unformat_error, input);
804  }
805 
806  if (!pm->server_uri)
807  {
808  clib_warning ("No server-uri provided, Using default: %s",
809  default_server_uri);
810  pm->server_uri = format (0, "%s%c", default_server_uri, 0);
811  }
812  if (!pm->client_uri)
813  {
814  clib_warning ("No client-uri provided, Using default: %s",
815  default_client_uri);
816  pm->client_uri = format (0, "%s%c", default_client_uri, 0);
817  }
818 
819  vnet_session_enable_disable (vm, 1 /* turn on session and transport */ );
820 
821  rv = proxy_server_create (vm);
822  switch (rv)
823  {
824  case 0:
825  break;
826  default:
827  return clib_error_return (0, "server_create returned %d", rv);
828  }
829 
830  return 0;
831 }
832 
833 /* *INDENT-OFF* */
834 VLIB_CLI_COMMAND (proxy_create_command, static) =
835 {
836  .path = "test proxy server",
837  .short_help = "test proxy server [server-uri <tcp://ip/port>]"
838  "[client-uri <tcp://ip/port>][fifo-size <nn>[k|m]]"
839  "[max-fifo-size <nn>[k|m]][high-watermark <nn>]"
840  "[low-watermark <nn>][rcv-buf-size <nn>][prealloc-fifos <nn>]"
841  "[private-segment-size <mem>][private-segment-count <nn>]",
842  .function = proxy_server_create_command_fn,
843 };
844 /* *INDENT-ON* */
845 
846 clib_error_t *
848 {
849  proxy_main_t *pm = &proxy_main;
850  pm->server_client_index = ~0;
851  pm->active_open_client_index = ~0;
854 
855  return 0;
856 }
857 
859 
860 /*
861 * fd.io coding-style-patch-verification: ON
862 *
863 * Local Variables:
864 * eval: (c-set-style "gnu")
865 * End:
866 */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
#define hash_set(h, key, value)
Definition: hash.h:255
u32 max_fifo_size
max fifo size
Definition: proxy.h:64
#define clib_min(x, y)
Definition: clib.h:328
u32 private_segment_count
Number of private fifo segs.
Definition: proxy.h:67
volatile int ao_disconnected
Definition: proxy.h:38
#define hash_unset(h, key)
Definition: hash.h:261
a
Definition: bitmap.h:544
static void svm_fifo_set_size(svm_fifo_t *f, u32 size)
Definition: svm_fifo.h:698
svm_fifo_t * tx_fifo
char uri[128]
Definition: proxy.c:29
struct _vnet_connect_args vnet_connect_args_t
fifo_segment_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool without lock.
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:254
Notify on dequeue.
Definition: svm_fifo.h:35
static u32 svm_fifo_size(svm_fifo_t *f)
Definition: svm_fifo.h:692
#define PREDICT_TRUE(x)
Definition: clib.h:122
u32 session_index
Index in thread pool where session was allocated.
static int proxy_accept_callback(session_t *s)
Definition: proxy.c:237
unsigned long u64
Definition: types.h:89
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
Definition: session.h:645
static void proxy_reset_callback(session_t *s)
Definition: proxy.c:265
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1631
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
u8 fifo_segment_get_mem_usage(fifo_segment_t *fs)
static int active_open_rx_callback(session_t *s)
Definition: proxy.c:523
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:129
static clib_error_t * proxy_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: proxy.c:748
struct _tcp_connection tcp_connection_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
Definition: session.c:110
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1127
uword * proxy_session_by_server_handle
Definition: proxy.h:55
vlib_main_t * vm
Definition: in2out_ed.c:1580
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:564
void(* session_reset_callback)(session_t *s)
Notify app that session was reset.
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
struct _vnet_bind_args_t vnet_listen_args_t
static int active_open_create_callback(session_t *s)
Definition: proxy.c:511
svm_fifo_t * server_rx_fifo
Definition: proxy.h:31
static session_handle_t session_handle(session_t *s)
#define clib_memcpy(d, s, n)
Definition: string.h:180
enum session_ft_action_ session_ft_action_t
u8 prealloc_fifos
Request fifo preallocation.
Definition: proxy.h:85
u32 fifo_size
initial fifo size
Definition: proxy.h:63
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:430
description fragment has unexpected format
Definition: map.api:433
static session_cb_vft_t proxy_session_cb_vft
Definition: proxy.c:417
#define clib_error_return(e, args...)
Definition: error.h:99
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:619
session_handle_t vpp_active_open_handle
Definition: proxy.h:35
unsigned int u32
Definition: types.h:88
int rcv_buffer_size
Definition: proxy.h:69
u32 server_app_index
server app index
Definition: proxy.h:51
static proxy_session_t * proxy_get_active_open(proxy_main_t *pm, session_handle_t handle)
Definition: proxy.c:65
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:79
volatile int active_open_establishing
Definition: proxy.h:36
static int proxy_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
Definition: proxy.c:271
#define SESSION_INVALID_HANDLE
Definition: session_types.h:23
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
static int proxy_tx_callback(session_t *proxy_s)
Definition: proxy.c:376
session_handle_t vpp_server_handle
Definition: proxy.h:34
clib_error_t * proxy_main_init(vlib_main_t *vm)
Definition: proxy.c:847
static int common_fifo_tuning_callback(session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 bytes)
Definition: proxy.c:193
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
proxy_session_t * sessions
Session pool, shared.
Definition: proxy.h:76
void tcp_send_ack(tcp_connection_t *tc)
Definition: tcp_output.c:1023
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:327
struct _unformat_input_t unformat_input_t
u8 data_len
Definition: ikev2_types.api:24
static void active_open_disconnect_callback(session_t *s)
Definition: proxy.c:517
static void proxy_cb_fn(void *data, u32 data_len)
Definition: proxy.c:35
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
#define PREDICT_FALSE(x)
Definition: clib.h:121
u8 low_watermark
low watermark (%)
Definition: proxy.h:66
proxy_main_t proxy_main
Definition: proxy.c:23
static int proxy_server_create(vlib_main_t *vm)
Definition: proxy.c:704
static u32 svm_fifo_max_dequeue_prod(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for producer.
Definition: svm_fifo.h:444
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1793
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
Definition: application.c:816
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:727
svm_msg_q_t ** active_open_event_queue
Definition: proxy.h:46
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
u32 active_open_client_index
active open API client handle
Definition: proxy.h:52
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:219
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static int active_open_connected_callback(u32 app_index, u32 opaque, session_t *s, session_error_t err)
Definition: proxy.c:430
#define clib_warning(format, args...)
Definition: error.h:59
u32 server_client_index
server API client handle
Definition: proxy.h:50
struct _transport_connection transport_connection_t
static void proxy_call_main_thread(vnet_connect_args_t *a)
Definition: proxy.c:48
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:298
u8 * server_uri
Definition: proxy.h:70
#define TCP_MSS
Definition: proxy.c:25
static void active_open_reset_callback(session_t *s)
Definition: proxy.c:505
volatile int po_disconnected
Definition: proxy.h:37
static void proxy_session_free(proxy_session_t *ps)
Definition: proxy.c:145
svm_msg_q_t ** server_event_queue
per-thread vectors
Definition: proxy.h:45
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
u32 active_open_app_index
active open index after attach
Definition: proxy.h:53
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define uword_to_pointer(u, type)
Definition: types.h:136
#define ASSERT(truth)
static int proxy_server_attach()
Definition: proxy.c:613
uword * proxy_session_by_active_open_handle
Definition: proxy.h:56
static int proxy_rx_callback(session_t *s)
Definition: proxy.c:286
u8 ** rx_buf
intermediate rx buffers
Definition: proxy.h:47
static proxy_session_t * proxy_get_passive_open(proxy_main_t *pm, session_handle_t handle)
Definition: proxy.c:77
static void svm_fifo_add_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Set specific want notification flag.
Definition: svm_fifo.h:754
clib_spinlock_t sessions_lock
Definition: proxy.h:77
static uword pointer_to_uword(const void *p)
Definition: types.h:131
u8 thread_index
Index of the thread that allocated the session.
u32 private_segment_size
size of private fifo segs
Definition: proxy.h:68
static int active_open_attach(void)
Definition: proxy.c:653
u8 high_watermark
high watermark (%)
Definition: proxy.h:65
svm_fifo_t * server_tx_fifo
Definition: proxy.h:32
u64 session_handle_t
static void proxy_disconnect_callback(session_t *s)
Definition: proxy.c:259
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
volatile u8 session_state
State in session layer state machine.
u64 uword
Definition: types.h:112
int vnet_bind_uri(vnet_listen_args_t *a)
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1086
struct _segment_manager segment_manager_t
segment_manager_t * segment_manager_get(u32 index)
static void proxy_force_ack(void *handlep)
Definition: proxy.c:365
session_cleanup_ntf_t
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:86
static void proxy_try_close_session(session_t *s, int is_active_open)
Definition: proxy.c:89
unformat_function_t unformat_memory_size
Definition: format.h:295
static int proxy_add_segment_callback(u32 client_index, u64 segment_handle)
Definition: proxy.c:279
static struct option options[]
Definition: main.c:52
static int proxy_server_listen()
Definition: proxy.c:693
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
static u32 vlib_num_workers()
Definition: threads.h:377
enum session_error_ session_error_t
static session_cb_vft_t active_open_clients
Definition: proxy.c:600
static int active_open_tx_callback(session_t *ao_s)
Definition: proxy.c:548
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
static void proxy_try_delete_session(session_t *s, u8 is_active_open)
Definition: proxy.c:154
int vnet_connect_uri(vnet_connect_args_t *a)
struct _svm_fifo svm_fifo_t
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:106
static void active_open_cleanup_callback(session_t *s, session_cleanup_ntf_t ntf)
Definition: proxy.c:591
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
u8 * client_uri
Definition: proxy.h:71
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
static void proxy_cleanup_callback(session_t *s, session_cleanup_ntf_t ntf)
Definition: proxy.c:409