FD.io VPP  v20.01-48-g3e0dafb74
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;
61  session_t *ls;
62  u32 sm_index;
63  int i;
64 
65  /*
66  * Listener cleanup
67  */
68 
69  /* *INDENT-OFF* */
70  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
71  ls = listen_session_get_from_handle (handle);
72  vec_add1 (handles, app_listen_session_handle (ls));
73  sm = segment_manager_get (sm_index);
74  sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
75  }));
76  /* *INDENT-ON* */
77 
78  for (i = 0; i < vec_len (handles); i++)
79  {
80  a->app_index = app->app_index;
81  a->wrk_map_index = app_wrk->wrk_map_index;
82  a->handle = handles[i];
83  /* seg manager is removed when unbind completes */
84  (void) vnet_unlisten (a);
85  }
86 
87  /*
88  * Connects segment manager cleanup
89  */
90 
92  {
94  sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
95  sm->first_is_protected = 0;
97  }
98 
99  /* If first segment manager is used by a listener */
101  && app_wrk->first_segment_manager != app_wrk->connects_seg_manager)
102  {
104  sm->first_is_protected = 0;
105  sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
106  /* .. and has no fifos, e.g. it might be used for redirected sessions,
107  * remove it */
108  if (!segment_manager_has_fifos (sm))
110  }
111 
112  if (CLIB_DEBUG)
113  clib_memset (app_wrk, 0xfe, sizeof (*app_wrk));
114  pool_put (app_workers, app_wrk);
115 }
116 
119 {
120  app_worker_t *app_wrk;
121  app_wrk = app_worker_get_if_valid (wrk_index);
122  if (!app_wrk)
123  return 0;
124  return application_get_if_valid (app_wrk->app_index);
125 }
126 
127 static segment_manager_t *
129 {
130  segment_manager_t *sm = 0;
131 
132  /* If the first segment manager is not in use, don't allocate a new one */
134  && app_wrk->first_segment_manager_in_use == 0)
135  {
137  app_wrk->first_segment_manager_in_use = 1;
138  return sm;
139  }
140 
141  sm = segment_manager_alloc ();
142  sm->app_wrk_index = app_wrk->wrk_index;
143 
144  return sm;
145 }
146 
147 static int
149 {
150  svm_fifo_t *rx_fifo = 0, *tx_fifo = 0;
151  int rv;
152 
154  &rx_fifo, &tx_fifo)))
155  return rv;
156 
157  rx_fifo->master_session_index = s->session_index;
158  rx_fifo->master_thread_index = s->thread_index;
159 
160  tx_fifo->master_session_index = s->session_index;
161  tx_fifo->master_thread_index = s->thread_index;
162 
163  s->rx_fifo = rx_fifo;
164  s->tx_fifo = tx_fifo;
165  return 0;
166 }
167 
168 int
170 {
171  segment_manager_t *sm;
172 
173  /* Allocate segment manager. All sessions derived out of a listen session
174  * have fifos allocated by the same segment manager. */
175  if (!(sm = app_worker_alloc_segment_manager (app_wrk)))
176  return -1;
177 
178  /* Keep track of the segment manager for the listener or this worker */
180  segment_manager_index (sm));
181 
183  {
184  if (!ls->rx_fifo && app_worker_alloc_session_fifos (sm, ls))
185  return -1;
186  }
187  return 0;
188 }
189 
190 int
192  app_listener_t * app_listener)
193 {
194  session_t *ls;
195 
196  if (clib_bitmap_get (app_listener->workers, app_wrk->wrk_map_index))
197  return VNET_API_ERROR_ADDRESS_IN_USE;
198 
199  app_listener->workers = clib_bitmap_set (app_listener->workers,
200  app_wrk->wrk_map_index, 1);
201 
202  if (app_listener->session_index != SESSION_INVALID_INDEX)
203  {
204  ls = session_get (app_listener->session_index, 0);
205  if (app_worker_init_listener (app_wrk, ls))
206  return -1;
207  }
208 
209  if (app_listener->local_index != SESSION_INVALID_INDEX)
210  {
211  ls = session_get (app_listener->local_index, 0);
212  if (app_worker_init_listener (app_wrk, ls))
213  return -1;
214  }
215 
216  return 0;
217 }
218 
219 static void
221 {
222  session_handle_t handle;
223  segment_manager_t *sm;
224  uword *sm_indexp;
225 
226  handle = listen_session_get_handle (ls);
227  sm_indexp = hash_get (app_wrk->listeners_table, handle);
228  if (PREDICT_FALSE (!sm_indexp))
229  return;
230 
231  sm = segment_manager_get (*sm_indexp);
232  if (app_wrk->first_segment_manager == *sm_indexp)
233  {
234  /* Delete sessions but don't remove segment manager */
235  app_wrk->first_segment_manager_in_use = 0;
237  }
238  else
239  {
241  }
242  hash_unset (app_wrk->listeners_table, handle);
243 }
244 
245 int
247 {
248  session_t *ls;
249 
250  if (!clib_bitmap_get (al->workers, app_wrk->wrk_map_index))
251  return 0;
252 
254  {
256  app_worker_stop_listen_session (app_wrk, ls);
257  }
258 
260  {
261  ls = listen_session_get (al->local_index);
262  app_worker_stop_listen_session (app_wrk, ls);
263  }
264 
266  if (clib_bitmap_is_zero (al->workers))
268 
269  return 0;
270 }
271 
272 int
274 {
275  app_worker_t *app_wrk;
276  segment_manager_t *sm;
278 
280  app_wrk = application_listener_select_worker (listener);
281  s->app_wrk_index = app_wrk->wrk_index;
282 
283  sm = app_worker_get_listen_segment_manager (app_wrk, listener);
284  if (app_worker_alloc_session_fifos (sm, s))
285  return -1;
286 
287  return 0;
288 }
289 
290 int
292 {
293  application_t *app = application_get (app_wrk->app_index);
294  return app->cb_fns.session_accept_callback (s);
295 }
296 
297 int
299 {
300  application_t *app = application_get (app_wrk->app_index);
301  segment_manager_t *sm;
302 
303  /* Allocate fifos for session, unless the app is a builtin proxy */
304  if (!application_is_builtin_proxy (app))
305  {
307  if (app_worker_alloc_session_fifos (sm, s))
308  return -1;
309  }
310  return 0;
311 }
312 
313 int
315 {
316  application_t *app = application_get (app_wrk->app_index);
317  return app->cb_fns.session_connected_callback (app_wrk->wrk_index, opaque,
318  s, s == 0 /* is_fail */ );
319 }
320 
321 int
323 {
324  application_t *app = application_get (app_wrk->app_index);
326  return 0;
327 }
328 
329 int
331 {
332  application_t *app = application_get (app_wrk->app_index);
335  return 0;
336 }
337 
338 int
340 {
341  application_t *app = application_get (app_wrk->app_index);
343  return 0;
344 }
345 
346 int
349 {
350  application_t *app = application_get (app_wrk->app_index);
352  app->cb_fns.session_cleanup_callback (s, ntf);
353  return 0;
354 }
355 
356 int
358 {
359  application_t *app = application_get (app_wrk->app_index);
361  return 0;
362 }
363 
364 int
366 {
367  application_t *app = application_get (app_wrk->app_index);
368 
370  return 0;
371 
373  return 0;
374 }
375 
376 int
378  session_handle_t new_sh)
379 {
380  application_t *app = application_get (app_wrk->app_index);
381  app->cb_fns.session_migrate_callback (s, new_sh);
382  return 0;
383 }
384 
385 int
387 {
388  segment_manager_t *sm;
389  svm_fifo_t *rxf, *txf;
390 
391  if (s->session_state == SESSION_STATE_LISTENING)
392  return application_change_listener_owner (s, app_wrk);
393 
394  s->app_wrk_index = app_wrk->wrk_index;
395 
396  rxf = s->rx_fifo;
397  txf = s->tx_fifo;
398 
399  if (!rxf || !txf)
400  return 0;
401 
402  s->rx_fifo = 0;
403  s->tx_fifo = 0;
404 
406  if (app_worker_alloc_session_fifos (sm, s))
407  return -1;
408 
409  if (!svm_fifo_is_empty_cons (rxf))
410  svm_fifo_clone (s->rx_fifo, rxf);
411 
412  if (!svm_fifo_is_empty_cons (txf))
413  svm_fifo_clone (s->tx_fifo, txf);
414 
416 
417  return 0;
418 }
419 
420 int
422  u32 api_context)
423 {
424  int rv;
425 
426  /* Make sure we have a segment manager for connects */
428 
429  if ((rv = session_open (app->wrk_index, sep, api_context)))
430  return rv;
431 
432  return 0;
433 }
434 
435 int
437 {
438  segment_manager_t *sm;
439 
441  {
442  sm = app_worker_alloc_segment_manager (app_wrk);
443  if (sm == 0)
444  return -1;
446  }
447  return 0;
448 }
449 
452 {
453  ASSERT (app->connects_seg_manager != (u32) ~ 0);
455 }
456 
459 {
460  if (app_wrk->connects_seg_manager == (u32) ~ 0)
462  return segment_manager_get (app_wrk->connects_seg_manager);
463 }
464 
468 {
469  uword *smp;
470  smp = hash_get (app->listeners_table, listen_session_get_handle (listener));
471  ASSERT (smp != 0);
472  return segment_manager_get (*smp);
473 }
474 
475 session_t *
477  u8 transport_proto)
478 {
480  u64 handle;
481  u32 sm_index;
482  u8 sst;
483 
484  sst = session_type_from_proto_and_ip (transport_proto,
485  fib_proto == FIB_PROTOCOL_IP4);
486 
487  /* *INDENT-OFF* */
488  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
489  listener = listen_session_get_from_handle (handle);
490  if (listener->session_type == sst
491  && !(listener->flags & SESSION_F_PROXY))
492  return listener;
493  }));
494  /* *INDENT-ON* */
495 
496  return 0;
497 }
498 
499 session_t *
501  u8 transport_proto)
502 {
504  u64 handle;
505  u32 sm_index;
506  u8 sst;
507 
508  sst = session_type_from_proto_and_ip (transport_proto,
509  fib_proto == FIB_PROTOCOL_IP4);
510 
511  /* *INDENT-OFF* */
512  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
513  listener = listen_session_get_from_handle (handle);
514  if (listener->session_type == sst && (listener->flags & SESSION_F_PROXY))
515  return listener;
516  }));
517  /* *INDENT-ON* */
518 
519  return 0;
520 }
521 
522 /**
523  * Send an API message to the external app, to map new segment
524  */
525 int
526 app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
527 {
528  application_t *app = application_get (app_wrk->app_index);
529 
530  return app->cb_fns.add_segment_callback (app_wrk->wrk_index,
531  segment_handle);
532 }
533 
534 int
535 app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
536 {
537  application_t *app = application_get (app_wrk->app_index);
538  return app->cb_fns.del_segment_callback (app_wrk->wrk_index,
539  segment_handle);
540 }
541 
542 static inline u8
544 {
545  return app_wrk->app_is_builtin;
546 }
547 
548 static inline int
550 {
551  session_event_t *evt;
552  svm_msg_q_msg_t msg;
553  svm_msg_q_t *mq;
554 
555  if (app_worker_application_is_builtin (app_wrk))
556  return app_worker_builtin_rx (app_wrk, s);
557 
558  /* Make sure the session is in established state within external apps.
559  * Should be removed once we confirm closes to apps */
560  if (PREDICT_FALSE (s->session_state != SESSION_STATE_READY
561  && s->session_state != SESSION_STATE_LISTENING))
562  return 0;
563 
564  if (svm_fifo_has_event (s->rx_fifo))
565  return 0;
566 
567  mq = app_wrk->event_queue;
568  svm_msg_q_lock (mq);
569 
570  if (PREDICT_FALSE (svm_msg_q_is_full (mq)))
571  {
572  clib_warning ("evt q full");
573  svm_msg_q_unlock (mq);
574  return -1;
575  }
576 
578  {
579  clib_warning ("evt q rings full");
580  svm_msg_q_unlock (mq);
581  return -1;
582  }
583 
585  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
586  evt->session_index = s->rx_fifo->client_session_index;
587  evt->event_type = SESSION_IO_EVT_RX;
588 
589  (void) svm_fifo_set_event (s->rx_fifo);
590  svm_msg_q_add_and_unlock (mq, &msg);
591 
592  return 0;
593 }
594 
595 static inline int
597 {
598  svm_msg_q_t *mq;
599  session_event_t *evt;
600  svm_msg_q_msg_t msg;
601 
602  if (app_worker_application_is_builtin (app_wrk))
603  return app_worker_builtin_tx (app_wrk, s);
604 
605  mq = app_wrk->event_queue;
606  svm_msg_q_lock (mq);
607 
608  if (PREDICT_FALSE (svm_msg_q_is_full (mq)))
609  {
610  clib_warning ("evt q full");
611  svm_msg_q_unlock (mq);
612  return -1;
613  }
614 
616  {
617  clib_warning ("evt q rings full");
618  svm_msg_q_unlock (mq);
619  return -1;
620  }
621 
623  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
624  evt->event_type = SESSION_IO_EVT_TX;
625  evt->session_index = s->tx_fifo->client_session_index;
626 
627  svm_msg_q_add_and_unlock (mq, &msg);
628  return 0;
629 }
630 
631 /* *INDENT-OFF* */
633  session_t *s);
637 };
638 /* *INDENT-ON* */
639 
640 /**
641  * Send event to application
642  *
643  * Logic from queue perspective is blocking. However, if queue is full,
644  * we return.
645  */
646 int
648  u8 evt_type)
649 {
650  return app_send_evt_handler_fns[evt_type] (app, s);
651 }
652 
653 u8 *
654 format_app_worker_listener (u8 * s, va_list * args)
655 {
656  app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
657  u64 handle = va_arg (*args, u64);
658  u32 sm_index = va_arg (*args, u32);
659  int verbose = va_arg (*args, int);
661  const u8 *app_name;
662  u8 *str;
663 
664  if (!app_wrk)
665  {
666  if (verbose)
667  s = format (s, "%-40s%-25s%=10s%-15s%-15s%-10s", "Connection", "App",
668  "Wrk", "API Client", "ListenerID", "SegManager");
669  else
670  s = format (s, "%-40s%-25s%=10s", "Connection", "App", "Wrk");
671 
672  return s;
673  }
674 
675  app_name = application_name_from_index (app_wrk->app_index);
676  listener = listen_session_get_from_handle (handle);
677  str = format (0, "%U", format_session, listener, verbose);
678 
679  if (verbose)
680  {
681  char buf[32];
682  sprintf (buf, "%u(%u)", app_wrk->wrk_map_index, app_wrk->wrk_index);
683  s = format (s, "%-40s%-25s%=10s%-15u%-15u%-10u", str, app_name,
684  buf, app_wrk->api_client_index, handle, sm_index);
685  }
686  else
687  s = format (s, "%-40s%-25s%=10u", str, app_name, app_wrk->wrk_map_index);
688 
689  return s;
690 }
691 
692 u8 *
693 format_app_worker (u8 * s, va_list * args)
694 {
695  app_worker_t *app_wrk = va_arg (*args, app_worker_t *);
696  u32 indent = 1;
697 
698  s = format (s, "%U wrk-index %u app-index %u map-index %u "
699  "api-client-index %d\n", format_white_space, indent,
700  app_wrk->wrk_index, app_wrk->app_index, app_wrk->wrk_map_index,
701  app_wrk->api_client_index);
702  return s;
703 }
704 
705 void
706 app_worker_format_connects (app_worker_t * app_wrk, int verbose)
707 {
708  segment_manager_t *sm;
709 
710  /* Header */
711  if (!app_wrk)
712  {
713  segment_manager_format_sessions (0, verbose);
714  return;
715  }
716 
717  if (app_wrk->connects_seg_manager == (u32) ~ 0)
718  return;
719 
721  segment_manager_format_sessions (sm, verbose);
722 }
723 
724 /*
725  * fd.io coding-style-patch-verification: ON
726  *
727  * Local Variables:
728  * eval: (c-set-style "gnu")
729  * End:
730  */
u32 segment_manager_index(segment_manager_t *sm)
int app_worker_init_accepted(session_t *s)
#define hash_set(h, key, value)
Definition: hash.h:255
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
int session_open(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Ask transport to open connection to remote transport endpoint.
Definition: session.c:1147
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
#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
svm_fifo_t * tx_fifo
struct _vnet_unlisten_args_t vnet_unlisten_args_t
int application_change_listener_owner(session_t *s, app_worker_t *app_wrk)
Definition: application.c:1096
u32 session_index
Index in thread pool where session was allocated.
static segment_manager_t * app_worker_alloc_segment_manager(app_worker_t *app_wrk)
unsigned long u64
Definition: types.h:89
session_t * app_worker_first_listener(app_worker_t *app_wrk, u8 fib_proto, u8 transport_proto)
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, u32 opaque)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
static session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:546
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
int app_worker_builtin_tx(app_worker_t *app_wrk, session_t *s)
static int svm_fifo_is_empty_cons(svm_fifo_t *f)
Check if fifo is empty optimized for consumer.
Definition: svm_fifo.h:566
int app_worker_builtin_rx(app_worker_t *app_wrk, session_t *s)
u32 wrk_map_index
Worker index in app&#39;s map pool.
Definition: application.h:40
int i
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
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
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:295
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
int vnet_unlisten(vnet_unlisten_args_t *a)
Definition: application.c:1045
int app_worker_reset_notify(app_worker_t *app_wrk, session_t *s)
void(* session_reset_callback)(session_t *s)
Notify app that session was reset.
uword * listeners_table
Lookup tables for listeners.
Definition: application.h:52
u8 app_is_builtin
Definition: application.h:65
static u8 app_worker_application_is_builtin(app_worker_t *app_wrk)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:237
u32 connects_seg_manager
Segment manager used for outgoing connects issued by the app.
Definition: application.h:49
static int app_send_io_evt_tx(app_worker_t *app_wrk, session_t *s)
unsigned char u8
Definition: types.h:56
application_t * application_get_if_valid(u32 app_index)
Definition: application.c:434
struct _svm_fifo svm_fifo_t
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
static int app_send_io_evt_rx(app_worker_t *app_wrk, session_t *s)
void(* session_migrate_callback)(session_t *s, session_handle_t new_sh)
Notify app that session pool migration happened.
int app_worker_connect_session(app_worker_t *app, session_endpoint_t *sep, u32 api_context)
application_t * app_worker_get_app(u32 wrk_index)
int(* builtin_app_rx_callback)(session_t *session)
Direct RX callback for built-in application.
void svm_fifo_clone(svm_fifo_t *df, svm_fifo_t *sf)
Clones fifo.
Definition: svm_fifo.c:1130
u32 first_segment_manager
First segment manager has in the the first segment the application&#39;s event fifo.
Definition: application.h:59
static int app_worker_alloc_session_fifos(segment_manager_t *sm, session_t *s)
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
u32 local_index
local listening session index
Definition: application.h:79
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
int app_worker_cleanup_notify(app_worker_t *app_wrk, session_t *s, session_cleanup_ntf_t ntf)
u32 session_index
global listening session index
Definition: application.h:80
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
unsigned int u32
Definition: types.h:88
app_worker_t * app_worker_alloc(application_t *app)
int app_worker_transport_closed_notify(app_worker_t *app_wrk, session_t *s)
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
#define hash_get(h, key)
Definition: hash.h:249
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:519
void app_worker_free(app_worker_t *app_wrk)
u8 * format_app_worker_listener(u8 *s, va_list *args)
int(* session_connected_callback)(u32 app_wrk_index, u32 opaque, session_t *s, u8 code)
Connection request callback.
int app_worker_stop_listen(app_worker_t *app_wrk, app_listener_t *al)
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
Definition: application.c:360
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:287
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
u8 segment_manager_has_fifos(segment_manager_t *sm)
#define PREDICT_FALSE(x)
Definition: clib.h:111
int(* add_segment_callback)(u32 app_wrk_index, u64 segment_handle)
Notify server of new segment.
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
segment_manager_t * app_worker_get_or_alloc_connect_segment_manager(app_worker_t *app_wrk)
#define SESSION_INVALID_INDEX
Definition: session_types.h:22
int() app_send_evt_handler_fn(app_worker_t *app, session_t *s)
static void app_worker_stop_listen_session(app_worker_t *app_wrk, session_t *ls)
static u64 listen_session_get_handle(session_t *s)
Definition: session.h:538
int(* del_segment_callback)(u32 app_wrk_index, u64 segment_handle)
Notify server of new segment.
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
#define SEGMENT_MANAGER_INVALID_APP_INDEX
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:749
session_t * app_worker_proxy_listener(app_worker_t *app_wrk, u8 fib_proto, u8 transport_proto)
session_handle_t listener_handle
Parent listener session index if the result of an accept.
int app_worker_migrate_notify(app_worker_t *app_wrk, session_t *s, session_handle_t new_sh)
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
segment_manager_t * segment_manager_alloc(void)
void(* session_cleanup_callback)(session_t *s, session_cleanup_ntf_t ntf)
Notify app that session or transport are about to be removed.
#define clib_warning(format, args...)
Definition: error.h:59
clib_bitmap_t * workers
workers accepting connections
Definition: application.h:75
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:284
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
int(* builtin_app_tx_callback)(session_t *session)
Direct TX callback for built-in application.
int app_worker_own_session(app_worker_t *app_wrk, session_t *s)
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
application_t * application_get(u32 app_index)
Definition: application.c:426
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
#define ASSERT(truth)
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.
app_worker_t * application_listener_select_worker(session_t *ls)
Definition: application.c:672
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:95
static app_send_evt_handler_fn *const app_send_evt_handler_fns[2]
u8 thread_index
Index of the thread that allocated the session.
app_worker_t * app_worker_get(u32 wrk_index)
u32 app_index
App index in app pool.
Definition: application.h:89
u64 session_handle_t
void app_worker_format_connects(app_worker_t *app_wrk, int verbose)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void(* session_disconnect_callback)(session_t *s)
Notify app that session is closing.
volatile u8 session_state
State in session layer state machine.
segment_manager_t * app_worker_get_listen_segment_manager(app_worker_t *app, session_t *listener)
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.
u8 * name
Name registered by builtin apps.
Definition: application.h:104
u64 uword
Definition: types.h:112
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions &#39;owned&#39; by a segment manager.
connectionless service
struct _segment_manager segment_manager_t
int app_worker_start_listen(app_worker_t *app_wrk, app_listener_t *app_listener)
segment_manager_t * segment_manager_get(u32 index)
void app_listener_cleanup(app_listener_t *al)
Definition: application.c:238
session_cleanup_ntf_t
void(* session_transport_closed_callback)(session_t *s)
Notify app that transport is closed.
u32 app_index
Index of owning app.
Definition: application.h:43
u8 * format_app_worker(u8 *s, va_list *args)
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
u32 app_wrk_index
Index of the app worker that owns the session.
static int svm_fifo_has_event(svm_fifo_t *f)
Check if fifo has io event.
Definition: svm_fifo.h:735
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
int app_worker_init_listener(app_worker_t *app_wrk, session_t *ls)
static app_worker_t * app_workers
Pool of workers associated to apps.
int application_is_builtin_proxy(application_t *app)
Definition: application.c:1141
u32 api_client_index
API index for the worker.
Definition: application.h:63
struct _session_endpoint session_endpoint_t
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
svm_msg_q_t * event_queue
Application listens for events on this svm queue.
Definition: application.h:46
static transport_service_type_t session_transport_service_type(session_t *s)
#define APP_INVALID_SEGMENT_MANAGER_INDEX
Definition: application.h:171
static u8 svm_msg_q_is_full(svm_msg_q_t *mq)
Check if message queue is full.
#define APP_DBG(_fmt, _args...)
Definition: application.h:29
segment_manager_t * app_worker_get_connect_segment_manager(app_worker_t *app)
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.
int app_worker_alloc_connects_segment_manager(app_worker_t *app_wrk)
static session_t * listen_session_get(u32 ls_index)
Definition: session.h:569
u8 first_segment_manager_in_use
Definition: application.h:60