FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
transport.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 <vnet/session/transport.h>
17 #include <vnet/session/session.h>
18 #include <vnet/fib/fib.h>
19 
20 typedef struct local_endpoint_
21 {
23  int refcnt;
25 
26 /**
27  * Per-type vector of transport protocol virtual function tables
28  */
30 
31 /*
32  * Port allocator seed
33  */
35 
36 /*
37  * Local endpoints table
38  */
40 
41 /*
42  * Pool of local endpoints
43  */
45 
46 /*
47  * Local endpoints pool lock
48  */
50 
51 u8 *
52 format_transport_proto (u8 * s, va_list * args)
53 {
54  u32 transport_proto = va_arg (*args, u32);
55 
56  if (tp_vfts[transport_proto].transport_options.name)
57  s = format (s, "%s", tp_vfts[transport_proto].transport_options.name);
58  else
59  s = format (s, "n/a");
60 
61  return s;
62 }
63 
64 u8 *
65 format_transport_proto_short (u8 * s, va_list * args)
66 {
67  u32 transport_proto = va_arg (*args, u32);
68  char *short_name;
69 
70  short_name = tp_vfts[transport_proto].transport_options.short_name;
71  if (short_name)
72  s = format (s, "%s", short_name);
73  else
74  s = format (s, "NA");
75 
76  return s;
77 }
78 
79 u8 *
80 format_transport_connection (u8 * s, va_list * args)
81 {
82  u32 transport_proto = va_arg (*args, u32);
83  u32 conn_index = va_arg (*args, u32);
84  u32 thread_index = va_arg (*args, u32);
85  u32 verbose = va_arg (*args, u32);
86  transport_proto_vft_t *tp_vft;
88  u32 indent;
89 
91  if (!tp_vft)
92  return s;
93 
94  s = format (s, "%U", tp_vft->format_connection, conn_index, thread_index,
95  verbose);
96  tc = tp_vft->get_connection (conn_index, thread_index);
97  if (tc && verbose > 1)
98  {
99  indent = format_get_indent (s) + 1;
101  s = format (s, "%Upacer: %U\n", format_white_space, indent,
102  format_transport_pacer, &tc->pacer, tc->thread_index);
103  s = format (s, "%Utransport: flags 0x%x\n", format_white_space, indent,
104  tc->flags);
105  }
106  return s;
107 }
108 
109 u8 *
111 {
112  u32 transport_proto = va_arg (*args, u32);
113  transport_proto_vft_t *tp_vft;
114 
116  if (!tp_vft)
117  return s;
118 
119  s = (tp_vft->format_listener) (s, args);
120  return s;
121 }
122 
123 u8 *
125 {
126  u32 transport_proto = va_arg (*args, u32);
127  u32 ho_index = va_arg (*args, u32);
128  transport_proto_vft_t *tp_vft;
129 
131  if (!tp_vft)
132  return s;
133 
134  s = format (s, "%U", tp_vft->format_half_open, ho_index);
135  return s;
136 }
137 
138 static u8
140 {
141  int i;
142 
143  if (strlen (str) > vec_len (input->buffer) - input->index)
144  return 0;
145 
146  for (i = 0; i < strlen (str); i++)
147  {
148  if (input->buffer[i + input->index] != str[i])
149  return 0;
150  }
151  return 1;
152 }
153 
154 uword
156 {
157  u32 *proto = va_arg (*args, u32 *);
158  transport_proto_vft_t *tp_vft;
159  u8 longest_match = 0, match;
160  char *str, *str_match = 0;
162 
163  for (tp = 0; tp < vec_len (tp_vfts); tp++)
164  {
165  tp_vft = &tp_vfts[tp];
166  str = tp_vft->transport_options.name;
167  if (!str)
168  continue;
169  if (unformat_transport_str_match (input, str))
170  {
171  match = strlen (str);
172  if (match > longest_match)
173  {
174  *proto = tp;
175  longest_match = match;
176  str_match = str;
177  }
178  }
179  }
180  if (longest_match)
181  {
182  (void) unformat (input, str_match);
183  return 1;
184  }
185 
186  return 0;
187 }
188 
189 u8 *
190 format_transport_protos (u8 * s, va_list * args)
191 {
192  transport_proto_vft_t *tp_vft;
193 
194  vec_foreach (tp_vft, tp_vfts)
195  s = format (s, "%s\n", tp_vft->transport_options.name);
196 
197  return s;
198 }
199 
200 u32
202  ip46_address_t * ip, u16 port)
203 {
205  int rv;
206 
207  kv.key[0] = ip->as_u64[0];
208  kv.key[1] = ip->as_u64[1];
209  kv.key[2] = (u64) port << 8 | (u64) proto;
210 
211  rv = clib_bihash_search_inline_24_8 (ht, &kv);
212  if (rv == 0)
213  return kv.value;
214 
215  return ENDPOINT_INVALID_INDEX;
216 }
217 
218 void
221 {
223 
224  kv.key[0] = te->ip.as_u64[0];
225  kv.key[1] = te->ip.as_u64[1];
226  kv.key[2] = (u64) te->port << 8 | (u64) proto;
227  kv.value = value;
228 
229  clib_bihash_add_del_24_8 (ht, &kv, 1);
230 }
231 
232 void
235 {
237 
238  kv.key[0] = te->ip.as_u64[0];
239  kv.key[1] = te->ip.as_u64[1];
240  kv.key[2] = (u64) te->port << 8 | (u64) proto;
241 
242  clib_bihash_add_del_24_8 (ht, &kv, 0);
243 }
244 
245 void
247  const transport_proto_vft_t * vft,
248  fib_protocol_t fib_proto, u32 output_node)
249 {
250  u8 is_ip4 = fib_proto == FIB_PROTOCOL_IP4;
251 
253  tp_vfts[transport_proto] = *vft;
254 
255  session_register_transport (transport_proto, vft, is_ip4, output_node);
256 }
257 
260  fib_protocol_t fib_proto, u32 output_node)
261 {
263  u8 is_ip4;
264 
266  is_ip4 = fib_proto == FIB_PROTOCOL_IP4;
267 
269  tp_vfts[transport_proto] = *vft;
270 
271  session_register_transport (transport_proto, vft, is_ip4, output_node);
272 
273  return transport_proto;
274 }
275 
276 /**
277  * Get transport virtual function table
278  *
279  * @param type - session type (not protocol type)
280  */
283 {
285  return 0;
286  return &tp_vfts[transport_proto];
287 }
288 
291 {
292  return tp_vfts[tp].transport_options.service_type;
293 }
294 
297 {
298  return tp_vfts[tp].transport_options.tx_type;
299 }
300 
301 void
303 {
304  tp_vfts[tp].cleanup (conn_index, thread_index);
305 }
306 
307 void
309 {
310  if (tp_vfts[tp].cleanup_ho)
311  tp_vfts[tp].cleanup_ho (conn_index);
312 }
313 
314 int
316 {
317  return tp_vfts[tp].connect (tep);
318 }
319 
320 void
322 {
323  if (tp_vfts[tp].half_close)
324  tp_vfts[tp].half_close (conn_index, thread_index);
325 }
326 
327 void
329 {
330  tp_vfts[tp].close (conn_index, thread_index);
331 }
332 
333 void
335 {
336  if (tp_vfts[tp].reset)
337  tp_vfts[tp].reset (conn_index, thread_index);
338  else
339  tp_vfts[tp].close (conn_index, thread_index);
340 }
341 
342 u32
344  transport_endpoint_t * tep)
345 {
346  return tp_vfts[tp].start_listen (session_index, tep);
347 }
348 
349 u32
351 {
352  return tp_vfts[tp].stop_listen (conn_index);
353 }
354 
355 u8
357 {
358  return (tp_vfts[tp].transport_options.service_type == TRANSPORT_SERVICE_CL);
359 }
360 
361 always_inline void
363  transport_endpoint_t * tep, u8 is_lcl)
364 {
365  if (is_lcl)
366  {
367  tep->port = tc->lcl_port;
368  tep->is_ip4 = tc->is_ip4;
369  clib_memcpy_fast (&tep->ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
370  }
371  else
372  {
373  tep->port = tc->rmt_port;
374  tep->is_ip4 = tc->is_ip4;
375  clib_memcpy_fast (&tep->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
376  }
377 }
378 
379 void
382  u8 is_lcl)
383 {
384  if (tp_vfts[tp].get_transport_endpoint)
385  tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, tep,
386  is_lcl);
387  else
388  {
390  tc = transport_get_connection (tp, conn_index, thread_index);
391  default_get_transport_endpoint (tc, tep, is_lcl);
392  }
393 }
394 
395 void
397  transport_endpoint_t * tep, u8 is_lcl)
398 {
399  if (tp_vfts[tp].get_transport_listener_endpoint)
400  tp_vfts[tp].get_transport_listener_endpoint (conn_index, tep, is_lcl);
401  else
402  {
404  tc = transport_get_listener (tp, conn_index);
405  default_get_transport_endpoint (tc, tep, is_lcl);
406  }
407 }
408 
409 int
411  u8 thread_index, u8 is_get,
413 {
414  if (!tp_vfts[tp].attribute)
415  return -1;
416 
417  return tp_vfts[tp].attribute (conn_index, thread_index, is_get, attr);
418 }
419 
420 #define PORT_MASK ((1 << 16)- 1)
421 
422 void
424 {
428 }
429 
432 {
433  local_endpoint_t *lep;
435  return lep;
436 }
437 
438 void
439 transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port)
440 {
441  local_endpoint_t *lep;
442  u32 lepi;
443 
444  /* Cleanup local endpoint if this was an active connect */
446  clib_net_to_host_u16 (port));
447  if (lepi != ENDPOINT_INVALID_INDEX)
448  {
449  lep = pool_elt_at_index (local_endpoints, lepi);
450  if (!clib_atomic_sub_fetch (&lep->refcnt, 1))
451  {
453  &lep->ep);
454  transport_endpoint_del (lepi);
455  }
456  }
457 }
458 
459 static void
461 {
462  local_endpoint_t *lep;
464  lep = transport_endpoint_new ();
465  clib_memcpy_fast (&lep->ep.ip, ip, sizeof (*ip));
466  lep->ep.port = port;
467  lep->refcnt = 1;
469  lep - local_endpoints);
471 }
472 
473 void
474 transport_share_local_endpoint (u8 proto, ip46_address_t * lcl_ip, u16 port)
475 {
476  local_endpoint_t *lep;
477  u32 lepi;
478 
480  clib_net_to_host_u16 (port));
481  if (lepi != ENDPOINT_INVALID_INDEX)
482  {
483  lep = pool_elt_at_index (local_endpoints, lepi);
484  clib_atomic_add_fetch (&lep->refcnt, 1);
485  }
486 }
487 
488 /**
489  * Allocate local port and add if successful add entry to local endpoint
490  * table to mark the pair as used.
491  */
492 int
494 {
495  u16 min = 1024, max = 65535; /* XXX configurable ? */
496  int tries, limit;
497  u32 tei;
498 
499  limit = max - min;
500 
501  /* Only support active opens from thread 0 */
502  ASSERT (vlib_get_thread_index () == 0);
503 
504  /* Search for first free slot */
505  for (tries = 0; tries < limit; tries++)
506  {
507  u16 port = 0;
508 
509  /* Find a port in the specified range */
510  while (1)
511  {
513  if (PREDICT_TRUE (port >= min && port < max))
514  break;
515  }
516 
517  /* Look it up. If not found, we're done */
519  port);
520  if (tei == ENDPOINT_INVALID_INDEX)
521  {
523  return port;
524  }
525  }
526  return -1;
527 }
528 
529 static session_error_t
530 transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
531 {
532  if (is_ip4)
533  {
536  if (!ip4)
537  return SESSION_E_NOIP;
538  addr->ip4.as_u32 = ip4->as_u32;
539  }
540  else
541  {
542  ip6_address_t *ip6;
544  if (ip6 == 0)
545  return SESSION_E_NOIP;
546  clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
547  }
548  return 0;
549 }
550 
551 static session_error_t
554  ip46_address_t *lcl_addr)
555 {
556  fib_node_index_t fei;
558 
560  {
561  /* Find a FIB path to the destination */
562  clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
563  prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
564  prefix.fp_len = rmt->is_ip4 ? 32 : 128;
565 
566  ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX);
567  fei = fib_table_lookup (rmt->fib_index, &prefix);
568 
569  /* Couldn't find route to destination. Bail out. */
570  if (fei == FIB_NODE_INDEX_INVALID)
571  return SESSION_E_NOROUTE;
572 
575  return SESSION_E_NOINTF;
576  }
577 
578  clib_memset (lcl_addr, 0, sizeof (*lcl_addr));
579  return transport_get_interface_ip (*sw_if_index, rmt->is_ip4, lcl_addr);
580 }
581 
582 int
584  ip46_address_t * lcl_addr, u16 * lcl_port)
585 {
586  transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg;
588  int port;
589  u32 tei;
590 
591  /*
592  * Find the local address
593  */
594  if (ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4))
595  {
596  error = transport_find_local_ip_for_remote (&rmt_cfg->peer.sw_if_index,
597  rmt, lcl_addr);
598  if (error)
599  return error;
600  }
601  else
602  {
603  /* Assume session layer vetted this address */
604  clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip,
605  sizeof (rmt_cfg->peer.ip));
606  }
607 
608  /*
609  * Allocate source port
610  */
611  if (rmt_cfg->peer.port == 0)
612  {
613  port = transport_alloc_local_port (proto, lcl_addr);
614  if (port < 1)
615  return SESSION_E_NOPORT;
616  *lcl_port = port;
617  }
618  else
619  {
620  port = clib_net_to_host_u16 (rmt_cfg->peer.port);
621  *lcl_port = port;
623  lcl_addr, port);
624  if (tei != ENDPOINT_INVALID_INDEX)
625  return SESSION_E_PORTINUSE;
626 
628  }
629 
630  return 0;
631 }
632 
633 u8 *
634 format_clib_us_time (u8 * s, va_list * args)
635 {
636  clib_us_time_t t = va_arg (*args, clib_us_time_t);
637  if (t < 1e3)
638  s = format (s, "%u us", t);
639  else
640  s = format (s, "%.3f s", (f64) t * CLIB_US_TIME_PERIOD);
641  return s;
642 }
643 
644 u8 *
645 format_transport_pacer (u8 * s, va_list * args)
646 {
647  spacer_t *pacer = va_arg (*args, spacer_t *);
648  u32 thread_index = va_arg (*args, int);
649  clib_us_time_t now, diff;
650 
652  diff = now - pacer->last_update;
653  s = format (s, "rate %lu bucket %ld t/p %.3f last_update %U burst %u",
654  pacer->bytes_per_sec, pacer->bucket, pacer->tokens_per_period,
655  format_clib_us_time, diff, pacer->max_burst);
656  return s;
657 }
658 
659 static inline u32
661 {
662  u64 n_periods = (time_now - pacer->last_update);
663  u64 inc;
664 
665  if ((inc = (f32) n_periods * pacer->tokens_per_period) > 10)
666  {
667  pacer->last_update = time_now;
668  pacer->bucket = clib_min (pacer->bucket + inc, pacer->max_burst);
669  }
670 
671  return pacer->bucket > 0 ? pacer->max_burst : 0;
672 }
673 
674 static inline void
676 {
677  pacer->bucket -= bytes;
678 }
679 
680 static inline void
681 spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec,
682  clib_us_time_t rtt, clib_time_type_t sec_per_loop)
683 {
684  clib_us_time_t max_time;
685 
686  ASSERT (rate_bytes_per_sec != 0);
687  pacer->bytes_per_sec = rate_bytes_per_sec;
688  pacer->tokens_per_period = rate_bytes_per_sec * CLIB_US_TIME_PERIOD;
689 
690  /* Allow a min number of bursts per rtt, if their size is acceptable. Goal
691  * is to spread the sending of data over the rtt but to also allow for some
692  * coalescing that can potentially
693  * 1) reduce load on session layer by reducing scheduling frequency for a
694  * session and
695  * 2) optimize sending when tso if available
696  *
697  * Max "time-length" of a burst cannot be less than 1us or more than 1ms.
698  */
699  max_time = clib_max (rtt / TRANSPORT_PACER_BURSTS_PER_RTT,
700  (clib_us_time_t) (sec_per_loop * CLIB_US_TIME_FREQ));
701  max_time = clib_clamp (max_time, 1 /* 1us */ , 1000 /* 1ms */ );
702  pacer->max_burst = (rate_bytes_per_sec * max_time) * CLIB_US_TIME_PERIOD;
703  pacer->max_burst = clib_clamp (pacer->max_burst, TRANSPORT_PACER_MIN_BURST,
705 }
706 
707 static inline u64
709 {
710  return pacer->bytes_per_sec;
711 }
712 
713 static inline void
714 spacer_reset (spacer_t * pacer, clib_us_time_t time_now, u64 bucket)
715 {
716  pacer->last_update = time_now;
717  pacer->bucket = bucket;
718 }
719 
720 void
722  u64 rate_bytes_per_sec, u32 start_bucket,
723  clib_us_time_t rtt)
724 {
725  spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec, rtt,
726  transport_seconds_per_loop (tc->thread_index));
727  spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index),
728  start_bucket);
729 }
730 
731 void
733  u32 bucket)
734 {
735  spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index), bucket);
736 }
737 
738 void
740  u64 rate_bytes_per_sec,
741  u32 initial_bucket)
742 {
744  transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec,
745  initial_bucket, 1e6);
746 }
747 
748 void
750  u64 bytes_per_sec, clib_us_time_t rtt)
751 {
752  spacer_set_pace_rate (&tc->pacer, bytes_per_sec, rtt,
753  transport_seconds_per_loop (tc->thread_index));
754 }
755 
756 u32
758 {
759  return spacer_max_burst (&tc->pacer,
760  transport_us_time_now (tc->thread_index));
761 }
762 
763 u64
765 {
766  return spacer_pace_rate (&tc->pacer);
767 }
768 
769 void
771 {
773  spacer_update_bucket (&tc->pacer, bytes);
774 }
775 
776 void
778  u32 bytes)
779 {
780  spacer_update_bucket (&tc->pacer, bytes);
781 }
782 
783 void
785 {
787 }
788 
789 void
791 {
792  tc->flags &= ~TRANSPORT_CONNECTION_F_DESCHED;
794  if (transport_max_tx_dequeue (tc))
796  else
797  {
798  session_t *s = session_get (tc->s_index, tc->thread_index);
801  if (svm_fifo_set_event (s->tx_fifo))
803  }
804 }
805 
806 void
808 {
809  session_t *s = session_get (tc->s_index, tc->thread_index);
810  svm_fifo_init_ooo_lookup (s->rx_fifo, 0 /* ooo enq */ );
811  svm_fifo_init_ooo_lookup (s->tx_fifo, 1 /* ooo deq */ );
812 }
813 
814 void
816 {
818  vec_foreach (vft, tp_vfts)
819  {
820  if (vft->update_time)
821  (vft->update_time) (time_now, thread_index);
822  }
823 }
824 
825 void
827 {
829  vec_foreach (vft, tp_vfts)
830  {
831  if (vft->enable)
832  (vft->enable) (vm, is_en);
833  }
834 }
835 
836 void
838 {
841  u32 num_threads;
842 
843  if (smm->local_endpoints_table_buckets == 0)
844  smm->local_endpoints_table_buckets = 250000;
845  if (smm->local_endpoints_table_memory == 0)
846  smm->local_endpoints_table_memory = 512 << 20;
847 
848  /* Initialize [port-allocator] random number seed */
850 
851  clib_bihash_init_24_8 (&local_endpoints_table, "local endpoints table",
854  num_threads = 1 /* main thread */ + vtm->n_threads;
855  if (num_threads > 1)
856  {
858  /* Main not polled if there are workers */
859  smm->transport_cl_thread = 1;
860  }
861 }
862 
863 /*
864  * fd.io coding-style-patch-verification: ON
865  *
866  * Local Variables:
867  * eval: (c-set-style "gnu")
868  * End:
869  */
transport_seconds_per_loop
static clib_time_type_t transport_seconds_per_loop(u32 thread_index)
Definition: session.h:598
tp_vfts
transport_proto_vft_t * tp_vfts
Per-type vector of transport protocol virtual function tables.
Definition: transport.c:29
clib_spinlock_init
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
transport_connection_tx_pacer_reset
void transport_connection_tx_pacer_reset(transport_connection_t *tc, u64 rate_bytes_per_sec, u32 start_bucket, clib_us_time_t rtt)
Definition: transport.c:721
transport_cleanup
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:302
svm_fifo_set_event
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:733
fib.h
transport_alloc_local_endpoint
int transport_alloc_local_endpoint(u8 proto, transport_endpoint_cfg_t *rmt_cfg, ip46_address_t *lcl_addr, u16 *lcl_port)
Definition: transport.c:583
sesssion_reschedule_tx
void sesssion_reschedule_tx(transport_connection_t *tc)
Definition: session.c:161
session_error_t
enum session_error_ session_error_t
spacer_reset
static void spacer_reset(spacer_t *pacer, clib_us_time_t time_now, u64 bucket)
Definition: transport.c:714
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
transport_protocol_tx_fn_type
transport_tx_fn_type_t transport_protocol_tx_fn_type(transport_proto_t tp)
Definition: transport.c:296
local_endpoints_lock
static clib_spinlock_t local_endpoints_lock
Definition: transport.c:49
transport_protocol_get_vft
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:282
transport_connection_tx_pacer_update
void transport_connection_tx_pacer_update(transport_connection_t *tc, u64 bytes_per_sec, clib_us_time_t rtt)
Update tx pacer pacing rate.
Definition: transport.c:749
transport_protocol_is_cl
u8 transport_protocol_is_cl(transport_proto_t tp)
Definition: transport.c:356
svm_fifo_unset_event
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
Definition: svm_fifo.h:746
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
local_endpoint_::refcnt
int refcnt
Definition: transport.c:23
clib_spinlock_lock_if_init
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:106
clib_max
#define clib_max(x, y)
Definition: clib.h:335
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
CLIB_US_TIME_FREQ
#define CLIB_US_TIME_FREQ
Definition: time.h:207
session_wrk_update_time
static void session_wrk_update_time(session_worker_t *wrk, f64 now)
Definition: session.h:757
transport_update_time
void transport_update_time(clib_time_type_t time_now, u8 thread_index)
Definition: transport.c:815
clib_atomic_add_fetch
#define clib_atomic_add_fetch(a, b)
Definition: atomics.h:30
session_::tx_fifo
svm_fifo_t * tx_fifo
Definition: session_types.h:179
session_main_::local_endpoints_table_memory
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
Definition: session.h:238
transport_connection_tx_pacer_init
void transport_connection_tx_pacer_init(transport_connection_t *tc, u64 rate_bytes_per_sec, u32 initial_bucket)
Initialize tx pacer for connection.
Definition: transport.c:739
format_transport_pacer
u8 * format_transport_pacer(u8 *s, va_list *args)
Definition: transport.c:645
session_
Definition: session_types.h:175
transport_connection_is_tx_paced
static u8 transport_connection_is_tx_paced(transport_connection_t *tc)
Check if transport connection is paced.
Definition: transport.h:325
transport_service_type_t
enum transport_service_type_ transport_service_type_t
clib_bihash_kv_24_8_t
Definition: bihash_24_8.h:40
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
transport_stop_listen
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
Definition: transport.c:350
transport_proto_vft_t
struct _transport_proto_vft transport_proto_vft_t
u16
unsigned short u16
Definition: types.h:57
session_register_transport
void session_register_transport(transport_proto_t transport_proto, const transport_proto_vft_t *vft, u8 is_ip4, u32 output_node)
Initialize session layer for given transport proto and ip version.
Definition: session.c:1702
f32
float f32
Definition: types.h:143
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
transport_connection_reschedule
void transport_connection_reschedule(transport_connection_t *tc)
Definition: transport.c:790
transport_alloc_local_port
int transport_alloc_local_port(u8 proto, ip46_address_t *ip)
Allocate local port and add if successful add entry to local endpoint table to mark the pair as used.
Definition: transport.c:493
port
u16 port
Definition: lb_types.api:73
fib_table_lookup
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
Definition: fib_table.c:68
transport_reset
void transport_reset(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:334
transport_connection_t
struct _transport_connection transport_connection_t
transport_connection_tx_pacer_update_bytes
void transport_connection_tx_pacer_update_bytes(transport_connection_t *tc, u32 bytes)
Definition: transport.c:777
unformat_input_t
struct _unformat_input_t unformat_input_t
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
local_endpoints_table
static transport_endpoint_table_t local_endpoints_table
Definition: transport.c:39
session_main_::transport_cl_thread
u32 transport_cl_thread
Thread for cl and ho that rely on cl allocs.
Definition: session.h:193
transport_endpoint_pair_
Definition: transport_types.h:216
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
transport_connection_tx_pacer_burst
u32 transport_connection_tx_pacer_burst(transport_connection_t *tc)
Get tx pacer max burst.
Definition: transport.c:757
transport_connection_tx_pacer_rate
u64 transport_connection_tx_pacer_rate(transport_connection_t *tc)
Get tx pacer current rate.
Definition: transport.c:764
error
Definition: cJSON.c:88
clib_time_type_t
f64 clib_time_type_t
Definition: time.h:203
spacer_update_bucket
static void spacer_update_bucket(spacer_t *pacer, u32 bytes)
Definition: transport.c:675
random_u32
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
transport_tx_fn_type_t
enum transport_dequeue_type_ transport_tx_fn_type_t
ip_interface_get_first_ip
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
Definition: ip_interface.c:174
session_::rx_fifo
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
Definition: session_types.h:178
session_add_transport_proto
transport_proto_t session_add_transport_proto(void)
Definition: session.c:1725
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vnet_get_session_main
static session_main_t * vnet_get_session_main()
Definition: session.h:697
unformat_transport_proto
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:155
transport_connection_tx_pacer_reset_bucket
void transport_connection_tx_pacer_reset_bucket(transport_connection_t *tc, u32 bucket)
Reset tx pacer bucket.
Definition: transport.c:732
spacer_set_pace_rate
static void spacer_set_pace_rate(spacer_t *pacer, u64 rate_bytes_per_sec, clib_us_time_t rtt, clib_time_type_t sec_per_loop)
Definition: transport.c:681
ENDPOINT_INVALID_INDEX
#define ENDPOINT_INVALID_INDEX
Definition: transport_types.h:293
transport_init
void transport_init(void)
Definition: transport.c:837
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
transport_connect
int transport_connect(transport_proto_t tp, transport_endpoint_cfg_t *tep)
Definition: transport.c:315
port_allocator_seed
static u32 port_allocator_seed
Definition: transport.c:34
clib_spinlock_s
Definition: lock.h:51
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
transport_fifos_init_ooo
void transport_fifos_init_ooo(transport_connection_t *tc)
Definition: transport.c:807
unformat_transport_str_match
static u8 unformat_transport_str_match(unformat_input_t *input, const char *str)
Definition: transport.c:139
transport_endpt_attr_
Definition: transport_types.h:256
uword
u64 uword
Definition: types.h:112
spacer_max_burst
static u32 spacer_max_burst(spacer_t *pacer, clib_us_time_t time_now)
Definition: transport.c:660
transport_max_tx_dequeue
static u32 transport_max_tx_dequeue(transport_connection_t *tc)
Definition: session.h:544
clib_bihash_kv_24_8_t::value
u64 value
Definition: bihash_24_8.h:43
transport_find_local_ip_for_remote
static session_error_t transport_find_local_ip_for_remote(u32 *sw_if_index, transport_endpoint_t *rmt, ip46_address_t *lcl_addr)
Definition: transport.c:552
TRANSPORT_CONNECTION_F_IS_TX_PACED
@ TRANSPORT_CONNECTION_F_IS_TX_PACED
Definition: transport_types.h:47
f64
double f64
Definition: types.h:142
transport_register_protocol
void transport_register_protocol(transport_proto_t transport_proto, const transport_proto_vft_t *vft, fib_protocol_t fib_proto, u32 output_node)
Register transport virtual function table.
Definition: transport.c:246
transport_endpoint_lookup
u32 transport_endpoint_lookup(transport_endpoint_table_t *ht, u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:201
local_endpoint_::ep
transport_endpoint_t ep
Definition: transport.c:22
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
spacer_t
struct _spacer spacer_t
ip4_address_t
Definition: ip4_packet.h:50
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
fib_entry_get_resolving_interface
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1474
clib_min
#define clib_min(x, y)
Definition: clib.h:342
transport_get_endpoint
void transport_get_endpoint(transport_proto_t tp, u32 conn_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:380
session_get
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:337
transport_cleanup_half_open
void transport_cleanup_half_open(transport_proto_t tp, u32 conn_index)
Definition: transport.c:308
transport_get_listener_endpoint
void transport_get_listener_endpoint(transport_proto_t tp, u32 conn_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:396
transport_update_pacer_time
void transport_update_pacer_time(u32 thread_index, clib_time_type_t now)
Request pacer time update.
Definition: transport.c:784
svm_fifo_init_ooo_lookup
void svm_fifo_init_ooo_lookup(svm_fifo_t *f, u8 ooo_type)
Initialize rbtrees used for ooo lookups.
Definition: svm_fifo.c:408
transport_endpoint_table_t
clib_bihash_24_8_t transport_endpoint_table_t
Definition: transport_types.h:291
clib_atomic_sub_fetch
#define clib_atomic_sub_fetch(a, b)
Definition: atomics.h:31
format_transport_half_open_connection
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
Definition: transport.c:124
transport_share_local_endpoint
void transport_share_local_endpoint(u8 proto, ip46_address_t *lcl_ip, u16 port)
Definition: transport.c:474
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
transport_endpoint_new
static local_endpoint_t * transport_endpoint_new(void)
Definition: transport.c:431
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
local_endpoint_t
struct local_endpoint_ local_endpoint_t
vlib_thread_main_t::n_threads
u32 n_threads
Definition: threads.h:271
u32
unsigned int u32
Definition: types.h:88
transport_endpoint_
Definition: transport_types.h:193
transport_start_listen
u32 transport_start_listen(transport_proto_t tp, u32 session_index, transport_endpoint_t *tep)
Definition: transport.c:343
transport_close
void transport_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:328
format_transport_listen_connection
u8 * format_transport_listen_connection(u8 *s, va_list *args)
Definition: transport.c:110
vlib_thread_main_t
Definition: threads.h:243
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
transport_register_new_protocol
transport_proto_t transport_register_new_protocol(const transport_proto_vft_t *vft, fib_protocol_t fib_proto, u32 output_node)
Definition: transport.c:259
transport_proto_t
enum _transport_proto transport_proto_t
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
format_transport_connection
u8 * format_transport_connection(u8 *s, va_list *args)
Definition: transport.c:80
clib_bihash_kv_24_8_t::key
u64 key[3]
Definition: bihash_24_8.h:42
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
transport_endpoint_table_del
void transport_endpoint_table_del(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te)
Definition: transport.c:233
local_endpoints
static local_endpoint_t * local_endpoints
Definition: transport.c:44
TRANSPORT_PACER_MAX_BURST
#define TRANSPORT_PACER_MAX_BURST
Definition: transport.h:24
transport_protocol_service_type
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
Definition: transport.c:290
value
u8 value
Definition: qos.api:54
TRANSPORT_PACER_MIN_BURST
#define TRANSPORT_PACER_MIN_BURST
Definition: transport.h:23
transport_endpoint_mark_used
static void transport_endpoint_mark_used(u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:460
transport_enable_disable
void transport_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: transport.c:826
TRANSPORT_SERVICE_CL
@ TRANSPORT_SERVICE_CL
connectionless service
Definition: transport_types.h:40
now
f64 now
Definition: nat44_ei_out2in.c:710
transport_endpoint_cleanup
void transport_endpoint_cleanup(u8 proto, ip46_address_t *lcl_ip, u16 port)
Definition: transport.c:439
clib_us_time_t
u64 clib_us_time_t
Definition: time.h:204
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
local_endpoint_
Definition: transport.c:20
clib_clamp
#define clib_clamp(x, lo, hi)
Definition: clib.h:349
transport_get_connection
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.h:156
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
transport.h
ip
vl_api_address_t ip
Definition: l2.api:558
format_transport_proto
u8 * format_transport_proto(u8 *s, va_list *args)
Definition: transport.c:52
session.h
i
int i
Definition: flowhash_template.h:376
transport_connection_update_tx_bytes
void transport_connection_update_tx_bytes(transport_connection_t *tc, u32 bytes)
Update tx bytes for paced transport connection.
Definition: transport.c:770
format_clib_us_time
u8 * format_clib_us_time(u8 *s, va_list *args)
Definition: transport.c:634
session_main_::local_endpoints_table_buckets
u32 local_endpoints_table_buckets
Definition: session.h:239
format_transport_protos
u8 * format_transport_protos(u8 *s, va_list *args)
Definition: transport.c:190
rv
int __clib_unused rv
Definition: application.c:491
transport_connection_attribute
int transport_connection_attribute(transport_proto_t tp, u32 conn_index, u8 thread_index, u8 is_get, transport_endpt_attr_t *attr)
Definition: transport.c:410
transport_proto
transport_proto
Definition: session.api:22
TRANSPORT_PACER_BURSTS_PER_RTT
#define TRANSPORT_PACER_BURSTS_PER_RTT
Definition: transport.h:26
transport_get_listener
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
Definition: transport.h:163
session_main_
Definition: session.h:173
clib_spinlock_unlock_if_init
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:129
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
transport_endpoint_del
void transport_endpoint_del(u32 tepi)
Definition: transport.c:423
PORT_MASK
#define PORT_MASK
Definition: transport.c:420
clib_cpu_time_now
static u64 clib_cpu_time_now(void)
Definition: time.h:81
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
format_transport_proto_short
u8 * format_transport_proto_short(u8 *s, va_list *args)
Definition: transport.c:65
svm_fifo_max_dequeue_cons
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:487
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
transport_half_close
void transport_half_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:321
transport_us_time_now
static clib_us_time_t transport_us_time_now(u32 thread_index)
Definition: session.h:592
TRANSPORT_CONNECTION_F_DESCHED
@ TRANSPORT_CONNECTION_F_DESCHED
Connection descheduled by the session layer.
Definition: transport_types.h:56
default_get_transport_endpoint
static void default_get_transport_endpoint(transport_connection_t *tc, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:362
session_main_get_worker
static session_worker_t * session_main_get_worker(u32 thread_index)
Definition: session.h:703
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
CLIB_US_TIME_PERIOD
#define CLIB_US_TIME_PERIOD
Definition: time.h:206
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
transport_get_interface_ip
static session_error_t transport_get_interface_ip(u32 sw_if_index, u8 is_ip4, ip46_address_t *addr)
Definition: transport.c:530
transport_endpoint_table_add
void transport_endpoint_table_add(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te, u32 value)
Definition: transport.c:219
prefix
vl_api_prefix_t prefix
Definition: ip.api:175
spacer_pace_rate
static u64 spacer_pace_rate(spacer_t *pacer)
Definition: transport.c:708
ip_is_zero
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
Definition: ip.c:22