FD.io VPP  v20.05-21-gb1500e9ff
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
35 proxy_cb_fn (void *data, u32 data_len)
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 void
65 delete_proxy_session (session_t * s, int is_active_open)
66 {
67  proxy_main_t *pm = &proxy_main;
68  proxy_session_t *ps = 0;
69  vnet_disconnect_args_t _a, *a = &_a;
70  session_t *active_open_session = 0;
71  session_t *server_session = 0;
72  uword *p;
73  u64 handle;
74 
76 
77  handle = session_handle (s);
78 
79  if (is_active_open)
80  {
82  if (p == 0)
83  {
84  clib_warning ("proxy session for %s handle %lld (%llx) AWOL",
85  is_active_open ? "active open" : "server",
86  handle, handle);
87  }
88  else if (!pool_is_free_index (pm->sessions, p[0]))
89  {
90  active_open_session = s;
91  ps = pool_elt_at_index (pm->sessions, p[0]);
92  if (ps->vpp_server_handle != ~0)
93  server_session = session_get_from_handle (ps->vpp_server_handle);
94  }
95  }
96  else
97  {
98  p = hash_get (pm->proxy_session_by_server_handle, handle);
99  if (p == 0)
100  {
101  clib_warning ("proxy session for %s handle %lld (%llx) AWOL",
102  is_active_open ? "active open" : "server",
103  handle, handle);
104  }
105  else if (!pool_is_free_index (pm->sessions, p[0]))
106  {
107  server_session = s;
108  ps = pool_elt_at_index (pm->sessions, p[0]);
109  if (ps->vpp_active_open_handle != ~0)
110  active_open_session = session_get_from_handle
112  }
113  }
114 
115  if (ps)
116  {
117  if (CLIB_DEBUG > 0)
118  clib_memset (ps, 0xFE, sizeof (*ps));
119  pool_put (pm->sessions, ps);
120  }
121 
122  if (active_open_session)
123  {
124  a->handle = session_handle (active_open_session);
125  a->app_index = pm->active_open_app_index;
127  session_handle (active_open_session));
129  }
130 
131  if (server_session)
132  {
133  a->handle = session_handle (server_session);
134  a->app_index = pm->server_app_index;
136  session_handle (server_session));
138  }
139 
141 }
142 
143 static int
145  session_ft_action_t act, u32 bytes)
146 {
147  proxy_main_t *pm = &proxy_main;
148 
149  segment_manager_t *sm = segment_manager_get (f->segment_manager);
150  fifo_segment_t *fs = segment_manager_get_segment (sm, f->segment_index);
151 
152  u8 seg_usage = fifo_segment_get_mem_usage (fs);
153  u32 fifo_in_use = svm_fifo_max_dequeue_prod (f);
154  u32 fifo_size = svm_fifo_size (f);
155  u8 fifo_usage = fifo_in_use * 100 / fifo_size;
156  u8 update_size = 0;
157 
159 
160  if (act == SESSION_FT_ACTION_ENQUEUED)
161  {
162  if (seg_usage < pm->low_watermark && fifo_usage > 50)
163  update_size = fifo_in_use;
164  else if (seg_usage < pm->high_watermark && fifo_usage > 80)
165  update_size = fifo_in_use;
166 
167  update_size = clib_min (update_size, sm->max_fifo_size - fifo_size);
168  if (update_size)
169  svm_fifo_set_size (f, fifo_size + update_size);
170  }
171  else /* dequeued */
172  {
173  if (seg_usage > pm->high_watermark || fifo_usage < 20)
174  update_size = bytes;
175  else if (seg_usage > pm->low_watermark && fifo_usage < 50)
176  update_size = (bytes / 2);
177 
178  ASSERT (fifo_size >= 4096);
179  update_size = clib_min (update_size, fifo_size - 4096);
180  if (update_size)
181  svm_fifo_set_size (f, fifo_size - update_size);
182  }
183 
184  return 0;
185 }
186 
187 static int
189 {
190  proxy_main_t *pm = &proxy_main;
191 
192  s->session_state = SESSION_STATE_READY;
193 
195 
196  return 0;
197 }
198 
199 static void
201 {
202  delete_proxy_session (s, 0 /* is_active_open */ );
203 }
204 
205 static void
207 {
208  clib_warning ("Reset session %U", format_session, s, 2);
209  delete_proxy_session (s, 0 /* is_active_open */ );
210 }
211 
212 static int
213 proxy_connected_callback (u32 app_index, u32 api_context,
214  session_t * s, session_error_t err)
215 {
216  clib_warning ("called...");
217  return -1;
218 }
219 
220 static int
221 proxy_add_segment_callback (u32 client_index, u64 segment_handle)
222 {
223  clib_warning ("called...");
224  return -1;
225 }
226 
227 static int
229 {
230  u32 max_dequeue;
231  int actual_transfer __attribute__ ((unused));
232  svm_fifo_t *tx_fifo, *rx_fifo;
233  proxy_main_t *pm = &proxy_main;
234  u32 thread_index = vlib_get_thread_index ();
235  vnet_connect_args_t _a, *a = &_a;
236  proxy_session_t *ps;
237  int proxy_index;
238  uword *p;
239  svm_fifo_t *ao_tx_fifo;
240 
241  ASSERT (s->thread_index == thread_index);
242 
245 
246  if (PREDICT_TRUE (p != 0))
247  {
249  ao_tx_fifo = s->rx_fifo;
250 
251  /*
252  * Send event for active open tx fifo
253  */
254  if (svm_fifo_set_event (ao_tx_fifo))
255  {
256  u32 ao_thread_index = ao_tx_fifo->master_thread_index;
257  u32 ao_session_index = ao_tx_fifo->master_session_index;
258  if (session_send_io_evt_to_thread_custom (&ao_session_index,
259  ao_thread_index,
261  clib_warning ("failed to enqueue tx evt");
262  }
263 
264  if (svm_fifo_max_enqueue (ao_tx_fifo) <= TCP_MSS)
266  }
267  else
268  {
269  rx_fifo = s->rx_fifo;
270  tx_fifo = s->tx_fifo;
271 
272  ASSERT (rx_fifo->master_thread_index == thread_index);
273  ASSERT (tx_fifo->master_thread_index == thread_index);
274 
275  max_dequeue = svm_fifo_max_dequeue_cons (s->rx_fifo);
276 
277  if (PREDICT_FALSE (max_dequeue == 0))
278  return 0;
279 
280  max_dequeue = clib_min (pm->rcv_buffer_size, max_dequeue);
281  actual_transfer = svm_fifo_peek (rx_fifo, 0 /* relative_offset */ ,
282  max_dequeue, pm->rx_buf[thread_index]);
283 
284  /* $$$ your message in this space: parse url, etc. */
285 
286  clib_memset (a, 0, sizeof (*a));
287 
288  pool_get (pm->sessions, ps);
289  clib_memset (ps, 0, sizeof (*ps));
290  ps->server_rx_fifo = rx_fifo;
291  ps->server_tx_fifo = tx_fifo;
293 
294  proxy_index = ps - pm->sessions;
295 
297  proxy_index);
298 
300 
301  a->uri = (char *) pm->client_uri;
302  a->api_context = proxy_index;
303  a->app_index = pm->active_open_app_index;
305  }
306 
307  return 0;
308 }
309 
310 static int
312 {
313  proxy_main_t *pm = &proxy_main;
315  session_handle_t handle;
316  proxy_session_t *ps;
317  session_t *ao_s;
318  u32 min_free;
319  uword *p;
320 
321  min_free = clib_min (svm_fifo_size (proxy_s->tx_fifo) >> 3, 128 << 10);
322  if (svm_fifo_max_enqueue (proxy_s->tx_fifo) < min_free)
323  {
325  return 0;
326  }
327 
329 
330  handle = session_handle (proxy_s);
331  p = hash_get (pm->proxy_session_by_server_handle, handle);
332  if (!p)
333  return 0;
334 
335  if (pool_is_free_index (pm->sessions, p[0]))
336  return 0;
337 
338  ps = pool_elt_at_index (pm->sessions, p[0]);
339  if (ps->vpp_active_open_handle == ~0)
340  return 0;
341 
343 
344  /* Force ack on active open side to update rcv wnd */
345  tc = session_get_transport (ao_s);
347 
349 
350  return 0;
351 }
352 
353 static session_cb_vft_t proxy_session_cb_vft = {
355  .session_disconnect_callback = proxy_disconnect_callback,
356  .session_connected_callback = proxy_connected_callback,
357  .add_segment_callback = proxy_add_segment_callback,
358  .builtin_app_rx_callback = proxy_rx_callback,
359  .builtin_app_tx_callback = proxy_tx_callback,
360  .session_reset_callback = proxy_reset_callback,
361  .fifo_tuning_callback = common_fifo_tuning_callback
362 };
363 
364 static int
366  session_t * s, session_error_t err)
367 {
368  proxy_main_t *pm = &proxy_main;
369  proxy_session_t *ps;
370  u8 thread_index = vlib_get_thread_index ();
371 
372  if (err)
373  {
374  clib_warning ("connection %d failed!", opaque);
375  return 0;
376  }
377 
378  /*
379  * Setup proxy session handle.
380  */
382 
383  ps = pool_elt_at_index (pm->sessions, opaque);
385 
386  s->tx_fifo = ps->server_rx_fifo;
387  s->rx_fifo = ps->server_tx_fifo;
388 
389  /*
390  * Reset the active-open tx-fifo master indices so the active-open session
391  * will receive data, etc.
392  */
393  s->tx_fifo->master_session_index = s->session_index;
394  s->tx_fifo->master_thread_index = s->thread_index;
395 
396  /*
397  * Account for the active-open session's use of the fifos
398  * so they won't disappear until the last session which uses
399  * them disappears
400  */
401  s->tx_fifo->refcnt++;
402  s->rx_fifo->refcnt++;
403 
404  svm_fifo_init_ooo_lookup (s->tx_fifo, 1 /* deq ooo */ );
405  svm_fifo_init_ooo_lookup (s->rx_fifo, 0 /* enq ooo */ );
406 
408  ps->vpp_active_open_handle, opaque);
409 
411 
412  /*
413  * Send event for active open tx fifo
414  */
415  ASSERT (s->thread_index == thread_index);
416  if (svm_fifo_set_event (s->tx_fifo))
418 
419  return 0;
420 }
421 
422 static void
424 {
425  delete_proxy_session (s, 1 /* is_active_open */ );
426 }
427 
428 static int
430 {
431  return 0;
432 }
433 
434 static void
436 {
437  delete_proxy_session (s, 1 /* is_active_open */ );
438 }
439 
440 static int
442 {
443  svm_fifo_t *proxy_tx_fifo;
444 
445  proxy_tx_fifo = s->rx_fifo;
446 
447  /*
448  * Send event for server tx fifo
449  */
450  if (svm_fifo_set_event (proxy_tx_fifo))
451  {
452  u8 thread_index = proxy_tx_fifo->master_thread_index;
453  u32 session_index = proxy_tx_fifo->master_session_index;
454  return session_send_io_evt_to_thread_custom (&session_index,
455  thread_index,
457  }
458 
459  if (svm_fifo_max_enqueue (proxy_tx_fifo) <= TCP_MSS)
461 
462  return 0;
463 }
464 
465 static int
467 {
468  proxy_main_t *pm = &proxy_main;
470  session_handle_t handle;
471  proxy_session_t *ps;
472  session_t *proxy_s;
473  u32 min_free;
474  uword *p;
475 
476  min_free = clib_min (svm_fifo_size (ao_s->tx_fifo) >> 3, 128 << 10);
477  if (svm_fifo_max_enqueue (ao_s->tx_fifo) < min_free)
478  {
480  return 0;
481  }
482 
484 
485  handle = session_handle (ao_s);
487  if (!p)
488  return 0;
489 
490  if (pool_is_free_index (pm->sessions, p[0]))
491  return 0;
492 
493  ps = pool_elt_at_index (pm->sessions, p[0]);
494  if (ps->vpp_server_handle == ~0)
495  return 0;
496 
498 
499  /* Force ack on proxy side to update rcv wnd */
500  tc = session_get_transport (proxy_s);
502 
504 
505  return 0;
506 }
507 
508 /* *INDENT-OFF* */
509 static session_cb_vft_t active_open_clients = {
511  .session_connected_callback = active_open_connected_callback,
512  .session_accept_callback = active_open_create_callback,
513  .session_disconnect_callback = active_open_disconnect_callback,
514  .builtin_app_rx_callback = active_open_rx_callback,
515  .builtin_app_tx_callback = active_open_tx_callback,
516  .fifo_tuning_callback = common_fifo_tuning_callback
517 };
518 /* *INDENT-ON* */
519 
520 static int
522 {
523  proxy_main_t *pm = &proxy_main;
525  vnet_app_attach_args_t _a, *a = &_a;
526  u32 segment_size = 512 << 20;
527 
528  clib_memset (a, 0, sizeof (*a));
529  clib_memset (options, 0, sizeof (options));
530 
531  if (pm->private_segment_size)
532  segment_size = pm->private_segment_size;
533  a->name = format (0, "proxy-server");
534  a->api_client_index = pm->server_client_index;
535  a->session_cb_vft = &proxy_session_cb_vft;
536  a->options = options;
537  a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
538  a->options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size;
539  a->options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
540  a->options[APP_OPTIONS_MAX_FIFO_SIZE] = pm->max_fifo_size;
541  a->options[APP_OPTIONS_HIGH_WATERMARK] = (u64) pm->high_watermark;
542  a->options[APP_OPTIONS_LOW_WATERMARK] = (u64) pm->low_watermark;
544  a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
545  pm->prealloc_fifos ? pm->prealloc_fifos : 0;
546 
547  a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
548 
549  if (vnet_application_attach (a))
550  {
551  clib_warning ("failed to attach server");
552  return -1;
553  }
554  pm->server_app_index = a->app_index;
555 
556  vec_free (a->name);
557  return 0;
558 }
559 
560 static int
562 {
563  proxy_main_t *pm = &proxy_main;
564  vnet_app_attach_args_t _a, *a = &_a;
566 
567  clib_memset (a, 0, sizeof (*a));
568  clib_memset (options, 0, sizeof (options));
569 
570  a->api_client_index = pm->active_open_client_index;
571  a->session_cb_vft = &active_open_clients;
572  a->name = format (0, "proxy-active-open");
573 
574  options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
575  options[APP_OPTIONS_SEGMENT_SIZE] = 512 << 20;
576  options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size;
577  options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
583  pm->prealloc_fifos ? pm->prealloc_fifos : 0;
584 
585  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN
586  | APP_OPTIONS_FLAGS_IS_PROXY;
587 
588  a->options = options;
589 
590  if (vnet_application_attach (a))
591  return -1;
592 
593  pm->active_open_app_index = a->app_index;
594 
595  vec_free (a->name);
596 
597  return 0;
598 }
599 
600 static int
602 {
603  proxy_main_t *pm = &proxy_main;
604  vnet_listen_args_t _a, *a = &_a;
605  clib_memset (a, 0, sizeof (*a));
606  a->app_index = pm->server_app_index;
607  a->uri = (char *) pm->server_uri;
608  return vnet_bind_uri (a);
609 }
610 
611 static int
613 {
614  proxy_main_t *pm = &proxy_main;
616  u32 num_threads;
617  int i;
618 
619  num_threads = 1 /* main thread */ + vtm->n_threads;
620  vec_validate (proxy_main.server_event_queue, num_threads - 1);
621  vec_validate (proxy_main.active_open_event_queue, num_threads - 1);
622  vec_validate (pm->rx_buf, num_threads - 1);
623 
624  for (i = 0; i < num_threads; i++)
625  vec_validate (pm->rx_buf[i], pm->rcv_buffer_size);
626 
627  if (proxy_server_attach ())
628  {
629  clib_warning ("failed to attach server app");
630  return -1;
631  }
632  if (proxy_server_listen ())
633  {
634  clib_warning ("failed to start listening");
635  return -1;
636  }
637  if (active_open_attach ())
638  {
639  clib_warning ("failed to attach active open app");
640  return -1;
641  }
642 
643  for (i = 0; i < num_threads; i++)
644  {
646 
648 
650  }
651 
652  return 0;
653 }
654 
655 static clib_error_t *
657  vlib_cli_command_t * cmd)
658 {
659  proxy_main_t *pm = &proxy_main;
660  char *default_server_uri = "tcp://0.0.0.0/23";
661  char *default_client_uri = "tcp://6.0.2.2/23";
662  int rv, tmp32;
663  u64 tmp64;
664 
665  pm->fifo_size = 64 << 10;
666  pm->max_fifo_size = 128 << 20;
667  pm->high_watermark = 80;
668  pm->low_watermark = 50;
669  pm->rcv_buffer_size = 1024;
670  pm->prealloc_fifos = 0;
671  pm->private_segment_count = 0;
672  pm->private_segment_size = 0;
673  pm->server_uri = 0;
674  pm->client_uri = 0;
675 
677  {
678  if (unformat (input, "fifo-size %U",
680  ;
681  else if (unformat (input, "max-fifo-size %U",
683  ;
684  else if (unformat (input, "high-watermark %d", &tmp32))
685  pm->high_watermark = (u8) tmp32;
686  else if (unformat (input, "low-watermark %d", &tmp32))
687  pm->low_watermark = (u8) tmp32;
688  else if (unformat (input, "rcv-buf-size %d", &pm->rcv_buffer_size))
689  ;
690  else if (unformat (input, "prealloc-fifos %d", &pm->prealloc_fifos))
691  ;
692  else if (unformat (input, "private-segment-count %d",
693  &pm->private_segment_count))
694  ;
695  else if (unformat (input, "private-segment-size %U",
696  unformat_memory_size, &tmp64))
697  {
698  if (tmp64 >= 0x100000000ULL)
699  return clib_error_return
700  (0, "private segment size %lld (%llu) too large", tmp64, tmp64);
701  pm->private_segment_size = tmp64;
702  }
703  else if (unformat (input, "server-uri %s", &pm->server_uri))
704  vec_add1 (pm->server_uri, 0);
705  else if (unformat (input, "client-uri %s", &pm->client_uri))
706  vec_add1 (pm->client_uri, 0);
707  else
708  return clib_error_return (0, "unknown input `%U'",
709  format_unformat_error, input);
710  }
711 
712  if (!pm->server_uri)
713  {
714  clib_warning ("No server-uri provided, Using default: %s",
715  default_server_uri);
716  pm->server_uri = format (0, "%s%c", default_server_uri, 0);
717  }
718  if (!pm->client_uri)
719  {
720  clib_warning ("No client-uri provided, Using default: %s",
721  default_client_uri);
722  pm->client_uri = format (0, "%s%c", default_client_uri, 0);
723  }
724 
725  vnet_session_enable_disable (vm, 1 /* turn on session and transport */ );
726 
727  rv = proxy_server_create (vm);
728  switch (rv)
729  {
730  case 0:
731  break;
732  default:
733  return clib_error_return (0, "server_create returned %d", rv);
734  }
735 
736  return 0;
737 }
738 
739 /* *INDENT-OFF* */
740 VLIB_CLI_COMMAND (proxy_create_command, static) =
741 {
742  .path = "test proxy server",
743  .short_help = "test proxy server [server-uri <tcp://ip/port>]"
744  "[client-uri <tcp://ip/port>][fifo-size <nn>[k|m]]"
745  "[max-fifo-size <nn>[k|m]][high-watermark <nn>]"
746  "[low-watermark <nn>][rcv-buf-size <nn>][prealloc-fifos <nn>]"
747  "[private-segment-size <mem>][private-segment-count <nn>]",
748  .function = proxy_server_create_command_fn,
749 };
750 /* *INDENT-ON* */
751 
752 clib_error_t *
754 {
755  proxy_main_t *pm = &proxy_main;
756  pm->server_client_index = ~0;
757  pm->active_open_client_index = ~0;
760 
761  return 0;
762 }
763 
765 
766 /*
767 * fd.io coding-style-patch-verification: ON
768 *
769 * Local Variables:
770 * eval: (c-set-style "gnu")
771 * End:
772 */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:507
u64 vpp_active_open_handle
Definition: proxy.h:35
#define hash_set(h, key, value)
Definition: hash.h:255
u32 max_fifo_size
max fifo size
Definition: proxy.h:61
#define clib_min(x, y)
Definition: clib.h:319
u32 private_segment_count
Number of private fifo segs.
Definition: proxy.h:64
#define hash_unset(h, key)
Definition: hash.h:261
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:101
a
Definition: bitmap.h:538
static void svm_fifo_set_size(svm_fifo_t *f, u32 size)
Definition: svm_fifo.h:670
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.
Notify on dequeue.
Definition: svm_fifo.h:35
static u32 svm_fifo_size(svm_fifo_t *f)
Definition: svm_fifo.h:664
#define PREDICT_TRUE(x)
Definition: clib.h:119
u32 session_index
Index in thread pool where session was allocated.
static int proxy_accept_callback(session_t *s)
Definition: proxy.c:188
unsigned long u64
Definition: types.h:89
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
Definition: session.h:633
static void proxy_reset_callback(session_t *s)
Definition: proxy.c:206
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1617
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:441
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:110
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:656
struct _tcp_connection tcp_connection_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:590
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1038
uword * proxy_session_by_server_handle
Definition: proxy.h:52
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:536
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
void(* session_reset_callback)(session_t *s)
Notify app that session was reset.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
unsigned char u8
Definition: types.h:56
struct _vnet_bind_args_t vnet_listen_args_t
static int active_open_create_callback(session_t *s)
Definition: proxy.c:429
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:82
u32 fifo_size
initial fifo size
Definition: proxy.h:60
#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:402
static session_cb_vft_t proxy_session_cb_vft
Definition: proxy.c:353
#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:608
unsigned int u32
Definition: types.h:88
int rcv_buffer_size
Definition: proxy.h:66
u32 server_app_index
server app index
Definition: proxy.h:48
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:79
static int proxy_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
Definition: proxy.c:213
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static int proxy_tx_callback(session_t *proxy_s)
Definition: proxy.c:311
clib_error_t * proxy_main_init(vlib_main_t *vm)
Definition: proxy.c:753
static int common_fifo_tuning_callback(session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 bytes)
Definition: proxy.c:144
#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:534
proxy_session_t * sessions
Session pool, shared.
Definition: proxy.h:73
void tcp_send_ack(tcp_connection_t *tc)
Definition: tcp_output.c:1011
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:321
struct _unformat_input_t unformat_input_t
static void active_open_disconnect_callback(session_t *s)
Definition: proxy.c:435
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:302
#define PREDICT_FALSE(x)
Definition: clib.h:118
u8 low_watermark
low watermark (%)
Definition: proxy.h:63
proxy_main_t proxy_main
Definition: proxy.c:23
static int proxy_server_create(vlib_main_t *vm)
Definition: proxy.c:612
static u32 svm_fifo_max_dequeue_prod(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for producer.
Definition: svm_fifo.h:416
vlib_main_t * vm
Definition: in2out_ed.c:1599
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1765
u64 vpp_server_handle
Definition: proxy.h:34
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
Definition: application.c:827
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:699
svm_msg_q_t ** active_open_event_queue
Definition: proxy.h:43
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 active_open_client_index
active open API client handle
Definition: proxy.h:49
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:218
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:365
#define clib_warning(format, args...)
Definition: error.h:59
u32 server_client_index
server API client handle
Definition: proxy.h:47
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:299
u8 * server_uri
Definition: proxy.h:67
#define TCP_MSS
Definition: proxy.c:25
static void active_open_reset_callback(session_t *s)
Definition: proxy.c:423
svm_msg_q_t ** server_event_queue
per-thread vectors
Definition: proxy.h:42
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
u32 active_open_app_index
active open index after attach
Definition: proxy.h:50
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define ASSERT(truth)
static int proxy_server_attach()
Definition: proxy.c:521
u8 data[128]
Definition: ipsec_types.api:89
uword * proxy_session_by_active_open_handle
Definition: proxy.h:53
static int proxy_rx_callback(session_t *s)
Definition: proxy.c:228
u8 ** rx_buf
intermediate rx buffers
Definition: proxy.h:44
static void delete_proxy_session(session_t *s, int is_active_open)
Definition: proxy.c:65
static void svm_fifo_add_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Set specific want notification flag.
Definition: svm_fifo.h:726
clib_spinlock_t sessions_lock
Definition: proxy.h:74
u8 thread_index
Index of the thread that allocated the session.
u32 private_segment_size
size of private fifo segs
Definition: proxy.h:65
static int active_open_attach(void)
Definition: proxy.c:561
u8 high_watermark
high watermark (%)
Definition: proxy.h:62
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:200
#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:1087
struct _segment_manager segment_manager_t
segment_manager_t * segment_manager_get(u32 index)
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:86
unformat_function_t unformat_memory_size
Definition: format.h:296
static int proxy_add_segment_callback(u32 client_index, u64 segment_handle)
Definition: proxy.c:221
static struct option options[]
Definition: main.c:52
static int proxy_server_listen()
Definition: proxy.c:601
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
enum session_error_ session_error_t
static session_cb_vft_t active_open_clients
Definition: proxy.c:509
static int active_open_tx_callback(session_t *ao_s)
Definition: proxy.c:466
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
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:95
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
void svm_fifo_init_ooo_lookup(svm_fifo_t *f, u8 ooo_type)
Initialize rbtrees used for ooo lookups.
Definition: svm_fifo.c:401
u8 * client_uri
Definition: proxy.h:68
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171