FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
api.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 <vlibapi/api.h>
23 #include <vlibmemory/memory_api.h>
25 #include <vlibmemory/socket_api.h>
27 
28 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
29 void vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
30 u16 vl_client_get_first_plugin_msg_id (const char *plugin_name);
33 
34 always_inline void
36 {
38  {
39  vl_socket_api_send (rp, elem);
40  }
41  else
42  {
43  vl_msg_api_send_shmem (rp->vl_input_queue, (u8 *) & elem);
44  }
45 }
46 
47 always_inline int
49 {
51  return 1;
52  else
54 }
55 
56 /*
57  * Suggests to an API handler to relinguish control. Currently limits
58  * an handler to a maximum of 1ms or it earlier if the client queue is
59  * full.
60  *
61  * May be enhanced in the future based on other performance
62  * characteristics of the main thread.
63  */
64 #define VL_API_MAX_TIME_IN_HANDLER 0.001 /* 1 ms */
65 always_inline int
67  f64 start)
68 {
69  /* Is client queue full (leave space for reply message) */
71  rp->vl_input_queue->cursize + 1 >= rp->vl_input_queue->maxsize)
72  return true;
74  return true;
75  return false;
76 }
77 
80 {
84 }
85 
88 {
89  return reg->clib_file_index;
90 }
91 
94 {
96 }
97 
98 always_inline void
100 {
102  if (cf)
103  clib_file_del (&file_main, cf);
104 }
105 
107 vl_api_send_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds)
108 {
110  if (cf)
111  return vl_sock_api_send_fd_msg (cf->file_descriptor, fds, n_fds);
112  return 0;
113 }
114 
116 vl_api_recv_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds,
117  u32 wait)
118 {
120  if (cf)
121  return vl_sock_api_recv_fd_msg (cf->file_descriptor, fds, n_fds, wait);
122  return 0;
123 }
124 
125 /*
126  * vl_api_clnt process data used by transports (socket api in particular)
127  */
129 extern volatile int **vl_api_queue_cursizes;
130 
132 {
136 
137 #define foreach_histogram_bucket \
138 _(400) \
139 _(200) \
140 _(100) \
141 _(10)
142 
143 typedef enum
144 {
145 #define _(n) SLEEP_##n##_US,
147 #undef _
150 
151 extern u64 vector_rate_histogram[];
152 
153 /*
154  * sockclnt APIs XXX are these actually used anywhere?
155  */
157 void socksvr_add_pending_output (struct clib_file *uf,
158  struct vl_api_registration_ *cf,
159  u8 * buffer, uword buffer_bytes);
160 void vl_socket_process_msg (struct clib_file *uf,
161  struct vl_api_registration_ *rp, i8 * input_v);
162 u32 sockclnt_open_index (char *client_name, char *hostname, int port);
165 
166 #endif /* included_vlibmemory_api_common_h */
167 
168 /*
169  * fd.io coding-style-patch-verification: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "gnu")
173  * End:
174  */
memory_client.h
clib_file::file_descriptor
u32 file_descriptor
Definition: file.h:54
vl_client_msg_api_send
void vl_client_msg_api_send(vl_api_registration_t *cm, u8 *elem)
vl_api_queue_cursizes
volatile int ** vl_api_queue_cursizes
Definition: memory_api.c:61
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
file_main
clib_file_main_t file_main
Definition: main.c:63
vl_api_registration_file_index
static u32 vl_api_registration_file_index(vl_api_registration_t *reg)
Definition: api.h:87
socket_api.h
buffer
char * buffer
Definition: cJSON.h:163
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
foreach_histogram_bucket
#define foreach_histogram_bucket
Definition: api.h:137
vl_api_registration_::registration_type
vl_registration_type_t registration_type
type
Definition: api_common.h:49
u16
unsigned short u16
Definition: types.h:57
vl_api_process_may_suspend
static int vl_api_process_may_suspend(vlib_main_t *vm, vl_api_registration_t *rp, f64 start)
Definition: api.h:66
am
app_main_t * am
Definition: application.c:489
sockclnt_get_registration
vl_api_registration_t * sockclnt_get_registration(u32 index)
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_registration_::vl_input_queue
svm_queue_t * vl_input_queue
shared memory only: pointer to client input queue
Definition: api_common.h:63
vl_socket_api_client_handle_to_registration
vl_api_registration_t * vl_socket_api_client_handle_to_registration(u32 handle)
Definition: socket_api.c:99
port
u16 port
Definition: lb_types.api:73
vl_api_send_pending_rpc_requests
void vl_api_send_pending_rpc_requests(vlib_main_t *vm)
Definition: main.c:1506
svm_common.h
vl_api_recv_fd_msg
static clib_error_t * vl_api_recv_fd_msg(vl_api_registration_t *reg, int fds[], int n_fds, u32 wait)
Definition: api.h:116
histogram_index_t
histogram_index_t
Definition: api.h:143
hostname
string hostname[64]
Definition: dhcp.api:159
socksvr_add_pending_output
void socksvr_add_pending_output(struct clib_file *uf, struct vl_api_registration_ *cf, u8 *buffer, uword buffer_bytes)
vl_api_serialize_message_table
u8 * vl_api_serialize_message_table(api_main_t *am, u8 *vector)
Definition: api_shared.c:204
vl_socket_api_send
void vl_socket_api_send(vl_api_registration_t *rp, u8 *elem)
Definition: socket_api.c:114
clib_file
Definition: file.h:51
vl_api_force_rpc_call_main_thread
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:631
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
uword
u64 uword
Definition: types.h:112
vl_api_registration_::clib_file_index
u32 clib_file_index
Socket only: file index.
Definition: api_common.h:68
socket_client.h
f64
double f64
Definition: types.h:142
SOCKET_READ_EVENT
@ SOCKET_READ_EVENT
Definition: api.h:134
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
memory_api.h
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
clib_file_get
static clib_file_t * clib_file_get(clib_file_main_t *fm, u32 file_index)
Definition: file.h:152
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
data
u8 data[128]
Definition: ipsec_types.api:92
vl_client_get_first_plugin_msg_id
u16 vl_client_get_first_plugin_msg_id(const char *plugin_name)
Definition: memory_client.c:552
vl_sock_api_send_fd_msg
clib_error_t * vl_sock_api_send_fd_msg(int socket_fd, int fds[], int n_fds)
Definition: socket_api.c:559
vl_api_clnt_process_events_t
enum vl_api_clnt_process_events vl_api_clnt_process_events_t
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
vl_api_send_fd_msg
static clib_error_t * vl_api_send_fd_msg(vl_api_registration_t *reg, int fds[], int n_fds)
Definition: api.h:107
u64
unsigned long u64
Definition: types.h:89
vl_api_registration_file
static clib_file_t * vl_api_registration_file(vl_api_registration_t *reg)
Definition: api.h:93
i8
signed char i8
Definition: types.h:45
vl_api_can_send_msg
static int vl_api_can_send_msg(vl_api_registration_t *rp)
Definition: api.h:48
QUEUE_SIGNAL_EVENT
@ QUEUE_SIGNAL_EVENT
Definition: api.h:133
clib_file_del
static void clib_file_del(clib_file_main_t *um, clib_file_t *f)
Definition: file.h:109
u32
unsigned int u32
Definition: types.h:88
vector_rate_histogram
u64 vector_rate_histogram[]
Definition: vlib_api.c:179
vl_api_rpc_call_main_thread
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:620
vlib_main_t
Definition: main.h:102
vl_socket_process_msg
void vl_socket_process_msg(struct clib_file *uf, struct vl_api_registration_ *rp, i8 *input_v)
SLEEP_N_BUCKETS
@ SLEEP_N_BUCKETS
Definition: api.h:148
vl_socket_api_registration_handle_is_valid
u8 vl_socket_api_registration_handle_is_valid(u32 reg_handle)
Definition: socket_api.c:66
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_msg_api_send_shmem
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
Definition: memory_shared.c:753
vl_api_registration_del_file
static void vl_api_registration_del_file(vl_api_registration_t *reg)
Definition: api.h:99
vl_sock_api_recv_fd_msg
clib_error_t * vl_sock_api_recv_fd_msg(int socket_fd, int fds[], int n_fds, u32 wait)
Definition: socket_client.c:332
sockclnt_close_index
void sockclnt_close_index(u32 index)
vl_mem_api_can_send
int vl_mem_api_can_send(svm_queue_t *q)
Definition: memory_shared.c:794
REGISTRATION_TYPE_SHMEM
@ REGISTRATION_TYPE_SHMEM
Shared memory connection.
Definition: api_common.h:39
vl_api_clnt_process_events
vl_api_clnt_process_events
Definition: api.h:131
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:325
sockclnt_open_index
u32 sockclnt_open_index(char *client_name, char *hostname, int port)
vl_mem_api_client_index_to_registration
vl_api_registration_t * vl_mem_api_client_index_to_registration(u32 handle)
Definition: memory_api.c:765
vl_api_clnt_node
vlib_node_registration_t vl_api_clnt_node
(constructor) VLIB_REGISTER_NODE (vl_api_clnt_node)
Definition: vlib_api.c:434
VL_API_MAX_TIME_IN_HANDLER
#define VL_API_MAX_TIME_IN_HANDLER
Definition: api.h:64