FD.io VPP  v19.04.1-1-ge4a0f9f
Vector Packet Processing
session_node.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 <math.h>
17 #include <vlib/vlib.h>
18 #include <vnet/vnet.h>
19 #include <vppinfra/elog.h>
20 #include <vnet/session/transport.h>
21 #include <vnet/session/session.h>
26 #include <svm/queue.h>
27 
28 static void session_mq_accepted_reply_handler (void *data);
29 
30 static void
31 accepted_notify_cb (void *data, u32 data_len)
32 {
34 }
35 
36 static void
38 {
40  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
41  session_state_t old_state;
42  app_worker_t *app_wrk;
43  session_t *s;
44 
45  /* Server isn't interested, kill the session */
46  if (mp->retval)
47  {
48  a->app_index = mp->context;
49  a->handle = mp->handle;
51  return;
52  }
53 
54  /* Mail this back from the main thread. We're not polling in main
55  * thread so we're using other workers for notifications. */
56  if (vlib_num_workers () && vlib_get_thread_index () != 0
57  && session_thread_from_handle (mp->handle) == 0)
58  {
61  return;
62  }
63 
65  if (!s)
66  return;
67 
68  app_wrk = app_worker_get (s->app_wrk_index);
69  if (app_wrk->app_index != mp->context)
70  {
71  clib_warning ("app doesn't own session");
72  return;
73  }
74 
75  if (!session_has_transport (s))
76  {
79  return;
80  }
81  else
82  {
83  old_state = s->session_state;
85  if (!svm_fifo_is_empty (s->rx_fifo))
87 
88  /* Closed while waiting for app to reply. Resend disconnect */
89  if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
90  {
91  app_worker_close_notify (app_wrk, s);
92  s->session_state = old_state;
93  return;
94  }
95  }
96 }
97 
98 static void
100 {
101  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
103  app_worker_t *app_wrk;
104  session_t *s;
105  application_t *app;
106  u32 index, thread_index;
107 
108  mp = (session_reset_reply_msg_t *) data;
109  app = application_lookup (mp->context);
110  if (!app)
111  return;
112 
113  session_parse_handle (mp->handle, &index, &thread_index);
114  s = session_get_if_valid (index, thread_index);
115 
116  /* Session was already closed or already cleaned up */
118  return;
119 
120  app_wrk = app_worker_get (s->app_wrk_index);
121  if (!app_wrk || app_wrk->app_index != app->app_index)
122  {
123  clib_warning ("App % does not own handle 0x%lx!", app->app_index,
124  mp->handle);
125  return;
126  }
127 
128  /* Client objected to resetting the session, log and continue */
129  if (mp->retval)
130  {
131  clib_warning ("client retval %d", mp->retval);
132  return;
133  }
134 
135  /* This comes as a response to a reset, transport only waiting for
136  * confirmation to remove connection state, no need to disconnect */
137  a->handle = mp->handle;
138  a->app_index = app->app_index;
140 }
141 
142 static void
144 {
146  vnet_disconnect_args_t _a, *a = &_a;
147  svm_msg_q_msg_t _msg, *msg = &_msg;
149  app_worker_t *app_wrk;
150  session_event_t *evt;
151  session_t *s;
152  application_t *app;
153  int rv = 0;
154 
155  mp = (session_disconnected_msg_t *) data;
156  if (!(s = session_get_from_handle_if_valid (mp->handle)))
157  {
158  clib_warning ("could not disconnect handle %llu", mp->handle);
159  return;
160  }
161  app_wrk = app_worker_get (s->app_wrk_index);
162  app = application_lookup (mp->client_index);
163  if (!(app_wrk && app && app->app_index == app_wrk->app_index))
164  {
165  clib_warning ("could not disconnect session: %llu app: %u",
166  mp->handle, mp->client_index);
167  return;
168  }
169 
170  a->handle = mp->handle;
171  a->app_index = app_wrk->wrk_index;
172  rv = vnet_disconnect_session (a);
173 
176  SVM_Q_WAIT, msg);
177  svm_msg_q_unlock (app_wrk->event_queue);
178  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
179  clib_memset (evt, 0, sizeof (*evt));
180  evt->event_type = SESSION_CTRL_EVT_DISCONNECTED_REPLY;
181  rmp = (session_disconnected_reply_msg_t *) evt->data;
182  rmp->handle = mp->handle;
183  rmp->context = mp->context;
184  rmp->retval = rv;
185  svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
186 }
187 
188 static void
190 {
192  vnet_disconnect_args_t _a, *a = &_a;
193  application_t *app;
194 
195  mp = (session_disconnected_reply_msg_t *) data;
196 
197  /* Client objected to disconnecting the session, log and continue */
198  if (mp->retval)
199  {
200  clib_warning ("client retval %d", mp->retval);
201  return;
202  }
203 
204  /* Disconnect has been confirmed. Confirm close to transport */
205  app = application_lookup (mp->context);
206  if (app)
207  {
208  a->handle = mp->handle;
209  a->app_index = app->app_index;
211  }
212 }
213 
214 static void
216 {
219  svm_msg_q_msg_t _msg, *msg = &_msg;
220  app_worker_t *app_wrk;
221  u32 owner_app_wrk_map;
222  session_event_t *evt;
223  session_t *s;
224  application_t *app;
225 
226  app = application_lookup (mp->client_index);
227  if (!app)
228  return;
229  if (!(s = session_get_from_handle_if_valid (mp->handle)))
230  {
231  clib_warning ("invalid handle %llu", mp->handle);
232  return;
233  }
234  app_wrk = app_worker_get (s->app_wrk_index);
235  if (app_wrk->app_index != app->app_index)
236  {
237  clib_warning ("app %u does not own session %llu", app->app_index,
238  mp->handle);
239  return;
240  }
241  owner_app_wrk_map = app_wrk->wrk_map_index;
242  app_wrk = application_get_worker (app, mp->wrk_index);
243 
244  /* This needs to come from the new owner */
245  if (mp->req_wrk_index == owner_app_wrk_map)
246  {
248 
251  SVM_Q_WAIT, msg);
252  svm_msg_q_unlock (app_wrk->event_queue);
253  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
254  clib_memset (evt, 0, sizeof (*evt));
255  evt->event_type = SESSION_CTRL_EVT_REQ_WORKER_UPDATE;
256  wump = (session_req_worker_update_msg_t *) evt->data;
257  wump->session_handle = mp->handle;
258  svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
259  return;
260  }
261 
262  app_worker_own_session (app_wrk, s);
263 
264  /*
265  * Send reply
266  */
269  SVM_Q_WAIT, msg);
270  svm_msg_q_unlock (app_wrk->event_queue);
271  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
272  clib_memset (evt, 0, sizeof (*evt));
273  evt->event_type = SESSION_CTRL_EVT_WORKER_UPDATE_REPLY;
274  rmp = (session_worker_update_reply_msg_t *) evt->data;
275  rmp->handle = mp->handle;
276  rmp->rx_fifo = pointer_to_uword (s->rx_fifo);
277  rmp->tx_fifo = pointer_to_uword (s->tx_fifo);
279  svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
280 
281  /*
282  * Retransmit messages that may have been lost
283  */
284  if (s->tx_fifo && !svm_fifo_is_empty (s->tx_fifo))
286 
287  if (s->rx_fifo && !svm_fifo_is_empty (s->rx_fifo))
289 
291  app_worker_close_notify (app_wrk, s);
292 }
293 
295 
296 typedef struct
297 {
301 
302 /* packet trace format function */
303 static u8 *
304 format_session_queue_trace (u8 * s, va_list * args)
305 {
306  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
307  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
308  session_queue_trace_t *t = va_arg (*args, session_queue_trace_t *);
309 
310  s = format (s, "SESSION_QUEUE: session index %d, server thread index %d",
312  return s;
313 }
314 
315 #define foreach_session_queue_error \
316 _(TX, "Packets transmitted") \
317 _(TIMER, "Timer events") \
318 _(NO_BUFFER, "Out of buffers")
319 
320 typedef enum
321 {
322 #define _(sym,str) SESSION_QUEUE_ERROR_##sym,
324 #undef _
327 
328 static char *session_queue_error_strings[] = {
329 #define _(sym,string) string,
331 #undef _
332 };
333 
334 enum
335 {
339 };
340 
341 static void
343  u32 next_index, u32 * to_next, u16 n_segs,
344  session_t * s, u32 n_trace)
345 {
347  vlib_buffer_t *b;
348  int i;
349 
350  for (i = 0; i < clib_min (n_trace, n_segs); i++)
351  {
352  b = vlib_get_buffer (vm, to_next[i - n_segs]);
353  vlib_trace_buffer (vm, node, next_index, b, 1 /* follow_chain */ );
354  t = vlib_add_trace (vm, node, b, sizeof (*t));
357  }
358  vlib_set_trace_count (vm, node, n_trace - i);
359 }
360 
361 always_inline void
363  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
364 {
365  vlib_buffer_t *chain_b, *prev_b;
366  u32 chain_bi0, to_deq, left_from_seg;
367  session_worker_t *wrk;
368  u16 len_to_deq, n_bytes_read;
369  u8 *data, j;
370 
371  wrk = session_main_get_worker (ctx->s->thread_index);
372  b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
374 
375  chain_b = b;
376  left_from_seg = clib_min (ctx->snd_mss - b->current_length,
377  ctx->left_to_snd);
378  to_deq = left_from_seg;
379  for (j = 1; j < ctx->n_bufs_per_seg; j++)
380  {
381  prev_b = chain_b;
382  len_to_deq = clib_min (to_deq, ctx->deq_per_buf);
383 
384  *n_bufs -= 1;
385  chain_bi0 = wrk->tx_buffers[*n_bufs];
386  chain_b = vlib_get_buffer (vm, chain_bi0);
387  chain_b->current_data = 0;
388  data = vlib_buffer_get_current (chain_b);
389  if (peek_data)
390  {
391  n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo,
392  ctx->tx_offset, len_to_deq, data);
393  ctx->tx_offset += n_bytes_read;
394  }
395  else
396  {
397  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
398  {
399  svm_fifo_t *f = ctx->s->tx_fifo;
400  session_dgram_hdr_t *hdr = &ctx->hdr;
401  u16 deq_now;
402  deq_now = clib_min (hdr->data_length - hdr->data_offset,
403  len_to_deq);
404  n_bytes_read = svm_fifo_peek (f, hdr->data_offset, deq_now,
405  data);
406  ASSERT (n_bytes_read > 0);
407 
408  hdr->data_offset += n_bytes_read;
409  if (hdr->data_offset == hdr->data_length)
410  {
412  svm_fifo_dequeue_drop (f, offset);
413  }
414  }
415  else
416  n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->tx_fifo,
417  len_to_deq, data);
418  }
419  ASSERT (n_bytes_read == len_to_deq);
420  chain_b->current_length = n_bytes_read;
422 
423  /* update previous buffer */
424  prev_b->next_buffer = chain_bi0;
425  prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
426 
427  /* update current buffer */
428  chain_b->next_buffer = 0;
429 
430  to_deq -= n_bytes_read;
431  if (to_deq == 0)
432  break;
433  }
434  ASSERT (to_deq == 0
435  && b->total_length_not_including_first_buffer == left_from_seg);
436  ctx->left_to_snd -= left_from_seg;
437 }
438 
439 always_inline void
441  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
442 {
443  u32 len_to_deq;
444  u8 *data0;
445  int n_bytes_read;
446 
447  /*
448  * Start with the first buffer in chain
449  */
450  b->error = 0;
451  b->flags = VNET_BUFFER_F_LOCALLY_ORIGINATED;
452  b->current_data = 0;
453 
455  len_to_deq = clib_min (ctx->left_to_snd, ctx->deq_per_first_buf);
456 
457  if (peek_data)
458  {
459  n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo, ctx->tx_offset,
460  len_to_deq, data0);
461  ASSERT (n_bytes_read > 0);
462  /* Keep track of progress locally, transport is also supposed to
463  * increment it independently when pushing the header */
464  ctx->tx_offset += n_bytes_read;
465  }
466  else
467  {
468  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
469  {
470  session_dgram_hdr_t *hdr = &ctx->hdr;
471  svm_fifo_t *f = ctx->s->tx_fifo;
472  u16 deq_now;
473  u32 offset;
474 
475  ASSERT (hdr->data_length > hdr->data_offset);
476  deq_now = clib_min (hdr->data_length - hdr->data_offset,
477  len_to_deq);
478  offset = hdr->data_offset + SESSION_CONN_HDR_LEN;
479  n_bytes_read = svm_fifo_peek (f, offset, deq_now, data0);
480  ASSERT (n_bytes_read > 0);
481 
483  {
484  ip_copy (&ctx->tc->rmt_ip, &hdr->rmt_ip, ctx->tc->is_ip4);
485  ctx->tc->rmt_port = hdr->rmt_port;
486  }
487  hdr->data_offset += n_bytes_read;
488  if (hdr->data_offset == hdr->data_length)
489  {
490  offset = hdr->data_length + SESSION_CONN_HDR_LEN;
491  svm_fifo_dequeue_drop (f, offset);
492  }
493  }
494  else
495  {
496  n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->tx_fifo,
497  len_to_deq, data0);
498  ASSERT (n_bytes_read > 0);
499  }
500  }
501  b->current_length = n_bytes_read;
502  ctx->left_to_snd -= n_bytes_read;
503 
504  /*
505  * Fill in the remaining buffers in the chain, if any
506  */
507  if (PREDICT_FALSE (ctx->n_bufs_per_seg > 1 && ctx->left_to_snd))
508  session_tx_fifo_chain_tail (vm, ctx, b, n_bufs, peek_data);
509 
510  /* *INDENT-OFF* */
511  SESSION_EVT_DBG(SESSION_EVT_DEQ, ctx->s, ({
512  ed->data[0] = SESSION_IO_EVT_TX;
513  ed->data[1] = ctx->max_dequeue;
514  ed->data[2] = len_to_deq;
515  ed->data[3] = ctx->left_to_snd;
516  }));
517  /* *INDENT-ON* */
518 }
519 
522 {
523  if (peek_data)
524  {
525  /* Can retransmit for closed sessions but can't send new data if
526  * session is not ready or closed */
528  return 1;
530  return 2;
531  }
532  return 0;
533 }
534 
537 {
538  if (peek_data)
539  {
540  return ctx->transport_vft->get_connection (ctx->s->connection_index,
541  ctx->s->thread_index);
542  }
543  else
544  {
546  return ctx->transport_vft->get_listener (ctx->s->connection_index);
547  else
548  {
549  return ctx->transport_vft->get_connection (ctx->s->connection_index,
550  ctx->s->thread_index);
551  }
552  }
553 }
554 
555 always_inline void
557  u32 max_segs, u8 peek_data)
558 {
559  u32 n_bytes_per_buf, n_bytes_per_seg;
560  ctx->max_dequeue = svm_fifo_max_dequeue (ctx->s->tx_fifo);
561  if (peek_data)
562  {
563  /* Offset in rx fifo from where to peek data */
564  ctx->tx_offset = ctx->transport_vft->tx_fifo_offset (ctx->tc);
565  if (PREDICT_FALSE (ctx->tx_offset >= ctx->max_dequeue))
566  {
567  ctx->max_len_to_snd = 0;
568  return;
569  }
570  ctx->max_dequeue -= ctx->tx_offset;
571  }
572  else
573  {
574  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
575  {
576  if (ctx->max_dequeue <= sizeof (ctx->hdr))
577  {
578  ctx->max_len_to_snd = 0;
579  return;
580  }
581  svm_fifo_peek (ctx->s->tx_fifo, 0, sizeof (ctx->hdr),
582  (u8 *) & ctx->hdr);
583  ASSERT (ctx->hdr.data_length > ctx->hdr.data_offset);
584  ctx->max_dequeue = ctx->hdr.data_length - ctx->hdr.data_offset;
585  }
586  }
587  ASSERT (ctx->max_dequeue > 0);
588 
589  /* Ensure we're not writing more than transport window allows */
590  if (ctx->max_dequeue < ctx->snd_space)
591  {
592  /* Constrained by tx queue. Try to send only fully formed segments */
593  ctx->max_len_to_snd =
594  (ctx->max_dequeue > ctx->snd_mss) ?
595  ctx->max_dequeue - ctx->max_dequeue % ctx->snd_mss : ctx->max_dequeue;
596  /* TODO Nagle ? */
597  }
598  else
599  {
600  /* Expectation is that snd_space0 is already a multiple of snd_mss */
601  ctx->max_len_to_snd = ctx->snd_space;
602  }
603 
604  /* Check if we're tx constrained by the node */
605  ctx->n_segs_per_evt = ceil ((f64) ctx->max_len_to_snd / ctx->snd_mss);
606  if (ctx->n_segs_per_evt > max_segs)
607  {
608  ctx->n_segs_per_evt = max_segs;
609  ctx->max_len_to_snd = max_segs * ctx->snd_mss;
610  }
611 
612  n_bytes_per_buf = vlib_buffer_get_default_data_size (vm);
613  ASSERT (n_bytes_per_buf > TRANSPORT_MAX_HDRS_LEN);
614  n_bytes_per_seg = TRANSPORT_MAX_HDRS_LEN + ctx->snd_mss;
615  ctx->n_bufs_per_seg = ceil ((f64) n_bytes_per_seg / n_bytes_per_buf);
616  ctx->deq_per_buf = clib_min (ctx->snd_mss, n_bytes_per_buf);
617  ctx->deq_per_first_buf = clib_min (ctx->snd_mss,
618  n_bytes_per_buf -
620 }
621 
622 always_inline int
624  session_worker_t * wrk,
625  session_event_t * e, int *n_tx_packets,
626  u8 peek_data)
627 {
628  u32 next_index, next0, next1, *to_next, n_left_to_next, n_left, pbi;
629  u32 n_trace = vlib_get_trace_count (vm, node), n_bufs_needed = 0;
631  session_tx_context_t *ctx = &wrk->ctx;
633  vlib_buffer_t *pb;
634  u16 n_bufs, rv;
635 
636  if (PREDICT_FALSE ((rv = session_tx_not_ready (ctx->s, peek_data))))
637  {
638  if (rv < 2)
639  vec_add1 (wrk->pending_event_vector, *e);
640  return SESSION_TX_NO_DATA;
641  }
642 
643  next_index = smm->session_type_to_next[ctx->s->session_type];
644  next0 = next1 = next_index;
645 
646  tp = session_get_transport_proto (ctx->s);
648  ctx->tc = session_tx_get_transport (ctx, peek_data);
649  ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc);
650 
651  if (PREDICT_FALSE (e->event_type == SESSION_IO_EVT_TX_FLUSH))
652  {
653  if (ctx->transport_vft->flush_data)
654  ctx->transport_vft->flush_data (ctx->tc);
655  }
656 
658  vm->clib_time.
659  last_cpu_time,
660  ctx->snd_mss);
661  if (ctx->snd_space == 0 || ctx->snd_mss == 0)
662  {
663  vec_add1 (wrk->pending_event_vector, *e);
664  return SESSION_TX_NO_DATA;
665  }
666 
667  /* Allow enqueuing of a new event */
669 
670  /* Check how much we can pull. */
671  session_tx_set_dequeue_params (vm, ctx, VLIB_FRAME_SIZE - *n_tx_packets,
672  peek_data);
673 
674  if (PREDICT_FALSE (!ctx->max_len_to_snd))
675  return SESSION_TX_NO_DATA;
676 
677  n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg;
678  vec_validate_aligned (wrk->tx_buffers, n_bufs_needed - 1,
680  n_bufs = vlib_buffer_alloc (vm, wrk->tx_buffers, n_bufs_needed);
681  if (PREDICT_FALSE (n_bufs < n_bufs_needed))
682  {
683  if (n_bufs)
684  vlib_buffer_free (vm, wrk->tx_buffers, n_bufs);
685  vec_add1 (wrk->pending_event_vector, *e);
686  return SESSION_TX_NO_BUFFERS;
687  }
688 
689  /*
690  * Write until we fill up a frame
691  */
692  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
693  if (PREDICT_FALSE (ctx->n_segs_per_evt > n_left_to_next))
694  {
695  ctx->n_segs_per_evt = n_left_to_next;
696  ctx->max_len_to_snd = ctx->snd_mss * n_left_to_next;
697  }
698  ctx->left_to_snd = ctx->max_len_to_snd;
699  n_left = ctx->n_segs_per_evt;
700 
701  while (n_left >= 4)
702  {
703  vlib_buffer_t *b0, *b1;
704  u32 bi0, bi1;
705 
706  pbi = wrk->tx_buffers[n_bufs - 3];
707  pb = vlib_get_buffer (vm, pbi);
708  vlib_prefetch_buffer_header (pb, STORE);
709  pbi = wrk->tx_buffers[n_bufs - 4];
710  pb = vlib_get_buffer (vm, pbi);
711  vlib_prefetch_buffer_header (pb, STORE);
712 
713  to_next[0] = bi0 = wrk->tx_buffers[--n_bufs];
714  to_next[1] = bi1 = wrk->tx_buffers[--n_bufs];
715 
716  b0 = vlib_get_buffer (vm, bi0);
717  b1 = vlib_get_buffer (vm, bi1);
718 
719  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
720  session_tx_fill_buffer (vm, ctx, b1, &n_bufs, peek_data);
721 
722  ctx->transport_vft->push_header (ctx->tc, b0);
723  ctx->transport_vft->push_header (ctx->tc, b1);
724 
725  to_next += 2;
726  n_left_to_next -= 2;
727  n_left -= 2;
728 
731 
732  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
733  n_left_to_next, bi0, bi1, next0,
734  next1);
735  }
736  while (n_left)
737  {
738  vlib_buffer_t *b0;
739  u32 bi0;
740 
741  if (n_left > 1)
742  {
743  pbi = wrk->tx_buffers[n_bufs - 2];
744  pb = vlib_get_buffer (vm, pbi);
745  vlib_prefetch_buffer_header (pb, STORE);
746  }
747 
748  to_next[0] = bi0 = wrk->tx_buffers[--n_bufs];
749  b0 = vlib_get_buffer (vm, bi0);
750  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
751 
752  /* Ask transport to push header after current_length and
753  * total_length_not_including_first_buffer are updated */
754  ctx->transport_vft->push_header (ctx->tc, b0);
755 
756  to_next += 1;
757  n_left_to_next -= 1;
758  n_left -= 1;
759 
761 
762  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
763  n_left_to_next, bi0, next0);
764  }
765 
766  if (PREDICT_FALSE (n_trace > 0))
767  session_tx_trace_frame (vm, node, next_index, to_next,
768  ctx->n_segs_per_evt, ctx->s, n_trace);
769  if (PREDICT_FALSE (n_bufs))
770  {
771  clib_warning ("not all buffers consumed");
772  vlib_buffer_free (vm, wrk->tx_buffers, n_bufs);
773  }
774  *n_tx_packets += ctx->n_segs_per_evt;
776  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
777 
778  /* If we couldn't dequeue all bytes mark as partially read */
779  ASSERT (ctx->left_to_snd == 0);
780  if (ctx->max_len_to_snd < ctx->max_dequeue)
781  if (svm_fifo_set_event (ctx->s->tx_fifo))
782  vec_add1 (wrk->pending_event_vector, *e);
783 
784  if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
785  {
786  /* Fix dgram pre header */
787  if (ctx->max_len_to_snd < ctx->max_dequeue)
788  svm_fifo_overwrite_head (ctx->s->tx_fifo, (u8 *) & ctx->hdr,
789  sizeof (session_dgram_pre_hdr_t));
790  /* More data needs to be read */
791  else if (svm_fifo_max_dequeue (ctx->s->tx_fifo) > 0)
792  if (svm_fifo_set_event (ctx->s->tx_fifo))
793  vec_add1 (wrk->pending_event_vector, *e);
794  }
795  return SESSION_TX_OK;
796 }
797 
798 int
800  session_worker_t * wrk,
801  session_event_t * e, int *n_tx_pkts)
802 {
803  return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 1);
804 }
805 
806 int
808  session_worker_t * wrk,
809  session_event_t * e, int *n_tx_pkts)
810 {
811  return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 0);
812 }
813 
814 int
816  vlib_node_runtime_t * node,
817  session_worker_t * wrk,
818  session_event_t * e, int *n_tx_pkts)
819 {
820  session_t *s = wrk->ctx.s;
821 
823  return 0;
826 }
827 
829 session_event_get_session (session_event_t * e, u8 thread_index)
830 {
831  return session_get_if_valid (e->session_index, thread_index);
832 }
833 
834 static void
836  u32 thread_index)
837 {
838  if (wrk->last_tx_packets)
839  {
840  f64 sample = now - wrk->last_vlib_time;
841  wrk->dispatch_period = (wrk->dispatch_period + sample) * 0.5;
842  }
843  wrk->last_vlib_time = now;
844 }
845 
846 static uword
848  vlib_frame_t * frame)
849 {
851  u32 thread_index = vm->thread_index, n_to_dequeue, n_events;
852  session_worker_t *wrk = &smm->wrk[thread_index];
853  session_event_t *e, *fifo_events;
854  svm_msg_q_msg_t _msg, *msg = &_msg;
855  f64 now = vlib_time_now (vm);
856  int n_tx_packets = 0, i, rv;
857  app_worker_t *app_wrk;
858  svm_msg_q_t *mq;
859  void (*fp) (void *);
860 
861  SESSION_EVT_DBG (SESSION_EVT_POLL_GAP_TRACK, smm, thread_index);
862 
863  /*
864  * Update transport time
865  */
866  session_update_dispatch_period (wrk, now, thread_index);
867  transport_update_time (now, thread_index);
868 
869  SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0);
870 
871  /* Make sure postponed events are handled first */
872  fifo_events = wrk->free_event_vector;
873  vec_append (fifo_events, wrk->postponed_event_vector);
874  _vec_len (wrk->postponed_event_vector) = 0;
875 
876  /* Try to dequeue what is available. Don't wait for lock.
877  * XXX: we may need priorities here */
878  mq = wrk->vpp_event_queue;
879  n_to_dequeue = svm_msg_q_size (mq);
880  if (n_to_dequeue && svm_msg_q_try_lock (mq) == 0)
881  {
882  for (i = 0; i < n_to_dequeue; i++)
883  {
884  vec_add2 (fifo_events, e, 1);
885  svm_msg_q_sub_w_lock (mq, msg);
886  /* Works because reply messages are smaller than a session evt.
887  * If we ever need to support bigger messages this needs to be
888  * fixed */
889  clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), sizeof (*e));
890  svm_msg_q_free_msg (mq, msg);
891  }
892  svm_msg_q_unlock (mq);
893  }
894 
895  vec_append (fifo_events, wrk->pending_event_vector);
896  vec_append (fifo_events, wrk->pending_disconnects);
897 
898  _vec_len (wrk->pending_event_vector) = 0;
899  _vec_len (wrk->pending_disconnects) = 0;
900 
901  n_events = vec_len (fifo_events);
902  if (PREDICT_FALSE (!n_events))
903  return 0;
904 
905  for (i = 0; i < n_events; i++)
906  {
907  session_t *s; /* $$$ prefetch 1 ahead maybe */
908  session_event_t *e;
909  u8 need_tx_ntf;
910 
911  e = &fifo_events[i];
912  switch (e->event_type)
913  {
915  case SESSION_IO_EVT_TX:
916  /* Don't try to send more that one frame per dispatch cycle */
917  if (n_tx_packets == VLIB_FRAME_SIZE)
918  {
919  vec_add1 (wrk->postponed_event_vector, *e);
920  break;
921  }
922 
923  s = session_event_get_session (e, thread_index);
924  if (PREDICT_FALSE (!s))
925  {
926  clib_warning ("session was freed!");
927  continue;
928  }
930  wrk->ctx.s = s;
931  /* Spray packets in per session type frames, since they go to
932  * different nodes */
933  rv = (smm->session_tx_fns[s->session_type]) (vm, node, wrk, e,
934  &n_tx_packets);
935  if (PREDICT_TRUE (rv == SESSION_TX_OK))
936  {
937  need_tx_ntf = svm_fifo_needs_tx_ntf (s->tx_fifo,
938  wrk->ctx.max_len_to_snd);
939  if (PREDICT_FALSE (need_tx_ntf))
941  }
942  else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
943  {
945  SESSION_QUEUE_ERROR_NO_BUFFER, 1);
946  continue;
947  }
948  break;
950  s = session_get_from_handle_if_valid (e->session_handle);
951  if (PREDICT_FALSE (!s))
952  break;
953 
954  /* Make sure session disconnects run after the pending list is
955  * drained, i.e., postpone if the first time. If not the first
956  * and the tx queue is still not empty, try to wait for some
957  * dispatch cycles */
958  if (!e->postponed
959  || (e->postponed < 200 && svm_fifo_max_dequeue (s->tx_fifo)))
960  {
961  e->postponed += 1;
962  vec_add1 (wrk->pending_disconnects, *e);
963  continue;
964  }
965 
967  break;
969  s = session_event_get_session (e, thread_index);
971  continue;
973  app_wrk = app_worker_get (s->app_wrk_index);
974  app_worker_builtin_rx (app_wrk, s);
975  break;
977  s = session_get_from_handle_if_valid (e->session_handle);
978  wrk->ctx.s = s;
979  if (PREDICT_TRUE (s != 0))
980  session_tx_fifo_dequeue_internal (vm, node, wrk, e,
981  &n_tx_packets);
982  break;
984  fp = e->rpc_args.fp;
985  (*fp) (e->rpc_args.arg);
986  break;
989  break;
992  break;
994  break;
997  break;
1000  break;
1003  break;
1004  default:
1005  clib_warning ("unhandled event type %d", e->event_type);
1006  }
1007  }
1008 
1009  _vec_len (fifo_events) = 0;
1010  wrk->free_event_vector = fifo_events;
1011  wrk->last_tx_packets = n_tx_packets;
1012 
1014  SESSION_QUEUE_ERROR_TX, n_tx_packets);
1015 
1016  SESSION_EVT_DBG (SESSION_EVT_DISPATCH_END, smm, thread_index);
1017 
1018  return n_tx_packets;
1019 }
1020 
1021 /* *INDENT-OFF* */
1023 {
1024  .function = session_queue_node_fn,
1025  .name = "session-queue",
1026  .format_trace = format_session_queue_trace,
1027  .type = VLIB_NODE_TYPE_INPUT,
1028  .n_errors = ARRAY_LEN (session_queue_error_strings),
1029  .error_strings = session_queue_error_strings,
1030  .state = VLIB_NODE_STATE_DISABLED,
1031 };
1032 /* *INDENT-ON* */
1033 
1034 void
1036 {
1039  u32 my_thread_index = vm->thread_index;
1040  session_event_t _e, *e = &_e;
1041  svm_msg_q_ring_t *ring;
1042  session_t *s0;
1043  svm_msg_q_msg_t *msg;
1044  svm_msg_q_t *mq;
1045  int i, index;
1046 
1047  mq = smm->wrk[my_thread_index].vpp_event_queue;
1048  index = mq->q->head;
1049 
1050  for (i = 0; i < mq->q->cursize; i++)
1051  {
1052  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
1053  ring = svm_msg_q_ring (mq, msg->ring_index);
1054  clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
1055 
1056  switch (e->event_type)
1057  {
1058  case SESSION_IO_EVT_TX:
1059  s0 = session_event_get_session (e, my_thread_index);
1060  fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
1061  break;
1062 
1064  s0 = session_get_from_handle (e->session_handle);
1065  fformat (stdout, "[%04d] disconnect session %d\n", i,
1066  s0->session_index);
1067  break;
1068 
1070  s0 = session_event_get_session (e, my_thread_index);
1071  fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
1072  break;
1073 
1074  case SESSION_CTRL_EVT_RPC:
1075  fformat (stdout, "[%04d] RPC call %llx with %llx\n",
1076  i, (u64) (uword) (e->rpc_args.fp),
1077  (u64) (uword) (e->rpc_args.arg));
1078  break;
1079 
1080  default:
1081  fformat (stdout, "[%04d] unhandled event type %d\n",
1082  i, e->event_type);
1083  break;
1084  }
1085 
1086  index++;
1087 
1088  if (index == mq->q->maxsize)
1089  index = 0;
1090  }
1091 }
1092 
1093 static u8
1094 session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
1095 {
1096  session_t *s;
1097  switch (e->event_type)
1098  {
1099  case SESSION_IO_EVT_RX:
1100  case SESSION_IO_EVT_TX:
1102  if (e->session_index == f->master_session_index)
1103  return 1;
1104  break;
1106  break;
1107  case SESSION_CTRL_EVT_RPC:
1108  s = session_get_from_handle (e->session_handle);
1109  if (!s)
1110  {
1111  clib_warning ("session has event but doesn't exist!");
1112  break;
1113  }
1114  if (s->rx_fifo == f || s->tx_fifo == f)
1115  return 1;
1116  break;
1117  default:
1118  break;
1119  }
1120  return 0;
1121 }
1122 
1123 u8
1124 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
1125 {
1126  session_event_t *pending_event_vector, *evt;
1127  session_worker_t *wrk;
1128  int i, index, found = 0;
1129  svm_msg_q_msg_t *msg;
1130  svm_msg_q_ring_t *ring;
1131  svm_msg_q_t *mq;
1132  u8 thread_index;
1133 
1134  ASSERT (e);
1135  thread_index = f->master_thread_index;
1136  wrk = session_main_get_worker (thread_index);
1137 
1138  /*
1139  * Search evt queue
1140  */
1141  mq = wrk->vpp_event_queue;
1142  index = mq->q->head;
1143  for (i = 0; i < mq->q->cursize; i++)
1144  {
1145  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
1146  ring = svm_msg_q_ring (mq, msg->ring_index);
1147  clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
1148  found = session_node_cmp_event (e, f);
1149  if (found)
1150  return 1;
1151  if (++index == mq->q->maxsize)
1152  index = 0;
1153  }
1154  /*
1155  * Search pending events vector
1156  */
1157  pending_event_vector = wrk->pending_event_vector;
1158  vec_foreach (evt, pending_event_vector)
1159  {
1160  found = session_node_cmp_event (evt, f);
1161  if (found)
1162  {
1163  clib_memcpy_fast (e, evt, sizeof (*evt));
1164  break;
1165  }
1166  }
1167  return found;
1168 }
1169 
1170 static clib_error_t *
1172 {
1173  if (vec_len (vlib_mains) < 2)
1174  return 0;
1175 
1176  /*
1177  * Shut off (especially) worker-thread session nodes.
1178  * Otherwise, vpp can crash as the main thread unmaps the
1179  * API segment.
1180  */
1182  session_node_enable_disable (0 /* is_enable */ );
1184  return 0;
1185 }
1186 
1188 
1189 static uword
1191  vlib_frame_t * f)
1192 {
1193  f64 now, timeout = 1.0;
1194  uword *event_data = 0;
1195  uword event_type;
1196 
1197  while (1)
1198  {
1200  now = vlib_time_now (vm);
1201  event_type = vlib_process_get_events (vm, (uword **) & event_data);
1202 
1203  switch (event_type)
1204  {
1206  /* Flush the frames by updating all transports times */
1207  transport_update_time (now, 0);
1208  break;
1210  timeout = 100000.0;
1211  break;
1212  case ~0:
1213  /* Timed out. Update time for all transports to trigger all
1214  * outstanding retransmits. */
1215  transport_update_time (now, 0);
1216  break;
1217  }
1218  vec_reset_length (event_data);
1219  }
1220  return 0;
1221 }
1222 
1223 /* *INDENT-OFF* */
1225 {
1226  .function = session_queue_process,
1227  .type = VLIB_NODE_TYPE_PROCESS,
1228  .name = "session-queue-process",
1229  .state = VLIB_NODE_STATE_DISABLED,
1230 };
1231 /* *INDENT-ON* */
1232 
1235  vlib_frame_t * frame)
1236 {
1238  if (!sm->wrk[0].vpp_event_queue)
1239  return 0;
1240  return session_queue_node_fn (vm, node, frame);
1241 }
1242 
1243 /* *INDENT-OFF* */
1245 {
1246  .function = session_queue_pre_input_inline,
1247  .type = VLIB_NODE_TYPE_PRE_INPUT,
1248  .name = "session-queue-main",
1249  .state = VLIB_NODE_STATE_DISABLED,
1250 };
1251 /* *INDENT-ON* */
1252 
1253 /*
1254  * fd.io coding-style-patch-verification: ON
1255  *
1256  * Local Variables:
1257  * eval: (c-set-style "gnu")
1258  * End:
1259  */
static void session_tx_trace_frame(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 *to_next, u16 n_segs, session_t *s, u32 n_trace)
Definition: session_node.c:342
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
u32 connection_index
Index of the transport connection associated to the session.
vlib_main_t vlib_global_main
Definition: main.c:1931
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
#define clib_min(x, y)
Definition: clib.h:295
#define CLIB_UNUSED(x)
Definition: clib.h:82
session_type_t session_type
Type built from transport and network protocol types.
void ip_copy(ip46_address_t *dst, ip46_address_t *src, u8 is_ip4)
Definition: ip.c:81
#define SESSION_Q_PROCESS_FLUSH_FRAMES
Definition: session.h:186
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:156
svm_msg_q_t * vpp_event_queue
vpp event message queue for worker
Definition: session.h:72
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:703
vlib_node_registration_t session_queue_pre_input_node
(constructor) VLIB_REGISTER_NODE (session_queue_pre_input_node)
a
Definition: bitmap.h:538
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:865
svm_fifo_t * tx_fifo
session_main_t session_main
Definition: session.c:26
int session_tx_fifo_dequeue_internal(vlib_main_t *vm, vlib_node_runtime_t *node, session_worker_t *wrk, session_event_t *e, int *n_tx_pkts)
Definition: session_node.c:815
#define PREDICT_TRUE(x)
Definition: clib.h:112
u32 session_index
Index in thread pool where session was allocated.
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
unsigned long u64
Definition: types.h:89
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
session_t * s
Definition: session.h:47
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
Definition: session.h:122
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:214
u32 thread_index
Definition: main.h:197
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static transport_proto_t session_get_transport_proto(session_t *s)
application_t * application_lookup(u32 api_client_index)
Definition: application.c:415
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *data, u32 len)
Definition: svm_fifo.c:607
u32 wrk_map_index
Worker index in app&#39;s map pool.
Definition: application.h:40
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
static clib_error_t * session_queue_exit(vlib_main_t *vm)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static uword session_queue_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: session_node.c:847
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 data[128]
Definition: ipsec.api:248
clib_time_t clib_time
Definition: main.h:72
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
int session_tx_fifo_peek_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_worker_t *wrk, session_event_t *e, int *n_tx_pkts)
Definition: session_node.c:799
void session_node_enable_disable(u8 is_en)
Definition: session.c:1392
vlib_main_t ** vlib_mains
Definition: buffer.c:321
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
unsigned char u8
Definition: types.h:56
app_worker_t * application_get_worker(application_t *app, u32 wrk_map_index)
Definition: application.c:674
static void session_tx_fill_buffer(vlib_main_t *vm, session_tx_context_t *ctx, vlib_buffer_t *b, u16 *n_bufs, u8 peek_data)
Definition: session_node.c:440
void transport_update_time(f64 time_now, u8 thread_index)
Definition: transport.c:650
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:204
struct _svm_fifo svm_fifo_t
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:114
u32 * tx_buffers
Vector of tx buffer free lists.
Definition: session.h:87
int svm_msg_q_lock_and_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index, u8 noblock, svm_msg_q_msg_t *msg)
Lock message queue and allocate message buffer on ring.
static int svm_fifo_is_empty(svm_fifo_t *f)
Definition: svm_fifo.h:141
static session_worker_t * session_main_get_worker(u32 thread_index)
Definition: session.h:499
void dump_thread_0_event_queue(void)
#define static_always_inline
Definition: clib.h:99
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:546
struct _vnet_disconnect_args_t vnet_disconnect_args_t
u8 session_node_lookup_fifo_event(svm_fifo_t *f, session_event_t *e)
#define always_inline
Definition: clib.h:98
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Definition: svm_fifo.h:129
u32 * session_type_to_next
Per session type output nodes.
Definition: session.h:136
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
u32 last_tx_packets
Definition: session.h:104
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:623
unsigned int u32
Definition: types.h:88
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:86
session_event_t * free_event_vector
Vector of partially read events.
Definition: session.h:90
#define VLIB_FRAME_SIZE
Definition: node.h:376
session_state_t
static char * session_queue_error_strings[]
Definition: session_node.c:328
int session_dequeue_notify(session_t *s)
Definition: session.c:529
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:266
static u8 svm_fifo_needs_tx_ntf(svm_fifo_t *f, u32 n_last_deq)
Definition: svm_fifo.h:286
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
#define TRANSPORT_MAX_HDRS_LEN
static void * vlib_buffer_make_headroom(vlib_buffer_t *b, u8 size)
Make head room, typically for packet headers.
Definition: buffer.h:350
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:227
session_queue_error_t
Definition: session_node.c:320
transport_proto_vft_t * transport_vft
Definition: session.h:48
long ctx[MAX_CONNS]
Definition: main.c:144
session_event_t * pending_disconnects
Vector of postponed disconnects.
Definition: session.h:96
static int session_tx_fifo_read_and_snd_i(vlib_main_t *vm, vlib_node_runtime_t *node, session_worker_t *wrk, session_event_t *e, int *n_tx_packets, u8 peek_data)
Definition: session_node.c:623
int session_tx_fifo_dequeue_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_worker_t *wrk, session_event_t *e, int *n_tx_pkts)
Definition: session_node.c:807
unsigned short u16
Definition: types.h:57
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
static uword session_queue_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
#define PREDICT_FALSE(x)
Definition: clib.h:111
static u8 session_node_cmp_event(session_event_t *e, svm_fifo_t *f)
svm_msg_q_ring_t * svm_msg_q_ring(svm_msg_q_t *mq, u32 ring_index)
Get message queue ring.
Definition: message_queue.c:27
static void svm_fifo_unset_event(svm_fifo_t *f)
Unsets fifo event flag.
Definition: svm_fifo.h:185
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
u32 node_index
Node index.
Definition: node.h:495
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
session_fifo_rx_fn ** session_tx_fns
Per transport rx function that can either dequeue or peek.
Definition: session.h:131
u64 session_segment_handle(session_t *s)
Definition: session.c:1226
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:368
word fformat(FILE *f, char *fmt,...)
Definition: format.c:462
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1180
static session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:236
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
Definition: svm_fifo.h:172
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define SESSION_EVT_DBG(_evt, _args...)
f64 dispatch_period
Our approximation of a "complete" dispatch loop period.
Definition: session.h:75
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
static void session_tx_fifo_chain_tail(vlib_main_t *vm, session_tx_context_t *ctx, vlib_buffer_t *b, u16 *n_bufs, u8 peek_data)
Definition: session_node.c:362
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:312
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
#define SESSION_CONN_HDR_LEN
int app_worker_builtin_rx(app_worker_t *app_wrk, session_t *s)
static void accepted_notify_cb(void *data, u32 data_len)
Definition: session_node.c:31
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
Definition: init.h:168
#define clib_warning(format, args...)
Definition: error.h:59
svm_queue_t * q
queue for exchanging messages
Definition: message_queue.h:39
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait)
Producer enqueue one message to queue.
struct _transport_connection transport_connection_t
static void session_update_dispatch_period(session_worker_t *wrk, f64 now, u32 thread_index)
Definition: session_node.c:835
static_always_inline uword session_queue_pre_input_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:465
blocking call - best used in combination with condvars, for eventfds we don&#39;t yield the cpu ...
Definition: queue.h:42
session_event_t * pending_event_vector
Vector of active event vectors.
Definition: session.h:93
void transport_connection_update_tx_stats(transport_connection_t *tc, u32 bytes)
Update tx byte stats for transport connection.
Definition: transport.c:628
static int svm_msg_q_try_lock(svm_msg_q_t *mq)
Try locking message queue.
static u32 session_thread_from_handle(session_handle_t handle)
#define SESSION_Q_PROCESS_STOP
Definition: session.h:187
u32 ring_index
ring index, could be u8
Definition: message_queue.h:62
#define foreach_session_queue_error
Definition: session_node.c:315
#define ASSERT(truth)
static void session_mq_disconnected_reply_handler(void *data)
Definition: session_node.c:189
static session_t * session_event_get_session(session_event_t *e, u8 thread_index)
Definition: session_node.c:829
int ct_session_connect_notify(session_t *ss)
datagram mode
session_tx_context_t ctx
Context for session tx.
Definition: session.h:84
enum _transport_proto transport_proto_t
#define vec_append(v1, v2)
Append v2 after v1.
Definition: vec.h:818
u32 transport_connection_snd_space(transport_connection_t *tc, u64 time_now, u16 mss)
Get maximum tx burst allowed for transport connection.
Definition: transport.c:610
ip46_address_t rmt_ip
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static int transport_custom_tx(transport_proto_t tp, void *s)
Definition: transport.h:109
static u8 * format_session_queue_trace(u8 *s, va_list *args)
Definition: session_node.c:304
session_dgram_hdr_t hdr
Definition: session.h:61
u8 thread_index
Index of the thread that allocated the session.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
static void session_tx_set_dequeue_params(vlib_main_t *vm, session_tx_context_t *ctx, u32 max_segs, u8 peek_data)
Definition: session_node.c:556
u32 app_index
App index in app pool.
Definition: application.h:86
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
Definition: bihash_doc.h:44
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
Definition: svm_fifo.c:734
app_worker_t * app_worker_get(u32 wrk_index)
void svm_msg_q_free_msg(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Free message buffer.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u8 session_tx_not_ready(session_t *s, u8 peek_data)
Definition: session_node.c:521
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
volatile u8 session_state
State in session layer state machine.
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:451
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void session_mq_worker_update_handler(void *data)
Definition: session_node.c:215
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1094
static void session_mq_accepted_reply_handler(void *data)
Definition: session_node.c:37
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
Definition: session_node.c:294
f64 last_vlib_time
vlib_time_now last time around the track
Definition: session.h:78
u32 elsize
size of an element
Definition: message_queue.h:33
struct clib_bihash_value offset
template key/value backing page structure
static void session_mq_disconnected_handler(void *data)
Definition: session_node.c:143
static u8 session_has_transport(session_t *s)
static transport_connection_t * session_tx_get_transport(session_tx_context_t *ctx, u8 peek_data)
Definition: session_node.c:536
u32 app_index
Index of owning app.
Definition: application.h:43
transport_connection_t * tc
Definition: session.h:49
int app_worker_own_session(app_worker_t *app_wrk, session_t *s)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1487
static u32 vlib_num_workers()
Definition: threads.h:366
static u32 svm_msg_q_size(svm_msg_q_t *mq)
Check length of message queue.
#define vec_foreach(var, vec)
Vector iterator.
u32 app_wrk_index
Index of the app worker that owns the session.
session_event_t * postponed_event_vector
Vector of postponed events.
Definition: session.h:99
static session_main_t * vnet_get_session_main()
Definition: session.h:493
void session_transport_close(session_t *s)
Notify transport the session can be disconnected.
Definition: session.c:1099
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
Definition: trace_funcs.h:172
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:167
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:612
vlib_node_registration_t session_queue_process_node
(constructor) VLIB_REGISTER_NODE (session_queue_process_node)
svm_msg_q_t * event_queue
Application listens for events on this svm queue.
Definition: application.h:46
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
Definition: svm_fifo.c:726
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
Definition: svm_fifo.c:678
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static void session_mq_reset_reply_handler(void *data)
Definition: session_node.c:99
void svm_msg_q_sub_w_lock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Consumer dequeue one message from queue with mutex held.