From 4edc37eb90a74bcd1aad20d6447159c05853d23e Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Mon, 4 Feb 2019 23:01:34 -0800 Subject: session: cleanup part 3 Aggregate session specific types, getters and setters under session_types.h Change-Id: Ib205337502654969d60c72d1800c90247e1a9068 Signed-off-by: Florin Coras --- src/vnet/session/session_types.h | 260 ++++++++++++++++++++++++++++++--------- 1 file changed, 200 insertions(+), 60 deletions(-) (limited to 'src/vnet/session/session_types.h') diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h index ec5841f5ea4..b334c3c9f69 100644 --- a/src/vnet/session/session_types.h +++ b/src/vnet/session/session_types.h @@ -19,7 +19,80 @@ #include #include +#define SESSION_LOCAL_HANDLE_PREFIX 0x7FFFFFFF + +#define foreach_session_endpoint_fields \ + foreach_transport_endpoint_cfg_fields \ + _(u8, transport_proto) \ + +typedef struct _session_endpoint +{ +#define _(type, name) type name; + foreach_session_endpoint_fields +#undef _ +} session_endpoint_t; + +typedef struct _session_endpoint_cfg +{ +#define _(type, name) type name; + foreach_session_endpoint_fields +#undef _ + u32 app_wrk_index; + u32 opaque; + u8 *hostname; +} session_endpoint_cfg_t; + +#define SESSION_IP46_ZERO \ +{ \ + .ip6 = { \ + { 0, 0, }, \ + }, \ +} + +#define TRANSPORT_ENDPOINT_NULL \ +{ \ + .sw_if_index = ENDPOINT_INVALID_INDEX, \ + .ip = SESSION_IP46_ZERO, \ + .fib_index = ENDPOINT_INVALID_INDEX, \ + .is_ip4 = 0, \ + .port = 0, \ +} +#define SESSION_ENDPOINT_NULL \ +{ \ + .sw_if_index = ENDPOINT_INVALID_INDEX, \ + .ip = SESSION_IP46_ZERO, \ + .fib_index = ENDPOINT_INVALID_INDEX, \ + .is_ip4 = 0, \ + .port = 0, \ + .peer = TRANSPORT_ENDPOINT_NULL, \ + .transport_proto = 0, \ +} +#define SESSION_ENDPOINT_CFG_NULL \ +{ \ + .sw_if_index = ENDPOINT_INVALID_INDEX, \ + .ip = SESSION_IP46_ZERO, \ + .fib_index = ENDPOINT_INVALID_INDEX, \ + .is_ip4 = 0, \ + .port = 0, \ + .peer = TRANSPORT_ENDPOINT_NULL, \ + .transport_proto = 0, \ + .app_wrk_index = ENDPOINT_INVALID_INDEX, \ + .opaque = ENDPOINT_INVALID_INDEX, \ + .hostname = 0, \ +} + +#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep) +#define session_endpoint_to_transport_cfg(_sep) \ + ((transport_endpoint_cfg_t *)_sep) + +always_inline u8 +session_endpoint_fib_proto (session_endpoint_t * sep) +{ + return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; +} + typedef u8 session_type_t; +typedef u64 session_handle_t; /* * Application session state @@ -101,6 +174,99 @@ typedef struct session_ CLIB_CACHE_LINE_ALIGN_MARK (pad); } session_t; +always_inline session_type_t +session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4) +{ + return (proto << 1 | is_ip4); +} + +always_inline transport_proto_t +session_type_transport_proto (session_type_t st) +{ + return (st >> 1); +} + +always_inline u8 +session_type_is_ip4 (session_type_t st) +{ + return (st & 1); +} + +always_inline transport_proto_t +session_get_transport_proto (session_t * s) +{ + return (s->session_type >> 1); +} + +always_inline fib_protocol_t +session_get_fib_proto (session_t * s) +{ + u8 is_ip4 = s->session_type & 1; + return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6); +} + +always_inline u8 +session_has_transport (session_t * s) +{ + return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE); +} + +static inline transport_service_type_t +session_transport_service_type (session_t * s) +{ + transport_proto_t tp; + tp = session_get_transport_proto (s); + return transport_protocol_service_type (tp); +} + +static inline transport_tx_fn_type_t +session_transport_tx_fn_type (session_t * s) +{ + transport_proto_t tp; + tp = session_get_transport_proto (s); + return transport_protocol_tx_fn_type (tp); +} + +static inline u8 +session_tx_is_dgram (session_t * s) +{ + return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM); +} + +always_inline session_handle_t +session_handle (session_t * s) +{ + return ((u64) s->thread_index << 32) | (u64) s->session_index; +} + +always_inline u32 +session_index_from_handle (session_handle_t handle) +{ + return handle & 0xFFFFFFFF; +} + +always_inline u32 +session_thread_from_handle (session_handle_t handle) +{ + return handle >> 32; +} + +always_inline void +session_parse_handle (session_handle_t handle, u32 * index, + u32 * thread_index) +{ + *index = session_index_from_handle (handle); + *thread_index = session_thread_from_handle (handle); +} + +always_inline u8 +session_handle_is_local (session_handle_t handle) +{ + if ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX) + return 1; + return 0; +} + typedef struct local_session_ { /** fifo pointers. Once allocated, these do not move */ @@ -154,74 +320,48 @@ typedef struct local_session_ CLIB_CACHE_LINE_ALIGN_MARK (pad); } local_session_t; -#define foreach_session_endpoint_fields \ - foreach_transport_endpoint_cfg_fields \ - _(u8, transport_proto) \ - -typedef struct _session_endpoint +always_inline u32 +local_session_id (local_session_t * ls) { -#define _(type, name) type name; - foreach_session_endpoint_fields -#undef _ -} session_endpoint_t; + ASSERT (ls->session_index < (2 << 16)); + u32 app_or_wrk_index; + + if (ls->session_state == SESSION_STATE_LISTENING) + { + ASSERT (ls->app_index < (2 << 16)); + app_or_wrk_index = ls->app_index; + } + else + { + ASSERT (ls->app_wrk_index < (2 << 16)); + app_or_wrk_index = ls->app_wrk_index; + } + + return ((u32) app_or_wrk_index << 16 | (u32) ls->session_index); +} -typedef struct _session_endpoint_cfg +always_inline void +local_session_parse_id (u32 ls_id, u32 * app_or_wrk, u32 * session_index) { -#define _(type, name) type name; - foreach_session_endpoint_fields -#undef _ - u32 app_wrk_index; - u32 opaque; - u8 *hostname; -} session_endpoint_cfg_t; - -#define SESSION_IP46_ZERO \ -{ \ - .ip6 = { \ - { 0, 0, }, \ - }, \ + *app_or_wrk = ls_id >> 16; + *session_index = ls_id & 0xFF; } -#define TRANSPORT_ENDPOINT_NULL \ -{ \ - .sw_if_index = ENDPOINT_INVALID_INDEX, \ - .ip = SESSION_IP46_ZERO, \ - .fib_index = ENDPOINT_INVALID_INDEX, \ - .is_ip4 = 0, \ - .port = 0, \ -} -#define SESSION_ENDPOINT_NULL \ -{ \ - .sw_if_index = ENDPOINT_INVALID_INDEX, \ - .ip = SESSION_IP46_ZERO, \ - .fib_index = ENDPOINT_INVALID_INDEX, \ - .is_ip4 = 0, \ - .port = 0, \ - .peer = TRANSPORT_ENDPOINT_NULL, \ - .transport_proto = 0, \ -} -#define SESSION_ENDPOINT_CFG_NULL \ -{ \ - .sw_if_index = ENDPOINT_INVALID_INDEX, \ - .ip = SESSION_IP46_ZERO, \ - .fib_index = ENDPOINT_INVALID_INDEX, \ - .is_ip4 = 0, \ - .port = 0, \ - .peer = TRANSPORT_ENDPOINT_NULL, \ - .transport_proto = 0, \ - .app_wrk_index = ENDPOINT_INVALID_INDEX, \ - .opaque = ENDPOINT_INVALID_INDEX, \ - .hostname = 0, \ +always_inline void +local_session_parse_handle (session_handle_t handle, u32 * app_or_wrk_index, + u32 * session_index) +{ + u32 bottom; + ASSERT ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX); + bottom = (handle & 0xFFFFFFFF); + local_session_parse_id (bottom, app_or_wrk_index, session_index); } -#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep) -#define session_endpoint_to_transport_cfg(_sep) \ - ((transport_endpoint_cfg_t *)_sep) - -always_inline u8 -session_endpoint_fib_proto (session_endpoint_t * sep) +always_inline session_handle_t +application_local_session_handle (local_session_t * ls) { - return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; + return ((u64) SESSION_LOCAL_HANDLE_PREFIX << 32) + | (u64) local_session_id (ls); } #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */ -- cgit 1.2.3-korg