FD.io VPP  v19.08-27-gf4dcae4
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 /*
46  * Period used by transport pacers. Initialized by session layer
47  */
48 static double transport_pacer_period;
49 
50 #define TRANSPORT_PACER_MIN_MSS 1460
51 #define TRANSPORT_PACER_MIN_BURST TRANSPORT_PACER_MIN_MSS
52 #define TRANSPORT_PACER_MAX_BURST (32 * TRANSPORT_PACER_MIN_MSS)
53 
54 u8 *
55 format_transport_proto (u8 * s, va_list * args)
56 {
57  u32 transport_proto = va_arg (*args, u32);
58  switch (transport_proto)
59  {
61  s = format (s, "TCP");
62  break;
64  s = format (s, "UDP");
65  break;
67  s = format (s, "SCTP");
68  break;
70  s = format (s, "NONE");
71  break;
73  s = format (s, "TLS");
74  break;
76  s = format (s, "UDPC");
77  break;
79  s = format (s, "QUIC");
80  break;
81  default:
82  s = format (s, "UNKNOWN");
83  break;
84  }
85  return s;
86 }
87 
88 u8 *
89 format_transport_proto_short (u8 * s, va_list * args)
90 {
91  u32 transport_proto = va_arg (*args, u32);
92  switch (transport_proto)
93  {
95  s = format (s, "T");
96  break;
98  s = format (s, "U");
99  break;
101  s = format (s, "S");
102  break;
104  s = format (s, "N");
105  break;
106  case TRANSPORT_PROTO_TLS:
107  s = format (s, "J");
108  break;
110  s = format (s, "U");
111  break;
113  s = format (s, "Q");
114  break;
115  default:
116  s = format (s, "?");
117  break;
118  }
119  return s;
120 }
121 
122 u8 *
123 format_transport_connection (u8 * s, va_list * args)
124 {
125  u32 transport_proto = va_arg (*args, u32);
126  u32 conn_index = va_arg (*args, u32);
127  u32 thread_index = va_arg (*args, u32);
128  u32 verbose = va_arg (*args, u32);
129  transport_proto_vft_t *tp_vft;
131  u32 indent;
132 
133  tp_vft = transport_protocol_get_vft (transport_proto);
134  if (!tp_vft)
135  return s;
136 
137  s = format (s, "%U", tp_vft->format_connection, conn_index, thread_index,
138  verbose);
139  tc = tp_vft->get_connection (conn_index, thread_index);
140  if (tc && transport_connection_is_tx_paced (tc) && verbose > 1)
141  {
142  indent = format_get_indent (s) + 1;
143  s = format (s, "%Upacer: %U\n", format_white_space, indent,
144  format_transport_pacer, &tc->pacer);
145  }
146  return s;
147 }
148 
149 u8 *
151 {
152  u32 transport_proto = va_arg (*args, u32);
153  transport_proto_vft_t *tp_vft;
154 
155  tp_vft = transport_protocol_get_vft (transport_proto);
156  if (!tp_vft)
157  return s;
158 
159  s = (tp_vft->format_listener) (s, args);
160  return s;
161 }
162 
163 u8 *
165 {
166  u32 transport_proto = va_arg (*args, u32);
167  u32 listen_index = va_arg (*args, u32);
168  transport_proto_vft_t *tp_vft;
169 
170  tp_vft = transport_protocol_get_vft (transport_proto);
171  if (!tp_vft)
172  return s;
173 
174  s = format (s, "%U", tp_vft->format_half_open, listen_index);
175  return s;
176 }
177 
178 uword
180 {
181  u32 *proto = va_arg (*args, u32 *);
182  if (unformat (input, "tcp"))
183  *proto = TRANSPORT_PROTO_TCP;
184  else if (unformat (input, "TCP"))
185  *proto = TRANSPORT_PROTO_TCP;
186  else if (unformat (input, "udpc"))
187  *proto = TRANSPORT_PROTO_UDPC;
188  else if (unformat (input, "UDPC"))
189  *proto = TRANSPORT_PROTO_UDPC;
190  else if (unformat (input, "udp"))
191  *proto = TRANSPORT_PROTO_UDP;
192  else if (unformat (input, "UDP"))
193  *proto = TRANSPORT_PROTO_UDP;
194  else if (unformat (input, "sctp"))
195  *proto = TRANSPORT_PROTO_SCTP;
196  else if (unformat (input, "SCTP"))
197  *proto = TRANSPORT_PROTO_SCTP;
198  else if (unformat (input, "tls"))
199  *proto = TRANSPORT_PROTO_TLS;
200  else if (unformat (input, "TLS"))
201  *proto = TRANSPORT_PROTO_TLS;
202  else if (unformat (input, "quic"))
203  *proto = TRANSPORT_PROTO_QUIC;
204  else if (unformat (input, "QUIC"))
205  *proto = TRANSPORT_PROTO_QUIC;
206  else
207  return 0;
208  return 1;
209 }
210 
211 u32
213  ip46_address_t * ip, u16 port)
214 {
216  int rv;
217 
218  kv.key[0] = ip->as_u64[0];
219  kv.key[1] = ip->as_u64[1];
220  kv.key[2] = (u64) port << 8 | (u64) proto;
221 
222  rv = clib_bihash_search_inline_24_8 (ht, &kv);
223  if (rv == 0)
224  return kv.value;
225 
226  return ENDPOINT_INVALID_INDEX;
227 }
228 
229 void
232 {
234 
235  kv.key[0] = te->ip.as_u64[0];
236  kv.key[1] = te->ip.as_u64[1];
237  kv.key[2] = (u64) te->port << 8 | (u64) proto;
238  kv.value = value;
239 
240  clib_bihash_add_del_24_8 (ht, &kv, 1);
241 }
242 
243 void
246 {
248 
249  kv.key[0] = te->ip.as_u64[0];
250  kv.key[1] = te->ip.as_u64[1];
251  kv.key[2] = (u64) te->port << 8 | (u64) proto;
252 
253  clib_bihash_add_del_24_8 (ht, &kv, 0);
254 }
255 
256 /**
257  * Register transport virtual function table.
258  *
259  * @param transport_proto - transport protocol type (i.e., TCP, UDP ..)
260  * @param vft - virtual function table for transport proto
261  * @param fib_proto - network layer protocol
262  * @param output_node - output node index that session layer will hand off
263  * buffers to, for requested fib proto
264  */
265 void
267  const transport_proto_vft_t * vft,
268  fib_protocol_t fib_proto, u32 output_node)
269 {
270  u8 is_ip4 = fib_proto == FIB_PROTOCOL_IP4;
271 
272  vec_validate (tp_vfts, transport_proto);
273  tp_vfts[transport_proto] = *vft;
274 
275  session_register_transport (transport_proto, vft, is_ip4, output_node);
276 }
277 
278 /**
279  * Get transport virtual function table
280  *
281  * @param type - session type (not protocol type)
282  */
285 {
286  if (transport_proto >= vec_len (tp_vfts))
287  return 0;
288  return &tp_vfts[transport_proto];
289 }
290 
291 u8
293 {
294  return tp_vfts[tp].transport_options.half_open_has_fifos;
295 }
296 
299 {
300  return tp_vfts[tp].transport_options.service_type;
301 }
302 
305 {
306  return tp_vfts[tp].transport_options.tx_type;
307 }
308 
309 void
310 transport_cleanup (transport_proto_t tp, u32 conn_index, u8 thread_index)
311 {
312  tp_vfts[tp].cleanup (conn_index, thread_index);
313 }
314 
315 int
317 {
318  return tp_vfts[tp].connect (tep);
319 }
320 
321 void
322 transport_close (transport_proto_t tp, u32 conn_index, u8 thread_index)
323 {
324  tp_vfts[tp].close (conn_index, thread_index);
325 }
326 
327 u32
329  transport_endpoint_t * tep)
330 {
331  return tp_vfts[tp].start_listen (session_index, tep);
332 }
333 
334 u32
336 {
337  return tp_vfts[tp].stop_listen (conn_index);
338 }
339 
340 u8
342 {
343  return (tp_vfts[tp].transport_options.service_type == TRANSPORT_SERVICE_CL);
344 }
345 
346 always_inline void
348  transport_endpoint_t * tep, u8 is_lcl)
349 {
350  if (is_lcl)
351  {
352  tep->port = tc->lcl_port;
353  tep->is_ip4 = tc->is_ip4;
354  clib_memcpy_fast (&tep->ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
355  }
356  else
357  {
358  tep->port = tc->rmt_port;
359  tep->is_ip4 = tc->is_ip4;
360  clib_memcpy_fast (&tep->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
361  }
362 }
363 
364 void
366  u32 thread_index, transport_endpoint_t * tep,
367  u8 is_lcl)
368 {
369  if (tp_vfts[tp].get_transport_endpoint)
370  tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, tep,
371  is_lcl);
372  else
373  {
375  tc = transport_get_connection (tp, conn_index, thread_index);
376  default_get_transport_endpoint (tc, tep, is_lcl);
377  }
378 }
379 
380 void
382  transport_endpoint_t * tep, u8 is_lcl)
383 {
384  if (tp_vfts[tp].get_transport_listener_endpoint)
385  tp_vfts[tp].get_transport_listener_endpoint (conn_index, tep, is_lcl);
386  else
387  {
389  tc = transport_get_listener (tp, conn_index);
390  default_get_transport_endpoint (tc, tep, is_lcl);
391  }
392 }
393 
394 #define PORT_MASK ((1 << 16)- 1)
395 
396 void
398 {
399  clib_spinlock_lock_if_init (&local_endpoints_lock);
400  pool_put_index (local_endpoints, tepi);
401  clib_spinlock_unlock_if_init (&local_endpoints_lock);
402 }
403 
406 {
408  pool_get_zero (local_endpoints, tep);
409  return tep;
410 }
411 
412 void
413 transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port)
414 {
415  u32 tepi;
417 
418  /* Cleanup local endpoint if this was an active connect */
419  tepi = transport_endpoint_lookup (&local_endpoints_table, proto, lcl_ip,
420  clib_net_to_host_u16 (port));
421  if (tepi != ENDPOINT_INVALID_INDEX)
422  {
423  tep = pool_elt_at_index (local_endpoints, tepi);
425  transport_endpoint_del (tepi);
426  }
427 }
428 
429 static void
431 {
433  clib_spinlock_lock_if_init (&local_endpoints_lock);
434  tep = transport_endpoint_new ();
435  clib_memcpy_fast (&tep->ip, ip, sizeof (*ip));
436  tep->port = port;
438  tep - local_endpoints);
439  clib_spinlock_unlock_if_init (&local_endpoints_lock);
440 }
441 
442 /**
443  * Allocate local port and add if successful add entry to local endpoint
444  * table to mark the pair as used.
445  */
446 int
448 {
449  u16 min = 1024, max = 65535; /* XXX configurable ? */
450  int tries, limit;
451  u32 tei;
452 
453  limit = max - min;
454 
455  /* Only support active opens from thread 0 */
456  ASSERT (vlib_get_thread_index () == 0);
457 
458  /* Search for first free slot */
459  for (tries = 0; tries < limit; tries++)
460  {
461  u16 port = 0;
462 
463  /* Find a port in the specified range */
464  while (1)
465  {
467  if (PREDICT_TRUE (port >= min && port < max))
468  break;
469  }
470 
471  /* Look it up. If not found, we're done */
473  port);
474  if (tei == ENDPOINT_INVALID_INDEX)
475  {
476  transport_endpoint_mark_used (proto, ip, port);
477  return port;
478  }
479  }
480  return -1;
481 }
482 
483 static clib_error_t *
484 transport_get_interface_ip (u32 sw_if_index, u8 is_ip4, ip46_address_t * addr)
485 {
486  if (is_ip4)
487  {
488  ip4_address_t *ip4;
489  ip4 = ip_interface_get_first_ip (sw_if_index, 1);
490  if (!ip4)
491  return clib_error_return (0, "no routable ip4 address on %U",
493  vnet_get_main (), sw_if_index);
494  addr->ip4.as_u32 = ip4->as_u32;
495  }
496  else
497  {
498  ip6_address_t *ip6;
499  ip6 = ip_interface_get_first_ip (sw_if_index, 0);
500  if (ip6 == 0)
501  return clib_error_return (0, "no routable ip6 addresses on %U",
503  vnet_get_main (), sw_if_index);
504  clib_memcpy_fast (&addr->ip6, ip6, sizeof (*ip6));
505  }
506  return 0;
507 }
508 
509 static clib_error_t *
511  transport_endpoint_t * rmt,
512  ip46_address_t * lcl_addr)
513 {
514  fib_node_index_t fei;
516 
517  if (sw_if_index == ENDPOINT_INVALID_INDEX)
518  {
519  /* Find a FIB path to the destination */
520  clib_memcpy_fast (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
521  prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
522  prefix.fp_len = rmt->is_ip4 ? 32 : 128;
523 
524  ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX);
525  fei = fib_table_lookup (rmt->fib_index, &prefix);
526 
527  /* Couldn't find route to destination. Bail out. */
528  if (fei == FIB_NODE_INDEX_INVALID)
529  return clib_error_return (0, "no route to %U", format_ip46_address,
530  &rmt->ip, (rmt->is_ip4 == 0) + 1);
531 
532  sw_if_index = fib_entry_get_resolving_interface (fei);
533  if (sw_if_index == ENDPOINT_INVALID_INDEX)
534  return clib_error_return (0, "no resolving interface for %U",
535  format_ip46_address, &rmt->ip,
536  (rmt->is_ip4 == 0) + 1);
537  }
538 
539  clib_memset (lcl_addr, 0, sizeof (*lcl_addr));
540  return transport_get_interface_ip (sw_if_index, rmt->is_ip4, lcl_addr);
541 }
542 
543 int
545  ip46_address_t * lcl_addr, u16 * lcl_port)
546 {
547  transport_endpoint_t *rmt = (transport_endpoint_t *) rmt_cfg;
548  clib_error_t *error;
549  int port;
550  u32 tei;
551 
552  /*
553  * Find the local address
554  */
555  if (ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4))
556  {
557  error = transport_find_local_ip_for_remote (rmt_cfg->peer.sw_if_index,
558  rmt, lcl_addr);
559  if (error)
560  {
561  clib_error_report (error);
562  return -1;
563  }
564  }
565  else
566  {
567  /* Assume session layer vetted this address */
568  clib_memcpy_fast (lcl_addr, &rmt_cfg->peer.ip,
569  sizeof (rmt_cfg->peer.ip));
570  }
571 
572  /*
573  * Allocate source port
574  */
575  if (rmt_cfg->peer.port == 0)
576  {
577  port = transport_alloc_local_port (proto, lcl_addr);
578  if (port < 1)
579  {
580  clib_warning ("Failed to allocate src port");
581  return -1;
582  }
583  *lcl_port = port;
584  }
585  else
586  {
587  port = clib_net_to_host_u16 (rmt_cfg->peer.port);
589  lcl_addr, port);
590  if (tei != ENDPOINT_INVALID_INDEX)
591  return -1;
592 
593  transport_endpoint_mark_used (proto, lcl_addr, port);
594  *lcl_port = port;
595  }
596 
597  return 0;
598 }
599 
600 #define SPACER_CPU_TICKS_PER_PERIOD_SHIFT 10
601 #define SPACER_CPU_TICKS_PER_PERIOD (1 << SPACER_CPU_TICKS_PER_PERIOD_SHIFT)
602 
603 u8 *
604 format_transport_pacer (u8 * s, va_list * args)
605 {
606  spacer_t *pacer = va_arg (*args, spacer_t *);
607 
608  s = format (s, "bucket %u tokens/period %.3f last_update %x",
609  pacer->bucket, pacer->tokens_per_period, pacer->last_update);
610  return s;
611 }
612 
613 static inline u32
614 spacer_max_burst (spacer_t * pacer, u64 norm_time_now)
615 {
616  u64 n_periods = norm_time_now - pacer->last_update;
617  u64 inc;
618 
619  if (n_periods > 0 && (inc = n_periods * pacer->tokens_per_period) > 10)
620  {
621  pacer->last_update = norm_time_now;
622  pacer->bucket += inc;
623  }
624 
625  return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST);
626 }
627 
628 static inline void
630 {
631  ASSERT (pacer->bucket >= bytes);
632  pacer->bucket -= bytes;
633 }
634 
635 static inline void
636 spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec)
637 {
638  ASSERT (rate_bytes_per_sec != 0);
639  pacer->tokens_per_period = rate_bytes_per_sec / transport_pacer_period;
640 }
641 
642 static inline u64
644 {
645  return pacer->tokens_per_period * transport_pacer_period;
646 }
647 
648 void
650  u32 rate_bytes_per_sec,
651  u32 start_bucket, u64 time_now)
652 {
653  spacer_t *pacer = &tc->pacer;
654  spacer_set_pace_rate (&tc->pacer, rate_bytes_per_sec);
655  pacer->last_update = time_now >> SPACER_CPU_TICKS_PER_PERIOD_SHIFT;
656  pacer->bucket = start_bucket;
657 }
658 
659 void
661  u32 rate_bytes_per_sec,
662  u32 initial_bucket)
663 {
666  transport_connection_tx_pacer_reset (tc, rate_bytes_per_sec,
667  initial_bucket,
669 }
670 
671 void
673  u64 bytes_per_sec)
674 {
675  spacer_set_pace_rate (&tc->pacer, bytes_per_sec);
676 }
677 
678 u32
680  u64 time_now)
681 {
683  return spacer_max_burst (&tc->pacer, time_now);
684 }
685 
686 u32
688  u16 mss)
689 {
690  u32 snd_space, max_paced_burst;
691 
692  snd_space = tp_vfts[tc->proto].send_space (tc);
694  {
696  max_paced_burst = spacer_max_burst (&tc->pacer, time_now);
697  max_paced_burst = (max_paced_burst < mss) ? 0 : max_paced_burst;
698  snd_space = clib_min (snd_space, max_paced_burst);
699  snd_space = snd_space - snd_space % mss;
700  }
701  return snd_space;
702 }
703 
704 u64
706 {
707  return spacer_pace_rate (&tc->pacer);
708 }
709 
710 void
712 {
714  spacer_update_bucket (&tc->pacer, bytes);
715 }
716 
717 void
719  u32 bytes)
720 {
721  spacer_update_bucket (&tc->pacer, bytes);
722 }
723 
724 void
726 {
727  f64 cpu_freq = os_cpu_clock_frequency ();
729 }
730 
731 void
732 transport_update_time (f64 time_now, u8 thread_index)
733 {
735  vec_foreach (vft, tp_vfts)
736  {
737  if (vft->update_time)
738  (vft->update_time) (time_now, thread_index);
739  }
740 }
741 
742 void
744 {
746  vec_foreach (vft, tp_vfts)
747  {
748  if (vft->enable)
749  (vft->enable) (vm, is_en);
750  }
751 }
752 
753 void
755 {
758  u32 num_threads;
759 
760  if (smm->local_endpoints_table_buckets == 0)
761  smm->local_endpoints_table_buckets = 250000;
762  if (smm->local_endpoints_table_memory == 0)
763  smm->local_endpoints_table_memory = 512 << 20;
764 
765  /* Initialize [port-allocator] random number seed */
767 
768  clib_bihash_init_24_8 (&local_endpoints_table, "local endpoints table",
771  num_threads = 1 /* main thread */ + vtm->n_threads;
772  if (num_threads > 1)
773  clib_spinlock_init (&local_endpoints_lock);
774 }
775 
776 /*
777  * fd.io coding-style-patch-verification: ON
778  *
779  * Local Variables:
780  * eval: (c-set-style "gnu")
781  * End:
782  */
#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:322
#define ENDPOINT_INVALID_INDEX
u8 * format_transport_connection(u8 *s, va_list *args)
Definition: transport.c:123
u32 transport_endpoint_lookup(transport_endpoint_table_t *ht, u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:212
#define clib_min(x, y)
Definition: clib.h:295
u8 * format_transport_proto_short(u8 *s, va_list *args)
Definition: transport.c:89
void transport_get_listener_endpoint(transport_proto_t tp, u32 conn_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:381
static void transport_endpoint_mark_used(u8 proto, ip46_address_t *ip, u16 port)
Definition: transport.c:430
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:230
#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
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:108
static u64 clib_cpu_time_now(void)
Definition: time.h:75
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:304
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
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:328
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
clib_time_t clib_time
Definition: main.h:72
vl_api_mprefix_t prefix
Definition: ip.api:456
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
Definition: session.h:173
void transport_endpoint_del(u32 tepi)
Definition: transport.c:397
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
u32 transport_connection_tx_pacer_burst(transport_connection_t *tc, u64 time_now)
Get tx pacer max burst.
Definition: transport.c:679
void transport_update_time(f64 time_now, u8 thread_index)
Definition: transport.c:732
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
double f64
Definition: types.h:142
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:292
static clib_error_t * transport_get_interface_ip(u32 sw_if_index, u8 is_ip4, ip46_address_t *addr)
Definition: transport.c:484
#define always_inline
Definition: clib.h:98
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
Aggregrate 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:544
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
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
void transport_connection_tx_pacer_init(transport_connection_t *tc, u32 rate_bytes_per_sec, u32 initial_bucket)
Initialize tx pacer for connection.
Definition: transport.c:660
struct _transport_proto_vft transport_proto_vft_t
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:61
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:284
static void spacer_set_pace_rate(spacer_t *pacer, u64 rate_bytes_per_sec)
Definition: transport.c:636
#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:244
#define SPACER_CPU_TICKS_PER_PERIOD
Definition: transport.c:601
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
Definition: transport.c:298
void transport_get_endpoint(transport_proto_t tp, u32 conn_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:365
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
enum transport_service_type_ transport_service_type_t
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:232
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:310
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
Definition: transport.c:335
void transport_connection_tx_pacer_update(transport_connection_t *tc, u64 bytes_per_sec)
Update tx pacer pacing rate.
Definition: transport.c:672
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1448
void transport_init(void)
Definition: transport.c:754
static double transport_pacer_period
Definition: transport.c:48
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:316
vlib_main_t * vm
Definition: buffer.c:312
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.h:111
#define clib_warning(format, args...)
Definition: error.h:59
#define PORT_MASK
Definition: transport.c:394
void transport_init_tx_pacers_period(void)
Initialize period for tx pacers.
Definition: transport.c:725
static void default_get_transport_endpoint(transport_connection_t *tc, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:347
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:743
void transport_endpoint_cleanup(u8 proto, ip46_address_t *lcl_ip, u16 port)
Definition: transport.c:413
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:266
#define SPACER_CPU_TICKS_PER_PERIOD_SHIFT
Definition: transport.c:600
static u64 spacer_pace_rate(spacer_t *pacer)
Definition: transport.c:643
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)
u64 last_cpu_time
Definition: time.h:50
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:179
void transport_connection_update_tx_bytes(transport_connection_t *tc, u32 bytes)
Update tx bytes for paced transport connection.
Definition: transport.c:711
static transport_endpoint_t * transport_endpoint_new(void)
Definition: transport.c:405
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
Definition: transport.c:164
enum _transport_proto transport_proto_t
#define clib_error_report(e)
Definition: error.h:113
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
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
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:718
static u32 port_allocator_seed
Definition: transport.c:28
void transport_connection_tx_pacer_reset(transport_connection_t *tc, u32 rate_bytes_per_sec, u32 start_bucket, u64 time_now)
Definition: transport.c:649
u32 local_endpoints_table_buckets
Definition: session.h:174
vl_api_address_t ip
Definition: l2.api:489
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
#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:629
u64 uword
Definition: types.h:112
static u32 spacer_max_burst(spacer_t *pacer, u64 norm_time_now)
Definition: transport.c:614
connectionless service
u8 * format_transport_listen_connection(u8 *s, va_list *args)
Definition: transport.c:150
u8 * format_transport_pacer(u8 *s, va_list *args)
Definition: transport.c:604
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.
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:510
clib_bihash_24_8_t transport_endpoint_table_t
static session_main_t * vnet_get_session_main()
Definition: session.h:542
#define TRANSPORT_PACER_MAX_BURST
Definition: transport.c:52
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:447
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
Definition: transport.h:118
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:1368
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:93
u8 transport_protocol_is_cl(transport_proto_t tp)
Definition: transport.c:341
u8 * format_transport_proto(u8 *s, va_list *args)
Definition: transport.c:55
u64 transport_connection_tx_pacer_rate(transport_connection_t *tc)
Get tx pacer current rate.
Definition: transport.c:705
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
f64 os_cpu_clock_frequency(void)
Definition: time.c:143