FD.io VPP  v19.08-27-gf4dcae4
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 
88 
89  /* Closed while waiting for app to reply. Resend disconnect */
90  if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
91  {
92  app_worker_close_notify (app_wrk, s);
93  s->session_state = old_state;
94  return;
95  }
96  }
97 }
98 
99 static void
101 {
102  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
104  app_worker_t *app_wrk;
105  session_t *s;
106  application_t *app;
107  u32 index, thread_index;
108 
109  mp = (session_reset_reply_msg_t *) data;
110  app = application_lookup (mp->context);
111  if (!app)
112  return;
113 
114  session_parse_handle (mp->handle, &index, &thread_index);
115  s = session_get_if_valid (index, thread_index);
116 
117  /* Session was already closed or already cleaned up */
119  return;
120 
121  app_wrk = app_worker_get (s->app_wrk_index);
122  if (!app_wrk || app_wrk->app_index != app->app_index)
123  {
124  clib_warning ("App % does not own handle 0x%lx!", app->app_index,
125  mp->handle);
126  return;
127  }
128 
129  /* Client objected to resetting the session, log and continue */
130  if (mp->retval)
131  {
132  clib_warning ("client retval %d", mp->retval);
133  return;
134  }
135 
136  /* This comes as a response to a reset, transport only waiting for
137  * confirmation to remove connection state, no need to disconnect */
138  a->handle = mp->handle;
139  a->app_index = app->app_index;
141 }
142 
143 static void
145 {
147  vnet_disconnect_args_t _a, *a = &_a;
148  svm_msg_q_msg_t _msg, *msg = &_msg;
150  app_worker_t *app_wrk;
151  session_event_t *evt;
152  session_t *s;
153  application_t *app;
154  int rv = 0;
155 
156  mp = (session_disconnected_msg_t *) data;
157  if (!(s = session_get_from_handle_if_valid (mp->handle)))
158  {
159  clib_warning ("could not disconnect handle %llu", mp->handle);
160  return;
161  }
162  app_wrk = app_worker_get (s->app_wrk_index);
163  app = application_lookup (mp->client_index);
164  if (!(app_wrk && app && app->app_index == app_wrk->app_index))
165  {
166  clib_warning ("could not disconnect session: %llu app: %u",
167  mp->handle, mp->client_index);
168  return;
169  }
170 
171  a->handle = mp->handle;
172  a->app_index = app_wrk->wrk_index;
173  rv = vnet_disconnect_session (a);
174 
177  SVM_Q_WAIT, msg);
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_and_unlock (app_wrk->event_queue, msg);
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  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
253  clib_memset (evt, 0, sizeof (*evt));
254  evt->event_type = SESSION_CTRL_EVT_REQ_WORKER_UPDATE;
255  wump = (session_req_worker_update_msg_t *) evt->data;
256  wump->session_handle = mp->handle;
257  svm_msg_q_add_and_unlock (app_wrk->event_queue, msg);
258  return;
259  }
260 
261  app_worker_own_session (app_wrk, s);
262 
263  /*
264  * Send reply
265  */
268  SVM_Q_WAIT, msg);
269  evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
270  clib_memset (evt, 0, sizeof (*evt));
271  evt->event_type = SESSION_CTRL_EVT_WORKER_UPDATE_REPLY;
272  rmp = (session_worker_update_reply_msg_t *) evt->data;
273  rmp->handle = mp->handle;
274  rmp->rx_fifo = pointer_to_uword (s->rx_fifo);
275  rmp->tx_fifo = pointer_to_uword (s->tx_fifo);
277  svm_msg_q_add_and_unlock (app_wrk->event_queue, msg);
278 
279  /*
280  * Retransmit messages that may have been lost
281  */
282  if (s->tx_fifo && !svm_fifo_is_empty (s->tx_fifo))
284 
285  if (s->rx_fifo && !svm_fifo_is_empty (s->rx_fifo))
287 
289  app_worker_close_notify (app_wrk, s);
290 }
291 
293 
294 typedef struct
295 {
299 
300 /* packet trace format function */
301 static u8 *
302 format_session_queue_trace (u8 * s, va_list * args)
303 {
304  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
305  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
306  session_queue_trace_t *t = va_arg (*args, session_queue_trace_t *);
307 
308  s = format (s, "SESSION_QUEUE: session index %d, server thread index %d",
310  return s;
311 }
312 
313 #define foreach_session_queue_error \
314 _(TX, "Packets transmitted") \
315 _(TIMER, "Timer events") \
316 _(NO_BUFFER, "Out of buffers")
317 
318 typedef enum
319 {
320 #define _(sym,str) SESSION_QUEUE_ERROR_##sym,
322 #undef _
325 
326 static char *session_queue_error_strings[] = {
327 #define _(sym,string) string,
329 #undef _
330 };
331 
332 enum
333 {
337 };
338 
339 static void
341  u32 next_index, u32 * to_next, u16 n_segs,
342  session_t * s, u32 n_trace)
343 {
345  vlib_buffer_t *b;
346  int i;
347 
348  for (i = 0; i < clib_min (n_trace, n_segs); i++)
349  {
350  b = vlib_get_buffer (vm, to_next[i - n_segs]);
351  vlib_trace_buffer (vm, node, next_index, b, 1 /* follow_chain */ );
352  t = vlib_add_trace (vm, node, b, sizeof (*t));
355  }
356  vlib_set_trace_count (vm, node, n_trace - i);
357 }
358 
359 always_inline void
361  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
362 {
363  vlib_buffer_t *chain_b, *prev_b;
364  u32 chain_bi0, to_deq, left_from_seg;
365  session_worker_t *wrk;
366  u16 len_to_deq, n_bytes_read;
367  u8 *data, j;
368 
369  wrk = session_main_get_worker (ctx->s->thread_index);
370  b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
372 
373  chain_b = b;
374  left_from_seg = clib_min (ctx->snd_mss - b->current_length,
375  ctx->left_to_snd);
376  to_deq = left_from_seg;
377  for (j = 1; j < ctx->n_bufs_per_seg; j++)
378  {
379  prev_b = chain_b;
380  len_to_deq = clib_min (to_deq, ctx->deq_per_buf);
381 
382  *n_bufs -= 1;
383  chain_bi0 = wrk->tx_buffers[*n_bufs];
384  chain_b = vlib_get_buffer (vm, chain_bi0);
385  chain_b->current_data = 0;
386  data = vlib_buffer_get_current (chain_b);
387  if (peek_data)
388  {
389  n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo,
390  ctx->tx_offset, len_to_deq, data);
391  ctx->tx_offset += n_bytes_read;
392  }
393  else
394  {
395  if (ctx->transport_vft->transport_options.tx_type ==
397  {
398  svm_fifo_t *f = ctx->s->tx_fifo;
399  session_dgram_hdr_t *hdr = &ctx->hdr;
400  u16 deq_now;
401  deq_now = clib_min (hdr->data_length - hdr->data_offset,
402  len_to_deq);
403  n_bytes_read = svm_fifo_peek (f, hdr->data_offset, deq_now,
404  data);
405  ASSERT (n_bytes_read > 0);
406 
407  hdr->data_offset += n_bytes_read;
408  if (hdr->data_offset == hdr->data_length)
409  {
411  svm_fifo_dequeue_drop (f, offset);
412  }
413  }
414  else
415  n_bytes_read = svm_fifo_dequeue (ctx->s->tx_fifo,
416  len_to_deq, data);
417  }
418  ASSERT (n_bytes_read == len_to_deq);
419  chain_b->current_length = n_bytes_read;
421 
422  /* update previous buffer */
423  prev_b->next_buffer = chain_bi0;
424  prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
425 
426  /* update current buffer */
427  chain_b->next_buffer = 0;
428 
429  to_deq -= n_bytes_read;
430  if (to_deq == 0)
431  break;
432  }
433  ASSERT (to_deq == 0
434  && b->total_length_not_including_first_buffer == left_from_seg);
435  ctx->left_to_snd -= left_from_seg;
436 }
437 
438 always_inline void
440  vlib_buffer_t * b, u16 * n_bufs, u8 peek_data)
441 {
442  u32 len_to_deq;
443  u8 *data0;
444  int n_bytes_read;
445 
446  /*
447  * Start with the first buffer in chain
448  */
449  b->error = 0;
450  b->flags = VNET_BUFFER_F_LOCALLY_ORIGINATED;
451  b->current_data = 0;
452 
454  len_to_deq = clib_min (ctx->left_to_snd, ctx->deq_per_first_buf);
455 
456  if (peek_data)
457  {
458  n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo, ctx->tx_offset,
459  len_to_deq, data0);
460  ASSERT (n_bytes_read > 0);
461  /* Keep track of progress locally, transport is also supposed to
462  * increment it independently when pushing the header */
463  ctx->tx_offset += n_bytes_read;
464  }
465  else
466  {
467  if (ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
468  {
469  session_dgram_hdr_t *hdr = &ctx->hdr;
470  svm_fifo_t *f = ctx->s->tx_fifo;
471  u16 deq_now;
472  u32 offset;
473 
474  ASSERT (hdr->data_length > hdr->data_offset);
475  deq_now = clib_min (hdr->data_length - hdr->data_offset,
476  len_to_deq);
477  offset = hdr->data_offset + SESSION_CONN_HDR_LEN;
478  n_bytes_read = svm_fifo_peek (f, offset, deq_now, data0);
479  ASSERT (n_bytes_read > 0);
480 
482  {
483  ip_copy (&ctx->tc->rmt_ip, &hdr->rmt_ip, ctx->tc->is_ip4);
484  ctx->tc->rmt_port = hdr->rmt_port;
485  }
486  hdr->data_offset += n_bytes_read;
487  if (hdr->data_offset == hdr->data_length)
488  {
489  offset = hdr->data_length + SESSION_CONN_HDR_LEN;
490  svm_fifo_dequeue_drop (f, offset);
491  }
492  }
493  else
494  {
495  n_bytes_read = svm_fifo_dequeue (ctx->s->tx_fifo,
496  len_to_deq, data0);
497  ASSERT (n_bytes_read > 0);
498  }
499  }
500  b->current_length = n_bytes_read;
501  ctx->left_to_snd -= n_bytes_read;
502 
503  /*
504  * Fill in the remaining buffers in the chain, if any
505  */
506  if (PREDICT_FALSE (ctx->n_bufs_per_seg > 1 && ctx->left_to_snd))
507  session_tx_fifo_chain_tail (vm, ctx, b, n_bufs, peek_data);
508 }
509 
512 {
513  if (peek_data)
514  {
516  return 0;
517  /* Can retransmit for closed sessions but can't send new data if
518  * session is not ready or closed */
519  else if (s->session_state < SESSION_STATE_READY)
520  return 1;
522  {
523  /* Allow closed transports to still send custom packets.
524  * For instance, tcp may want to send acks in time-wait. */
526  && (s->flags & SESSION_F_CUSTOM_TX))
527  return 0;
528  return 2;
529  }
530  }
531  return 0;
532 }
533 
536 {
537  if (peek_data)
538  {
539  return ctx->transport_vft->get_connection (ctx->s->connection_index,
540  ctx->s->thread_index);
541  }
542  else
543  {
545  return ctx->transport_vft->get_listener (ctx->s->connection_index);
546  else
547  {
548  return ctx->transport_vft->get_connection (ctx->s->connection_index,
549  ctx->s->thread_index);
550  }
551  }
552 }
553 
554 always_inline void
556  u32 max_segs, u8 peek_data)
557 {
558  u32 n_bytes_per_buf, n_bytes_per_seg;
560  if (peek_data)
561  {
562  /* Offset in rx fifo from where to peek data */
563  ctx->tx_offset = ctx->transport_vft->tx_fifo_offset (ctx->tc);
564  if (PREDICT_FALSE (ctx->tx_offset >= ctx->max_dequeue))
565  {
566  ctx->max_len_to_snd = 0;
567  return;
568  }
569  ctx->max_dequeue -= ctx->tx_offset;
570  }
571  else
572  {
573  if (ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
574  {
575  if (ctx->max_dequeue <= sizeof (ctx->hdr))
576  {
577  ctx->max_len_to_snd = 0;
578  return;
579  }
580  svm_fifo_peek (ctx->s->tx_fifo, 0, sizeof (ctx->hdr),
581  (u8 *) & ctx->hdr);
582  ASSERT (ctx->hdr.data_length > ctx->hdr.data_offset);
583  ctx->max_dequeue = ctx->hdr.data_length - ctx->hdr.data_offset;
584  }
585  }
586  ASSERT (ctx->max_dequeue > 0);
587 
588  /* Ensure we're not writing more than transport window allows */
589  if (ctx->max_dequeue < ctx->snd_space)
590  {
591  /* Constrained by tx queue. Try to send only fully formed segments */
592  ctx->max_len_to_snd =
593  (ctx->max_dequeue > ctx->snd_mss) ?
594  ctx->max_dequeue - ctx->max_dequeue % ctx->snd_mss : ctx->max_dequeue;
595  /* TODO Nagle ? */
596  }
597  else
598  {
599  /* Expectation is that snd_space0 is already a multiple of snd_mss */
600  ctx->max_len_to_snd = ctx->snd_space;
601  }
602 
603  /* Check if we're tx constrained by the node */
604  ctx->n_segs_per_evt = ceil ((f64) ctx->max_len_to_snd / ctx->snd_mss);
605  if (ctx->n_segs_per_evt > max_segs)
606  {
607  ctx->n_segs_per_evt = max_segs;
608  ctx->max_len_to_snd = max_segs * ctx->snd_mss;
609  }
610 
611  n_bytes_per_buf = vlib_buffer_get_default_data_size (vm);
612  ASSERT (n_bytes_per_buf > TRANSPORT_MAX_HDRS_LEN);
613  n_bytes_per_seg = TRANSPORT_MAX_HDRS_LEN + ctx->snd_mss;
614  ctx->n_bufs_per_seg = ceil ((f64) n_bytes_per_seg / n_bytes_per_buf);
615  ctx->deq_per_buf = clib_min (ctx->snd_mss, n_bytes_per_buf);
616  ctx->deq_per_first_buf = clib_min (ctx->snd_mss,
617  n_bytes_per_buf -
619 }
620 
621 always_inline int
623  vlib_node_runtime_t * node,
624  session_evt_elt_t * elt,
625  int *n_tx_packets, u8 peek_data)
626 {
627  u32 next_index, next0, next1, *to_next, n_left_to_next, max_burst;
628  u32 n_trace, n_bufs_needed = 0, n_left, pbi;
629  session_tx_context_t *ctx = &wrk->ctx;
631  session_event_t *e = &elt->evt;
632  vlib_main_t *vm = wrk->vm;
634  vlib_buffer_t *pb;
635  u16 n_bufs, rv;
636 
637  if (PREDICT_FALSE ((rv = session_tx_not_ready (ctx->s, peek_data))))
638  {
639  if (rv < 2)
640  session_evt_add_old (wrk, elt);
641  return SESSION_TX_NO_DATA;
642  }
643 
644  next_index = smm->session_type_to_next[ctx->s->session_type];
645  next0 = next1 = next_index;
646  max_burst = VLIB_FRAME_SIZE - *n_tx_packets;
647 
648  tp = session_get_transport_proto (ctx->s);
650  ctx->tc = session_tx_get_transport (ctx, peek_data);
651 
652  if (PREDICT_FALSE (e->event_type == SESSION_IO_EVT_TX_FLUSH))
653  {
654  if (ctx->transport_vft->flush_data)
655  ctx->transport_vft->flush_data (ctx->tc);
656  }
657 
658  if (ctx->s->flags & SESSION_F_CUSTOM_TX)
659  {
660  u32 n_custom_tx;
661  ctx->s->flags &= ~SESSION_F_CUSTOM_TX;
662  n_custom_tx = ctx->transport_vft->custom_tx (ctx->tc, max_burst);
663  *n_tx_packets += n_custom_tx;
664  if (PREDICT_FALSE
666  return SESSION_TX_OK;
667  max_burst -= n_custom_tx;
668  if (!max_burst)
669  {
670  session_evt_add_old (wrk, elt);
671  return SESSION_TX_OK;
672  }
673  }
674 
675  ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc);
677  vm->clib_time.
678  last_cpu_time,
679  ctx->snd_mss);
680 
681  if (ctx->snd_space == 0 || ctx->snd_mss == 0)
682  {
683  session_evt_add_old (wrk, elt);
684  return SESSION_TX_NO_DATA;
685  }
686 
687  /* Allow enqueuing of a new event */
689 
690  /* Check how much we can pull. */
691  session_tx_set_dequeue_params (vm, ctx, max_burst, peek_data);
692 
693  if (PREDICT_FALSE (!ctx->max_len_to_snd))
694  return SESSION_TX_NO_DATA;
695 
696  n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg;
697  vec_validate_aligned (wrk->tx_buffers, n_bufs_needed - 1,
699  n_bufs = vlib_buffer_alloc (vm, wrk->tx_buffers, n_bufs_needed);
700  if (PREDICT_FALSE (n_bufs < n_bufs_needed))
701  {
702  if (n_bufs)
703  vlib_buffer_free (vm, wrk->tx_buffers, n_bufs);
704  session_evt_add_old (wrk, elt);
706  SESSION_QUEUE_ERROR_NO_BUFFER, 1);
707  return SESSION_TX_NO_BUFFERS;
708  }
709 
710  /*
711  * Write until we fill up a frame
712  */
713  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
714  if (PREDICT_FALSE (ctx->n_segs_per_evt > n_left_to_next))
715  {
716  ctx->n_segs_per_evt = n_left_to_next;
717  ctx->max_len_to_snd = ctx->snd_mss * n_left_to_next;
718  }
719  ctx->left_to_snd = ctx->max_len_to_snd;
720  n_left = ctx->n_segs_per_evt;
721 
722  while (n_left >= 4)
723  {
724  vlib_buffer_t *b0, *b1;
725  u32 bi0, bi1;
726 
727  pbi = wrk->tx_buffers[n_bufs - 3];
728  pb = vlib_get_buffer (vm, pbi);
729  vlib_prefetch_buffer_header (pb, STORE);
730  pbi = wrk->tx_buffers[n_bufs - 4];
731  pb = vlib_get_buffer (vm, pbi);
732  vlib_prefetch_buffer_header (pb, STORE);
733 
734  to_next[0] = bi0 = wrk->tx_buffers[--n_bufs];
735  to_next[1] = bi1 = wrk->tx_buffers[--n_bufs];
736 
737  b0 = vlib_get_buffer (vm, bi0);
738  b1 = vlib_get_buffer (vm, bi1);
739 
740  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
741  session_tx_fill_buffer (vm, ctx, b1, &n_bufs, peek_data);
742 
743  ctx->transport_vft->push_header (ctx->tc, b0);
744  ctx->transport_vft->push_header (ctx->tc, b1);
745 
746  to_next += 2;
747  n_left_to_next -= 2;
748  n_left -= 2;
749 
752 
753  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
754  n_left_to_next, bi0, bi1, next0,
755  next1);
756  }
757  while (n_left)
758  {
759  vlib_buffer_t *b0;
760  u32 bi0;
761 
762  if (n_left > 1)
763  {
764  pbi = wrk->tx_buffers[n_bufs - 2];
765  pb = vlib_get_buffer (vm, pbi);
766  vlib_prefetch_buffer_header (pb, STORE);
767  }
768 
769  to_next[0] = bi0 = wrk->tx_buffers[--n_bufs];
770  b0 = vlib_get_buffer (vm, bi0);
771  session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data);
772 
773  /* Ask transport to push header after current_length and
774  * total_length_not_including_first_buffer are updated */
775  ctx->transport_vft->push_header (ctx->tc, b0);
776 
777  to_next += 1;
778  n_left_to_next -= 1;
779  n_left -= 1;
780 
782 
783  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
784  n_left_to_next, bi0, next0);
785  }
786 
787  if (PREDICT_FALSE ((n_trace = vlib_get_trace_count (vm, node)) > 0))
788  session_tx_trace_frame (vm, node, next_index, to_next,
789  ctx->n_segs_per_evt, ctx->s, n_trace);
790 
791  if (PREDICT_FALSE (n_bufs))
792  vlib_buffer_free (vm, wrk->tx_buffers, n_bufs);
793 
794  *n_tx_packets += ctx->n_segs_per_evt;
796  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
797 
798  SESSION_EVT (SESSION_EVT_DEQ, ctx->s, ctx->max_len_to_snd, ctx->max_dequeue,
799  ctx->s->tx_fifo->has_event, wrk->last_vlib_time);
800 
801  /* If we couldn't dequeue all bytes mark as partially read */
802  ASSERT (ctx->left_to_snd == 0);
803  if (ctx->max_len_to_snd < ctx->max_dequeue)
804  if (svm_fifo_set_event (ctx->s->tx_fifo))
805  session_evt_add_old (wrk, elt);
806 
807  if (!peek_data
808  && ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
809  {
810  /* Fix dgram pre header */
811  if (ctx->max_len_to_snd < ctx->max_dequeue)
812  svm_fifo_overwrite_head (ctx->s->tx_fifo, (u8 *) & ctx->hdr,
813  sizeof (session_dgram_pre_hdr_t));
814  /* More data needs to be read */
815  else if (svm_fifo_max_dequeue_cons (ctx->s->tx_fifo) > 0)
816  if (svm_fifo_set_event (ctx->s->tx_fifo))
817  session_evt_add_old (wrk, elt);
818 
820  session_dequeue_notify (ctx->s);
821  }
822  return SESSION_TX_OK;
823 }
824 
825 int
827  vlib_node_runtime_t * node,
828  session_evt_elt_t * e, int *n_tx_packets)
829 {
830  return session_tx_fifo_read_and_snd_i (wrk, node, e, n_tx_packets, 1);
831 }
832 
833 int
835  vlib_node_runtime_t * node,
836  session_evt_elt_t * e, int *n_tx_packets)
837 {
838  return session_tx_fifo_read_and_snd_i (wrk, node, e, n_tx_packets, 0);
839 }
840 
841 int
843  vlib_node_runtime_t * node,
844  session_evt_elt_t * e, int *n_tx_packets)
845 {
846  session_t *s = wrk->ctx.s;
847 
849  return 0;
852  VLIB_FRAME_SIZE - *n_tx_packets);
853 }
854 
856 session_event_get_session (session_event_t * e, u8 thread_index)
857 {
858  return session_get_if_valid (e->session_index, thread_index);
859 }
860 
861 always_inline void
863  session_evt_elt_t * elt, u32 thread_index,
864  int *n_tx_packets)
865 {
867  app_worker_t *app_wrk;
869  void (*fp) (void *);
870  session_event_t *e;
871  session_t *s;
872 
873  ei = clib_llist_entry_index (wrk->event_elts, elt);
874  e = &elt->evt;
875 
876  switch (e->event_type)
877  {
879  case SESSION_IO_EVT_TX:
880  s = session_event_get_session (e, thread_index);
881  if (PREDICT_FALSE (!s))
882  {
883  clib_warning ("session %u was freed!", e->session_index);
884  break;
885  }
887  wrk->ctx.s = s;
888  /* Spray packets in per session type frames, since they go to
889  * different nodes */
890  (smm->session_tx_fns[s->session_type]) (wrk, node, elt, n_tx_packets);
891  break;
892  case SESSION_IO_EVT_RX:
893  s = session_event_get_session (e, thread_index);
894  if (!s)
895  break;
898  break;
900  s = session_get_from_handle_if_valid (e->session_handle);
901  if (PREDICT_FALSE (!s))
902  break;
904  break;
906  s = session_event_get_session (e, thread_index);
908  break;
910  app_wrk = app_worker_get (s->app_wrk_index);
911  app_worker_builtin_rx (app_wrk, s);
912  break;
914  s = session_get_from_handle_if_valid (e->session_handle);
915  wrk->ctx.s = s;
916  if (PREDICT_TRUE (s != 0))
917  session_tx_fifo_dequeue_internal (wrk, node, elt, n_tx_packets);
918  break;
920  fp = e->rpc_args.fp;
921  (*fp) (e->rpc_args.arg);
922  break;
925  break;
928  break;
930  break;
933  break;
936  break;
939  break;
940  default:
941  clib_warning ("unhandled event type %d", e->event_type);
942  }
943 
944  /* Regrab elements in case pool moved */
945  elt = pool_elt_at_index (wrk->event_elts, ei);
946  if (!clib_llist_elt_is_linked (elt, evt_list))
947  session_evt_elt_free (wrk, elt);
948 }
949 
950 static uword
952  vlib_frame_t * frame)
953 {
955  u32 thread_index = vm->thread_index, n_to_dequeue;
956  session_worker_t *wrk = &smm->wrk[thread_index];
957  session_evt_elt_t *elt, *ctrl_he, *new_he, *old_he;
958  svm_msg_q_msg_t _msg, *msg = &_msg;
959  clib_llist_index_t old_ti;
960  int i, n_tx_packets = 0;
961  session_event_t *evt;
962  svm_msg_q_t *mq;
963 
964  SESSION_EVT (SESSION_EVT_DISPATCH_START, wrk);
965 
966  wrk->last_vlib_time = vlib_time_now (vm);
967 
968  /*
969  * Update transport time
970  */
971  transport_update_time (wrk->last_vlib_time, thread_index);
972 
973  /*
974  * Dequeue and handle new events
975  */
976 
977  /* Try to dequeue what is available. Don't wait for lock.
978  * XXX: we may need priorities here */
979  mq = wrk->vpp_event_queue;
980  n_to_dequeue = svm_msg_q_size (mq);
981  if (n_to_dequeue && svm_msg_q_try_lock (mq) == 0)
982  {
983  for (i = 0; i < n_to_dequeue; i++)
984  {
985  svm_msg_q_sub_w_lock (mq, msg);
986  evt = svm_msg_q_msg_data (mq, msg);
987  if (evt->event_type > SESSION_IO_EVT_BUILTIN_TX)
988  elt = session_evt_alloc_ctrl (wrk);
989  else
990  elt = session_evt_alloc_new (wrk);
991  /* Works because reply messages are smaller than a session evt.
992  * If we ever need to support bigger messages this needs to be
993  * fixed */
994  clib_memcpy_fast (&elt->evt, evt, sizeof (elt->evt));
995  svm_msg_q_free_msg (mq, msg);
996  }
997  svm_msg_q_unlock (mq);
998  }
999 
1000  /*
1001  * Handle control events
1002  */
1003 
1004  ctrl_he = pool_elt_at_index (wrk->event_elts, wrk->ctrl_head);
1005 
1006  /* *INDENT-OFF* */
1007  clib_llist_foreach_safe (wrk->event_elts, evt_list, ctrl_he, elt, ({
1008  clib_llist_remove (wrk->event_elts, evt_list, elt);
1009  session_event_dispatch (wrk, node, elt, thread_index, &n_tx_packets);
1010  }));
1011  /* *INDENT-ON* */
1012 
1013  /*
1014  * Handle the new io events.
1015  */
1016 
1017  new_he = pool_elt_at_index (wrk->event_elts, wrk->new_head);
1018 
1019  /* *INDENT-OFF* */
1020  clib_llist_foreach_safe (wrk->event_elts, evt_list, new_he, elt, ({
1021  session_evt_type_t et;
1022 
1023  et = elt->evt.event_type;
1024  clib_llist_remove (wrk->event_elts, evt_list, elt);
1025 
1026  /* Postpone tx events if we can't handle them this dispatch cycle */
1027  if (n_tx_packets >= VLIB_FRAME_SIZE
1028  && (et == SESSION_IO_EVT_TX || et == SESSION_IO_EVT_TX_FLUSH))
1029  {
1030  clib_llist_add (wrk->event_elts, evt_list, elt, new_he);
1031  continue;
1032  }
1033 
1034  session_event_dispatch (wrk, node, elt, thread_index, &n_tx_packets);
1035  }));
1036  /* *INDENT-ON* */
1037 
1038  /*
1039  * Handle the old io events
1040  */
1041 
1042  old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
1043  old_ti = clib_llist_prev_index (old_he, evt_list);
1044 
1045  while (!clib_llist_is_empty (wrk->event_elts, evt_list, old_he))
1046  {
1047  clib_llist_index_t ei;
1048 
1049  clib_llist_pop_first (wrk->event_elts, evt_list, elt, old_he);
1050  ei = clib_llist_entry_index (wrk->event_elts, elt);
1051  session_event_dispatch (wrk, node, elt, thread_index, &n_tx_packets);
1052 
1053  old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
1054  if (n_tx_packets >= VLIB_FRAME_SIZE || ei == old_ti)
1055  break;
1056  };
1057 
1059  SESSION_QUEUE_ERROR_TX, n_tx_packets);
1060 
1061  SESSION_EVT (SESSION_EVT_DISPATCH_END, wrk, n_tx_packets);
1062 
1063  return n_tx_packets;
1064 }
1065 
1066 /* *INDENT-OFF* */
1068 {
1069  .function = session_queue_node_fn,
1070  .name = "session-queue",
1071  .format_trace = format_session_queue_trace,
1072  .type = VLIB_NODE_TYPE_INPUT,
1073  .n_errors = ARRAY_LEN (session_queue_error_strings),
1074  .error_strings = session_queue_error_strings,
1075  .state = VLIB_NODE_STATE_DISABLED,
1076 };
1077 /* *INDENT-ON* */
1078 
1079 void
1081 {
1084  u32 my_thread_index = vm->thread_index;
1085  session_event_t _e, *e = &_e;
1086  svm_msg_q_ring_t *ring;
1087  session_t *s0;
1088  svm_msg_q_msg_t *msg;
1089  svm_msg_q_t *mq;
1090  int i, index;
1091 
1092  mq = smm->wrk[my_thread_index].vpp_event_queue;
1093  index = mq->q->head;
1094 
1095  for (i = 0; i < mq->q->cursize; i++)
1096  {
1097  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
1098  ring = svm_msg_q_ring (mq, msg->ring_index);
1099  clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
1100 
1101  switch (e->event_type)
1102  {
1103  case SESSION_IO_EVT_TX:
1104  s0 = session_event_get_session (e, my_thread_index);
1105  fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index);
1106  break;
1107 
1109  s0 = session_get_from_handle (e->session_handle);
1110  fformat (stdout, "[%04d] disconnect session %d\n", i,
1111  s0->session_index);
1112  break;
1113 
1115  s0 = session_event_get_session (e, my_thread_index);
1116  fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index);
1117  break;
1118 
1119  case SESSION_CTRL_EVT_RPC:
1120  fformat (stdout, "[%04d] RPC call %llx with %llx\n",
1121  i, (u64) (uword) (e->rpc_args.fp),
1122  (u64) (uword) (e->rpc_args.arg));
1123  break;
1124 
1125  default:
1126  fformat (stdout, "[%04d] unhandled event type %d\n",
1127  i, e->event_type);
1128  break;
1129  }
1130 
1131  index++;
1132 
1133  if (index == mq->q->maxsize)
1134  index = 0;
1135  }
1136 }
1137 
1138 static u8
1139 session_node_cmp_event (session_event_t * e, svm_fifo_t * f)
1140 {
1141  session_t *s;
1142  switch (e->event_type)
1143  {
1144  case SESSION_IO_EVT_RX:
1145  case SESSION_IO_EVT_TX:
1147  if (e->session_index == f->master_session_index)
1148  return 1;
1149  break;
1151  break;
1152  case SESSION_CTRL_EVT_RPC:
1153  s = session_get_from_handle (e->session_handle);
1154  if (!s)
1155  {
1156  clib_warning ("session has event but doesn't exist!");
1157  break;
1158  }
1159  if (s->rx_fifo == f || s->tx_fifo == f)
1160  return 1;
1161  break;
1162  default:
1163  break;
1164  }
1165  return 0;
1166 }
1167 
1168 u8
1169 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e)
1170 {
1171  session_evt_elt_t *elt;
1172  session_worker_t *wrk;
1173  int i, index, found = 0;
1174  svm_msg_q_msg_t *msg;
1175  svm_msg_q_ring_t *ring;
1176  svm_msg_q_t *mq;
1177  u8 thread_index;
1178 
1179  ASSERT (e);
1180  thread_index = f->master_thread_index;
1181  wrk = session_main_get_worker (thread_index);
1182 
1183  /*
1184  * Search evt queue
1185  */
1186  mq = wrk->vpp_event_queue;
1187  index = mq->q->head;
1188  for (i = 0; i < mq->q->cursize; i++)
1189  {
1190  msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index);
1191  ring = svm_msg_q_ring (mq, msg->ring_index);
1192  clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize);
1193  found = session_node_cmp_event (e, f);
1194  if (found)
1195  return 1;
1196  if (++index == mq->q->maxsize)
1197  index = 0;
1198  }
1199  /*
1200  * Search pending events vector
1201  */
1202 
1203  /* *INDENT-OFF* */
1204  clib_llist_foreach (wrk->event_elts, evt_list,
1205  pool_elt_at_index (wrk->event_elts, wrk->old_head),
1206  elt, ({
1207  found = session_node_cmp_event (&elt->evt, f);
1208  if (found)
1209  {
1210  clib_memcpy_fast (e, &elt->evt, sizeof (*e));
1211  break;
1212  }
1213 
1214  }));
1215  /* *INDENT-ON* */
1216 
1217  return found;
1218 }
1219 
1220 static clib_error_t *
1222 {
1223  if (vec_len (vlib_mains) < 2)
1224  return 0;
1225 
1226  /*
1227  * Shut off (especially) worker-thread session nodes.
1228  * Otherwise, vpp can crash as the main thread unmaps the
1229  * API segment.
1230  */
1232  session_node_enable_disable (0 /* is_enable */ );
1234  return 0;
1235 }
1236 
1238 
1239 static uword
1241  vlib_frame_t * f)
1242 {
1243  f64 now, timeout = 1.0;
1244  uword *event_data = 0;
1245  uword event_type;
1246 
1247  while (1)
1248  {
1250  now = vlib_time_now (vm);
1251  event_type = vlib_process_get_events (vm, (uword **) & event_data);
1252 
1253  switch (event_type)
1254  {
1256  /* Flush the frames by updating all transports times */
1257  transport_update_time (now, 0);
1258  break;
1260  timeout = 100000.0;
1261  break;
1262  case ~0:
1263  /* Timed out. Update time for all transports to trigger all
1264  * outstanding retransmits. */
1265  transport_update_time (now, 0);
1266  break;
1267  }
1268  vec_reset_length (event_data);
1269  }
1270  return 0;
1271 }
1272 
1273 /* *INDENT-OFF* */
1275 {
1276  .function = session_queue_process,
1277  .type = VLIB_NODE_TYPE_PROCESS,
1278  .name = "session-queue-process",
1279  .state = VLIB_NODE_STATE_DISABLED,
1280 };
1281 /* *INDENT-ON* */
1282 
1285  vlib_frame_t * frame)
1286 {
1288  if (!sm->wrk[0].vpp_event_queue)
1289  return 0;
1290  return session_queue_node_fn (vm, node, frame);
1291 }
1292 
1293 /* *INDENT-OFF* */
1295 {
1296  .function = session_queue_pre_input_inline,
1297  .type = VLIB_NODE_TYPE_PRE_INPUT,
1298  .name = "session-queue-main",
1299  .state = VLIB_NODE_STATE_DISABLED,
1300 };
1301 /* *INDENT-ON* */
1302 
1303 /*
1304  * fd.io coding-style-patch-verification: ON
1305  *
1306  * Local Variables:
1307  * eval: (c-set-style "gnu")
1308  * End:
1309  */
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:340
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:1937
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_llist_is_empty(LP, name, H)
Check is list is empty.
Definition: llist.h:121
#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:171
svm_msg_q_t * vpp_event_queue
vpp event message queue for worker
Definition: session.h:79
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:673
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
#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
static int svm_fifo_is_empty_prod(svm_fifo_t *f)
Check if fifo is empty optimized for producer.
Definition: svm_fifo.h:568
session_t * s
Definition: session.h:48
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:258
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
Definition: session.h:130
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:265
u32 thread_index
Definition: main.h:197
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static transport_proto_t session_get_transport_proto(session_t *s)
application_t * application_lookup(u32 api_client_index)
Definition: application.c:386
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:926
u32 wrk_map_index
Worker index in app&#39;s map pool.
Definition: application.h:40
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:951
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
session_evt_elt_t * event_elts
Pool of session event list elements.
Definition: session.h:97
u8 data[128]
Definition: ipsec.api:249
clib_time_t clib_time
Definition: main.h:72
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *src, u32 len)
Overwrite fifo head with new data.
Definition: svm_fifo.c:785
#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_dequeue_and_snd(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *e, int *n_tx_packets)
Definition: session_node.c:834
u32 flags
Session flags.
void session_node_enable_disable(u8 is_en)
Definition: session.c:1509
vlib_main_t ** vlib_mains
Definition: buffer.c:321
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
#define clib_llist_foreach(LP, name, H, E, body)
Walk list starting at head.
Definition: llist.h:255
unsigned char u8
Definition: types.h:56
app_worker_t * application_get_worker(application_t *app, u32 wrk_map_index)
Definition: application.c:644
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:439
void transport_update_time(f64 time_now, u8 thread_index)
Definition: transport.c:732
#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:124
u32 * tx_buffers
Vector of tx buffer free lists.
Definition: session.h:94
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)
Check if fifo is empty.
Definition: svm_fifo.h:581
static session_worker_t * session_main_get_worker(u32 thread_index)
Definition: session.h:548
void dump_thread_0_event_queue(void)
#define static_always_inline
Definition: clib.h:99
vlib_main_t * vm
Convenience pointer to this worker&#39;s vlib_main.
Definition: session.h:85
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:516
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
clib_llist_index_t new_head
Head of list of elements.
Definition: session.h:103
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:489
u32 * session_type_to_next
Per session type output nodes.
Definition: session.h:144
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:600
unsigned int u32
Definition: types.h:88
int svm_fifo_dequeue(svm_fifo_t *f, u32 len, u8 *dst)
Dequeue data from fifo.
Definition: svm_fifo.c:900
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:79
#define VLIB_FRAME_SIZE
Definition: node.h:376
session_state_t
static char * session_queue_error_strings[]
Definition: session_node.c:326
int session_dequeue_notify(session_t *s)
Definition: session.c:601
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:284
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
#define TRANSPORT_MAX_HDRS_LEN
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
session_event_t evt
Definition: session.h:68
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:278
session_queue_error_t
Definition: session_node.c:318
transport_proto_vft_t * transport_vft
Definition: session.h:49
long ctx[MAX_CONNS]
Definition: main.c:144
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)
int session_tx_fifo_peek_and_snd(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *e, int *n_tx_packets)
Definition: session_node.c:826
#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)
Unset fifo event flag.
Definition: svm_fifo.h:752
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
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
session_fifo_rx_fn ** session_tx_fns
Per transport rx function that can either dequeue or peek.
Definition: session.h:139
u64 session_segment_handle(session_t *s)
Definition: session.c:1340
#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:338
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:1150
static session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:287
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)
Set fifo event flag.
Definition: svm_fifo.h:739
#define clib_llist_pop_first(LP, name, E, H)
Removes and returns the first element in the list.
Definition: llist.h:215
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
static void session_evt_elt_free(session_worker_t *wrk, session_evt_elt_t *elt)
Definition: session.h:198
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
Definition: svm_fifo.h:830
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:360
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:213
#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:178
#define clib_warning(format, args...)
Definition: error.h:59
svm_queue_t * q
queue for exchanging messages
Definition: message_queue.h:39
struct _transport_connection transport_connection_t
static session_evt_elt_t * session_evt_alloc_new(session_worker_t *wrk)
Definition: session.h:221
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:458
blocking call - best used in combination with condvars, for eventfds we don&#39;t yield the cpu ...
Definition: queue.h:42
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:313
#define ASSERT(truth)
static void session_mq_disconnected_reply_handler(void *data)
Definition: session_node.c:189
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
static session_t * session_event_get_session(session_event_t *e, u8 thread_index)
Definition: session_node.c:856
static int transport_custom_tx(transport_proto_t tp, void *s, u32 max_burst_size)
Definition: transport.h:130
int ct_session_connect_notify(session_t *ss)
datagram mode
session_tx_context_t ctx
Context for session tx.
Definition: session.h:91
void transport_connection_update_tx_bytes(transport_connection_t *tc, u32 bytes)
Update tx bytes for paced transport connection.
Definition: transport.c:711
u32 clib_llist_index_t
Definition: llist.h:27
enum _transport_proto transport_proto_t
#define clib_llist_elt_is_linked(E, name)
Check if element is linked in a list.
Definition: llist.h:129
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:687
ip46_address_t rmt_ip
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static u8 * format_session_queue_trace(u8 *s, va_list *args)
Definition: session_node.c:302
static int transport_app_rx_evt(transport_proto_t tp, u32 conn_index, u32 thread_index)
Definition: transport.h:136
session_dgram_hdr_t hdr
Definition: session.h:62
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:55
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:555
u32 app_index
App index in app pool.
Definition: application.h:89
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
Definition: bihash_doc.h:44
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:511
clib_llist_index_t old_head
Head of list of pending events.
Definition: session.h:106
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:489
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
static void session_evt_add_old(session_worker_t *wrk, session_evt_elt_t *elt)
Definition: session.h:204
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1064
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:292
static void session_event_dispatch(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *elt, u32 thread_index, int *n_tx_packets)
Definition: session_node.c:862
f64 last_vlib_time
vlib_time_now last time around the track
Definition: session.h:82
static session_evt_elt_t * session_evt_alloc_ctrl(session_worker_t *wrk)
Definition: session.h:211
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:144
static u8 session_has_transport(session_t *s)
#define clib_llist_prev_index(E, name)
Definition: llist.h:61
static transport_connection_t * session_tx_get_transport(session_tx_context_t *ctx, u8 peek_data)
Definition: session_node.c:535
u32 app_index
Index of owning app.
Definition: application.h:43
transport_connection_t * tc
Definition: session.h:50
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:367
static u32 svm_msg_q_size(svm_msg_q_t *mq)
Check length of message queue.
u32 app_wrk_index
Index of the app worker that owns the session.
static int session_tx_fifo_read_and_snd_i(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *elt, int *n_tx_packets, u8 peek_data)
Definition: session_node.c:622
static session_main_t * vnet_get_session_main()
Definition: session.h:542
void session_transport_close(session_t *s)
Notify transport the session can be disconnected.
Definition: session.c:1213
clib_llist_index_t ctrl_head
Head of control events list.
Definition: session.h:100
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:187
#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
#define clib_llist_foreach_safe(LP, name, H, E, body)
Walk list starting at head safe.
Definition: llist.h:275
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:948
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
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
#define SESSION_EVT(_evt, _args...)
static void session_mq_reset_reply_handler(void *data)
Definition: session_node.c:100
int session_tx_fifo_dequeue_internal(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *e, int *n_tx_packets)
Definition: session_node.c:842
#define clib_llist_entry_index(LP, E)
Get list entry index.
Definition: llist.h:53
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.