56 if (
tp_vfts[transport_proto].transport_options.name)
57 s =
format (s,
"%s",
tp_vfts[transport_proto].transport_options.name);
72 s =
format (s,
"%s", short_name);
83 u32 conn_index = va_arg (*args,
u32);
84 u32 thread_index = va_arg (*args,
u32);
85 u32 verbose = va_arg (*args,
u32);
94 s =
format (s,
"%U", tp_vft->format_connection, conn_index, thread_index,
96 tc = tp_vft->get_connection (conn_index, thread_index);
97 if (tc && verbose > 1)
119 s = (tp_vft->format_listener) (s, args);
127 u32 listen_index = va_arg (*args,
u32);
134 s =
format (s,
"%U", tp_vft->format_half_open, listen_index);
143 if (strlen (str) >
vec_len (input->buffer) - input->index)
146 for (i = 0; i < strlen (str); i++)
148 if (input->buffer[i + input->index] != str[i])
159 u8 longest_match = 0, match;
160 char *str, *str_match = 0;
166 str = tp_vft->transport_options.name;
171 match = strlen (str);
172 if (match > longest_match)
175 longest_match = match;
195 s =
format (s,
"%s\n", tp_vft->transport_options.name);
207 kv.
key[0] = ip->as_u64[0];
208 kv.
key[1] = ip->as_u64[1];
211 rv = clib_bihash_search_inline_24_8 (ht, &kv);
224 kv.
key[0] = te->ip.as_u64[0];
225 kv.
key[1] = te->ip.as_u64[1];
229 clib_bihash_add_del_24_8 (ht, &kv, 1);
238 kv.
key[0] = te->ip.as_u64[0];
239 kv.
key[1] = te->ip.as_u64[1];
242 clib_bihash_add_del_24_8 (ht, &kv, 0);
292 return tp_vfts[tp].transport_options.service_type;
298 return tp_vfts[tp].transport_options.tx_type;
304 tp_vfts[tp].cleanup (conn_index, thread_index);
311 tp_vfts[tp].cleanup_ho (conn_index);
317 return tp_vfts[tp].connect (tep);
323 tp_vfts[tp].close (conn_index, thread_index);
330 tp_vfts[tp].reset (conn_index, thread_index);
332 tp_vfts[tp].close (conn_index, thread_index);
339 return tp_vfts[tp].start_listen (session_index, tep);
345 return tp_vfts[tp].stop_listen (conn_index);
360 tep->port = tc->lcl_port;
361 tep->is_ip4 = tc->is_ip4;
366 tep->port = tc->rmt_port;
367 tep->is_ip4 = tc->is_ip4;
377 if (
tp_vfts[tp].get_transport_endpoint)
378 tp_vfts[tp].get_transport_endpoint (conn_index, thread_index, tep,
392 if (
tp_vfts[tp].get_transport_listener_endpoint)
393 tp_vfts[tp].get_transport_listener_endpoint (conn_index, tep, is_lcl);
402 #define PORT_MASK ((1 << 16)- 1) 428 clib_net_to_host_u16 (port));
451 lep - local_endpoints);
462 clib_net_to_host_u16 (port));
477 u16 min = 1024, max = 65535;
487 for (tries = 0; tries < limit; tries++)
519 return SESSION_E_NOIP;
520 addr->ip4.as_u32 = ip4->
as_u32;
527 return SESSION_E_NOIP;
536 ip46_address_t * lcl_addr)
546 prefix.
fp_len = rmt->is_ip4 ? 32 : 128;
553 return SESSION_E_NOROUTE;
557 return SESSION_E_NOINTF;
566 ip46_address_t * lcl_addr,
u16 * lcl_port)
576 if (
ip_is_zero (&rmt_cfg->peer.ip, rmt_cfg->peer.is_ip4))
587 sizeof (rmt_cfg->peer.ip));
593 if (rmt_cfg->peer.port == 0)
597 return SESSION_E_NOPORT;
602 port = clib_net_to_host_u16 (rmt_cfg->peer.port);
607 return SESSION_E_PORTINUSE;
620 s =
format (s,
"%u us", t);
630 u32 thread_index = va_arg (*args,
int);
634 diff = now - pacer->last_update;
635 s =
format (s,
"rate %lu bucket %ld t/p %.3f last_update %U burst %u",
636 pacer->bytes_per_sec, pacer->bucket, pacer->tokens_per_period,
644 u64 n_periods = (time_now - pacer->last_update);
647 if ((inc = (
f32) n_periods * pacer->tokens_per_period) > 10)
649 pacer->last_update = time_now;
650 pacer->bucket =
clib_min (pacer->bucket + inc, pacer->max_burst);
653 return pacer->bucket > 0 ? pacer->max_burst : 0;
659 pacer->bucket -= bytes;
668 ASSERT (rate_bytes_per_sec != 0);
669 pacer->bytes_per_sec = rate_bytes_per_sec;
684 pacer->max_burst = (rate_bytes_per_sec * max_time) * CLIB_US_TIME_PERIOD;
692 return pacer->bytes_per_sec;
698 pacer->last_update = time_now;
699 pacer->bucket = bucket;
704 u64 rate_bytes_per_sec,
u32 start_bucket,
722 u64 rate_bytes_per_sec,
727 initial_bucket, 1e6);
796 if (vft->update_time)
797 (vft->update_time) (time_now, thread_index);
808 (vft->enable) (vm, is_en);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
fib_protocol_t fp_proto
protocol type
void transport_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
#define ENDPOINT_INVALID_INDEX
u8 * format_transport_connection(u8 *s, va_list *args)
u32 transport_endpoint_lookup(transport_endpoint_table_t *ht, u8 proto, ip46_address_t *ip, u16 port)
u8 * format_transport_proto_short(u8 *s, va_list *args)
static local_endpoint_t * local_endpoints
void transport_get_listener_endpoint(transport_proto_t tp, u32 conn_index, transport_endpoint_t *tep, u8 is_lcl)
static void transport_endpoint_mark_used(u8 proto, ip46_address_t *ip, u16 port)
#define clib_atomic_add_fetch(a, b)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
void transport_endpoint_table_add(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te, u32 value)
void transport_share_local_endpoint(u8 proto, ip46_address_t *lcl_ip, u16 port)
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
transport_proto_t session_add_transport_proto(void)
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
static transport_endpoint_table_t local_endpoints_table
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
static u64 clib_cpu_time_now(void)
static void spacer_reset(spacer_t *pacer, clib_us_time_t time_now, u64 bucket)
u8 * format_transport_protos(u8 *s, va_list *args)
transport_tx_fn_type_t transport_protocol_tx_fn_type(transport_proto_t tp)
u32 transport_start_listen(transport_proto_t tp, u32 session_index, transport_endpoint_t *tep)
static session_t * session_get(u32 si, u32 thread_index)
struct local_endpoint_ local_endpoint_t
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
void transport_endpoint_del(u32 tepi)
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static clib_time_type_t transport_seconds_per_loop(u32 thread_index)
void transport_update_time(clib_time_type_t time_now, u8 thread_index)
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)
#define clib_clamp(x, lo, hi)
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
description fragment has unexpected format
void transport_fifos_init_ooo(transport_connection_t *tc)
Aggregate type for a prefix.
int transport_alloc_local_endpoint(u8 proto, transport_endpoint_cfg_t *rmt_cfg, ip46_address_t *lcl_addr, u16 *lcl_port)
u16 fp_len
The mask length.
static clib_spinlock_t local_endpoints_lock
void transport_reset(transport_proto_t tp, u32 conn_index, u8 thread_index)
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.
struct _transport_proto_vft transport_proto_vft_t
static void clib_spinlock_init(clib_spinlock_t *p)
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
void transport_endpoint_table_del(transport_endpoint_table_t *ht, u8 proto, transport_endpoint_t *te)
#define CLIB_US_TIME_FREQ
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
void transport_get_endpoint(transport_proto_t tp, u32 conn_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
static session_error_t transport_get_interface_ip(u32 sw_if_index, u8 is_ip4, ip46_address_t *addr)
static void cleanup(void)
void transport_connection_tx_pacer_init(transport_connection_t *tc, u64 rate_bytes_per_sec, u32 initial_bucket)
Initialize tx pacer for connection.
enum transport_service_type_ transport_service_type_t
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
transport_proto_vft_t * tp_vfts
Per-type vector of transport protocol virtual function tables.
static u8 transport_connection_is_tx_paced(transport_connection_t *tc)
Check if transport connection is paced.
void transport_connection_tx_pacer_reset(transport_connection_t *tc, u64 rate_bytes_per_sec, u32 start_bucket, clib_us_time_t rtt)
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
u8 * format_clib_us_time(u8 *s, va_list *args)
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
#define clib_atomic_sub_fetch(a, b)
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
void transport_init(void)
void transport_connection_reschedule(transport_connection_t *tc)
static_always_inline uword vlib_get_thread_index(void)
int transport_connect(transport_proto_t tp, transport_endpoint_cfg_t *tep)
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
sll srl srl sll sra u16x4 i
static void default_get_transport_endpoint(transport_connection_t *tc, transport_endpoint_t *tep, u8 is_lcl)
struct _transport_connection transport_connection_t
u32 fib_node_index_t
A typedef of a node index.
void transport_enable_disable(vlib_main_t *vm, u8 is_en)
void transport_endpoint_cleanup(u8 proto, ip46_address_t *lcl_ip, u16 port)
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.
static clib_us_time_t transport_us_time_now(u32 thread_index)
static u32 transport_max_tx_dequeue(transport_connection_t *tc)
static u64 spacer_pace_rate(spacer_t *pacer)
#define CLIB_US_TIME_PERIOD
#define pool_put_index(p, i)
Free pool element with given index.
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
void transport_connection_tx_pacer_reset_bucket(transport_connection_t *tc, u32 bucket)
Reset tx pacer bucket.
#define TRANSPORT_PACER_MAX_BURST
void sesssion_reschedule_tx(transport_connection_t *tc)
void transport_connection_update_tx_bytes(transport_connection_t *tc, u32 bytes)
Update tx bytes for paced transport connection.
#define TRANSPORT_PACER_MIN_BURST
u8 * format_transport_half_open_connection(u8 *s, va_list *args)
enum _transport_proto transport_proto_t
#define TRANSPORT_PACER_BURSTS_PER_RTT
static session_error_t transport_find_local_ip_for_remote(u32 sw_if_index, transport_endpoint_t *rmt, ip46_address_t *lcl_addr)
void transport_connection_tx_pacer_update(transport_connection_t *tc, u64 bytes_per_sec, clib_us_time_t rtt)
Update tx pacer pacing rate.
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
void transport_connection_tx_pacer_update_bytes(transport_connection_t *tc, u32 bytes)
static u32 port_allocator_seed
static local_endpoint_t * transport_endpoint_new(void)
u32 local_endpoints_table_buckets
#define FIB_NODE_INDEX_INVALID
static u32 spacer_max_burst(spacer_t *pacer, clib_us_time_t time_now)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void spacer_update_bucket(spacer_t *pacer, u32 bytes)
u8 * format_transport_listen_connection(u8 *s, va_list *args)
transport_proto_t transport_register_new_protocol(const transport_proto_vft_t *vft, fib_protocol_t fib_proto, u32 output_node)
u8 * format_transport_pacer(u8 *s, va_list *args)
static u32 random_u32(u32 *seed)
32-bit random number generator
Connection descheduled by the session layer.
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
enum session_error_ session_error_t
void transport_cleanup_half_open(transport_proto_t tp, u32 conn_index)
clib_bihash_24_8_t transport_endpoint_table_t
static session_main_t * vnet_get_session_main()
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...
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
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.
enum transport_dequeue_type_ transport_tx_fn_type_t
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
u8 transport_protocol_is_cl(transport_proto_t tp)
u8 * format_transport_proto(u8 *s, va_list *args)
u32 transport_connection_tx_pacer_burst(transport_connection_t *tc)
Get tx pacer max burst.
u64 transport_connection_tx_pacer_rate(transport_connection_t *tc)
Get tx pacer current rate.
static u8 unformat_transport_str_match(unformat_input_t *input, const char *str)
vl_api_interface_index_t sw_if_index
void svm_fifo_init_ooo_lookup(svm_fifo_t *f, u8 ooo_type)
Initialize rbtrees used for ooo lookups.