FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
vapi.c File Reference
+ Include dependency graph for vapi.c:

Go to the source code of this file.

Data Structures

struct  vapi_req_t
 
struct  vapi_generic_cb_with_ctx
 
struct  vapi_event_cb_with_ctx
 
struct  vapi_ctx_s
 

Functions

u32 vapi_gen_req_context (vapi_ctx_t ctx)
 
size_t vapi_get_request_count (vapi_ctx_t ctx)
 
bool vapi_requests_full (vapi_ctx_t ctx)
 
bool vapi_requests_empty (vapi_ctx_t ctx)
 
static int vapi_requests_end (vapi_ctx_t ctx)
 
void vapi_store_request (vapi_ctx_t ctx, u32 context, bool is_dump, vapi_cb_t callback, void *callback_ctx)
 
void * vapi_msg_alloc (vapi_ctx_t ctx, size_t size)
 allocate vapi message of given size More...
 
void vapi_msg_free (vapi_ctx_t ctx, void *msg)
 free a vapi message More...
 
vapi_msg_id_t vapi_lookup_vapi_msg_id_t (vapi_ctx_t ctx, u16 vl_msg_id)
 
vapi_error_e vapi_ctx_alloc (vapi_ctx_t *result)
 allocate vapi context More...
 
void vapi_ctx_free (vapi_ctx_t ctx)
 free vapi context More...
 
bool vapi_is_msg_available (vapi_ctx_t ctx, vapi_msg_id_t id)
 check if message identified by it's message id is known by the vpp to which the connection is open More...
 
vapi_error_e vapi_connect (vapi_ctx_t ctx, const char *name, const char *chroot_prefix, int max_outstanding_requests, int response_queue_size, vapi_mode_e mode, bool handle_keepalives)
 connect to vpp More...
 
vapi_error_e vapi_disconnect (vapi_ctx_t ctx)
 disconnect from vpp More...
 
vapi_error_e vapi_get_fd (vapi_ctx_t ctx, int *fd)
 get event file descriptor More...
 
vapi_error_e vapi_send (vapi_ctx_t ctx, void *msg)
 low-level api for sending messages to vpp More...
 
vapi_error_e vapi_send2 (vapi_ctx_t ctx, void *msg1, void *msg2)
 low-level api for atomically sending two messages to vpp - either both messages are sent or neither one is More...
 
vapi_error_e vapi_recv (vapi_ctx_t ctx, void **msg, size_t *msg_size, svm_q_conditional_wait_t cond, u32 time)
 low-level api for reading messages from vpp More...
 
vapi_error_e vapi_wait (vapi_ctx_t ctx, vapi_wait_mode_e mode)
 wait for connection to become readable or writable More...
 
static vapi_error_e vapi_dispatch_response (vapi_ctx_t ctx, vapi_msg_id_t id, u32 context, void *msg)
 
static vapi_error_e vapi_dispatch_event (vapi_ctx_t ctx, vapi_msg_id_t id, void *msg)
 
bool vapi_msg_is_with_context (vapi_msg_id_t id)
 
vapi_error_e vapi_dispatch_one (vapi_ctx_t ctx)
 pick next message sent by vpp and call the appropriate callback More...
 
vapi_error_e vapi_dispatch (vapi_ctx_t ctx)
 loop vapi_dispatch_one until responses to all currently outstanding requests have been received and their callbacks called More...
 
void vapi_set_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id, vapi_event_cb callback, void *callback_ctx)
 set event callback to call when message with given id is dispatched More...
 
void vapi_clear_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id)
 clear event callback for given message id More...
 
void vapi_set_generic_event_cb (vapi_ctx_t ctx, vapi_generic_event_cb callback, void *callback_ctx)
 set generic event callback More...
 
void vapi_clear_generic_event_cb (vapi_ctx_t ctx)
 clear generic event callback More...
 
u16 vapi_lookup_vl_msg_id (vapi_ctx_t ctx, vapi_msg_id_t id)
 
int vapi_get_client_index (vapi_ctx_t ctx)
 
bool vapi_is_nonblocking (vapi_ctx_t ctx)
 
size_t vapi_get_max_request_count (vapi_ctx_t ctx)
 
int vapi_get_payload_offset (vapi_msg_id_t id)
 
size_t vapi_get_message_size (vapi_msg_id_t id)
 
size_t vapi_get_context_offset (vapi_msg_id_t id)
 
vapi_msg_id_t vapi_register_msg (vapi_message_desc_t *msg)
 
vapi_error_e vapi_producer_lock (vapi_ctx_t ctx)
 
vapi_error_e vapi_producer_unlock (vapi_ctx_t ctx)
 
size_t vapi_get_message_count ()
 
const char * vapi_get_msg_name (vapi_msg_id_t id)
 

Variables

vapi_msg_id_t vapi_msg_id_control_ping = 0
 
vapi_msg_id_t vapi_msg_id_control_ping_reply = 0
 
 DEFINE_VAPI_MSG_IDS_MEMCLNT_API_JSON
 
 DEFINE_VAPI_MSG_IDS_VPE_API_JSON
 
static const u32 context_counter_mask = (1 << 31)
 
void(*)(void *msg) vapi_get_swap_to_host_func (vapi_msg_id_t id)
 
void(*)(void *msg) vapi_get_swap_to_be_func (vapi_msg_id_t id)
 

Function Documentation

◆ vapi_clear_event_cb()

void vapi_clear_event_cb ( vapi_ctx_t  ctx,
vapi_msg_id_t  id 
)

clear event callback for given message id

Parameters
ctxopaque vapi context
idmessage id

Definition at line 828 of file vapi.c.

+ Here is the call graph for this function:

◆ vapi_clear_generic_event_cb()

void vapi_clear_generic_event_cb ( vapi_ctx_t  ctx)

clear generic event callback

Parameters
ctxopaque vapi context

Definition at line 842 of file vapi.c.

◆ vapi_connect()

vapi_error_e vapi_connect ( vapi_ctx_t  ctx,
const char *  name,
const char *  chroot_prefix,
int  max_outstanding_requests,
int  response_queue_size,
vapi_mode_e  mode,
bool  handle_keepalives 
)

connect to vpp

Parameters
ctxopaque vapi context, must be allocated using vapi_ctx_alloc first
nameapplication name
chroot_prefixshared memory prefix
max_outstanding_requestsmax number of outstanding requests queued
response_queue_sizesize of the response queue
modemode of operation - blocking or nonblocking
handle_keepalives- if true, automatically handle memclnt_keepalive
Returns
VAPI_OK on success, other error code on error

Definition at line 301 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_ctx_alloc()

vapi_error_e vapi_ctx_alloc ( vapi_ctx_t result)

allocate vapi context

Parameters
[out]pointerto result variable
Returns
VAPI_OK on success, other error code on error

Definition at line 251 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_ctx_free()

void vapi_ctx_free ( vapi_ctx_t  ctx)

free vapi context

Definition at line 283 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_disconnect()

vapi_error_e vapi_disconnect ( vapi_ctx_t  ctx)

disconnect from vpp

Parameters
ctxopaque vapi context
Returns
VAPI_OK on success, other error code on error

Definition at line 419 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_dispatch()

vapi_error_e vapi_dispatch ( vapi_ctx_t  ctx)

loop vapi_dispatch_one until responses to all currently outstanding requests have been received and their callbacks called

Note
the dispatch loop is interrupted if any error is encountered or returned from the callback, in which case this error is returned as the result of vapi_dispatch. In this case it might be necessary to call dispatch again to process the remaining messages. Returning VAPI_EUSER from a callback allows the user to break the dispatch loop (and distinguish this case in the calling code from other failures). VAPI never returns VAPI_EUSER on its own.
Returns
VAPI_OK on success, other error code on error

Definition at line 804 of file vapi.c.

+ Here is the call graph for this function:

◆ vapi_dispatch_event()

static vapi_error_e vapi_dispatch_event ( vapi_ctx_t  ctx,
vapi_msg_id_t  id,
void *  msg 
)
static

Definition at line 720 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_dispatch_one()

vapi_error_e vapi_dispatch_one ( vapi_ctx_t  ctx)

pick next message sent by vpp and call the appropriate callback

Returns
VAPI_OK on success, other error code on error

Definition at line 747 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_dispatch_response()

static vapi_error_e vapi_dispatch_response ( vapi_ctx_t  ctx,
vapi_msg_id_t  id,
u32  context,
void *  msg 
)
static

Definition at line 622 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_gen_req_context()

u32 vapi_gen_req_context ( vapi_ctx_t  ctx)

Definition at line 94 of file vapi.c.

◆ vapi_get_client_index()

int vapi_get_client_index ( vapi_ctx_t  ctx)

Definition at line 856 of file vapi.c.

◆ vapi_get_context_offset()

size_t vapi_get_context_offset ( vapi_msg_id_t  id)

Definition at line 900 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_fd()

vapi_error_e vapi_get_fd ( vapi_ctx_t  ctx,
int *  fd 
)

get event file descriptor

Note
this file descriptor becomes readable when messages (from vpp) are waiting in queue
Parameters
ctxopaque vapi context
[out]fdpointer to result variable
Returns
VAPI_OK on success, other error code on error

Definition at line 435 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_max_request_count()

size_t vapi_get_max_request_count ( vapi_ctx_t  ctx)

Definition at line 868 of file vapi.c.

◆ vapi_get_message_count()

size_t vapi_get_message_count ( )

Definition at line 965 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_message_size()

size_t vapi_get_message_size ( vapi_msg_id_t  id)

Definition at line 893 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_msg_name()

const char* vapi_get_msg_name ( vapi_msg_id_t  id)

Definition at line 971 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_payload_offset()

int vapi_get_payload_offset ( vapi_msg_id_t  id)

Definition at line 874 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_get_request_count()

size_t vapi_get_request_count ( vapi_ctx_t  ctx)

Definition at line 102 of file vapi.c.

◆ vapi_is_msg_available()

bool vapi_is_msg_available ( vapi_ctx_t  ctx,
vapi_msg_id_t  id 
)

check if message identified by it's message id is known by the vpp to which the connection is open

Definition at line 295 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_is_nonblocking()

bool vapi_is_nonblocking ( vapi_ctx_t  ctx)

Definition at line 862 of file vapi.c.

◆ vapi_lookup_vapi_msg_id_t()

vapi_msg_id_t vapi_lookup_vapi_msg_id_t ( vapi_ctx_t  ctx,
u16  vl_msg_id 
)

Definition at line 241 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_lookup_vl_msg_id()

u16 vapi_lookup_vl_msg_id ( vapi_ctx_t  ctx,
vapi_msg_id_t  id 
)

Definition at line 849 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_msg_alloc()

void* vapi_msg_alloc ( vapi_ctx_t  ctx,
size_t  size 
)

allocate vapi message of given size

Note
message must be freed by vapi_msg_free if not consumed by vapi_send call
Parameters
ctxopaque vapi context
Returns
pointer to message or NULL if out of memory

Definition at line 217 of file vapi.c.

+ Here is the call graph for this function:

◆ vapi_msg_free()

void vapi_msg_free ( vapi_ctx_t  ctx,
void *  msg 
)

free a vapi message

Note
messages received by vapi_recv must be freed when no longer needed
Parameters
ctxopaque vapi context
msgmessage to be freed

Definition at line 228 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_msg_is_with_context()

bool vapi_msg_is_with_context ( vapi_msg_id_t  id)

Definition at line 740 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_producer_lock()

vapi_error_e vapi_producer_lock ( vapi_ctx_t  ctx)

Definition at line 938 of file vapi.c.

◆ vapi_producer_unlock()

vapi_error_e vapi_producer_unlock ( vapi_ctx_t  ctx)

Definition at line 951 of file vapi.c.

◆ vapi_recv()

vapi_error_e vapi_recv ( vapi_ctx_t  ctx,
void **  msg,
size_t *  msg_size,
svm_q_conditional_wait_t  cond,
u32  time 
)

low-level api for reading messages from vpp

Note
it is not recommended to use this api directly, use generated api instead
Parameters
ctxopaque vapi context
[out]msgpointer to result variable containing message
[out]msg_sizepointer to result variable containing message size
condenum type for blocking, non-blocking or timed wait call
timein sec for timed wait
Returns
VAPI_OK on success, other error code on error

Definition at line 527 of file vapi.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vapi_register_msg()

vapi_msg_id_t vapi_register_msg ( vapi_message_desc_t msg)

Definition at line 907 of file vapi.c.

◆ vapi_requests_empty()

bool vapi_requests_empty ( vapi_ctx_t  ctx)

Definition at line 114 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_requests_end()

static int vapi_requests_end ( vapi_ctx_t  ctx)
static

Definition at line 120 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_requests_full()

bool vapi_requests_full ( vapi_ctx_t  ctx)

Definition at line 108 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_send()

vapi_error_e vapi_send ( vapi_ctx_t  ctx,
void *  msg 
)

low-level api for sending messages to vpp

Note
it is not recommended to use this api directly, use generated api instead
Parameters
ctxopaque vapi context
msgmessage to send
Returns
VAPI_OK on success, other error code on error

Definition at line 441 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_send2()

vapi_error_e vapi_send2 ( vapi_ctx_t  ctx,
void *  msg1,
void *  msg2 
)

low-level api for atomically sending two messages to vpp - either both messages are sent or neither one is

Note
it is not recommended to use this api directly, use generated api instead
Parameters
ctxopaque vapi context
msg1first message to send
msg2second message to send
Returns
VAPI_OK on success, other error code on error

Definition at line 483 of file vapi.c.

◆ vapi_set_event_cb()

void vapi_set_event_cb ( vapi_ctx_t  ctx,
vapi_msg_id_t  id,
vapi_event_cb  callback,
void *  callback_ctx 
)

set event callback to call when message with given id is dispatched

Parameters
ctxopaque vapi context
idmessage id
callbackcallback
callback_ctxcontext pointer stored and passed to callback

Definition at line 819 of file vapi.c.

+ Here is the caller graph for this function:

◆ vapi_set_generic_event_cb()

void vapi_set_generic_event_cb ( vapi_ctx_t  ctx,
vapi_generic_event_cb  callback,
void *  callback_ctx 
)

set generic event callback

Note
this callback is called by dispatch if no message-type specific callback is set (so it's a fallback callback)
Parameters
ctxopaque vapi context
callbackcallback
callback_ctxcontext pointer stored and passed to callback

Definition at line 834 of file vapi.c.

◆ vapi_store_request()

void vapi_store_request ( vapi_ctx_t  ctx,
u32  context,
bool  is_dump,
vapi_cb_t  callback,
void *  callback_ctx 
)

Definition at line 126 of file vapi.c.

+ Here is the call graph for this function:

◆ vapi_wait()

vapi_error_e vapi_wait ( vapi_ctx_t  ctx,
vapi_wait_mode_e  mode 
)

wait for connection to become readable or writable

Parameters
ctxopaque vapi context
modetype of property to wait for - readability, writability or both
Returns
VAPI_OK on success, other error code on error

Definition at line 616 of file vapi.c.

Variable Documentation

◆ context_counter_mask

const u32 context_counter_mask = (1 << 31)
static

Definition at line 60 of file vapi.c.

◆ count

size_t count

Definition at line 47 of file vapi.c.

◆ DEFINE_VAPI_MSG_IDS_MEMCLNT_API_JSON

DEFINE_VAPI_MSG_IDS_MEMCLNT_API_JSON

Definition at line 42 of file vapi.c.

◆ DEFINE_VAPI_MSG_IDS_VPE_API_JSON

DEFINE_VAPI_MSG_IDS_VPE_API_JSON

Definition at line 43 of file vapi.c.

◆ max_len_name_with_crc

size_t max_len_name_with_crc

Definition at line 49 of file vapi.c.

◆ msgs

Definition at line 48 of file vapi.c.

◆ vapi_get_swap_to_be_func

void(*)(void *msg) vapi_get_swap_to_be_func(vapi_msg_id_t id)

Definition at line 886 of file vapi.c.

◆ vapi_get_swap_to_host_func

void(*)(void *msg) vapi_get_swap_to_host_func(vapi_msg_id_t id)

Definition at line 880 of file vapi.c.

◆ vapi_msg_id_control_ping

vapi_msg_id_t vapi_msg_id_control_ping = 0

Definition at line 39 of file vapi.c.

◆ vapi_msg_id_control_ping_reply

vapi_msg_id_t vapi_msg_id_control_ping_reply = 0

Definition at line 40 of file vapi.c.