FD.io VPP  v19.08.1-401-g8e4ed521a
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 /**
21  * Per-type vector of transport protocol virtual function tables
22  */
24 
25 /*
26  * Port allocator seed
27  */
29 
30 /*
31  * Local endpoints table
32  */
34 
35 /*
36  * Pool of local endpoints
37  */
39 
40 /*
41  * Local endpoints pool lock
42  */
44 
45 u8 *
46 format_transport_proto (u8 * s, va_list * args)
47 {
48  u32 transport_proto = va_arg (*args, u32);
49  switch (transport_proto)
50  {
51 #define _(sym, str, sstr) \
52  case TRANSPORT_PROTO_ ## sym: \
53  s = format (s, str); \
54  break;
56 #undef _
57  default:
58  s = format (s, "UNKNOWN");
59  break;
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  switch (transport_proto)
69  {
70 #define _(sym, str, sstr) \
71  case TRANSPORT_PROTO_ ## sym: \
72  s = format (s, sstr); \
73  break;
75 #undef _
76  default:
77  s = format (s, "?");
78  break;
79  }
80  return s;
81 }
82 
83 u8 *
84 format_transport_connection (u8 * s, va_list * args)
85 {
86  u32 transport_proto = va_arg (*args, u32);
87  u32 conn_index = va_arg (*args, u32);
88  u32 thread_index = va_arg (*args, u32);
89  u32 verbose = va_arg (*args, u32);
90  transport_proto_vft_t *tp_vft;
92  u32 indent;
93 
94  tp_vft = transport_protocol_get_vft (transport_proto);
95  if (!tp_vft)
96  return s;
97 
98  s = format (s, "%U", tp_vft->format_connection, conn_index, thread_index,
99  verbose);
100  tc = tp_vft->get_connection (conn_index, thread_index);
101  if (tc && transport_connection_is_tx_paced (tc) && verbose > 1)
102  {
103  indent = format_get_indent (s) + 1;
104  s = format (s, "%Upacer: %U\n", format_white_space, indent,
105  format_transport_pacer, &tc->pacer, tc->thread_index);
106  }
107  return s;
108 }
109 
110 u8 *
112 {
113  u32 transport_proto = va_arg (*args, u32);
114  transport_proto_vft_t *tp_vft;
115 
116  tp_vft = transport_protocol_get_vft (transport_proto);
117  if (!tp_vft)
118  return s;
119 
120  s = (tp_vft->format_listener) (s, args);
121  return s;
122 }
123 
124 u8 *
126 {
127  u32 transport_proto = va_arg (*args, u32);
128  u32 listen_index = va_arg (*args, u32);
129  transport_proto_vft_t *tp_vft;
130 
131  tp_vft = transport_protocol_get_vft (transport_proto);
132  if (!tp_vft)
133  return s;
134 
135  s = format (s, "%U", tp_vft->format_half_open, listen_index);
136  return s;
137 }
138 
139 uword
141 {
142  u32 *proto = va_arg (*args, u32 *);
143 
144 #define _(sym, str, sstr) \
145  if (unformat (input, str)) \
146  { \
147  *proto = TRANSPORT_PROTO_ ## sym; \
148  return 1; \
149  }
151 #undef _
152  return 0;
153 }
154 
155 u32
157  ip46_address_t * ip, u16 port)
158 {
160  int rv;
161 
162  kv.key[0] = ip->as_u64[0];
163  kv.key[1] = ip->as_u64[1];
164  kv.key[2] = (u64) port << 8 | (u64) proto;
165 
166  rv = clib_bihash_search_inline_24_8 (ht, &kv);
167  if (rv == 0)
168  return kv.value;
169 
170  return ENDPOINT_INVALID_INDEX;
171 }
172 
173 void
176 {
178 
179  kv.key[0] = te->ip.as_u64[0];
180  kv.key[1] = te->ip.as_u64[1];
181  kv.key[2] = (u64) te->port << 8 | (u64) proto;
182  kv.value = value;
183 
184  clib_bihash_add_del_24_8 (ht, &kv, 1);
185 }
186 
187 void
190 {
192 
193  kv.key[0] = te->ip.as_u64[0];
194  kv.key[1] = te->ip.as_u64[1];
195  kv.key[2] = (u64) te->port << 8 | (u64) proto;
196 
197  clib_bihash_add_del_24_8 (ht, &kv, 0);
198 }
199 
200 /**
201  * Register transport virtual function table.
202  *
203  * @param transport_proto - transport protocol type (i.e., TCP, UDP ..)
204  * @param vft - virtual function table for transport proto
205  * @param fib_proto - network layer protocol
206  * @param output_node - output node index that session layer will hand off
207  * buffers to, for requested fib proto
208  */
209 void
211  const transport_proto_vft_t * vft,
212  fib_protocol_t fib_proto, u32 output_node)
213 {
214  u8 is_ip4 = fib_proto == FIB_PROTOCOL_IP4;
215 
216  vec_validate (tp_vfts, transport_proto);
217  tp_vfts[transport_proto] = *vft;
218 
219  session_register_transport (transport_proto, vft, is_ip4, output_node);
220 }
221 
222 /**
223  * Get transport virtual function table
224  *
225  * @param type - session type (not protocol type)
226  */
229 {
230  if (transport_proto >= vec_len (tp_vfts))
231  return 0;
232  return &tp_vfts[transport_proto];
233 }
234 
235 u8
237 {
238  return tp_vfts[tp].transport_options.half_open_has_fifos;
239 }
240 
243 {
244  return tp_vfts[tp].transport_options.service_type;
245 }
246 
249 {
250  return tp_vfts[tp].transport_options.tx_type;
251 }
252 
253 void
254 transport_cleanup (transport_proto_t tp, u32 conn_index, u8 thread_index)
255 {
256  tp_vfts[tp].cleanup (conn_index, thread_index);
257 }
258 
259 int
261 {
262  return tp_vfts[tp].connect (tep);
263 }
264 
265 void
266 transport_close (transport_proto_t tp, u32 conn_index, u8 thread_index)
267 {
268  tp_vfts[tp].close (conn_index, thread_index);
269 }
270 
271 void
272 transport_reset (transport_proto_t tp, u32 conn_index, u8 thread_index)
273 {
274  if (tp_vfts[tp].reset)
275  tp_vfts[tp].reset (conn_index, thread_index);
276  else
277  tp_vfts[tp].close (conn_index, thread_index);
278 }
279 
280 u32
282  transport_endpoint_t * tep)
283 {
284  return tp_vfts[tp].start_listen (session_index, tep);
285 }
286 
287 u32
289 {
290  return tp_vfts[tp].stop_listen (conn_index);
291 }
292 
293 u8
295 {
296  return (tp_vfts[tp].transport_options.service_type == TRANSPORT_SERVICE_CL);
297 }
298 
299 always_inline void
301  transport_endpoint_t * tep, u8 is_lcl)
302 {
303  if (is_lcl)
304  {
305  tep->port = tc->lcl_port;
306  tep->is_ip4 = tc->is_ip4;
307  clib_memcpy_fast (&tep->ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
308  }
309  else
310  {
311  tep->port = tc->rmt_port;
312  tep->is_ip4 = tc->is_ip4;
313  clib_memcpy_fast (&tep->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
314  }
315 }
316 
317 void
319  u32 thread_index, transport_endpoint_t * tep,
320  u8 is_lcl)
321 {
322  if (tp_vfts[tp].get_transport_endpoint)
323  tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, tep,
324  is_lcl);
325  else
326  {
328  tc = transport_get_connection (tp, conn_index, thread_index);
329  default_get_transport_endpoint (tc, tep, is_lcl);
330  }
331 }
332 
333 void
335  transport_endpoint_t * tep, u8 is_lcl)
336 {
337  if (tp_vfts[tp].get_transport_listener_endpoint)
338  tp_vfts[tp].get_transport_listener_endpoint (conn_index, tep, is_lcl);
339  else
340  {
342  tc = transport_get_listener (tp, conn_index);
343  default_get_transport_endpoint (tc, tep, is_lcl);
344  }
345 }
346 
347 #define PORT_MASK ((1 << 16)- 1)
348 
349 void
351 {
352  clib_spinlock_lock_if_init (&local_endpoints_lock);
353  pool_put_index (local_endpoints, tepi);
354  clib_spinlock_unlock_if_init (&local_endpoints_lock);
355 }
356 
359 {
361  pool_get_zero (local_endpoints, tep);
362  return tep;
363 }
364 
365 void
366 transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port)
367 {
368  u32 tepi;
370 
371  /* Cleanup local endpoint if this was an active connect */
372  tepi = transport_endpoint_lookup (&local_endpoints_table, proto, lcl_ip,
373  clib_net_to_host_u16 (port));
374  if (tepi != ENDPOINT_INVALID_INDEX)
375  {
376  tep = pool_elt_at_index (local_endpoints, tepi);
378  transport_endpoint_del (tepi);
379  }
380 }
381 
382 static void
384 {
386  clib_spinlock_lock_if_init (&local_endpoints_lock);
387  tep = transport_endpoint_new ();
388  clib_memcpy_fast (&tep->ip, ip, sizeof (*ip));
389  tep->port = port;
391  tep - local_endpoints);
392  clib_spinlock_unlock_if_init (&local_endpoints_lock);
393 }
394 
395 /**
396  * Allocate local port and add if successful add entry to local endpoint
397  * table to mark the pair as used.
398  */
399 int
401 {
402  u16 min = 1024, max = 65535; /* XXX configurable ? */
403  int tries, limit;
404  u32 tei;
405 
406  limit = max - min;
407 
408  /* Only support active opens from thread 0 */
409  ASSERT (vlib_get_thread_index () == 0);
410 
411  /* Search for first free slot */
412  for (tries = 0; tries < limit; tries++)
413  {
414  u16 port = 0;
415 
416  /* Find a port in the specified range */
417  while (1)
418  {
420  if (PREDICT_TRUE (port >= min && port < max))
421  break;
422  }
423 
424  /* Look it up. If not found, we're done */
426  port);
427  if (tei == ENDPOINT_INVALID_INDEX)
428  {
429  transport_endpoint_mark_used (proto, ip, port);
430  return port;
431  }
432  }
433  return -1;
434 }
435 
436 static clib_error_t *
437 transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
438 {
439  if (is_ip4)
440  {
441  ip4_address_t *ip4;
442  ip4 = ip_interface_get_first_ip (sw_if_index, 1);
443  if (!ip4)
444  return clib_error_return (0, "no routable ip4 address on %U",
446  vnet_get_main (), sw_if_index);
447  addr->ip4.as_u32 = ip4->as_u32;
448  }
449  else
450  {
451  ip6_address_t *ip6;
452  ip6 = ip_interface_get_first_ip (sw_if_index, 0);
453  if (ip6 == 0)
454  return clib_error_return (0, "no routable ip6 addresses on %U",
456  vnet_get_main (), sw_if_index);
457  clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
458  }
459  return 0;
460 }
461 
462 static clib_error_t *
464  transport_endpoint_t * rmt,
465  ip46_address_t * lcl_addr)
466 {
467  fib_node_index_t fei;
469 
470  if (sw_if_index == ENDPOINT_INVALID_INDEX)
471  {
472  /* Find a FIB path to the destination */
473  clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
474  prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
475  prefix.fp_len = rmt->is_ip4 ? 32 : 128;
476 
477  ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX);
478  fei = fib_table_lookup (rmt->fib_index, &prefix);
479 
480  /* Couldn't find route to destination. Bail out. */
481  if (fei == FIB_NODE_INDEX_INVALID)
482  return clib_error_return (0, "no route to %U", format_ip46_address,
483  &rmt->ip, (rmt->is_ip4 == 0) + 1);
484 
485  sw_if_index = fib_entry_get_resolving_interface (fei);
486  if (sw_if_index == ENDPOINT_INVALID_INDEX)
487  return clib_error_return (0, "no resolving interface for %U",
488  format_ip46_address, &rmt->ip,
489  (rmt->is_ip4 == 0) + 1);
490  }
491 
492  clib_memset (lcl_addr, 0, sizeof (*lcl_addr));
493  return transport_get_interface_ip (sw_if_index, rmt->is_ip4, lcl_addr);
494 }
495 
496 int
498  ip46_address_t * lcl_addr, u16 * lcl_port)
499 {
500  transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg;
501  clib_error_t *error;
502  int port;
503  u32 tei;
504 
505  /*
506  * Find the local address
507  */
508  if (ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4))
509  {
510  error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index,
511  rmt, lcl_addr);
512  if (error)
513  {
514  clib_error_report (error);
515  return -1;
516  }
517  }
518  else
519  {
520  /* Assume session layer vetted this address */
521  clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip,
522  sizeof (rmt_cfg->peer.ip));
523  }
524 
525  /*
526  * Allocate source port
527  */
528  if (rmt_cfg->peer.port == 0)
529  {
530  port = transport_alloc_local_port (proto, lcl_addr);
531  if (port < 1)
532  {
533  clib_warning ("Failed to allocate src port");
534  return -1;
535  }
536  *lcl_port = port;
537  }
538  else
539  {
540  port = clib_net_to_host_u16 (rmt_cfg->peer.port);
542  lcl_addr, port);
543  if (tei != ENDPOINT_INVALID_INDEX)
544  return -1;
545 
546  transport_endpoint_mark_used (proto, lcl_addr, port);
547  *lcl_port = port;
548  }
549 
550  return 0;
551 }
552 
553 u8 *
554 format_clib_us_time (u8 * s, va_list * args)
555 {
556  clib_us_time_t t = va_arg (*args, clib_us_time_t);
557  if (t < 1e3)
558  s = format (s, "%u us", t);
559  else
560  s = format (s, "%.3f s", (f64) t * CLIB_US_TIME_PERIOD);
561  return s;
562 }
563 
564 u8 *
565 format_transport_pacer (u8 * s, va_list * args)
566 {
567  spacer_t *pacer = va_arg (*args, spacer_t *);
568  u32 thread_index = va_arg (*args, int);
569  clib_us_time_t now, diff;
570 
571  now = transport_us_time_now (thread_index);
572  diff = now - pacer->last_update;
573  s = format (s, "rate %lu bucket %lu t/p %.3f last_update %U",
574  pacer->bytes_per_sec, pacer->bucket, pacer->tokens_per_period,
575  format_clib_us_time, diff);
576  return s;
577 }
578 
579 static inline u32
581 {
582  u64 n_periods = (time_now - pacer->last_update);
583  u64 inc;
584 
585  if (PREDICT_FALSE (n_periods > 5e4))
586  {
587  pacer->last_update = time_now;
588  pacer->bucket = TRANSPORT_PACER_MIN_BURST;
590  }
591 
592  if (n_periods > 0
593  && (inc = (f32) n_periods * pacer->tokens_per_period) > 10)
594  {
595  pacer->last_update = time_now;
596  pacer->bucket = clib_min (pacer->bucket + inc, pacer->bytes_per_sec);
597  }
598 
599  return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST);
600 }
601 
602 static inline void
604 {
605  ASSERT (pacer->bucket >= bytes);
606  pacer->bucket -= bytes;
607 }
608 
609 static inline void
610 spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec)
611 {
612  ASSERT (rate_bytes_per_sec != 0);
613  pacer->bytes_per_sec = rate_bytes_per_sec;
614  pacer->tokens_per_period = rate_bytes_per_sec * CLIB_US_TIME_PERIOD;
615 }
616 
617 static inline u64
619 {
620  return pacer->bytes_per_sec;
621 }
622 
623 static inline void
624 spacer_reset (spacer_t * pacer, clib_us_time_t time_now, u64 bucket)
625 {
626  pacer->last_update = time_now;
627  pacer->bucket = bucket;
628 }
629 
630 void
632  u64 rate_bytes_per_sec, u32 start_bucket)
633 {
634  spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec);
635  spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index),
636  start_bucket);
637 }
638 
639 void
641 {
642  spacer_reset (&tc->pacer, transport_us_time_now (tc->thread_index), 0);
643 }
644 
645 void
647  u64 rate_bytes_per_sec,
648  u32 initial_bucket)
649 {
651  transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec,
652  initial_bucket);
653 }
654 
655 void
657  u64 bytes_per_sec)
658 {
659  spacer_set_pace_rate (&tc->pacer, bytes_per_sec);
660 }
661 
662 u32
664 {
665  return spacer_max_burst (&tc->pacer,
666  transport_us_time_now (tc->thread_index));
667 }
668 
669 u32
671 {
672  u32 snd_space, max_paced_burst;
673 
674  snd_space = tp_vfts[tc->proto].send_space (tc);
675  if (snd_space && transport_connection_is_tx_paced (tc))
676  {
677  clib_us_time_t now = transport_us_time_now (tc->thread_index);
678  max_paced_burst = spacer_max_burst (&tc->pacer, now);
679  max_paced_burst =
680  (max_paced_burst < TRANSPORT_PACER_MIN_BURST) ? 0 : max_paced_burst;
681  snd_space = clib_min (snd_space, max_paced_burst);
682  return snd_space >= mss ? snd_space - snd_space % mss : snd_space;
683  }
684  return snd_space;
685 }
686 
687 u64
689 {
690  return spacer_pace_rate (&tc->pacer);
691 }
692 
693 void
695 {
697  spacer_update_bucket (&tc->pacer, bytes);
698 }
699 
700 void
702  u32 bytes)
703 {
704  spacer_update_bucket (&tc->pacer, bytes);
705 }
706 
707 void
708 transport_update_time (clib_time_type_t time_now, u8 thread_index)
709 {
711  vec_foreach (vft, tp_vfts)
712  {
713  if (vft->update_time)
714  (vft->update_time) (time_now, thread_index);
715  }
716 }
717 
718 void
720 {
722  vec_foreach (vft, tp_vfts)
723  {
724  if (vft->enable)
725  (vft->enable) (vm, is_en);
726  }
727 }
728 
729 void
731 {
734  u32 num_threads;
735 
736  if (smm->local_endpoints_table_buckets == 0)
737  smm->local_endpoints_table_buckets = 250000;
738  if (smm->local_endpoints_table_memory == 0)
739  smm->local_endpoints_table_memory = 512 << 20;
740 
741  /* Initialize [port-allocator] random number seed */
743 
744  clib_bihash_init_24_8 (&local_endpoints_table, "local endpoints table",
747  num_threads = 1 /* main thread */ + vtm->n_threads;
748  if (num_threads > 1)
749  clib_spinlock_init (&local_endpoints_lock);
750 }
751 
752 /*
753  * fd.io coding-style-patch-verification: ON
754  *
755  * Local Variables:
756  * eval: (c-set-style "gnu")
757  * End:
758  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
void transport_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:266
#define ENDPOINT_INVALID_INDEX
u8 * format_transport_connection(u8 *s, va_list *args)
Definition: transport.c:84
u32 transport_endpoint_lookup(transport_endpoint_table_t *ht, u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:156
#define clib_min(x, y)
Definition: clib.h:295
f64 clib_time_type_t
Definition: time.h:203
u8 * format_transport_proto_short(u8 *s, va_list *args)
Definition: transport.c:65
void transport_get_listener_endpoint(transport_proto_t tp, u32 conn_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:334
static void transport_endpoint_mark_used(u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:383
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:239
void transport_endpoint_table_add(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te, u32 value)
Definition: transport.c:174
#define PREDICT_TRUE(x)
Definition: clib.h:112
unsigned long u64
Definition: types.h:89
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static transport_endpoint_table_t local_endpoints_table
Definition: transport.c:33
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:110
static u64 clib_cpu_time_now(void)
Definition: time.h:81
static void spacer_reset(spacer_t *pacer, clib_us_time_t time_now, u64 bucket)
Definition: transport.c:624
format_function_t format_ip46_address
Definition: format.h:61
static u32 format_get_indent(u8 *s)
Definition: format.h:72
transport_tx_fn_type_t transport_protocol_tx_fn_type(transport_proto_t tp)
Definition: transport.c:248
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
Definition: ip.c:134
u32 transport_start_listen(transport_proto_t tp, u32 session_index, transport_endpoint_t *tep)
Definition: transport.c:281
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vl_api_mprefix_t prefix
Definition: ip.api:456
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
Definition: session.h:190
void transport_endpoint_del(u32 tepi)
Definition: transport.c:350
vhost_vring_addr_t addr
Definition: vhost_user.h:147
struct _spacer spacer_t
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
double f64
Definition: types.h:142
void transport_update_time(clib_time_type_t time_now, u8 thread_index)
Definition: transport.c:708
#define foreach_transport_proto
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
u8 transport_half_open_has_fifos(transport_proto_t tp)
Definition: transport.c:236
static clib_error_t * transport_get_interface_ip(u32 sw_if_index, u8 is_ip4, ip46_address_t *addr)
Definition: transport.c:437
#define always_inline
Definition: clib.h:98
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
Aggregate type for a prefix.
Definition: fib_types.h:203
#define clib_error_return(e, args...)
Definition: error.h:99
int transport_alloc_local_endpoint(u8 proto, transport_endpoint_cfg_t *rmt_cfg, ip46_address_t *lcl_addr, u16 *lcl_port)
Definition: transport.c:497
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
static clib_spinlock_t local_endpoints_lock
Definition: transport.c:43
void transport_reset(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:272
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:66
struct _transport_proto_vft transport_proto_vft_t
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:228
static void spacer_set_pace_rate(spacer_t *pacer, u64 rate_bytes_per_sec)
Definition: transport.c:610
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
void transport_endpoint_table_del(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te)
Definition: transport.c:188
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
Definition: transport.c:242
void transport_get_endpoint(transport_proto_t tp, u32 conn_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:318
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static transport_endpoint_t * local_endpoints
Definition: transport.c:38
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:646
enum transport_service_type_ transport_service_type_t
#define PREDICT_FALSE(x)
Definition: clib.h:111
u16 port
Definition: punt.api:40
transport_proto_vft_t * tp_vfts
Per-type vector of transport protocol virtual function tables.
Definition: transport.c:23
static u8 transport_connection_is_tx_paced(transport_connection_t *tc)
Check if transport connection is paced.
Definition: transport.h:236
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:254
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
Definition: transport.c:288
u8 * format_clib_us_time(u8 *s, va_list *args)
Definition: transport.c:554
void transport_connection_tx_pacer_update(transport_connection_t *tc, u64 bytes_per_sec)
Update tx pacer pacing rate.
Definition: transport.c:656
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1458
void transport_init(void)
Definition: transport.c:730
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:213
int transport_connect(transport_proto_t tp, transport_endpoint_cfg_t *tep)
Definition: transport.c:260
vlib_main_t * vm
Definition: buffer.c:323
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.h:117
#define clib_warning(format, args...)
Definition: error.h:59
#define PORT_MASK
Definition: transport.c:347
static void default_get_transport_endpoint(transport_connection_t *tc, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:300
struct _transport_connection transport_connection_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
void transport_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: transport.c:719
void transport_endpoint_cleanup(u8 proto, ip46_address_t *lcl_ip, u16 port)
Definition: transport.c:366
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:210
static clib_us_time_t transport_us_time_now(u32 thread_index)
Definition: session.h:517
static u64 spacer_pace_rate(spacer_t *pacer)
Definition: transport.c:618
#define CLIB_US_TIME_PERIOD
Definition: time.h:206
u8 value
Definition: qos.api:53
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:311
#define ASSERT(truth)
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:140
#define TRANSPORT_PACER_MAX_BURST
Definition: transport.h:24
void transport_connection_update_tx_bytes(transport_connection_t *tc, u32 bytes)
Update tx bytes for paced transport connection.
Definition: transport.c:694
static transport_endpoint_t * transport_endpoint_new(void)
Definition: transport.c:358
#define TRANSPORT_PACER_MIN_BURST
Definition: transport.h:23
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
Definition: transport.c:125
enum _transport_proto transport_proto_t
#define clib_error_report(e)
Definition: error.h:113
float f32
Definition: types.h:143
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
Definition: ip.c:20
void transport_connection_tx_pacer_update_bytes(transport_connection_t *tc, u32 bytes)
Definition: transport.c:701
static u32 port_allocator_seed
Definition: transport.c:28
u32 local_endpoints_table_buckets
Definition: session.h:191
vl_api_address_t ip
Definition: l2.api:489
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
static u32 spacer_max_burst(spacer_t *pacer, clib_us_time_t time_now)
Definition: transport.c:580
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void spacer_update_bucket(spacer_t *pacer, u32 bytes)
Definition: transport.c:603
u64 uword
Definition: types.h:112
connectionless service
u8 * format_transport_listen_connection(u8 *s, va_list *args)
Definition: transport.c:111
u8 * format_transport_pacer(u8 *s, va_list *args)
Definition: transport.c:565
void transport_connection_tx_pacer_reset_bucket(transport_connection_t *tc)
Reset tx pacer bucket.
Definition: transport.c:640
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define vec_foreach(var, vec)
Vector iterator.
u32 transport_connection_snd_space(transport_connection_t *tc, u16 mss)
Get maximum tx burst allowed for transport connection.
Definition: transport.c:670
static clib_error_t * transport_find_local_ip_for_remote(u32 sw_if_index, transport_endpoint_t *rmt, ip46_address_t *lcl_addr)
Definition: transport.c:463
clib_bihash_24_8_t transport_endpoint_table_t
static session_main_t * vnet_get_session_main()
Definition: session.h:585
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:400
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
Definition: transport.h:124
u64 clib_us_time_t
Definition: time.h:204
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:1429
enum transport_dequeue_type_ transport_tx_fn_type_t
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:95
u8 transport_protocol_is_cl(transport_proto_t tp)
Definition: transport.c:294
u8 * format_transport_proto(u8 *s, va_list *args)
Definition: transport.c:46
void transport_connection_tx_pacer_reset(transport_connection_t *tc, u64 rate_bytes_per_sec, u32 start_bucket)
Definition: transport.c:631
u32 transport_connection_tx_pacer_burst(transport_connection_t *tc)
Get tx pacer max burst.
Definition: transport.c:663
u64 transport_connection_tx_pacer_rate(transport_connection_t *tc)
Get tx pacer current rate.
Definition: transport.c:688
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125