23 #include <sys/types.h> 26 #include <netinet/in.h> 59 #define vl_print(handle, ...) clib_warning (__VA_ARGS__) 129 vec_add1 (keys, (u8 *) hp->key);
132 for (i = 0; i <
vec_len (keys); i++)
144 for (i = 0; i < nmsgs; i++)
190 pthread_mutex_lock (&svm->
mutex);
195 pthread_mutex_unlock (&svm->
mutex);
203 memset (mp, 0,
sizeof (*mp));
204 mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE);
207 strncpy ((
char *) mp->
name, name, sizeof (mp->
name) - 1);
214 struct timespec ts, tsrem;
218 for (i = 0; i < 1000; i++)
225 ts.tv_nsec = 10000 * 1000;
226 while (nanosleep (&ts, &tsrem) < 0)
234 if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_CREATE_REPLY)
236 clib_warning (
"unexpected reply: id %d", ntohs (rp->_vl_msg_id));
239 rv = clib_net_to_host_u32 (rp->
response);
281 memset (mp, 0,
sizeof (*mp));
282 mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE);
300 if (now >= (begin + 2))
312 if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_DELETE_REPLY)
322 #define foreach_api_msg \ 323 _(RX_THREAD_EXIT, rx_thread_exit) \ 324 _(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \ 325 _(MEMCLNT_DELETE_REPLY, memclnt_delete_reply) 339 vl_msg_api_set_handlers(VL_API_##N, #n, \ 340 vl_api_##n##_t_handler, \ 342 vl_api_##n##_t_endian, \ 343 vl_api_##n##_t_print, \ 344 sizeof(vl_api_##n##_t), 1); 358 const char *client_name,
359 int rx_queue_size,
int want_pthread)
393 const char *client_name,
int rx_queue_size)
401 const char *client_name,
419 ep->_vl_msg_id = ntohs (VL_API_RX_THREAD_EXIT);
428 memset (mm, 0,
sizeof (*mm));
452 if (strlen (plugin_name) + 1 >
sizeof (mp->
name))
455 memset (&clib_time, 0,
sizeof (clib_time));
459 old_handler = am->
msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY];
460 am->
msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = (
void *)
467 memset (mp, 0,
sizeof (*mp));
468 mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
470 strncpy ((
char *) mp->
name, plugin_name, sizeof (mp->
name) - 1);
488 am->
msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;
497 am->
msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;
500 clib_warning (
"plugin '%s' not registered", plugin_name);
sll srl srl sll sra u16x4 i
static void svm_pop_heap(void *oldheap)
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
static u64 unserialize_likely_small_unsigned_integer(serialize_main_t *m)
u8 rx_thread_jmpbuf_valid
int vl_client_connect_to_vlib_no_rx_pthread(const char *svm_name, const char *client_name, int rx_queue_size)
Fixed length block allocator.
unix_shared_memory_queue_t * vl_input_queue
void unix_shared_memory_queue_free(unix_shared_memory_queue_t *q)
static f64 clib_time_now(clib_time_t *c)
#define hash_set_mem(h, key, value)
static void noop_handler(void *notused)
unix_shared_memory_queue_t * vl_input_queue
void vl_client_api_unmap(void)
static int connect_to_vlib_internal(const char *svm_name, const char *client_name, int rx_queue_size, int want_pthread)
vl_api_registration_t * my_registration
pthread_t rx_thread_handle
static void * svm_push_data_heap(svm_region_t *rp)
static void * rx_thread_fn(void *arg)
struct vl_shmem_hdr_ * shmem_hdr
void * vl_msg_api_alloc(int nbytes)
#define hash_create_string(elts, value_bytes)
vl_shmem_hdr_t * shmem_hdr
static void vl_api_memclnt_create_reply_t_handler(vl_api_memclnt_create_reply_t *mp)
int vl_client_connect(const char *name, int ctx_quota, int input_queue_size)
void vl_msg_api_free(void *)
void vl_msg_api_handler(void *the_msg)
void clib_time_init(clib_time_t *c)
void unserialize_cstring(serialize_main_t *m, char **s)
#define uword_to_pointer(u, type)
static void vl_api_memclnt_delete_reply_t_handler(vl_api_memclnt_delete_reply_t *mp)
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
void serialize_open_vector(serialize_main_t *m, u8 *vector)
void vl_unmap_shmem(void)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
int vl_client_api_map(const char *region_name)
void vlib_node_sync_stats(vlib_main_t *vm, vlib_node_t *n)
static void unserialize_integer(serialize_main_t *m, void *x, u32 n_bytes)
u16 vl_client_get_first_plugin_msg_id(const char *plugin_name)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
unix_shared_memory_queue_t * unix_shared_memory_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
Bitmaps built as vectors of machine words.
void vl_client_disconnect(void)
static void vl_api_get_first_msg_id_reply_t_handler(vl_api_get_first_msg_id_reply_t *mp)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
static void vl_api_rx_thread_exit_t_handler(vl_api_rx_thread_exit_t *mp)
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
memory_client_main_t memory_client_main
void(** msg_handlers)(void *)
void vl_client_disconnect_from_vlib(void)
int vl_map_shmem(const char *region_name, int is_vlib)
uword * msg_index_by_name_and_crc
volatile u8 first_msg_id_reply_ready
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
struct _unix_shared_memory_queue unix_shared_memory_queue_t