vcl/ldp: add locked sessions shim layer

Moves LDP logic that allows sharing of sessions between multi-process
app workers into a separate VCL shim layer. Also refactors LDP to use
the new layer.

Change-Id: I8198b51eae7d099a8c486e36b29e3a0cb8cee8e9
Signed-off-by: Florin Coras <fcoras@cisco.com>
This commit is contained in:
Florin Coras
2019-01-04 17:05:43 -08:00
committed by Florin Coras
parent 8dc146e000
commit 7baeb71f92
7 changed files with 889 additions and 1296 deletions

View File

@ -20,6 +20,7 @@ add_vpp_library(vppcom
vcl_bapi.c
vcl_cfg.c
vcl_private.c
vcl_locked.c
LINK_LIBRARIES
vppinfra svm vlibmemoryclient rt pthread
@ -43,6 +44,7 @@ add_vpp_headers(vcl
ldp_glibc_socket.h
vcl_test.h
vppcom.h
vcl_locked.h
ldp_socket_wrapper.h
)

File diff suppressed because it is too large Load Diff

457
src/vcl/vcl_locked.c Normal file

File diff suppressed because it is too large Load Diff

60
src/vcl/vcl_locked.h Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2019 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* VCL Locked Sessions
*/
#ifndef SRC_VCL_VCL_LOCKED_H_
#define SRC_VCL_VCL_LOCKED_H_
#include <vcl/vppcom.h>
#define VLS_INVALID_HANDLE ((int)-1)
typedef int vls_handle_t;
vls_handle_t vls_create (uint8_t proto, uint8_t is_nonblocking);
int vls_close (vls_handle_t vlsh);
int vls_bind (vls_handle_t vlsh, vppcom_endpt_t * ep);
int vls_listen (vls_handle_t vlsh, int q_len);
int vls_connect (vls_handle_t vlsh, vppcom_endpt_t * server_ep);
vls_handle_t vls_accept (vls_handle_t vlsh, vppcom_endpt_t * ep, int flags);
ssize_t vls_read (vls_handle_t vlsh, void *buf, size_t nbytes);
ssize_t vls_recvfrom (vls_handle_t vlsh, void *buffer, uint32_t buflen,
int flags, vppcom_endpt_t * ep);
int vls_write (vls_handle_t vlsh, void *buf, size_t nbytes);
int vls_write_msg (vls_handle_t vlsh, void *buf, size_t nbytes);
int vls_sendto (vls_handle_t vlsh, void *buf, int buflen, int flags,
vppcom_endpt_t * ep);
int vls_attr (vls_handle_t vlsh, uint32_t op, void *buffer,
uint32_t * buflen);
vls_handle_t vls_epoll_create (void);
int vls_epoll_ctl (vls_handle_t ep_vlsh, int op, vls_handle_t vlsh,
struct epoll_event *event);
int vls_epoll_wait (vls_handle_t ep_vlsh, struct epoll_event *events,
int maxevents, double wait_for_time);
vcl_session_handle_t vlsh_to_sh (vls_handle_t vlsh);
vcl_session_handle_t vlsh_to_session_index (vls_handle_t vlsh);
vls_handle_t vls_session_index_to_vlsh (uint32_t session_index);
int vls_app_create (char *app_name);
#endif /* SRC_VCL_VCL_LOCKED_H_ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -125,6 +125,8 @@ enum
VCL_SESS_ATTR_TCP_NODELAY, // SOL_TCP,TCP_NODELAY
VCL_SESS_ATTR_TCP_KEEPIDLE, // SOL_TCP,TCP_KEEPIDLE
VCL_SESS_ATTR_TCP_KEEPINTVL, // SOL_TCP,TCP_KEEPINTVL
VCL_SESS_ATTR_SHUT_RD,
VCL_SESS_ATTR_SHUT_WR,
VCL_SESS_ATTR_MAX
} vppcom_session_attr_t;
@ -583,6 +585,7 @@ u32 vcl_max_nsid_len (void);
u8 *format_api_error (u8 * s, va_list * args);
void vls_init ();
#endif /* SRC_VCL_VCL_PRIVATE_H_ */
/*

View File

@ -22,7 +22,6 @@
__thread uword __vcl_worker_index = ~0;
static int
vcl_wait_for_segment (u64 segment_handle)
{
@ -1594,9 +1593,9 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
if (PREDICT_FALSE (session->session_state & CLIENT_STATE_OPEN))
{
VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: session already "
VDBG (0, "session handle %u [0x%llx]: session already "
"connected to %s %U port %d proto %s, state 0x%x (%s)",
getpid (), session->vpp_handle, session_handle,
session_handle, session->vpp_handle,
session->transport.is_ip4 ? "IPv4" : "IPv6",
format_ip46_address,
&session->transport.rmt_ip, session->transport.is_ip4 ?
@ -1616,9 +1615,8 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
sizeof (ip6_address_t));
session->transport.rmt_port = server_ep->port;
VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: connecting to server %s %U "
"port %d proto %s",
getpid (), session->vpp_handle, session_handle,
VDBG (0, "session handle %u [0x%llx]: connecting to server %s %U "
"port %d proto %s", session_handle, session->vpp_handle,
session->transport.is_ip4 ? "IPv4" : "IPv6",
format_ip46_address,
&session->transport.rmt_ip, session->transport.is_ip4 ?
@ -2993,7 +2991,7 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
vcl_worker_t *wrk = vcl_worker_get_current ();
vcl_session_t *session;
int rv = VPPCOM_OK;
u32 *flags = buffer;
u32 *flags = buffer, tmp_flags = 0;
vppcom_endpt_t *ep = buffer;
session = vcl_session_get_w_handle (wrk, session_handle);
@ -3004,8 +3002,7 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
{
case VPPCOM_ATTR_GET_NREAD:
rv = vppcom_session_read_ready (session);
VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d",
getpid (), rv);
VDBG (2, "VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d", rv);
break;
case VPPCOM_ATTR_GET_NWRITE:
@ -3514,6 +3511,26 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
rv = vcl_session_get_refcnt (session);
break;
case VPPCOM_ATTR_SET_SHUT:
if (*flags == SHUT_RD || *flags == SHUT_RDWR)
VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_SHUT_RD);
if (*flags == SHUT_WR || *flags == SHUT_RDWR)
VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_SHUT_WR);
break;
case VPPCOM_ATTR_GET_SHUT:
if (VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_SHUT_RD))
tmp_flags = 1;
if (VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_SHUT_WR))
tmp_flags |= 2;
if (tmp_flags == 1)
*(int *) buffer = SHUT_RD;
else if (tmp_flags == 2)
*(int *) buffer = SHUT_WR;
else if (tmp_flags == 3)
*(int *) buffer = SHUT_RDWR;
*buflen = sizeof (int);
break;
default:
rv = VPPCOM_EINVAL;
break;
@ -3620,7 +3637,7 @@ vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time)
for (i = 0; i < n_sids; i++)
{
session = vcl_session_get (wrk, vp[i].sid);
session = vcl_session_get (wrk, vp[i].sh);
if (!session)
{
vp[i].revents = POLLHUP;
@ -3695,7 +3712,7 @@ vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time)
for (i = 0; i < n_sids; i++)
{
clib_warning ("VCL<%d>: vp[%d].sid %d (0x%x), .events 0x%x, "
".revents 0x%x", getpid (), i, vp[i].sid, vp[i].sid,
".revents 0x%x", getpid (), i, vp[i].sh, vp[i].sh,
vp[i].events, vp[i].revents);
}
}

View File

@ -31,7 +31,7 @@ extern "C"
/*
* VPPCOM Public API Definitions, Enums, and Data Structures
*/
#define INVALID_SESSION_ID (~0)
#define INVALID_SESSION_ID ((u32)~0)
#define VPPCOM_CONF_DEFAULT "/etc/vpp/vcl.conf"
#define VPPCOM_ENV_CONF "VCL_CONFIG"
#define VPPCOM_ENV_DEBUG "VCL_DEBUG"
@ -153,12 +153,14 @@ typedef enum
VPPCOM_ATTR_GET_TCP_USER_MSS,
VPPCOM_ATTR_SET_TCP_USER_MSS,
VPPCOM_ATTR_GET_REFCNT,
VPPCOM_ATTR_SET_SHUT,
VPPCOM_ATTR_GET_SHUT,
} vppcom_attr_op_t;
typedef struct _vcl_poll
{
uint32_t fds_ndx;
uint32_t sid;
vcl_session_handle_t sh;
short events;
short revents;
} vcl_poll_t;