FD.io VPP  v18.01.1-37-g7ea3975
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)
 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)
 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
 
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

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 781 of file vapi.c.

+ Here is the call graph for this function:

void vapi_clear_generic_event_cb ( vapi_ctx_t  ctx)

clear generic event callback

Parameters
ctxopaque vapi context

Definition at line 795 of file vapi.c.

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 
)

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
Returns
VAPI_OK on success, other error code on error

Definition at line 292 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 245 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vapi_ctx_free ( vapi_ctx_t  ctx)

free vapi context

Definition at line 274 of file vapi.c.

+ Here is the caller graph for this function:

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 397 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 757 of file vapi.c.

+ Here is the call graph for this function:

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

Definition at line 673 of file vapi.c.

+ Here is the caller graph for this function:

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 700 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 574 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 vapi_gen_req_context ( vapi_ctx_t  ctx)

Definition at line 88 of file vapi.c.

int vapi_get_client_index ( vapi_ctx_t  ctx)

Definition at line 809 of file vapi.c.

size_t vapi_get_context_offset ( vapi_msg_id_t  id)

Definition at line 853 of file vapi.c.

+ Here is the caller graph for this function:

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 413 of file vapi.c.

+ Here is the caller graph for this function:

size_t vapi_get_max_request_count ( vapi_ctx_t  ctx)

Definition at line 821 of file vapi.c.

size_t vapi_get_message_count ( )

Definition at line 918 of file vapi.c.

+ Here is the caller graph for this function:

size_t vapi_get_message_size ( vapi_msg_id_t  id)

Definition at line 846 of file vapi.c.

+ Here is the caller graph for this function:

const char* vapi_get_msg_name ( vapi_msg_id_t  id)

Definition at line 924 of file vapi.c.

+ Here is the caller graph for this function:

int vapi_get_payload_offset ( vapi_msg_id_t  id)

Definition at line 827 of file vapi.c.

+ Here is the caller graph for this function:

size_t vapi_get_request_count ( vapi_ctx_t  ctx)

Definition at line 96 of file vapi.c.

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 286 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool vapi_is_nonblocking ( vapi_ctx_t  ctx)

Definition at line 815 of file vapi.c.

vapi_msg_id_t vapi_lookup_vapi_msg_id_t ( vapi_ctx_t  ctx,
u16  vl_msg_id 
)

Definition at line 235 of file vapi.c.

+ Here is the caller graph for this function:

u16 vapi_lookup_vl_msg_id ( vapi_ctx_t  ctx,
vapi_msg_id_t  id 
)

Definition at line 802 of file vapi.c.

+ Here is the caller graph for this function:

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 211 of file vapi.c.

+ Here is the call graph for this function:

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 222 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool vapi_msg_is_with_context ( vapi_msg_id_t  id)

Definition at line 693 of file vapi.c.

+ Here is the caller graph for this function:

vapi_error_e vapi_producer_lock ( vapi_ctx_t  ctx)

Definition at line 891 of file vapi.c.

vapi_error_e vapi_producer_unlock ( vapi_ctx_t  ctx)

Definition at line 904 of file vapi.c.

vapi_error_e vapi_recv ( vapi_ctx_t  ctx,
void **  msg,
size_t *  msg_size 
)

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
Returns
VAPI_OK on success, other error code on error

Definition at line 507 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

vapi_msg_id_t vapi_register_msg ( vapi_message_desc_t msg)

Definition at line 860 of file vapi.c.

bool vapi_requests_empty ( vapi_ctx_t  ctx)

Definition at line 108 of file vapi.c.

+ Here is the caller graph for this function:

static int vapi_requests_end ( vapi_ctx_t  ctx)
static

Definition at line 114 of file vapi.c.

+ Here is the caller graph for this function:

bool vapi_requests_full ( vapi_ctx_t  ctx)

Definition at line 102 of file vapi.c.

+ Here is the caller graph for this function:

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 419 of file vapi.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 462 of file vapi.c.

+ Here is the call graph for this function:

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 772 of file vapi.c.

+ Here is the caller graph for this function:

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 787 of file vapi.c.

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

Definition at line 120 of file vapi.c.

+ Here is the call graph for this function:

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 568 of file vapi.c.

Variable Documentation

const u32 context_counter_mask = (1 << 31)
static

Definition at line 55 of file vapi.c.

size_t count

Definition at line 42 of file vapi.c.

size_t max_len_name_with_crc

Definition at line 44 of file vapi.c.

Definition at line 43 of file vapi.c.

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

Definition at line 839 of file vapi.c.

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

Definition at line 833 of file vapi.c.

vapi_msg_id_t vapi_msg_id_control_ping = 0

Definition at line 37 of file vapi.c.

vapi_msg_id_t vapi_msg_id_control_ping_reply = 0

Definition at line 38 of file vapi.c.