FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
api_common.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2009 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #ifndef included_vlibmemory_api_common_h
19 #define included_vlibmemory_api_common_h
20 
21 #include <svm/svm_common.h>
22 #include <vppinfra/file.h>
23 #include <vlibapi/api_common.h>
25 
26 /* Allocated in shared memory */
27 
28 /*
29  * Ring-allocation scheme for client API messages
30  *
31  * Only one proc/thread has control of a given message buffer.
32  * To free a buffer allocated from one of these rings, we clear
33  * a field in the buffer (header), and leave.
34  *
35  * No locks, no hits, no errors...
36  */
37 typedef struct ring_alloc_
38 {
44 } ring_alloc_t;
45 
46 /*
47  * Initializers for the (shared-memory) rings
48  * _(size, n). Note: each msg has space for a header.
49  */
50 #define foreach_vl_aring_size \
51 _(64+sizeof(ring_alloc_t), 1024) \
52 _(256+sizeof(ring_alloc_t), 128) \
53 _(1024+sizeof(ring_alloc_t), 64)
54 
55 #define foreach_clnt_aring_size \
56  _(1024+sizeof(ring_alloc_t), 1024) \
57  _(2048+sizeof(ring_alloc_t), 128) \
58  _(4096+sizeof(ring_alloc_t), 8)
59 
60 typedef struct vl_shmem_hdr_
61 {
62  int version;
63 
64  /* getpid () for the VLIB client process */
65  volatile int vl_pid;
66 
67  /* Client sends VLIB msgs here. */
69 
70  /* Vector of rings; one for each size. */
71 
72  /* VLIB allocates buffers to send msgs to clients here. */
74 
75  /* Clients allocate buffer to send msgs to VLIB here. */
77 
78  /* Number of detected application restarts */
80 
81  /* Number of messages reclaimed during application restart */
83 
84  /* Number of garbage-collected messages */
87 
88 #define VL_SHM_VERSION 2
89 
90 #define VL_API_EPOCH_MASK 0xFF
91 #define VL_API_EPOCH_SHIFT 8
92 
93 void *vl_msg_api_alloc (int nbytes);
94 void *vl_msg_api_alloc_or_null (int nbytes);
95 void *vl_msg_api_alloc_as_if_client (int nbytes);
96 void *vl_msg_api_alloc_as_if_client_or_null (int nbytes);
97 void vl_msg_api_free (void *a);
98 int vl_map_shmem (const char *region_name, int is_vlib);
100 void vl_unmap_shmem (void);
103 void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem);
104 int vl_client_connect (const char *name, int ctx_quota, int input_queue_size);
105 void vl_client_disconnect (void);
108 int vl_client_api_map (const char *region_name);
109 void vl_client_api_unmap (void);
110 void vl_set_memory_region_name (const char *name);
111 void vl_set_memory_root_path (const char *root_path);
112 void vl_set_memory_uid (int uid);
113 void vl_set_memory_gid (int gid);
114 void vl_set_global_memory_baseva (u64 baseva);
120 int vl_client_connect_to_vlib (const char *svm_name, const char *client_name,
121  int rx_queue_size);
122 int vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name,
123  const char *client_name,
124  int rx_queue_size);
125 int vl_client_connect_to_vlib_no_map (const char *svm_name,
126  const char *client_name,
127  int rx_queue_size);
128 u16 vl_client_get_first_plugin_msg_id (const char *plugin_name);
129 
130 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
132 void vl_init_shmem (svm_region_t * vlib_rp, int is_vlib,
133  int is_private_region);
136 
137 /* API messages over sockets */
138 
140 extern volatile int **vl_api_queue_cursizes;
141 
142 /* Events sent to the memclnt process */
143 #define QUEUE_SIGNAL_EVENT 1
144 #define SOCKET_READ_EVENT 2
145 
146 #define API_SOCKET_FILE "/run/vpp-api.sock"
147 
148 typedef struct
149 {
154 
155 typedef struct
156 {
157  /* Server port number */
159 
160  /* By default, localhost... */
162 
163  /*
164  * (listen, server, client) registrations. Shared memory
165  * registrations are in shared memory
166  */
168  /*
169  * Chain-drag variables, so message API handlers
170  * (generally) don't know whether they're talking to a socket
171  * or to a shared-memory connection.
172  */
175  /* One input buffer, shared across all sockets */
177 
178  /* pool of process args for socket clients */
180 
181  /* Listen for API connections here */
183 } socket_main_t;
184 
186 
187 typedef struct
188 {
190  /* Temporarily disable the connection, so we can keep it around... */
192 
194 
201 
203 
204 #define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE 4096
205 
206 void socksvr_add_pending_output (struct clib_file *uf,
207  struct vl_api_registration_ *cf,
208  u8 * buffer, uword buffer_bytes);
209 
210 void vl_free_socket_registration_index (u32 pool_index);
211 void vl_socket_process_msg (struct clib_file *uf,
212  struct vl_api_registration_ *rp, i8 * input_v);
214 void vl_socket_add_pending_output (struct clib_file *uf,
215  struct vl_api_registration_ *rp,
216  u8 * buffer, uword buffer_bytes);
218  struct vl_api_registration_ *rp,
219  u8 * buffer, uword buffer_bytes);
222 u32 sockclnt_open_index (char *client_name, char *hostname, int port);
223 void sockclnt_close_index (u32 index);
227  i8 * input_v);
228 
229 int
230 vl_socket_client_connect (socket_client_main_t * scm, char *socket_path,
231  char *client_name, u32 socket_buffer_size);
234 
235 #endif /* included_vlibmemory_api_common_h */
236 
237 /*
238  * fd.io coding-style-patch-verification: ON
239  *
240  * Local Variables:
241  * eval: (c-set-style "gnu")
242  * End:
243  */
volatile int ** vl_api_queue_cursizes
Definition: memory_vlib.c:1183
vl_api_registration_t * regp
Definition: api_common.h:151
void * vl_msg_api_alloc_as_if_client(int nbytes)
void vl_set_api_memory_size(u64 size)
vl_api_registration_t * registration_pool
Definition: api_common.h:167
a
Definition: bitmap.h:516
struct ring_alloc_ ring_alloc_t
void vl_client_disconnect(void)
void vl_socket_client_read_reply(socket_client_main_t *scm)
Definition: socket_client.c:75
void vl_set_memory_gid(int gid)
u32 application_restarts
Definition: api_common.h:79
void vl_init_shmem(svm_region_t *vlib_rp, int is_vlib, int is_private_region)
void vl_socket_process_msg(struct clib_file *uf, struct vl_api_registration_ *rp, i8 *input_v)
unix_shared_memory_queue_t * vl_input_queue
Definition: api_common.h:68
vl_socket_args_for_process_t * process_args
Definition: api_common.h:179
clib_file_t * current_uf
Definition: api_common.h:174
struct _vlib_node_registration vlib_node_registration_t
ring_alloc_t * client_rings
Definition: api_common.h:76
void vl_set_memory_uid(int uid)
i8 * input_buffer
Definition: api_common.h:176
int vl_client_connect(const char *name, int ctx_quota, int input_queue_size)
void vl_api_socket_process_msg(clib_file_t *uf, vl_api_registration_t *rp, i8 *input_v)
Definition: socksvr_vlib.c:143
void vl_client_api_unmap(void)
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
char i8
Definition: types.h:45
unsigned long u64
Definition: types.h:89
u8 * socket_name
Definition: api_common.h:158
void * vl_msg_api_alloc(int nbytes)
volatile int vl_pid
Definition: api_common.h:65
void vl_free_socket_registration_index(u32 pool_index)
Definition: socksvr_vlib.c:119
void vl_msg_api_free(void *)
vlib_node_registration_t memclnt_node
(constructor) VLIB_REGISTER_NODE (memclnt_node)
Definition: memory_vlib.c:1102
void vl_client_install_client_message_handlers(void)
void vl_api_send_pending_rpc_requests(vlib_main_t *vm)
Definition: main.c:1428
void vl_socket_api_send(vl_api_registration_t *rp, u8 *elem)
Definition: socksvr_vlib.c:79
void vl_set_global_memory_baseva(u64 baseva)
void vl_client_msg_api_send(vl_api_registration_t *cm, u8 *elem)
clib_error_t * vl_socket_write_ready(struct clib_file *uf)
Definition: socksvr_vlib.c:310
socket_main_t socket_main
Definition: memory_shared.c:42
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
ring_alloc_t * vl_rings
Definition: api_common.h:73
vlib_main_t * vm
Definition: buffer.c:283
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
void vl_unmap_shmem(void)
clib_socket_t client_socket
Definition: api_common.h:193
clib_socket_t socksvr_listen_socket
Definition: api_common.h:182
u32 sockclnt_open_index(char *client_name, char *hostname, int port)
Definition: sockclnt_vlib.c:72
socket_client_main_t socket_client_main
Definition: socket_client.c:64
void vl_set_global_pvt_heap_size(u64 size)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
void vl_set_memory_region_name(const char *name)
Definition: memory_vlib.c:1717
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1916
u32 garbage_collects
Definition: api_common.h:85
u32 vl_api_memclnt_create_internal(char *, unix_shared_memory_queue_t *)
Definition: memory_vlib.c:142
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
unsigned int u32
Definition: types.h:88
int vl_socket_client_connect(socket_client_main_t *scm, char *socket_path, char *client_name, u32 socket_buffer_size)
struct _socket_t clib_socket_t
void vl_register_mapped_shmem_region(svm_region_t *rp)
int vl_client_connect_to_vlib_no_map(const char *svm_name, const char *client_name, int rx_queue_size)
vl_api_registration_t * current_rp
Definition: api_common.h:173
u32 restart_reclaims
Definition: api_common.h:82
void vl_set_api_pvt_heap_size(u64 size)
void vl_socket_add_pending_output(struct clib_file *uf, struct vl_api_registration_ *rp, u8 *buffer, uword buffer_bytes)
Definition: socksvr_vlib.c:269
u64 uword
Definition: types.h:112
clib_error_t * vl_socket_read_ready(struct clib_file *uf)
Definition: socksvr_vlib.c:157
unsigned short u16
Definition: types.h:57
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
unsigned char u8
Definition: types.h:56
void vl_socket_client_enable_disable(socket_client_main_t *scm, int enable)
void vl_client_disconnect_from_vlib(void)
void vl_socket_add_pending_output_no_flush(struct clib_file *uf, struct vl_api_registration_ *rp, u8 *buffer, uword buffer_bytes)
Definition: socksvr_vlib.c:286
unix_shared_memory_queue_t * rp
Definition: api_common.h:39
vl_api_registration_t * sockclnt_get_registration(u32 index)
vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
int vl_client_api_map(const char *region_name)
struct vl_shmem_hdr_ vl_shmem_hdr_t
Definition: file.h:50
void vl_set_global_memory_size(u64 size)
void vl_set_memory_root_path(const char *root_path)
int vl_client_connect_to_vlib_no_rx_pthread(const char *svm_name, const char *client_name, int rx_queue_size)
int vl_map_shmem(const char *region_name, int is_vlib)
void socksvr_add_pending_output(struct clib_file *uf, struct vl_api_registration_ *cf, u8 *buffer, uword buffer_bytes)
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
Definition: memory_vlib.c:102
void * vl_msg_api_alloc_or_null(int nbytes)
u16 vl_client_get_first_plugin_msg_id(const char *plugin_name)
void sockclnt_close_index(u32 index)
struct _unix_shared_memory_queue unix_shared_memory_queue_t