X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Ftransport.h;h=952f97d9ac3326d3af5294e2696ebc95f9147182;hb=775f73c;hp=9c38bab9c4f02fbfa35d9e9aff0534096e097665;hpb=2c25a62cc1cc4937165de740a3b32d78429c72d6;p=vpp.git diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h index 9c38bab9c4f..952f97d9ac3 100644 --- a/src/vnet/session/transport.h +++ b/src/vnet/session/transport.h @@ -18,27 +18,58 @@ #include #include -#include -#include #include + +typedef struct _transport_stats +{ + u64 tx_bytes; +} transport_stats_t; + +typedef struct _spacer +{ + u64 bucket; + u32 max_burst_size; + f32 tokens_per_period; + u64 last_update; +} spacer_t; + /* * Protocol independent transport properties associated to a session */ typedef struct _transport_connection { - ip46_address_t rmt_ip; /**< Remote IP */ - ip46_address_t lcl_ip; /**< Local IP */ - u16 lcl_port; /**< Local port */ - u16 rmt_port; /**< Remote port */ - u8 proto; /**< Protocol id (also session type) */ + /** Connection ID */ + union + { + /* + * Network connection ID tuple + */ + struct + { + ip46_address_t rmt_ip; /**< Remote IP */ + ip46_address_t lcl_ip; /**< Local IP */ + u16 rmt_port; /**< Remote port */ + u16 lcl_port; /**< Local port */ + u8 is_ip4; /**< Flag if IP4 connection */ + u8 proto; /**< Protocol id */ + u32 fib_index; /**< Network namespace */ + }; + /* + * Opaque connection ID + */ + u8 opaque_conn_id[42]; + }; u32 s_index; /**< Parent session index */ u32 c_index; /**< Connection index in transport pool */ - u8 is_ip4; /**< Flag if IP4 connection */ u32 thread_index; /**< Worker-thread index */ - fib_node_index_t rmt_fei; /**< FIB entry index for rmt */ - dpo_id_t rmt_dpo; /**< Forwarding DPO for rmt */ + /*fib_node_index_t rmt_fei; + dpo_id_t rmt_dpo; */ + + u8 flags; /**< Transport specific flags */ + transport_stats_t stats; /**< Transport connection stats */ + spacer_t pacer; /**< Simple transport pacer */ #if TRANSPORT_DEBUG elog_track_t elog_track; /**< Event logging */ @@ -55,7 +86,7 @@ typedef struct _transport_connection #define c_lcl_port connection.lcl_port #define c_rmt_port connection.rmt_port #define c_proto connection.proto -#define c_state connection.state +#define c_fib_index connection.fib_index #define c_s_index connection.s_index #define c_c_index connection.c_index #define c_is_ip4 connection.is_ip4 @@ -64,192 +95,81 @@ typedef struct _transport_connection #define c_cc_stat_tstamp connection.cc_stat_tstamp #define c_rmt_fei connection.rmt_fei #define c_rmt_dpo connection.rmt_dpo +#define c_opaque_id connection.opaque_conn_id +#define c_stats connection.stats +#define c_pacer connection.pacer +#define c_flags connection.flags } transport_connection_t; -/* - * Transport protocol virtual function table - */ -typedef struct _transport_proto_vft -{ - /* - * Setup - */ - u32 (*bind) (u32, ip46_address_t *, u16); - u32 (*unbind) (u32); - int (*open) (ip46_address_t * addr, u16 port_host_byte_order); - void (*close) (u32 conn_index, u32 thread_index); - void (*cleanup) (u32 conn_index, u32 thread_index); - - /* - * Transmission - */ - u32 (*push_header) (transport_connection_t * tconn, vlib_buffer_t * b); - u16 (*send_mss) (transport_connection_t * tc); - u32 (*send_space) (transport_connection_t * tc); - u32 (*tx_fifo_offset) (transport_connection_t * tc); - - /* - * Connection retrieval - */ - transport_connection_t *(*get_connection) (u32 conn_idx, u32 thread_idx); - transport_connection_t *(*get_listener) (u32 conn_index); - transport_connection_t *(*get_half_open) (u32 conn_index); - - /* - * Format - */ - u8 *(*format_connection) (u8 * s, va_list * args); - u8 *(*format_listener) (u8 * s, va_list * args); - u8 *(*format_half_open) (u8 * s, va_list * args); -} transport_proto_vft_t; - -/* *INDENT-OFF* */ -/* 16 octets */ -typedef CLIB_PACKED (struct { - union - { - struct - { - ip4_address_t src; - ip4_address_t dst; - u16 src_port; - u16 dst_port; - /* align by making this 4 octets even though its a 1-bit field - * NOTE: avoid key overlap with other transports that use 5 tuples for - * session identification. - */ - u32 proto; - }; - u64 as_u64[2]; - }; -}) v4_connection_key_t; - -typedef CLIB_PACKED (struct { - union - { - struct - { - /* 48 octets */ - ip6_address_t src; - ip6_address_t dst; - u16 src_port; - u16 dst_port; - u32 proto; - u64 unused; - }; - u64 as_u64[6]; - }; -}) v6_connection_key_t; -/* *INDENT-ON* */ - -typedef clib_bihash_kv_16_8_t session_kv4_t; -typedef clib_bihash_kv_48_8_t session_kv6_t; - -always_inline void -make_v4_ss_kv (session_kv4_t * kv, ip4_address_t * lcl, ip4_address_t * rmt, - u16 lcl_port, u16 rmt_port, u8 proto) -{ - v4_connection_key_t *key = (v4_connection_key_t *) kv->key; - - key->src.as_u32 = lcl->as_u32; - key->dst.as_u32 = rmt->as_u32; - key->src_port = lcl_port; - key->dst_port = rmt_port; - key->proto = proto; - - kv->value = ~0ULL; -} +#define TRANSPORT_CONNECTION_F_IS_TX_PACED 1 << 0 -always_inline void -make_v4_listener_kv (session_kv4_t * kv, ip4_address_t * lcl, u16 lcl_port, - u8 proto) +typedef enum _transport_proto { - v4_connection_key_t *key = (v4_connection_key_t *) kv->key; + TRANSPORT_PROTO_TCP, + TRANSPORT_PROTO_UDP, + TRANSPORT_PROTO_SCTP, + TRANSPORT_PROTO_NONE, + TRANSPORT_PROTO_TLS, + TRANSPORT_PROTO_UDPC, + TRANSPORT_N_PROTO +} transport_proto_t; - key->src.as_u32 = lcl->as_u32; - key->dst.as_u32 = 0; - key->src_port = lcl_port; - key->dst_port = 0; - key->proto = proto; +u8 *format_transport_proto (u8 * s, va_list * args); +u8 *format_transport_proto_short (u8 * s, va_list * args); +u8 *format_transport_connection (u8 * s, va_list * args); +u8 *format_transport_listen_connection (u8 * s, va_list * args); +u8 *format_transport_half_open_connection (u8 * s, va_list * args); - kv->value = ~0ULL; -} +uword unformat_transport_proto (unformat_input_t * input, va_list * args); -always_inline void -make_v4_ss_kv_from_tc (session_kv4_t * kv, transport_connection_t * t) -{ - return make_v4_ss_kv (kv, &t->lcl_ip.ip4, &t->rmt_ip.ip4, t->lcl_port, - t->rmt_port, t->proto); -} +#define foreach_transport_endpoint_fields \ + _(ip46_address_t, ip) /**< ip address in net order */ \ + _(u16, port) /**< port in net order */ \ + _(u8, is_ip4) /**< set if ip4 */ \ + _(u32, sw_if_index) /**< interface endpoint is associated with */ \ + _(u32, fib_index) /**< fib table endpoint is associated with */ \ -always_inline void -make_v6_ss_kv (session_kv6_t * kv, ip6_address_t * lcl, ip6_address_t * rmt, - u16 lcl_port, u16 rmt_port, u8 proto) +typedef struct transport_endpoint_ { - v6_connection_key_t *key = (v6_connection_key_t *) kv->key; - - key->src.as_u64[0] = lcl->as_u64[0]; - key->src.as_u64[1] = lcl->as_u64[1]; - key->dst.as_u64[0] = rmt->as_u64[0]; - key->dst.as_u64[1] = rmt->as_u64[1]; - key->src_port = lcl_port; - key->dst_port = rmt_port; - key->proto = proto; - key->unused = 0; +#define _(type, name) type name; + foreach_transport_endpoint_fields +#undef _ +} transport_endpoint_t; - kv->value = ~0ULL; -} +#define foreach_transport_endpoint_cfg_fields \ + foreach_transport_endpoint_fields \ + _(transport_endpoint_t, peer) \ -always_inline void -make_v6_listener_kv (session_kv6_t * kv, ip6_address_t * lcl, u16 lcl_port, - u8 proto) +typedef struct transport_endpoint_pair_ { - v6_connection_key_t *key = (v6_connection_key_t *) kv->key; +#define _(type, name) type name; + foreach_transport_endpoint_cfg_fields +#undef _ +} transport_endpoint_cfg_t; - key->src.as_u64[0] = lcl->as_u64[0]; - key->src.as_u64[1] = lcl->as_u64[1]; - key->dst.as_u64[0] = 0; - key->dst.as_u64[1] = 0; - key->src_port = lcl_port; - key->dst_port = 0; - key->proto = proto; - key->unused = 0; +typedef clib_bihash_24_8_t transport_endpoint_table_t; - kv->value = ~0ULL; -} +#define ENDPOINT_INVALID_INDEX ((u32)~0) -always_inline void -make_v6_ss_kv_from_tc (session_kv6_t * kv, transport_connection_t * t) +always_inline u8 +transport_connection_fib_proto (transport_connection_t * tc) { - make_v6_ss_kv (kv, &t->lcl_ip.ip6, &t->rmt_ip.ip6, t->lcl_port, - t->rmt_port, t->proto); + return tc->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; } -typedef enum _transport_proto -{ - TRANSPORT_PROTO_TCP, - TRANSPORT_PROTO_UDP -} transport_proto_t; - -typedef struct _transport_endpoint +always_inline u8 +transport_endpoint_fib_proto (transport_endpoint_t * tep) { - ip46_address_t ip; /** ip address */ - u16 port; /** port in host order */ - u8 is_ip4; /** 1 if ip4 */ - u32 vrf; /** fib table the endpoint is associated with */ -} transport_endpoint_t; - -typedef clib_bihash_24_8_t transport_endpoint_table_t; - -#define TRANSPORT_ENDPOINT_INVALID_INDEX ((u32)~0) + return tep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; +} -u32 -transport_endpoint_lookup (transport_endpoint_table_t * ht, - ip46_address_t * ip, u16 port); -void transport_endpoint_table_add (transport_endpoint_table_t * ht, - transport_endpoint_t * te, u32 value); -void transport_endpoint_table_del (transport_endpoint_table_t * ht, - transport_endpoint_t * te); +int transport_alloc_local_port (u8 proto, ip46_address_t * ip); +int transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt, + ip46_address_t * lcl_addr, + u16 * lcl_port); +void transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port); +u8 transport_protocol_is_cl (transport_proto_t tp); +void transport_init (void); #endif /* VNET_VNET_URI_TRANSPORT_H_ */