FD.io VPP  v18.10-34-gcce845e
Vector Packet Processing
session_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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>
25 #include <svm/queue.h>
26 
27 static void
29 {
31  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
32  app_worker_t *app_wrk;
33  local_session_t *ls;
35 
36  /* Server isn't interested, kill the session */
37  if (mp->retval)
38  {
39  a->app_index = mp->context;
40  a->handle = mp->handle;
42  return;
43  }
44 
46  {
48  if (!ls)
49  {
50  clib_warning ("unknown local handle 0x%lx", mp->handle);
51  return;
52  }
53  app_wrk = app_worker_get (ls->app_wrk_index);
54  if (app_wrk->app_index != mp->context)
55  {
56  clib_warning ("server %u doesn't own local handle 0x%lx",
57  mp->context, mp->handle);
58  return;
59  }
61  return;
63  }
64  else
65  {
67  if (!s)
68  {
69  clib_warning ("session doesn't exist");
70  return;
71  }
72  app_wrk = app_worker_get (s->app_wrk_index);
73  if (app_wrk->app_index != mp->context)
74  {
75  clib_warning ("app doesn't own session");
76  return;
77  }
78  s->session_state = SESSION_STATE_READY;
79  if (!svm_fifo_is_empty (s->server_rx_fifo))
81  }
82 }
83 
84 static void
86 {
88  app_worker_t *app_wrk;
90  application_t *app;
91  u32 index, thread_index;
92 
93  mp = (session_reset_reply_msg_t *) data;
94  app = application_lookup (mp->client_index);
95  if (!app)
96  return;
97 
98  session_parse_handle (mp->handle, &index, &thread_index);
99  s = session_get_if_valid (index, thread_index);
100  if (!s)
101  {
102  clib_warning ("Invalid session!");
103  return;
104  }
105  app_wrk = app_worker_get (s->app_wrk_index);
106  if (!app_wrk || app_wrk->app_index != app->app_index)
107  {
108  clib_warning ("App % does not own handle 0x%lx!", app->app_index,
109  mp->handle);
110  return;
111  }
112 
113  /* Client objected to resetting the session, log and continue */
114  if (mp->retval)
115  {
116  clib_warning ("client retval %d", mp->retval);
117  return;
118  }
119 
120  /* This comes as a response to a reset, transport only waiting for
121  * confirmation to remove connection state, no need to disconnect */
123 }
124 
125 static void
127 {
129  vnet_disconnect_args_t _a, *a = &_a;
130  svm_msg_q_msg_t _msg, *msg = &_msg;
132  app_worker_t *app_wrk;
133  session_event_t *evt;
134  stream_session_t *s;
135  application_t *app;
136  int rv = 0;
137 
138  mp = (session_disconnected_msg_t *) data;
139  if (!(s = session_get_from_handle_if_valid (mp->handle)))
140  {
141  clib_warning ("could not disconnect handle %llu", mp->handle);
142  return;
143  }
144  app_wrk = app_worker_get (s->app_wrk_index);
145  app = application_lookup (mp->client_index);
146  if (!(app_wrk && app && app->app_index == app_wrk->app_index))
147  {
148  clib_warning ("could not disconnect session: %llu app: %u",
149  mp->handle, mp->client_index);
150  return;
151  }
152 
153  a->handle = mp->handle;
154  a->app_index = app_wrk->wrk_index;
155  rv = vnet_disconnect_session (a);
156 
159  SVM_Q_WAIT, msg);
160  svm_msg_q_unlock (app_wrk->event_queue);
161  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
162  memset (evt, 0, sizeof (*evt));
163  evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
164  rmp = (session_disconnected_reply_msg_t *) evt->data;
165  rmp->handle = mp->handle;
166  rmp->context = mp->context;
167  rmp->retval = rv;
168  svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
169 }
170 
171 static void
173 {
175  vnet_disconnect_args_t _a, *a = &_a;
176  application_t *app;
177 
178  mp = (session_disconnected_reply_msg_t *) data;
179 
180  /* Client objected to disconnecting the session, log and continue */
181  if (mp->retval)
182  {
183  clib_warning ("client retval %d", mp->retval);
184  return;
185  }
186 
187  /* Disconnect has been confirmed. Confirm close to transport */
188  app = application_lookup (mp->context);
189  if (app)
190  {
191  a->handle = mp->handle;
192  a->app_index = app->app_index;
194  }
195 }
196 
198 
199 typedef struct
200 {
204 
205 /* packet trace format function */
206 static u8 *
207 format_session_queue_trace (u8 * s, va_list * args)
208 {
209  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
210  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
211  session_queue_trace_t *t = va_arg (*args, session_queue_trace_t *);
212 
213  s = format (s, "SESSION_QUEUE: session index %d, server thread index %d",
215  return s;
216 }
217 
218 #define foreach_session_queue_error \
219 _(TX, "Packets transmitted") \
220 _(TIMER, "Timer events") \
221 _(NO_BUFFER, "Out of buffers")
222 
223 typedef enum
224 {
225 #define _(sym,str) SESSION_QUEUE_ERROR_##sym,
227 #undef _
230 
231 static char *session_queue_error_strings[] = {
232 #define _(sym,string) string,
234 #undef _
235 };
236 
237 enum
238 {
242 };
243 
244 static void
246  u32 next_index, u32 * to_next, u16 n_segs,
247  stream_session_t * s, u32 n_trace)
248 {
250  vlib_buffer_t *b;
251  int i;
252 
253  for (i = 0; i < clib_min (n_trace, n_segs); i++)
254  {
255  b = vlib_get_buffer (vm, to_next[i - n_segs]);
256  vlib_trace_buffer (vm, node, next_index, b, 1 /* follow_chain */ );
257  t = vlib_add_trace (vm, node, b, sizeof (*t));
258  t->session_index = s->session_index;
259  t->server_thread_index = s->thread_index;
260  }
261  vlib_set_trace_count (vm, node, n_trace - i);
262 }
263 
264 always_inline void
266  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
267 {
269  vlib_buffer_t *chain_b, *prev_b;
270  u32 chain_bi0, to_deq, left_from_seg;
271  u16 len_to_deq, n_bytes_read;
272  u8 *data, j;
273 
274  b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
276 
277  chain_b = b;
278  left_from_seg = clib_min (ctx->snd_mss - b->current_length,
279  ctx->left_to_snd);
280  to_deq = left_from_seg;
281  for (j = 1; j < ctx->n_bufs_per_seg; j++)
282  {
283  prev_b = chain_b;
284  len_to_deq = clib_min (to_deq, ctx->deq_per_buf);
285 
286  *n_bufs -= 1;
287  chain_bi0 = smm->tx_buffers[ctx->s->thread_index][*n_bufs];
288  _vec_len (smm->tx_buffers[ctx->s->thread_index]) = *n_bufs;
289 
290  chain_b = vlib_get_buffer (vm, chain_bi0);
291  chain_b->current_data = 0;
292  data = vlib_buffer_get_current (chain_b);
293  if (peek_data)
294  {
295  n_bytes_read = svm_fifo_peek (ctx->s->server_tx_fifo,
296  ctx->tx_offset, len_to_deq, data);
297  ctx->tx_offset += n_bytes_read;
298  }
299  else
300  {
301  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
302  {
303  svm_fifo_t *f = ctx->s->server_tx_fifo;
304  session_dgram_hdr_t *hdr = &ctx->hdr;
305  u16 deq_now;
306  deq_now = clib_min (hdr->data_length - hdr->data_offset,
307  len_to_deq);
308  n_bytes_read = svm_fifo_peek (f, hdr->data_offset, deq_now,
309  data);
310  ASSERT (n_bytes_read > 0);
311 
312  hdr->data_offset += n_bytes_read;
313  if (hdr->data_offset == hdr->data_length)
314  {
315  u32 offset = hdr->data_length + SESSION_CONN_HDR_LEN;
316  svm_fifo_dequeue_drop (f, offset);
317  }
318  }
319  else
320  n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->server_tx_fifo,
321  len_to_deq, data);
322  }
323  ASSERT (n_bytes_read == len_to_deq);
324  chain_b->current_length = n_bytes_read;
326 
327  /* update previous buffer */
328  prev_b->next_buffer = chain_bi0;
329  prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
330 
331  /* update current buffer */
332  chain_b->next_buffer = 0;
333 
334  to_deq -= n_bytes_read;
335  if (to_deq == 0)
336  break;
337  }
338  ASSERT (to_deq == 0
339  && b->total_length_not_including_first_buffer == left_from_seg);
340  ctx->left_to_snd -= left_from_seg;
341 }
342 
343 always_inline int
346  u32 thread_index, u16 * n_bufs, u32 wanted)
347 {
348  u32 n_alloc;
349  vec_validate_aligned (smm->tx_buffers[thread_index], wanted - 1,
351  n_alloc = vlib_buffer_alloc (vm, &smm->tx_buffers[thread_index][*n_bufs],
352  wanted - *n_bufs);
353  *n_bufs += n_alloc;
354  _vec_len (smm->tx_buffers[thread_index]) = *n_bufs;
355  return n_alloc;
356 }
357 
358 always_inline void
360  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
361 {
362  u32 len_to_deq;
363  u8 *data0;
364  int n_bytes_read;
365 
366  /*
367  * Start with the first buffer in chain
368  */
369  b->error = 0;
370  b->flags = VNET_BUFFER_F_LOCALLY_ORIGINATED;
371  b->current_data = 0;
372 
374  len_to_deq = clib_min (ctx->left_to_snd, ctx->deq_per_first_buf);
375 
376  if (peek_data)
377  {
378  n_bytes_read = svm_fifo_peek (ctx->s->server_tx_fifo, ctx->tx_offset,
379  len_to_deq, data0);
380  ASSERT (n_bytes_read > 0);
381  /* Keep track of progress locally, transport is also supposed to
382  * increment it independently when pushing the header */
383  ctx->tx_offset += n_bytes_read;
384  }
385  else
386  {
387  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
388  {
389  session_dgram_hdr_t *hdr = &ctx->hdr;
390  svm_fifo_t *f = ctx->s->server_tx_fifo;
391  u16 deq_now;
392  u32 offset;
393 
394  ASSERT (hdr->data_length > hdr->data_offset);
395  deq_now = clib_min (hdr->data_length - hdr->data_offset,
396  len_to_deq);
397  offset = hdr->data_offset + SESSION_CONN_HDR_LEN;
398  n_bytes_read = svm_fifo_peek (f, offset, deq_now, data0);
399  ASSERT (n_bytes_read > 0);
400 
401  if (ctx->s->session_state == SESSION_STATE_LISTENING)
402  {
403  ip_copy (&ctx->tc->rmt_ip, &hdr->rmt_ip, ctx->tc->is_ip4);
404  ctx->tc->rmt_port = hdr->rmt_port;
405  }
406  hdr->data_offset += n_bytes_read;
407  if (hdr->data_offset == hdr->data_length)
408  {
409  offset = hdr->data_length + SESSION_CONN_HDR_LEN;
410  svm_fifo_dequeue_drop (f, offset);
411  }
412  }
413  else
414  {
415  n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->server_tx_fifo,
416  len_to_deq, data0);
417  ASSERT (n_bytes_read > 0);
418  }
419  }
420  b->current_length = n_bytes_read;
421  ctx->left_to_snd -= n_bytes_read;
422 
423  /*
424  * Fill in the remaining buffers in the chain, if any
425  */
426  if (PREDICT_FALSE (ctx->n_bufs_per_seg > 1 && ctx->left_to_snd))
427  session_tx_fifo_chain_tail (vm, ctx, b, n_bufs, peek_data);
428 
429  /* *INDENT-OFF* */
430  SESSION_EVT_DBG(SESSION_EVT_DEQ, ctx->s, ({
431  ed->data[0] = FIFO_EVENT_APP_TX;
432  ed->data[1] = ctx->max_dequeue;
433  ed->data[2] = len_to_deq;
434  ed->data[3] = ctx->left_to_snd;
435  }));
436  /* *INDENT-ON* */
437 }
438 
441 {
442  if (peek_data)
443  {
444  /* Can retransmit for closed sessions but can't send new data if
445  * session is not ready or closed */
446  if (s->session_state < SESSION_STATE_READY)
447  return 1;
448  if (s->session_state == SESSION_STATE_CLOSED)
449  return 2;
450  }
451  return 0;
452 }
453 
456 {
457  if (peek_data)
458  {
459  return ctx->transport_vft->get_connection (ctx->s->connection_index,
460  ctx->s->thread_index);
461  }
462  else
463  {
464  if (ctx->s->session_state == SESSION_STATE_LISTENING)
465  return ctx->transport_vft->get_listener (ctx->s->connection_index);
466  else
467  {
468  return ctx->transport_vft->get_connection (ctx->s->connection_index,
469  ctx->s->thread_index);
470  }
471  }
472 }
473 
474 always_inline void
476  u32 max_segs, u8 peek_data)
477 {
478  u32 n_bytes_per_buf, n_bytes_per_seg;
479  ctx->max_dequeue = svm_fifo_max_dequeue (ctx->s->server_tx_fifo);
480  if (peek_data)
481  {
482  /* Offset in rx fifo from where to peek data */
483  ctx->tx_offset = ctx->transport_vft->tx_fifo_offset (ctx->tc);
484  if (PREDICT_FALSE (ctx->tx_offset >= ctx->max_dequeue))
485  {
486  ctx->max_len_to_snd = 0;
487  return;
488  }
489  ctx->max_dequeue -= ctx->tx_offset;
490  }
491  else
492  {
493  if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
494  {
495  if (ctx->max_dequeue <= sizeof (ctx->hdr))
496  {
497  ctx->max_len_to_snd = 0;
498  return;
499  }
500  svm_fifo_peek (ctx->s->server_tx_fifo, 0, sizeof (ctx->hdr),
501  (u8 *) & ctx->hdr);
502  ASSERT (ctx->hdr.data_length > ctx->hdr.data_offset);
503  ctx->max_dequeue = ctx->hdr.data_length - ctx->hdr.data_offset;
504  }
505  }
506  ASSERT (ctx->max_dequeue > 0);
507 
508  /* Ensure we're not writing more than transport window allows */
509  if (ctx->max_dequeue < ctx->snd_space)
510  {
511  /* Constrained by tx queue. Try to send only fully formed segments */
512  ctx->max_len_to_snd =
513  (ctx->max_dequeue > ctx->snd_mss) ?
514  ctx->max_dequeue - ctx->max_dequeue % ctx->snd_mss : ctx->max_dequeue;
515  /* TODO Nagle ? */
516  }
517  else
518  {
519  /* Expectation is that snd_space0 is already a multiple of snd_mss */
520  ctx->max_len_to_snd = ctx->snd_space;
521  }
522 
523  /* Check if we're tx constrained by the node */
524  ctx->n_segs_per_evt = ceil ((f64) ctx->max_len_to_snd / ctx->snd_mss);
525  if (ctx->n_segs_per_evt > max_segs)
526  {
527  ctx->n_segs_per_evt = max_segs;
528  ctx->max_len_to_snd = max_segs * ctx->snd_mss;
529  }
530 
531  n_bytes_per_buf = vlib_buffer_free_list_buffer_size (vm,
533  ASSERT (n_bytes_per_buf > MAX_HDRS_LEN);
534  n_bytes_per_seg = MAX_HDRS_LEN + ctx->snd_mss;
535  ctx->n_bufs_per_seg = ceil ((f64) n_bytes_per_seg / n_bytes_per_buf);
536  ctx->deq_per_buf = clib_min (ctx->snd_mss, n_bytes_per_buf);
537  ctx->deq_per_first_buf = clib_min (ctx->snd_mss,
538  n_bytes_per_buf - MAX_HDRS_LEN);
539 }
540 
541 always_inline int
543  session_event_t * e,
544  stream_session_t * s, int *n_tx_packets,
545  u8 peek_data)
546 {
547  u32 next_index, next0, next1, *to_next, n_left_to_next;
548  u32 n_trace = vlib_get_trace_count (vm, node), n_bufs_needed = 0;
549  u32 thread_index = s->thread_index, n_left, pbi;
551  session_tx_context_t *ctx = &smm->ctx[thread_index];
553  vlib_buffer_t *pb;
554  u16 n_bufs, rv;
555 
556  if (PREDICT_FALSE ((rv = session_tx_not_ready (s, peek_data))))
557  {
558  if (rv < 2)
559  vec_add1 (smm->pending_event_vector[thread_index], *e);
560  return SESSION_TX_NO_DATA;
561  }
562 
563  next_index = smm->session_type_to_next[s->session_type];
564  next0 = next1 = next_index;
565 
567  ctx->s = s;
569  ctx->tc = session_tx_get_transport (ctx, peek_data);
570  ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc);
571  ctx->snd_space = ctx->transport_vft->send_space (ctx->tc);
572  if (ctx->snd_space == 0 || ctx->snd_mss == 0)
573  {
574  vec_add1 (smm->pending_event_vector[thread_index], *e);
575  return SESSION_TX_NO_DATA;
576  }
577 
578  /* Allow enqueuing of a new event */
579  svm_fifo_unset_event (s->server_tx_fifo);
580 
581  /* Check how much we can pull. */
582  session_tx_set_dequeue_params (vm, ctx, VLIB_FRAME_SIZE - *n_tx_packets,
583  peek_data);
584 
585  if (PREDICT_FALSE (!ctx->max_len_to_snd))
586  return SESSION_TX_NO_DATA;
587 
588  n_bufs = vec_len (smm->tx_buffers[thread_index]);
589  n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg;
590 
591  /*
592  * Make sure we have at least one full frame of buffers ready
593  */
594  if (n_bufs < n_bufs_needed)
595  {
596  session_output_try_get_buffers (vm, smm, thread_index, &n_bufs,
598  if (PREDICT_FALSE (n_bufs < n_bufs_needed))
599  {
600  vec_add1 (smm->pending_event_vector[thread_index], *e);
601  return SESSION_TX_NO_BUFFERS;
602  }
603  }
604 
605  /*
606  * Write until we fill up a frame
607  */
608  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
609  if (PREDICT_FALSE (ctx->n_segs_per_evt > n_left_to_next))
610  {
611  ctx->n_segs_per_evt = n_left_to_next;
612  ctx->max_len_to_snd = ctx->snd_mss * n_left_to_next;
613  }
614  ctx->left_to_snd = ctx->max_len_to_snd;
615  n_left = ctx->n_segs_per_evt;
616 
617  while (n_left >= 4)
618  {
619  vlib_buffer_t *b0, *b1;
620  u32 bi0, bi1;
621 
622  pbi = smm->tx_buffers[thread_index][n_bufs - 3];
623  pb = vlib_get_buffer (vm, pbi);
624  vlib_prefetch_buffer_header (pb, STORE);
625  pbi = smm->tx_buffers[thread_index][n_bufs - 4];
626  pb = vlib_get_buffer (vm, pbi);
627  vlib_prefetch_buffer_header (pb, STORE);
628 
629  to_next[0] = bi0 = smm->tx_buffers[thread_index][--n_bufs];
630  to_next[1] = bi1 = smm->tx_buffers[thread_index][--n_bufs];
631 
632  b0 = vlib_get_buffer (vm, bi0);
633  b1 = vlib_get_buffer (vm, bi1);
634 
635  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
636  session_tx_fill_buffer (vm, ctx, b1, &n_bufs, peek_data);
637 
638  ctx->transport_vft->push_header (ctx->tc, b0);
639  ctx->transport_vft->push_header (ctx->tc, b1);
640 
641  to_next += 2;
642  n_left_to_next -= 2;
643  n_left -= 2;
644 
647 
648  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
649  n_left_to_next, bi0, bi1, next0,
650  next1);
651  }
652  while (n_left)
653  {
654  vlib_buffer_t *b0;
655  u32 bi0;
656 
657  if (n_left > 1)
658  {
659  pbi = smm->tx_buffers[thread_index][n_bufs - 2];
660  pb = vlib_get_buffer (vm, pbi);
661  vlib_prefetch_buffer_header (pb, STORE);
662  }
663 
664  to_next[0] = bi0 = smm->tx_buffers[thread_index][--n_bufs];
665  b0 = vlib_get_buffer (vm, bi0);
666  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
667 
668  /* Ask transport to push header after current_length and
669  * total_length_not_including_first_buffer are updated */
670  ctx->transport_vft->push_header (ctx->tc, b0);
671 
672  to_next += 1;
673  n_left_to_next -= 1;
674  n_left -= 1;
675 
677 
678  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
679  n_left_to_next, bi0, next0);
680  }
681 
682  if (PREDICT_FALSE (n_trace > 0))
683  session_tx_trace_frame (vm, node, next_index, to_next,
684  ctx->n_segs_per_evt, s, n_trace);
685 
686  _vec_len (smm->tx_buffers[thread_index]) = n_bufs;
687  *n_tx_packets += ctx->n_segs_per_evt;
688  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
689 
690  /* If we couldn't dequeue all bytes mark as partially read */
691  ASSERT (ctx->left_to_snd == 0);
692  if (ctx->max_len_to_snd < ctx->max_dequeue)
693  if (svm_fifo_set_event (s->server_tx_fifo))
694  vec_add1 (smm->pending_event_vector[thread_index], *e);
695 
696  if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
697  {
698  /* Fix dgram pre header */
699  if (ctx->max_len_to_snd < ctx->max_dequeue)
700  svm_fifo_overwrite_head (s->server_tx_fifo, (u8 *) & ctx->hdr,
701  sizeof (session_dgram_pre_hdr_t));
702  /* More data needs to be read */
703  else if (svm_fifo_max_dequeue (s->server_tx_fifo) > 0)
704  if (svm_fifo_set_event (s->server_tx_fifo))
705  vec_add1 (smm->pending_event_vector[thread_index], *e);
706  }
707  return SESSION_TX_OK;
708 }
709 
710 int
712  session_event_t * e,
713  stream_session_t * s, int *n_tx_pkts)
714 {
715  return session_tx_fifo_read_and_snd_i (vm, node, e, s, n_tx_pkts, 1);
716 }
717 
718 int
720  session_event_t * e,
721  stream_session_t * s, int *n_tx_pkts)
722 {
723  return session_tx_fifo_read_and_snd_i (vm, node, e, s, n_tx_pkts, 0);
724 }
725 
726 int
728  vlib_node_runtime_t * node,
729  session_event_t * e,
730  stream_session_t * s, int *n_tx_pkts)
731 {
732  application_t *app;
733  if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED))
734  return 0;
735  app = application_get (s->t_app_index);
736  svm_fifo_unset_event (s->server_tx_fifo);
737  return app->cb_fns.builtin_app_tx_callback (s);
738 }
739 
741 session_event_get_session (session_event_t * e, u8 thread_index)
742 {
743  return session_get_if_valid (e->fifo->master_session_index, thread_index);
744 }
745 
746 static uword
748  vlib_frame_t * frame)
749 {
751  u32 thread_index = vm->thread_index, n_to_dequeue, n_events;
752  session_event_t *pending_events, *e;
753  session_event_t *fifo_events;
754  svm_msg_q_msg_t _msg, *msg = &_msg;
755  f64 now = vlib_time_now (vm);
756  int n_tx_packets = 0, i, rv;
757  app_worker_t *app_wrk;
758  application_t *app;
759  svm_msg_q_t *mq;
760  void (*fp) (void *);
761 
762  SESSION_EVT_DBG (SESSION_EVT_POLL_GAP_TRACK, smm, thread_index);
763 
764  /*
765  * Update transport time
766  */
767  transport_update_time (now, thread_index);
768 
769  /*
770  * Get vpp queue events that we can dequeue without blocking
771  */
772  mq = smm->vpp_event_queues[thread_index];
773  fifo_events = smm->free_event_vector[thread_index];
774  n_to_dequeue = svm_msg_q_size (mq);
775  pending_events = smm->pending_event_vector[thread_index];
776 
777  if (!n_to_dequeue && !vec_len (pending_events)
778  && !vec_len (smm->pending_disconnects[thread_index]))
779  return 0;
780 
781  SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0);
782 
783  /*
784  * If we didn't manage to process previous events try going
785  * over them again without dequeuing new ones.
786  * XXX: Handle senders to sessions that can't keep up
787  */
788  if (0 && vec_len (pending_events) >= 100)
789  {
790  clib_warning ("too many fifo events unsolved");
791  goto skip_dequeue;
792  }
793 
794  /* See you in the next life, don't be late
795  * XXX: we may need priorities here */
796  if (svm_msg_q_try_lock (mq))
797  return 0;
798 
799  for (i = 0; i < n_to_dequeue; i++)
800  {
801  vec_add2 (fifo_events, e, 1);
802  svm_msg_q_sub_w_lock (mq, msg);
803  clib_memcpy (e, svm_msg_q_msg_data (mq, msg), sizeof (*e));
804  svm_msg_q_free_msg (mq, msg);
805  }
806 
807  svm_msg_q_unlock (mq);
808 
809  vec_append (fifo_events, pending_events);
810  vec_append (fifo_events, smm->pending_disconnects[thread_index]);
811 
812  _vec_len (pending_events) = 0;
813  smm->pending_event_vector[thread_index] = pending_events;
814  _vec_len (smm->pending_disconnects[thread_index]) = 0;
815 
816 skip_dequeue:
817  n_events = vec_len (fifo_events);
818  for (i = 0; i < n_events; i++)
819  {
820  stream_session_t *s; /* $$$ prefetch 1 ahead maybe */
821  session_event_t *e;
822  u8 want_tx_evt;
823 
824  e = &fifo_events[i];
825  switch (e->event_type)
826  {
827  case FIFO_EVENT_APP_TX:
828  /* Don't try to send more that one frame per dispatch cycle */
829  if (n_tx_packets == VLIB_FRAME_SIZE)
830  {
831  vec_add1 (smm->pending_event_vector[thread_index], *e);
832  break;
833  }
834 
835  s = session_event_get_session (e, thread_index);
836  if (PREDICT_FALSE (!s))
837  {
838  clib_warning ("session was freed!");
839  continue;
840  }
841 
842  want_tx_evt = svm_fifo_want_tx_evt (s->server_tx_fifo);
843  /* Spray packets in per session type frames, since they go to
844  * different nodes */
845  rv = (smm->session_tx_fns[s->session_type]) (vm, node, e, s,
846  &n_tx_packets);
847  if (PREDICT_TRUE (rv == SESSION_TX_OK))
848  {
849  if (PREDICT_FALSE (want_tx_evt))
850  {
851  svm_fifo_set_want_tx_evt (s->server_tx_fifo, 0);
853  }
854  }
855  else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
856  {
858  SESSION_QUEUE_ERROR_NO_BUFFER, 1);
859  continue;
860  }
861  break;
863  /* Make sure stream disconnects run after the pending list is
864  * drained */
865  s = session_get_from_handle (e->session_handle);
866  if (!e->postponed)
867  {
868  e->postponed = 1;
869  vec_add1 (smm->pending_disconnects[thread_index], *e);
870  continue;
871  }
872  /* If tx queue is still not empty, wait */
873  if (svm_fifo_max_dequeue (s->server_tx_fifo))
874  {
875  vec_add1 (smm->pending_disconnects[thread_index], *e);
876  continue;
877  }
878 
880  break;
882  s = session_event_get_session (e, thread_index);
883  if (PREDICT_FALSE (!s || s->session_state >= SESSION_STATE_CLOSING))
884  continue;
885  svm_fifo_unset_event (s->server_rx_fifo);
886  app_wrk = app_worker_get (s->app_wrk_index);
887  app = application_get (app_wrk->app_index);
888  app->cb_fns.builtin_app_rx_callback (s);
889  break;
891  s = session_get_from_handle_if_valid (e->session_handle);
892  if (PREDICT_TRUE (s != 0))
893  session_tx_fifo_dequeue_internal (vm, node, e, s, &n_tx_packets);
894  break;
895  case FIFO_EVENT_RPC:
896  fp = e->rpc_args.fp;
897  (*fp) (e->rpc_args.arg);
898  break;
901  break;
904  break;
906  break;
909  break;
912  break;
913  default:
914  clib_warning ("unhandled event type %d", e->event_type);
915  }
916  }
917 
918  _vec_len (fifo_events) = 0;
919  smm->free_event_vector[thread_index] = fifo_events;
920 
922  SESSION_QUEUE_ERROR_TX, n_tx_packets);
923 
924  SESSION_EVT_DBG (SESSION_EVT_DISPATCH_END, smm, thread_index);
925 
926  return n_tx_packets;
927 }
928 
929 /* *INDENT-OFF* */
931 {
932  .function = session_queue_node_fn,
933  .name = "session-queue",
934  .format_trace = format_session_queue_trace,
935  .type = VLIB_NODE_TYPE_INPUT,
937  .error_strings = session_queue_error_strings,
938  .state = VLIB_NODE_STATE_DISABLED,
939 };
940 /* *INDENT-ON* */
941 
942 void
944 {
947  u32 my_thread_index = vm->thread_index;
948  session_event_t _e, *e = &_e;
949  svm_msg_q_ring_t *ring;
950  stream_session_t *s0;
951  svm_msg_q_msg_t *msg;
952  svm_msg_q_t *mq;
953  int i, index;
954 
955  mq = smm->vpp_event_queues[my_thread_index];
956  index = mq->q->head;
957 
958  for (i = 0; i < mq->q->cursize; i++)
959  {
960  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
961  ring = svm_msg_q_ring (mq, msg->ring_index);
962  clib_memcpy (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
963 
964  switch (e->event_type)
965  {
966  case FIFO_EVENT_APP_TX:
967  s0 = session_event_get_session (e, my_thread_index);
968  fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
969  break;
970 
972  s0 = session_get_from_handle (e->session_handle);
973  fformat (stdout, "[%04d] disconnect session %d\n", i,
974  s0->session_index);
975  break;
976 
978  s0 = session_event_get_session (e, my_thread_index);
979  fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
980  break;
981 
982  case FIFO_EVENT_RPC:
983  fformat (stdout, "[%04d] RPC call %llx with %llx\n",
984  i, (u64) (e->rpc_args.fp), (u64) (e->rpc_args.arg));
985  break;
986 
987  default:
988  fformat (stdout, "[%04d] unhandled event type %d\n",
989  i, e->event_type);
990  break;
991  }
992 
993  index++;
994 
995  if (index == mq->q->maxsize)
996  index = 0;
997  }
998 }
999 
1000 static u8
1001 session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
1002 {
1003  stream_session_t *s;
1004  switch (e->event_type)
1005  {
1006  case FIFO_EVENT_APP_RX:
1007  case FIFO_EVENT_APP_TX:
1008  case FIFO_EVENT_BUILTIN_RX:
1009  if (e->fifo == f)
1010  return 1;
1011  break;
1012  case FIFO_EVENT_DISCONNECT:
1013  break;
1014  case FIFO_EVENT_RPC:
1015  s = session_get_from_handle (e->session_handle);
1016  if (!s)
1017  {
1018  clib_warning ("session has event but doesn't exist!");
1019  break;
1020  }
1021  if (s->server_rx_fifo == f || s->server_tx_fifo == f)
1022  return 1;
1023  break;
1024  default:
1025  break;
1026  }
1027  return 0;
1028 }
1029 
1030 u8
1031 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
1032 {
1034  svm_msg_q_t *mq;
1035  session_event_t *pending_event_vector, *evt;
1036  int i, index, found = 0;
1037  svm_msg_q_msg_t *msg;
1038  svm_msg_q_ring_t *ring;
1039  u8 thread_index;
1040 
1041  ASSERT (e);
1042  thread_index = f->master_thread_index;
1043  /*
1044  * Search evt queue
1045  */
1046  mq = smm->vpp_event_queues[thread_index];
1047  index = mq->q->head;
1048  for (i = 0; i < mq->q->cursize; i++)
1049  {
1050  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
1051  ring = svm_msg_q_ring (mq, msg->ring_index);
1052  clib_memcpy (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
1053  found = session_node_cmp_event (e, f);
1054  if (found)
1055  return 1;
1056  if (++index == mq->q->maxsize)
1057  index = 0;
1058  }
1059  /*
1060  * Search pending events vector
1061  */
1062  pending_event_vector = smm->pending_event_vector[thread_index];
1063  vec_foreach (evt, pending_event_vector)
1064  {
1065  found = session_node_cmp_event (evt, f);
1066  if (found)
1067  {
1068  clib_memcpy (e, evt, sizeof (*evt));
1069  break;
1070  }
1071  }
1072  return found;
1073 }
1074 
1075 static clib_error_t *
1077 {
1078  if (vec_len (vlib_mains) < 2)
1079  return 0;
1080 
1081  /*
1082  * Shut off (especially) worker-thread session nodes.
1083  * Otherwise, vpp can crash as the main thread unmaps the
1084  * API segment.
1085  */
1087  session_node_enable_disable (0 /* is_enable */ );
1089  return 0;
1090 }
1091 
1093 
1094 static uword
1096  vlib_frame_t * f)
1097 {
1098  f64 now, timeout = 1.0;
1099  uword *event_data = 0;
1100  uword event_type;
1101 
1102  while (1)
1103  {
1105  now = vlib_time_now (vm);
1106  event_type = vlib_process_get_events (vm, (uword **) & event_data);
1107 
1108  switch (event_type)
1109  {
1111  /* Flush the frames by updating all transports times */
1112  transport_update_time (now, 0);
1113  break;
1115  timeout = 100000.0;
1116  break;
1117  case ~0:
1118  /* Timed out. Update time for all transports to trigger all
1119  * outstanding retransmits. */
1120  transport_update_time (now, 0);
1121  break;
1122  }
1123  vec_reset_length (event_data);
1124  }
1125  return 0;
1126 }
1127 
1128 /* *INDENT-OFF* */
1130 {
1131  .function = session_queue_process,
1132  .type = VLIB_NODE_TYPE_PROCESS,
1133  .name = "session-queue-process",
1134  .state = VLIB_NODE_STATE_DISABLED,
1135 };
1136 /* *INDENT-ON* */
1137 
1138 
1139 /*
1140  * fd.io coding-style-patch-verification: ON
1141  *
1142  * Local Variables:
1143  * eval: (c-set-style "gnu")
1144  * End:
1145  */
app_worker_t * app_worker_get(u32 wrk_index)
Definition: application.c:499
vlib_main_t vlib_global_main
Definition: main.c:1638
static void session_tx_trace_frame(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 *to_next, u16 n_segs, stream_session_t *s, u32 n_trace)
Definition: session_node.c:245
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:291
#define CLIB_UNUSED(x)
Definition: clib.h:81
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:282
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:156
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:699
a
Definition: bitmap.h:538
#define SESSION_CONN_HDR_LEN
Definition: session.h:149
struct _transport_connection transport_connection_t
static int session_output_try_get_buffers(vlib_main_t *vm, session_manager_main_t *smm, u32 thread_index, u16 *n_bufs, u32 wanted)
Definition: session_node.c:344
#define PREDICT_TRUE(x)
Definition: clib.h:108
unsigned long u64
Definition: types.h:89
session_manager_main_t session_manager_main
Definition: session.c:27
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:227
u32 thread_index
Definition: main.h:179
local_session_t * application_get_local_session_from_handle(session_handle_t handle)
Definition: application.c:1374
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
application_t * application_lookup(u32 api_client_index)
Definition: application.c:211
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *data, u32 len)
Definition: svm_fifo.c:599
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:562
int i
static clib_error_t * session_queue_exit(vlib_main_t *vm)
static uword session_queue_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: session_node.c:747
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
Definition: session.h:352
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:448
static stream_session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:360
void session_node_enable_disable(u8 is_en)
Definition: session.c:1427
vlib_main_t ** vlib_mains
Definition: buffer.c:303
unsigned char u8
Definition: types.h:56
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:359
void transport_update_time(f64 time_now, u8 thread_index)
Definition: transport.c:380
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
static stream_session_t * session_event_get_session(session_event_t *e, u8 thread_index)
Definition: session_node.c:741
#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
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:126
void dump_thread_0_event_queue(void)
Definition: session_node.c:943
memset(h->entries, 0, sizeof(h->entries[0])*entries)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:109
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:542
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:94
static u8 svm_fifo_want_tx_evt(svm_fifo_t *f)
Definition: svm_fifo.h:182
int application_local_session_connect_notify(local_session_t *ls)
Definition: application.c:1677
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Definition: svm_fifo.h:114
int session_dequeue_notify(stream_session_t *s)
Definition: session.c:520
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:187
stream_session_t * s
Definition: session.h:157
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
Definition: session.c:1127
unsigned int u32
Definition: types.h:88
struct _stream_session_t stream_session_t
#define VLIB_FRAME_SIZE
Definition: node.h:382
static char * session_queue_error_strings[]
Definition: session_node.c:231
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:191
static int session_tx_fifo_read_and_snd_i(vlib_main_t *vm, vlib_node_runtime_t *node, session_event_t *e, stream_session_t *s, int *n_tx_packets, u8 peek_data)
Definition: session_node.c:542
static transport_proto_t session_get_transport_proto(stream_session_t *s)
Definition: session.h:397
static session_manager_main_t * vnet_get_session_manager_main()
Definition: session.h:289
int session_tx_fifo_dequeue_internal(vlib_main_t *vm, vlib_node_runtime_t *node, session_event_t *e, stream_session_t *s, int *n_tx_pkts)
Definition: session_node.c:727
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static void * vlib_buffer_make_headroom(vlib_buffer_t *b, u8 size)
Make head room, typically for packet headers.
Definition: buffer.h:320
#define MAX_HDRS_LEN
Definition: session.h:31
session_queue_error_t
Definition: session_node.c:223
transport_proto_vft_t * transport_vft
Definition: session.h:158
long ctx[MAX_CONNS]
Definition: main.c:144
static u8 session_handle_is_local(session_handle_t handle)
Definition: session.h:377
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:205
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
Definition: buffer.h:440
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:107
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:170
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:66
static stream_session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:321
u32 node_index
Node index.
Definition: node.h:494
#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
int session_tx_fifo_peek_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_event_t *e, stream_session_t *s, int *n_tx_pkts)
Definition: session_node.c:711
struct _session_manager_main session_manager_main_t
Definition: session.h:176
#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:364
volatile u8 session_state
State.
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:138
word fformat(FILE *f, char *fmt,...)
Definition: format.c:453
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1176
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
Definition: svm_fifo.h:157
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define SESSION_EVT_DBG(_evt, _args...)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:155
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:265
vlib_main_t * vm
Definition: buffer.c:294
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
static void svm_fifo_set_want_tx_evt(svm_fifo_t *f, u8 want_evt)
Definition: svm_fifo.h:176
#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
#define clib_memcpy(a, b, c)
Definition: string.h:75
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait)
Producer enqueue one message to queue.
int vnet_disconnect_session(vnet_disconnect_args_t *a)
#define ARRAY_LEN(x)
Definition: clib.h:61
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:455
blocking call - best used in combination with condvars, for eventfds we don&#39;t yield the cpu ...
Definition: queue.h:42
u32 app_wrk_index
Server index.
static int svm_msg_q_try_lock(svm_msg_q_t *mq)
Try locking message queue.
application_t * application_get(u32 app_index)
Definition: application.c:243
int app_worker_lock_and_send_event(app_worker_t *app, stream_session_t *s, u8 evt_type)
Send event to application.
Definition: application.c:1339
static stream_session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:369
#define SESSION_Q_PROCESS_STOP
Definition: session.h:283
u32 ring_index
ring index, could be u8
Definition: message_queue.h:62
#define foreach_session_queue_error
Definition: session_node.c:218
#define ASSERT(truth)
static void session_mq_disconnected_reply_handler(void *data)
Definition: session_node.c:172
int session_tx_fifo_dequeue_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_event_t *e, stream_session_t *s, int *n_tx_pkts)
Definition: session_node.c:719
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:129
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:131
#define vec_append(v1, v2)
Append v2 after v1.
Definition: vec.h:820
static u8 * format_session_queue_trace(u8 *s, va_list *args)
Definition: session_node.c:207
session_dgram_hdr_t hdr
Definition: session.h:172
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
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:155
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:475
u32 app_index
App index in app pool.
Definition: application.h:122
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:726
static u8 session_tx_not_ready(stream_session_t *s, u8 peek_data)
Definition: session_node.c:440
void svm_msg_q_free_msg(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Free message buffer.
enum _transport_proto transport_proto_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:547
u64 uword
Definition: types.h:112
static void session_mq_accepted_reply_handler(void *data)
Definition: session_node.c:28
static u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, vlib_buffer_free_list_index_t index)
Definition: buffer_funcs.h:689
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
Definition: session_node.c:197
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:126
static transport_connection_t * session_tx_get_transport(session_tx_context_t *ctx, u8 peek_data)
Definition: session_node.c:455
u32 app_index
Index of owning app.
Definition: application.h:72
transport_connection_t * tc
Definition: session.h:159
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1455
static u32 svm_msg_q_size(svm_msg_q_t *mq)
Check length of message queue.
#define vec_foreach(var, vec)
Vector iterator.
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 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:116
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:503
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:75
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
Definition: svm_fifo.c:718
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
Definition: svm_fifo.c:670
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:58
static void session_mq_reset_reply_handler(void *data)
Definition: session_node.c:85
void stream_session_disconnect_transport(stream_session_t *s)
Notify transport the session can be disconnected.
Definition: session.c:1106
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.