FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
application_worker.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 
18 #include <vnet/session/session.h>
19 
20 /**
21  * Pool of workers associated to apps
22  */
24 
27 {
28  app_worker_t *app_wrk;
29  pool_get (app_workers, app_wrk);
30  clib_memset (app_wrk, 0, sizeof (*app_wrk));
31  app_wrk->wrk_index = app_wrk - app_workers;
32  app_wrk->app_index = app->app_index;
33  app_wrk->wrk_map_index = ~0;
36  APP_DBG ("New app %v worker %u", app->name, app_wrk->wrk_index);
37  return app_wrk;
38 }
39 
41 app_worker_get (u32 wrk_index)
42 {
43  return pool_elt_at_index (app_workers, wrk_index);
44 }
45 
48 {
49  if (pool_is_free_index (app_workers, wrk_index))
50  return 0;
51  return pool_elt_at_index (app_workers, wrk_index);
52 }
53 
54 void
56 {
57  application_t *app = application_get (app_wrk->app_index);
58  vnet_unlisten_args_t _a, *a = &_a;
59  u64 handle, *handles = 0, *sm_indices = 0;
61  session_handle_t *sh;
62  session_t *ls;
63  u32 sm_index;
64  int i;
65 
66  /*
67  * Listener cleanup
68  */
69 
70  /* *INDENT-OFF* */
71  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
72  ls = listen_session_get_from_handle (handle);
73  vec_add1 (handles, app_listen_session_handle (ls));
74  vec_add1 (sm_indices, sm_index);
75  sm = segment_manager_get (sm_index);
76  }));
77  /* *INDENT-ON* */
78 
79  for (i = 0; i < vec_len (handles); i++)
80  {
81  /* Cleanup listener */
82  a->app_index = app->app_index;
83  a->wrk_map_index = app_wrk->wrk_map_index;
84  a->handle = handles[i];
85  (void) vnet_unlisten (a);
86 
87  sm = segment_manager_get_if_valid (sm_indices[i]);
88  if (sm && !segment_manager_app_detached (sm))
89  {
90  sm->first_is_protected = 0;
92  }
93  }
94  vec_reset_length (handles);
95  vec_free (sm_indices);
96  hash_free (app_wrk->listeners_table);
97 
98  /*
99  * Connects segment manager cleanup
100  */
101 
103  {
105  sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
106  sm->first_is_protected = 0;
108  }
109 
110  /*
111  * Half-open cleanup
112  */
113 
114  pool_foreach (sh, app_wrk->half_open_table)
116 
117  pool_free (app_wrk->half_open_table);
118 
119  /*
120  * Detached listener segment managers cleanup
121  */
122  for (i = 0; i < vec_len (app_wrk->detached_seg_managers); i++)
123  {
126  }
127  vec_free (app_wrk->detached_seg_managers);
129 
130  if (CLIB_DEBUG)
131  clib_memset (app_wrk, 0xfe, sizeof (*app_wrk));
132  pool_put (app_workers, app_wrk);
133 }
134 
137 {
138  app_worker_t *app_wrk;
139  app_wrk = app_worker_get_if_valid (wrk_index);
140  if (!app_wrk)
141  return 0;
142  return application_get_if_valid (app_wrk->app_index);
143 }
144 
145 static segment_manager_t *
147 {
148  segment_manager_t *sm;
149 
150  sm = segment_manager_alloc ();
151  sm->app_wrk_index = app_wrk->wrk_index;
153  return sm;
154 }
155 
156 static int
158 {
159  svm_fifo_t *rx_fifo = 0, *tx_fifo = 0;
160  int rv;
161 
163  &rx_fifo, &tx_fifo)))
164  return rv;
165 
166  rx_fifo->shr->master_session_index = s->session_index;
167  rx_fifo->master_thread_index = s->thread_index;
168 
169  tx_fifo->shr->master_session_index = s->session_index;
170  tx_fifo->master_thread_index = s->thread_index;
171 
172  s->rx_fifo = rx_fifo;
173  s->tx_fifo = tx_fifo;
174  return 0;
175 }
176 
177 int
179 {
180  segment_manager_t *sm;
181 
182  /* Allocate segment manager. All sessions derived out of a listen session
183  * have fifos allocated by the same segment manager. */
184  if (!(sm = app_worker_alloc_segment_manager (app_wrk)))
185  return SESSION_E_ALLOC;
186 
187  /* Keep track of the segment manager for the listener or this worker */
189  segment_manager_index (sm));
190 
192  {
193  if (ls->rx_fifo)
194  return SESSION_E_NOSUPPORT;
195  return app_worker_alloc_session_fifos (sm, ls);
196  }
197  return 0;
198 }
199 
200 int
202  app_listener_t * app_listener)
203 {
204  session_t *ls;
205  int rv;
206 
207  if (clib_bitmap_get (app_listener->workers, app_wrk->wrk_map_index))
208  return SESSION_E_ALREADY_LISTENING;
209 
210  app_listener->workers = clib_bitmap_set (app_listener->workers,
211  app_wrk->wrk_map_index, 1);
212 
213  if (app_listener->session_index != SESSION_INVALID_INDEX)
214  {
215  ls = session_get (app_listener->session_index, 0);
216  if ((rv = app_worker_init_listener (app_wrk, ls)))
217  return rv;
218  }
219 
220  if (app_listener->local_index != SESSION_INVALID_INDEX)
221  {
222  ls = session_get (app_listener->local_index, 0);
223  if ((rv = app_worker_init_listener (app_wrk, ls)))
224  return rv;
225  }
226 
227  return 0;
228 }
229 
230 static void
232 {
233  vec_add1 (app_wrk->detached_seg_managers, sm_index);
234 }
235 
236 void
238 {
239  u32 i;
240 
242  for (i = 0; i < vec_len (app_wrk->detached_seg_managers); i++)
243  {
244  if (app_wrk->detached_seg_managers[i] == sm_index)
245  {
246  vec_del1 (app_wrk->detached_seg_managers, i);
247  break;
248  }
249  }
251 }
252 
253 static void
255 {
256  session_handle_t handle;
257  segment_manager_t *sm;
258  uword *sm_indexp;
259  session_state_t *states = 0;
260 
261  handle = listen_session_get_handle (ls);
262  sm_indexp = hash_get (app_wrk->listeners_table, handle);
263  if (PREDICT_FALSE (!sm_indexp))
264  return;
265 
266  /* Dealloc fifos, if any (dgram listeners) */
267  if (ls->rx_fifo)
268  {
270  ls->tx_fifo = ls->rx_fifo = 0;
271  }
272 
273  /* Try to cleanup segment manager */
274  sm = segment_manager_get (*sm_indexp);
275  if (sm)
276  {
278  if (!segment_manager_has_fifos (sm))
279  {
280  /* Empty segment manager, cleanup it up */
282  }
283  else
284  {
285  /* Delete sessions in CREATED state */
286  vec_add1 (states, SESSION_STATE_CREATED);
288  vec_free (states);
289 
290  /* Track segment manager in case app detaches and all the
291  * outstanding sessions need to be closed */
292  app_worker_add_detached_sm (app_wrk, *sm_indexp);
293  sm->flags |= SEG_MANAGER_F_DETACHED_LISTENER;
294  }
295  }
296 
297  hash_unset (app_wrk->listeners_table, handle);
298 }
299 
300 int
302 {
303  session_t *ls;
304 
305  if (!clib_bitmap_get (al->workers, app_wrk->wrk_map_index))
306  return 0;
307 
309  {
311  app_worker_stop_listen_session (app_wrk, ls);
312  }
313 
315  {
316  ls = listen_session_get (al->local_index);
317  app_worker_stop_listen_session (app_wrk, ls);
318  }
319 
321  if (clib_bitmap_is_zero (al->workers))
323 
324  return 0;
325 }
326 
327 int
329 {
330  app_worker_t *app_wrk;
331  segment_manager_t *sm;
333  application_t *app;
334 
337  s->app_wrk_index = app_wrk->wrk_index;
338 
339  app = application_get (app_wrk->app_index);
340  if (app->cb_fns.fifo_tuning_callback)
341  s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
342 
344  if (app_worker_alloc_session_fifos (sm, s))
345  return -1;
346 
347  return 0;
348 }
349 
350 int
352 {
353  application_t *app = application_get (app_wrk->app_index);
354  return app->cb_fns.session_accept_callback (s);
355 }
356 
357 int
359 {
360  application_t *app = application_get (app_wrk->app_index);
361  segment_manager_t *sm;
362 
363  if (app->cb_fns.fifo_tuning_callback)
364  s->flags |= SESSION_F_CUSTOM_FIFO_TUNING;
365 
366  /* Allocate fifos for session, unless the app is a builtin proxy */
368  return 0;
369 
371  return app_worker_alloc_session_fifos (sm, s);
372 }
373 
374 int
376  session_error_t err, u32 opaque)
377 {
378  application_t *app = application_get (app_wrk->app_index);
379  return app->cb_fns.session_connected_callback (app_wrk->wrk_index, opaque,
380  s, err);
381 }
382 
383 int
385 {
386  session_handle_t *shp;
387 
388  ASSERT (vlib_get_thread_index () == 0);
389  pool_get (app_wrk->half_open_table, shp);
390  *shp = sh;
391 
392  return (shp - app_wrk->half_open_table);
393 }
394 
395 int
397 {
398  application_t *app = application_get (app_wrk->app_index);
399  ASSERT (vlib_get_thread_index () <= 1);
400  pool_put_index (app_wrk->half_open_table, s->ho_index);
403  return 0;
404 }
405 
406 int
408 {
409  application_t *app = application_get (app_wrk->app_index);
411  return 0;
412 }
413 
414 int
416 {
417  application_t *app = application_get (app_wrk->app_index);
420  return 0;
421 }
422 
423 int
425 {
426  application_t *app = application_get (app_wrk->app_index);
428  return 0;
429 }
430 
431 int
434 {
435  application_t *app = application_get (app_wrk->app_index);
437  app->cb_fns.session_cleanup_callback (s, ntf);
438  return 0;
439 }
440 
441 int
443 {
444  application_t *app = application_get (app_wrk->app_index);
446  return 0;
447 }
448 
449 int
451 {
452  application_t *app = application_get (app_wrk->app_index);
453 
455  return 0;
456 
458  return 0;
459 }
460 
461 int
463  session_handle_t new_sh)
464 {
465  application_t *app = application_get (app_wrk->app_index);
466  app->cb_fns.session_migrate_callback (s, new_sh);
467  return 0;
468 }
469 
470 int
472 {
473  segment_manager_t *sm;
474  svm_fifo_t *rxf, *txf;
475 
476  if (s->session_state == SESSION_STATE_LISTENING)
477  return application_change_listener_owner (s, app_wrk);
478 
479  s->app_wrk_index = app_wrk->wrk_index;
480 
481  rxf = s->rx_fifo;
482  txf = s->tx_fifo;
483 
484  if (!rxf || !txf)
485  return 0;
486 
487  s->rx_fifo = 0;
488  s->tx_fifo = 0;
489 
491  if (app_worker_alloc_session_fifos (sm, s))
492  return -1;
493 
494  if (!svm_fifo_is_empty_cons (rxf))
495  svm_fifo_clone (s->rx_fifo, rxf);
496 
497  if (!svm_fifo_is_empty_cons (txf))
498  svm_fifo_clone (s->tx_fifo, txf);
499 
501 
502  return 0;
503 }
504 
505 int
507  session_handle_t *rsh)
508 {
509  sep->app_wrk_index = app_wrk->wrk_index;
510 
511  return session_open (sep, rsh);
512 }
513 
514 int
516  svm_fifo_t * f,
518 {
519  application_t *app = application_get (app_wrk->app_index);
520  return app->cb_fns.fifo_tuning_callback (s, f, act, len);
521 }
522 
525 {
526  ASSERT (app->connects_seg_manager != (u32) ~ 0);
528 }
529 
533 {
534  uword *smp;
536  ALWAYS_ASSERT (smp != 0);
537  return segment_manager_get (*smp);
538 }
539 
540 session_t *
543 {
545  u64 handle;
546  u32 sm_index;
547  u8 sst;
548 
550  fib_proto == FIB_PROTOCOL_IP4);
551 
552  /* *INDENT-OFF* */
553  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
554  listener = listen_session_get_from_handle (handle);
555  if (listener->session_type == sst
556  && !(listener->flags & SESSION_F_PROXY))
557  return listener;
558  }));
559  /* *INDENT-ON* */
560 
561  return 0;
562 }
563 
564 session_t *
567 {
569  u64 handle;
570  u32 sm_index;
571  u8 sst;
572 
574  fib_proto == FIB_PROTOCOL_IP4);
575 
576  /* *INDENT-OFF* */
577  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
578  listener = listen_session_get_from_handle (handle);
579  if (listener->session_type == sst && (listener->flags & SESSION_F_PROXY))
580  return listener;
581  }));
582  /* *INDENT-ON* */
583 
584  return 0;
585 }
586 
587 /**
588  * Send an API message to the external app, to map new segment
589  */
590 int
591 app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
592 {
593  application_t *app = application_get (app_wrk->app_index);
594 
595  return app->cb_fns.add_segment_callback (app_wrk->wrk_index,
596  segment_handle);
597 }
598 
599 int
600 app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
601 {
602  application_t *app = application_get (app_wrk->app_index);
603  return app->cb_fns.del_segment_callback (app_wrk->wrk_index,
604  segment_handle);
605 }
606 
607 static inline u8
609 {
610  return app_wrk->app_is_builtin;
611 }
612 
613 static inline int
615 {
616  session_event_t *evt;
617  svm_msg_q_msg_t msg;
618  svm_msg_q_t *mq;
619 
620  if (app_worker_application_is_builtin (app_wrk))
621  return app_worker_builtin_rx (app_wrk, s);
622 
623  if (svm_fifo_has_event (s->rx_fifo))
624  return 0;
625 
626  mq = app_wrk->event_queue;
627  svm_msg_q_lock (mq);
628 
629  if (PREDICT_FALSE (svm_msg_q_is_full (mq)))
630  {
631  clib_warning ("evt q full");
632  svm_msg_q_unlock (mq);
633  return -1;
634  }
635 
637  {
638  clib_warning ("evt q rings full");
639  svm_msg_q_unlock (mq);
640  return -1;
641  }
642 
644  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
645  evt->session_index = s->rx_fifo->shr->client_session_index;
646  evt->event_type = SESSION_IO_EVT_RX;
647 
648  (void) svm_fifo_set_event (s->rx_fifo);
649  svm_msg_q_add_and_unlock (mq, &msg);
650 
651  return 0;
652 }
653 
654 static inline int
656 {
657  svm_msg_q_t *mq;
658  session_event_t *evt;
659  svm_msg_q_msg_t msg;
660 
661  if (app_worker_application_is_builtin (app_wrk))
662  return app_worker_builtin_tx (app_wrk, s);
663 
664  mq = app_wrk->event_queue;
665  svm_msg_q_lock (mq);
666 
667  if (PREDICT_FALSE (svm_msg_q_is_full (mq)))
668  {
669  clib_warning ("evt q full");
670  svm_msg_q_unlock (mq);
671  return -1;
672  }
673 
675  {
676  clib_warning ("evt q rings full");
677  svm_msg_q_unlock (mq);
678  return -1;
679  }
680 
682  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
683  evt->event_type = SESSION_IO_EVT_TX;
684  evt->session_index = s->tx_fifo->shr->client_session_index;
685 
686  svm_msg_q_add_and_unlock (mq, &msg);
687  return 0;
688 }
689 
690 /* *INDENT-OFF* */
692  session_t *s);
696 };
697 /* *INDENT-ON* */
698 
699 /**
700  * Send event to application
701  *
702  * Logic from queue perspective is blocking. However, if queue is full,
703  * we return.
704  */
705 int
707  u8 evt_type)
708 {
709  return app_send_evt_handler_fns[evt_type] (app, s);
710 }
711 
712 u8 *
713 format_app_worker_listener (u8 * s, va_list * args)
714 {
715  app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
716  u64 handle = va_arg (*args, u64);
717  u32 sm_index = va_arg (*args, u32);
718  int verbose = va_arg (*args, int);
720  const u8 *app_name;
721  u8 *str;
722 
723  if (!app_wrk)
724  {
725  if (verbose)
726  s = format (s, "%-" SESSION_CLI_ID_LEN "s%-25s%-10s%-15s%-15s%-10s",
727  "Connection", "App", "Wrk", "API Client", "ListenerID",
728  "SegManager");
729  else
730  s = format (s, "%-" SESSION_CLI_ID_LEN "s%-25s%-10s", "Connection",
731  "App", "Wrk");
732 
733  return s;
734  }
735 
738  str = format (0, "%U", format_session, listener, verbose);
739 
740  if (verbose)
741  {
742  u8 *buf;
743  buf = format (0, "%u(%u)", app_wrk->wrk_map_index, app_wrk->wrk_index);
744  s = format (s, "%-" SESSION_CLI_ID_LEN "v%-25v%-10v%-15u%-15u%-10u", str,
745  app_name, buf, app_wrk->api_client_index, handle, sm_index);
746  vec_free (buf);
747  }
748  else
749  s = format (s, "%-" SESSION_CLI_ID_LEN "v%-25v%=10u", str, app_name,
750  app_wrk->wrk_map_index);
751 
752  vec_free (str);
753 
754  return s;
755 }
756 
757 u8 *
758 format_app_worker (u8 * s, va_list * args)
759 {
760  app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
761  u32 indent = 1;
762 
763  s = format (s, "%U wrk-index %u app-index %u map-index %u "
764  "api-client-index %d\n", format_white_space, indent,
765  app_wrk->wrk_index, app_wrk->app_index, app_wrk->wrk_map_index,
766  app_wrk->api_client_index);
767  return s;
768 }
769 
770 void
771 app_worker_format_connects (app_worker_t * app_wrk, int verbose)
772 {
773  segment_manager_t *sm;
774 
775  /* Header */
776  if (!app_wrk)
777  {
778  segment_manager_format_sessions (0, verbose);
779  return;
780  }
781 
782  if (app_wrk->connects_seg_manager == (u32) ~ 0)
783  return;
784 
786  segment_manager_format_sessions (sm, verbose);
787 }
788 
789 /*
790  * fd.io coding-style-patch-verification: ON
791  *
792  * Local Variables:
793  * eval: (c-set-style "gnu")
794  * End:
795  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
app_worker_builtin_tx
int app_worker_builtin_tx(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:450
clib_spinlock_init
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
svm_fifo_set_event
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:733
app_worker_::half_open_table
session_handle_t * half_open_table
Pool of half-open session handles.
Definition: application.h:65
APP_DBG
#define APP_DBG(_fmt, _args...)
Definition: application.h:29
app_worker_::wrk_index
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
application_change_listener_owner
int application_change_listener_owner(session_t *s, app_worker_t *app_wrk)
Definition: application.c:1460
session_error_t
enum session_error_ session_error_t
app_worker_lock_and_send_event
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
Definition: application_worker.c:706
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
app_worker_add_half_open
int app_worker_add_half_open(app_worker_t *app_wrk, session_handle_t sh)
Definition: application_worker.c:384
segment_manager_get
segment_manager_t * segment_manager_get(u32 index)
Definition: segment_manager.c:547
app_workers
static app_worker_t * app_workers
Pool of workers associated to apps.
Definition: application_worker.c:23
app_worker_alloc_segment_manager
static segment_manager_t * app_worker_alloc_segment_manager(app_worker_t *app_wrk)
Definition: application_worker.c:146
hash_free
#define hash_free(h)
Definition: hash.h:310
session_::session_index
u32 session_index
Index in thread pool where session was allocated.
Definition: session_types.h:188
SESSION_MQ_IO_EVT_RING
@ SESSION_MQ_IO_EVT_RING
Definition: session_types.h:401
SESSION_CLI_ID_LEN
#define SESSION_CLI_ID_LEN
Definition: session_types.h:507
svm_msg_q_add_and_unlock
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
Definition: message_queue.c:394
app_worker_init_connected
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:358
svm_msg_q_alloc_msg_w_ring
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index)
Allocate message buffer on ring.
Definition: message_queue.c:221
f
vlib_frame_t * f
Definition: interface_output.c:1098
segment_manager_init
int segment_manager_init(segment_manager_t *sm)
Definition: segment_manager.c:347
app_listener_::local_index
u32 local_index
local listening session index
Definition: application.h:85
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
vnet_unlisten
int vnet_unlisten(vnet_unlisten_args_t *a)
Definition: application.c:1387
listen_session_get_handle
static u64 listen_session_get_handle(session_t *s)
Definition: session.h:623
svm_msg_q_msg_data
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
Definition: message_queue.c:287
session_::tx_fifo
svm_fifo_t * tx_fifo
Definition: session_types.h:179
app_worker_connect_session
int app_worker_connect_session(app_worker_t *app_wrk, session_endpoint_cfg_t *sep, session_handle_t *rsh)
Definition: application_worker.c:506
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
segment_manager_t
struct _segment_manager segment_manager_t
session_endpoint_cfg_t
struct _session_endpoint_cfg session_endpoint_cfg_t
app_worker_application_is_builtin
static u8 app_worker_application_is_builtin(app_worker_t *app_wrk)
Definition: application_worker.c:608
session_handle_t
u64 session_handle_t
Definition: session_types.h:111
hash_foreach
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:441
listen_session_get
static session_t * listen_session_get(u32 ls_index)
Definition: session.h:654
SESSION_INVALID_INDEX
#define SESSION_INVALID_INDEX
Definition: session_types.h:22
application_::app_index
u32 app_index
App index in app pool.
Definition: application.h:111
SESSION_IO_EVT_RX
@ SESSION_IO_EVT_RX
Definition: session_types.h:328
svm_msg_q_lock
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
Definition: message_queue.h:372
svm_msg_q_msg_t
Definition: message_queue.h:93
session_::thread_index
u8 thread_index
Index of the thread that allocated the session.
Definition: session_types.h:194
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
application_is_builtin_proxy
int application_is_builtin_proxy(application_t *app)
Definition: application.c:1506
app_worker_builtin_rx
int app_worker_builtin_rx(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:442
app_worker_del_detached_sm
void app_worker_del_detached_sm(app_worker_t *app_wrk, u32 sm_index)
Definition: application_worker.c:237
listener
Definition: test_stats.cpp:7
app_worker_transport_closed_notify
int app_worker_transport_closed_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:415
vnet_unlisten_args_t
struct _vnet_unlisten_args_t vnet_unlisten_args_t
application_
Definition: application.h:108
app_worker_reset_notify
int app_worker_reset_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:424
segment_manager_alloc
segment_manager_t * segment_manager_alloc(void)
Definition: segment_manager.c:336
app_send_io_evt_tx
static int app_send_io_evt_tx(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:655
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
app_worker_alloc
app_worker_t * app_worker_alloc(application_t *app)
Definition: application_worker.c:26
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
segment_manager_app_detached
u8 segment_manager_app_detached(segment_manager_t *sm)
Definition: segment_manager.c:67
svm_fifo_t
struct _svm_fifo svm_fifo_t
session_cb_vft_::session_cleanup_callback
void(* session_cleanup_callback)(session_t *s, session_cleanup_ntf_t ntf)
Notify app that session or transport are about to be removed.
Definition: application_interface.h:54
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
app_worker_::listeners_table
uword * listeners_table
Lookup tables for listeners.
Definition: application.h:57
app_worker_get_app
application_t * app_worker_get_app(u32 wrk_index)
Definition: application_worker.c:136
application_get
application_t * application_get(u32 app_index)
Definition: application.c:710
session_::app_wrk_index
u32 app_wrk_index
Index of the app worker that owns the session.
Definition: session_types.h:191
app_listener_cleanup
void app_listener_cleanup(app_listener_t *al)
Definition: application.c:264
app_send_evt_handler_fn
int() app_send_evt_handler_fn(app_worker_t *app, session_t *s)
Definition: application_worker.c:691
segment_manager_alloc_session_fifos
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:737
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
segment_manager_app_detach
void segment_manager_app_detach(segment_manager_t *sm)
Definition: segment_manager.c:73
app_worker_alloc_session_fifos
static int app_worker_alloc_session_fifos(segment_manager_t *sm, session_t *s)
Definition: application_worker.c:157
session_ft_action_t
enum session_ft_action_ session_ft_action_t
app_worker_cleanup_notify
int app_worker_cleanup_notify(app_worker_t *app_wrk, session_t *s, session_cleanup_ntf_t ntf)
Definition: application_worker.c:432
session_::rx_fifo
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
Definition: session_types.h:178
app_listener_::session_index
u32 session_index
global listening session index
Definition: application.h:86
app_worker_stop_listen_session
static void app_worker_stop_listen_session(app_worker_t *app_wrk, session_t *ls)
Definition: application_worker.c:254
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
clib_bitmap_get
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
len
u8 len
Definition: ip_types.api:103
svm_msg_q_is_full
static u8 svm_msg_q_is_full(svm_msg_q_t *mq)
Check if message queue is full.
Definition: message_queue.h:319
SEG_MANAGER_F_DETACHED_LISTENER
@ SEG_MANAGER_F_DETACHED_LISTENER
Definition: segment_manager.h:48
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
segment_manager_dealloc_fifos
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
Definition: segment_manager.c:825
session_get_transport
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1743
svm_fifo_is_empty_cons
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
Definition: svm_fifo.h:554
segment_manager_free
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
Definition: segment_manager.c:471
app_worker_migrate_notify
int app_worker_migrate_notify(app_worker_t *app_wrk, session_t *s, session_handle_t new_sh)
Definition: application_worker.c:462
app_send_io_evt_rx
static int app_send_io_evt_rx(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:614
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
application_listener_select_worker
app_worker_t * application_listener_select_worker(session_t *ls)
Definition: application.c:998
hash_get
#define hash_get(h, key)
Definition: hash.h:249
clib_spinlock_lock
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
segment_manager_format_sessions
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
Definition: segment_manager.c:1062
uword
u64 uword
Definition: types.h:112
session_cb_vft_::session_disconnect_callback
void(* session_disconnect_callback)(session_t *s)
Notify app that session is closing.
Definition: application_interface.h:48
session_cb_vft_::session_migrate_callback
void(* session_migrate_callback)(session_t *s, session_handle_t new_sh)
Notify app that session pool migration happened.
Definition: application_interface.h:63
app_worker_proxy_listener
session_t * app_worker_proxy_listener(app_worker_t *app_wrk, u8 fib_proto, u8 transport_proto)
Definition: application_worker.c:565
session_open
int session_open(session_endpoint_cfg_t *rmt, session_handle_t *rsh)
Ask transport to open connection to remote transport endpoint.
Definition: session.c:1407
clib_spinlock_free
static void clib_spinlock_free(clib_spinlock_t *p)
Definition: lock.h:72
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
session_cleanup_half_open
void session_cleanup_half_open(session_handle_t ho_handle)
Definition: session.c:304
app_name
static char * app_name
Definition: vapi_cpp_test.cpp:33
session_cb_vft_::session_reset_callback
void(* session_reset_callback)(session_t *s)
Notify app that session was reset.
Definition: application_interface.h:60
SESSION_IO_EVT_TX
@ SESSION_IO_EVT_TX
Definition: session_types.h:329
app_worker_connect_notify
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, session_error_t err, u32 opaque)
Definition: application_worker.c:375
ALWAYS_ASSERT
#define ALWAYS_ASSERT(truth)
Definition: error_bootstrap.h:89
clib_bitmap_set
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap.
Definition: bitmap.h:167
app_worker_::event_queue
svm_msg_q_t * event_queue
Application listens for events on this svm queue.
Definition: application.h:46
application_get_if_valid
application_t * application_get_if_valid(u32 app_index)
Definition: application.c:718
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
format_app_worker_listener
u8 * format_app_worker_listener(u8 *s, va_list *args)
Definition: application_worker.c:713
segment_manager_index
u32 segment_manager_index(segment_manager_t *sm)
Definition: segment_manager.c:561
app_worker_free
void app_worker_free(app_worker_t *app_wrk)
Definition: application_worker.c:55
app_worker_del_segment_notify
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Definition: application_worker.c:600
session_get
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:337
svm_msg_q_
Definition: message_queue.h:72
format_session
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:101
app_worker_close_notify
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:407
app_worker_::detached_seg_managers_lock
clib_spinlock_t detached_seg_managers_lock
Protects detached seg managers.
Definition: application.h:68
session_::listener_handle
session_handle_t listener_handle
Parent listener session index if the result of an accept.
Definition: session_types.h:208
session_type_from_proto_and_ip
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
Definition: session_types.h:224
app_worker_stop_listen
int app_worker_stop_listen(app_worker_t *app_wrk, app_listener_t *al)
Definition: application_worker.c:301
app_send_evt_handler_fns
static app_send_evt_handler_fn *const app_send_evt_handler_fns[2]
Definition: application_worker.c:693
app_worker_get_if_valid
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
Definition: application_worker.c:47
app_listener_::workers
clib_bitmap_t * workers
workers accepting connections
Definition: application.h:81
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
session_cb_vft_::add_segment_callback
int(* add_segment_callback)(u32 app_wrk_index, u64 segment_handle)
Notify server of new segment.
Definition: application_interface.h:35
segment_manager_init_free
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
Definition: segment_manager.c:532
session_cb_vft_::session_transport_closed_callback
void(* session_transport_closed_callback)(session_t *s)
Notify app that transport is closed.
Definition: application_interface.h:51
app_worker_::connects_seg_manager
u32 connects_seg_manager
Segment manager used for outgoing connects issued by the app.
Definition: application.h:54
segment_manager_get_if_valid
segment_manager_t * segment_manager_get_if_valid(u32 index)
Definition: segment_manager.c:553
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
app_worker_start_listen
int app_worker_start_listen(app_worker_t *app_wrk, app_listener_t *app_listener)
Definition: application_worker.c:201
APP_INVALID_SEGMENT_MANAGER_INDEX
#define APP_INVALID_SEGMENT_MANAGER_INDEX
Definition: application.h:228
session_state_t
session_state_t
Definition: session_types.h:143
app_worker_accept_notify
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:351
buf
u64 buf
Definition: application.c:493
u32
unsigned int u32
Definition: types.h:88
format_app_worker
u8 * format_app_worker(u8 *s, va_list *args)
Definition: application_worker.c:758
svm_fifo_clone
void svm_fifo_clone(svm_fifo_t *df, svm_fifo_t *sf)
Clones fifo.
Definition: svm_fifo.c:1338
SEGMENT_MANAGER_INVALID_APP_INDEX
#define SEGMENT_MANAGER_INVALID_APP_INDEX
Definition: segment_manager.h:81
app_worker_
Definition: application.h:32
app_worker_session_fifo_tuning
int app_worker_session_fifo_tuning(app_worker_t *app_wrk, session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 len)
Definition: application_worker.c:515
segment_manager_del_sessions_filter
void segment_manager_del_sessions_filter(segment_manager_t *sm, session_state_t *states)
Initiate disconnects for sessions in specified state 'owned' by a segment manager.
Definition: segment_manager.c:649
app_worker_init_listener
int app_worker_init_listener(app_worker_t *app_wrk, session_t *ls)
Definition: application_worker.c:178
clib_spinlock_unlock
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
application_name_from_index
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
Definition: application.c:386
session_cb_vft_::session_connected_callback
int(* session_connected_callback)(u32 app_wrk_index, u32 opaque, session_t *s, session_error_t code)
Connection request callback.
Definition: application_interface.h:44
app_worker_::app_is_builtin
u8 app_is_builtin
Definition: application.h:62
segment_manager_has_fifos
u8 segment_manager_has_fifos(segment_manager_t *sm)
Definition: segment_manager.c:567
session_cb_vft_::del_segment_callback
int(* del_segment_callback)(u32 app_wrk_index, u64 segment_handle)
Notify server of new segment.
Definition: application_interface.h:38
transport_connection_is_cless
static u8 transport_connection_is_cless(transport_connection_t *tc)
Definition: transport.h:221
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
app_worker_::wrk_map_index
u32 wrk_map_index
Worker index in app's map pool.
Definition: application.h:40
application_interface.h
app_worker_own_session
int app_worker_own_session(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:471
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
app_worker_get_connect_segment_manager
segment_manager_t * app_worker_get_connect_segment_manager(app_worker_t *app)
Definition: application_worker.c:524
session.h
i
int i
Definition: flowhash_template.h:376
pool_free
#define pool_free(p)
Free a pool.
Definition: pool.h:447
session_cb_vft_::builtin_app_tx_callback
int(* builtin_app_tx_callback)(session_t *session)
Direct TX callback for built-in application.
Definition: application_interface.h:69
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
session_cb_vft_::fifo_tuning_callback
int(* fifo_tuning_callback)(session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 bytes)
Delegate fifo-tuning-logic to application.
Definition: application_interface.h:75
app_worker_format_connects
void app_worker_format_connects(app_worker_t *app_wrk, int verbose)
Definition: application_worker.c:771
session_::flags
u32 flags
Session flags.
Definition: session_types.h:197
app_worker_add_segment_notify
int app_worker_add_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Send an API message to the external app, to map new segment.
Definition: application_worker.c:591
rv
int __clib_unused rv
Definition: application.c:491
session_::ho_index
u32 ho_index
Index in app worker's half-open table if a half-open.
Definition: session_types.h:214
application_::cb_fns
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:117
application_::name
u8 * name
Name registered by builtin apps.
Definition: application.h:126
app_worker_get_listen_segment_manager
segment_manager_t * app_worker_get_listen_segment_manager(app_worker_t *app, session_t *listener)
Definition: application_worker.c:531
transport_proto
transport_proto
Definition: session.api:22
app_worker_::detached_seg_managers
u32 * detached_seg_managers
Vector of detached listener segment managers.
Definition: application.h:71
app_worker_::app_index
u32 app_index
Index of owning app.
Definition: application.h:43
svm_msg_q_ring_is_full
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
Definition: message_queue.h:325
clib_bitmap_set_no_check
static uword clib_bitmap_set_no_check(uword *a, uword i, uword new_value)
Sets the ith bit of a bitmap to new_value.
Definition: bitmap.h:141
app_worker_::api_client_index
u32 api_client_index
API index for the worker.
Definition: application.h:60
app_worker_del_half_open
int app_worker_del_half_open(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:396
app_worker_get
app_worker_t * app_worker_get(u32 wrk_index)
Definition: application_worker.c:41
session_cleanup_ntf_t
session_cleanup_ntf_t
Definition: session_types.h:113
session_::session_state
volatile u8 session_state
State in session layer state machine.
Definition: session_types.h:185
session_cb_vft_::half_open_cleanup_callback
void(* half_open_cleanup_callback)(session_t *s)
Notify app that half open state was cleaned up (optional)
Definition: application_interface.h:57
svm_fifo_has_event
static int svm_fifo_has_event(svm_fifo_t *f)
Check if fifo has io event.
Definition: svm_fifo.h:719
app_worker_init_accepted
int app_worker_init_accepted(session_t *s)
Definition: application_worker.c:328
clib_bitmap_is_zero
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
listen_session_get_from_handle
static session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:631
app_worker_first_listener
session_t * app_worker_first_listener(app_worker_t *app_wrk, u8 fib_proto, u8 transport_proto)
Definition: application_worker.c:541
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
application.h
app_worker_add_detached_sm
static void app_worker_add_detached_sm(app_worker_t *app_wrk, u32 sm_index)
Definition: application_worker.c:231
app_listener_
Definition: application.h:79
svm_msg_q_unlock
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
Definition: message_queue.h:392