FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
vpp_echo_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __included_vpp_echo_common_h__
17 #define __included_vpp_echo_common_h__
18 
20 #include <vpp/api/vpe_msg_enum.h>
21 
22 #define vl_typedefs /* define message structures */
23 #include <vpp/api/vpe_all_api_h.h>
24 #undef vl_typedefs
25 
26 /* declare message handlers for each api */
27 
28 #define vl_endianfun /* define message structures */
29 #include <vpp/api/vpe_all_api_h.h>
30 #undef vl_endianfun
31 
32 /* instantiate all the print functions we know about */
33 #define vl_print(handle, ...)
34 #define vl_printfun
35 #include <vpp/api/vpe_all_api_h.h>
36 #undef vl_printfun
37 
38 #define TIMEOUT 10.0
39 
40 #define foreach_echo_fail_code \
41  _(ECHO_FAIL_NONE, "ECHO_FAIL_NONE") \
42  _(ECHO_FAIL_SEND_IO_EVT, "ECHO_FAIL_SEND_IO_EVT") \
43  _(ECHO_FAIL_SOCKET_CONNECT, "ECHO_FAIL_SOCKET_CONNECT") \
44  _(ECHO_FAIL_INIT_SHM_API, "ECHO_FAIL_INIT_SHM_API") \
45  _(ECHO_FAIL_SHMEM_CONNECT, "ECHO_FAIL_SHMEM_CONNECT") \
46  _(ECHO_FAIL_TEST_BYTES_ERR, "ECHO_FAIL_TEST_BYTES_ERR") \
47  _(ECHO_FAIL_BIND, "ECHO_FAIL_BIND") \
48  _(ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC, \
49  "ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC") \
50  _(ECHO_FAIL_SESSION_CONNECT, "ECHO_FAIL_SESSION_CONNECT") \
51  _(ECHO_FAIL_CONNECTED_WAIT_FOR_SEG_ALLOC, \
52  "ECHO_FAIL_CONNECTED_WAIT_FOR_SEG_ALLOC") \
53  _(ECHO_FAIL_APP_ATTACH, "ECHO_FAIL_APP_ATTACH") \
54  _(ECHO_FAIL_SERVER_DISCONNECT_TIMEOUT, \
55  "ECHO_FAIL_SERVER_DISCONNECT_TIMEOUT") \
56  _(ECHO_FAIL_INVALID_URI, "ECHO_FAIL_INVALID_URI") \
57  _(ECHO_FAIL_PROTOCOL_NOT_SUPPORTED, \
58  "ECHO_FAIL_PROTOCOL_NOT_SUPPORTED") \
59  _(ECHO_FAIL_CONNECT_TO_VPP, "ECHO_FAIL_CONNECT_TO_VPP") \
60  _(ECHO_FAIL_ATTACH_TO_VPP, "ECHO_FAIL_ATTACH_TO_VPP") \
61  _(ECHO_FAIL_1ST_PTHREAD_CREATE, "ECHO_FAIL_1ST_PTHREAD_CREATE") \
62  _(ECHO_FAIL_PTHREAD_CREATE, "ECHO_FAIL_PTHREAD_CREATE") \
63  _(ECHO_FAIL_DETACH, "ECHO_FAIL_DETACH") \
64  _(ECHO_FAIL_MQ_PTHREAD, "ECHO_FAIL_MQ_PTHREAD") \
65  _(ECHO_FAIL_VL_API_APP_ATTACH, "ECHO_FAIL_VL_API_APP_ATTACH") \
66  _(ECHO_FAIL_VL_API_MISSING_SEGMENT_NAME, \
67  "ECHO_FAIL_VL_API_MISSING_SEGMENT_NAME") \
68  _(ECHO_FAIL_VL_API_RECV_FD_MSG, "ECHO_FAIL_VL_API_RECV_FD_MSG") \
69  _(ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH, \
70  "ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH") \
71  _(ECHO_FAIL_VL_API_FIFO_SEG_ATTACH, \
72  "ECHO_FAIL_VL_API_FIFO_SEG_ATTACH") \
73  _(ECHO_FAIL_VL_API_DETACH_REPLY, "ECHO_FAIL_VL_API_DETACH_REPLY") \
74  _(ECHO_FAIL_VL_API_BIND_URI_REPLY, "ECHO_FAIL_VL_API_BIND_URI_REPLY") \
75  _(ECHO_FAIL_VL_API_UNBIND_REPLY, "ECHO_FAIL_VL_API_UNBIND_REPLY") \
76  _(ECHO_FAIL_VL_API_DISCONNECT_SESSION_REPLY, \
77  "ECHO_FAIL_VL_API_DISCONNECT_SESSION_REPLY") \
78  _(ECHO_FAIL_VL_API_TLS_CERT_ADD_REPLY, \
79  "ECHO_FAIL_VL_API_TLS_CERT_ADD_REPLY") \
80  _(ECHO_FAIL_VL_API_TLS_KEY_ADD_REPLY, \
81  "ECHO_FAIL_VL_API_TLS_KEY_ADD_REPLY") \
82  _(ECHO_FAIL_GET_SESSION_FROM_HANDLE, \
83  "ECHO_FAIL_GET_SESSION_FROM_HANDLE") \
84  _(ECHO_FAIL_QUIC_WRONG_CONNECT, "ECHO_FAIL_QUIC_WRONG_CONNECT") \
85  _(ECHO_FAIL_QUIC_WRONG_ACCEPT, "ECHO_FAIL_QUIC_WRONG_ACCEPT") \
86  _(ECHO_FAIL_TCP_BAPI_CONNECT, "ECHO_FAIL_TCP_BAPI_CONNECT") \
87  _(ECHO_FAIL_UDP_BAPI_CONNECT, "ECHO_FAIL_UDP_BAPI_CONNECT") \
88  _(ECHO_FAIL_MISSING_START_EVENT, "ECHO_FAIL_MISSING_START_EVENT") \
89  _(ECHO_FAIL_MISSING_END_EVENT, "ECHO_FAIL_MISSING_END_EVENT") \
90  _(ECHO_FAIL_TEST_ASSERT_RX_TOTAL, "ECHO_FAIL_TEST_ASSERT_RX_TOTAL") \
91  _(ECHO_FAIL_TEST_ASSERT_TX_TOTAL, "ECHO_FAIL_TEST_ASSERT_TX_TOTAL") \
92  _(ECHO_FAIL_TEST_ASSERT_ALL_SESSIONS_CLOSED, \
93  "ECHO_FAIL_TEST_ASSERT_ALL_SESSIONS_CLOSED")
94 
95 typedef enum
96 {
97 #define _(sym, str) sym,
99 #undef _
100 } echo_fail_t;
101 
102 extern char *echo_fail_code_str[];
103 
104 #define CHECK(fail, expected, result, _fmt, _args...) \
105  if (expected != result) \
106  ECHO_FAIL (fail, "expected %d, got %d : " _fmt, expected, \
107  result, ##_args); \
108 
109 #define ECHO_FAIL(fail, _fmt, _args...) \
110  { \
111  echo_main_t *em = &echo_main; \
112  em->has_failed = fail; \
113  if (vec_len(em->fail_descr)) \
114  em->fail_descr = format(em->fail_descr, " | %s (%d): "_fmt, \
115  echo_fail_code_str[fail], fail, ##_args); \
116  else \
117  em->fail_descr = format(0, "%s (%d): "_fmt, \
118  echo_fail_code_str[fail], fail, ##_args); \
119  em->time_to_stop = 1; \
120  if (em->log_lvl > 0) \
121  clib_warning ("%v", em->fail_descr); \
122  }
123 
124 #define ECHO_LOG(lvl, _fmt,_args...) \
125  { \
126  echo_main_t *em = &echo_main; \
127  if (em->log_lvl > lvl) \
128  clib_warning (_fmt, ##_args); \
129  }
130 
131 #define ECHO_REGISTER_PROTO(proto, vft) \
132  static void __clib_constructor \
133  vpp_echo_init_##proto () \
134  { \
135  echo_main_t *em = &echo_main; \
136  em->available_proto_cb_vft[proto] = &vft; \
137  }
138 
139 typedef struct
140 {
141  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
142 #define _(type, name) type name;
144 #undef _
148  volatile u64 bytes_received;
151  u32 listener_index; /* listener index in echo session pool */
152  u32 idle_cycles; /* consecutive enq/deq with no data */
153  volatile u64 accepted_session_count; /* sessions we accepted (as a listener) */
155 
156 typedef enum
157 {
162 } data_source_t;
163 
165 {
167  ECHO_CLOSE_F_PASSIVE, /* wait for close msg */
168  ECHO_CLOSE_F_ACTIVE, /* send close msg */
169  ECHO_CLOSE_F_NONE, /* don't bother sending close msg */
170 };
171 
173 {
177 };
178 
180 {
183  ECHO_SESSION_STATE_AWAIT_CLOSING, /* Data transfer is done, wait for close evt */
184  ECHO_SESSION_STATE_AWAIT_DATA, /* Peer closed, wait for outstanding data */
185  ECHO_SESSION_STATE_CLOSING, /* told vpp to close */
186  ECHO_SESSION_STATE_CLOSED, /* closed in vpp */
187 };
188 
189 typedef enum
190 {
199 
200 typedef enum echo_test_evt_
201 {
202  ECHO_EVT_START = 1, /* app starts */
203  ECHO_EVT_FIRST_QCONNECT = (1 << 1), /* First connect Quic session sent */
204  ECHO_EVT_LAST_QCONNECTED = (1 << 2), /* All Quic session are connected */
205  ECHO_EVT_FIRST_SCONNECT = (1 << 3), /* First connect Stream session sent */
206  ECHO_EVT_LAST_SCONNECTED = (1 << 4), /* All Stream session are connected */
207  ECHO_EVT_LAST_BYTE = (1 << 5), /* Last byte received */
208  ECHO_EVT_EXIT = (1 << 6), /* app exits */
210 
212 {
214  vl_api_connect_uri_reply_t *bmp;
216 
217 typedef struct echo_proto_cb_vft_
218 {
219  void (*connected_cb) (session_connected_bundled_msg_t * mp, u32 session_index, u8 is_failed); /* Session is connected */
220  void (*accepted_cb) (session_accepted_msg_t * mp, echo_session_t * session); /* Session got accepted */
221  void (*bound_uri_cb) (session_bound_msg_t * mp, echo_session_t * session); /* Session got bound */
222  void (*reset_cb) (session_reset_msg_t * mp, echo_session_t * s); /* Received RESET on session */
223  void (*disconnected_cb) (session_disconnected_msg_t * mp, echo_session_t * s); /* Received DISCONNECT on session */
224  void (*disconnected_reply_cb) (echo_session_t * s); /* ACK disconnect we sent to vpp */
225  void (*cleanup_cb) (echo_session_t * s, u8 parent_died); /* Session should be cleaned up (parent listener may be dead) */
226  /* Add CLI options */
227  int (*process_opts_cb) (unformat_input_t * a);
228  void (*set_defaults_before_opts_cb) (void);
229  void (*set_defaults_after_opts_cb) (void);
230  void (*print_usage_cb) (void);
232 
233 typedef enum
234 {
239 
240 typedef struct teardown_stat_
241 {
242  u32 q; /* quic sessions */
243  u32 s; /* stream sessions */
245 
246 typedef struct
247 {
248  svm_queue_t *vl_input_queue; /* vpe input queue */
249  u32 my_client_index; /* API client handle */
250  u8 *uri; /* The URI we're playing with */
251  echo_session_t *sessions; /* Session pool */
252  svm_msg_q_t *our_event_queue; /* Our event queue */
253  clib_time_t clib_time; /* For deadman timers */
256  u32 listen_session_index; /* Index of vpp listener session */
257 
258  uword *session_index_by_vpp_handles; /* Hash table : quic_echo s_id -> vpp s_handle */
259  clib_spinlock_t sid_vpp_handles_lock; /* Hash table lock */
260 
261  uword *shared_segment_handles; /* Hash table : segment_names -> 1 */
262  clib_spinlock_t segment_handles_lock; /* Hash table lock */
264  svm_msg_q_t *rpc_msq_queue; /* MQ between quic_echo threads */
266 
267  /* State of the connection, shared between msg RX thread and main thread */
268  volatile connection_state_t state;
269  volatile u8 time_to_stop; /* Signal variables */
270  u8 has_failed; /* stores the exit code */
271  u8 *fail_descr; /* vector containing fail description */
272 
273  /** Flag that decides if socket, instead of svm, api is used to connect to
274  * vpp. If sock api is used, shm binary api is subsequently bootstrapped
275  * and all other messages are exchanged using shm IPC. */
277 
280  u64 bytes_to_send; /* target per stream */
281  u64 bytes_to_receive; /* target per stream */
286  data_source_t data_source; /* Use no/dummy/mirrored data */
287  u8 send_stream_disconnects; /* actively send disconnect */
288  u8 output_json; /* Output stats as JSON */
289  u8 log_lvl; /* Verbosity of the logging */
290  int max_test_msg; /* Limit the number of incorrect data messages */
291  u32 evt_q_size; /* Size of the vpp MQ (app<->vpp events) */
292 
296 
297  pthread_t *data_thread_handles; /* vec of data thread handles */
298  pthread_t mq_thread_handle; /* Message queue thread handle */
300 
301  u32 n_connects; /* Target number of connects to send */
302  u32 n_sessions; /* Number of sessions to prealloc */
303  u32 n_clients; /* Target number of clients doing RX/TX */
304  u32 n_rx_threads; /* Number of data threads */
305 
306  volatile u32 n_clients_connected; /* Number of STREAM sessions connected */
307  volatile u32 nxt_available_sidx; /* next unused prealloced session_index */
308 
309  /* VNET_API_ERROR_FOO -> "Foo" hash table */
311  echo_proto_cb_vft_t *available_proto_cb_vft[TRANSPORT_N_PROTO];
312 
313  struct
314  {
317  teardown_stat_t reset_count; /* received reset from vpp */
318  teardown_stat_t close_count; /* received close from vpp */
319  teardown_stat_t active_count; /* sent close to vpp */
320  teardown_stat_t clean_count; /* cleaned up stale session */
321  } stats;
322 
323  struct /* Event based timing : start & end depend on CLI specified events */
324  {
330  } timing;
331 
332  struct
333  {
335  ip46_address_t ip;
338  } uri_elts;
339 } echo_main_t;
340 
341 extern echo_main_t echo_main;
342 
343 typedef void (*echo_rpc_t) (void *arg, u32 opaque);
344 
345 typedef struct
346 {
347  void *fp;
348  void *arg;
351 
352 u8 *format_ip4_address (u8 * s, va_list * args);
353 u8 *format_ip6_address (u8 * s, va_list * args);
354 u8 *format_ip46_address (u8 * s, va_list * args);
355 uword unformat_data (unformat_input_t * input, va_list * args);
356 u8 *format_api_error (u8 * s, va_list * args);
358 u8 *echo_format_app_state (u8 * s, va_list * args);
359 uword echo_unformat_close (unformat_input_t * input, va_list * args);
360 uword echo_unformat_timing_event (unformat_input_t * input, va_list * args);
361 u8 *echo_format_timing_event (u8 * s, va_list * args);
362 uword unformat_transport_proto (unformat_input_t * input, va_list * args);
363 u8 *format_transport_proto (u8 * s, va_list * args);
364 uword unformat_ip4_address (unformat_input_t * input, va_list * args);
365 uword unformat_ip6_address (unformat_input_t * input, va_list * args);
366 
367 void echo_session_handle_add_del (echo_main_t * em, u64 handle, u32 sid);
369 int echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque);
371 int wait_for_segment_allocation (u64 segment_handle);
372 int wait_for_state_change (echo_main_t * em, connection_state_t state,
373  f64 timeout);
376 
377 /* Binary API */
378 
379 void echo_send_attach (echo_main_t * em);
380 void echo_send_detach (echo_main_t * em);
381 void echo_send_listen (echo_main_t * em);
382 void echo_send_unbind (echo_main_t * em);
383 void echo_send_connect (u8 * uri, u32 opaque);
384 void echo_send_disconnect_session (u64 handle, u32 opaque);
385 void echo_api_hookup (echo_main_t * em);
386 
387 #endif /* __included_vpp_echo_common_h__ */
388 
389 /*
390  * fd.io coding-style-patch-verification: ON
391  *
392  * Local Variables:
393  * eval: (c-set-style "gnu")
394  * End:
395  */
#define foreach_app_session_field
flag for dgram mode
volatile u64 accepted_session_count
clib_time_t clib_time
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
teardown_stat_t clean_count
u8 * format_ip46_address(u8 *s, va_list *args)
Definition: ip6_format.c:395
uword unformat_data(unformat_input_t *input, va_list *args)
u32 listen_session_index
a
Definition: bitmap.h:538
vl_api_connect_uri_reply_t * bmp
echo_session_t * sessions
clib_spinlock_t sid_vpp_handles_lock
u8 use_sock_api
Flag that decides if socket, instead of svm, api is used to connect to vpp.
svm_queue_t * vl_input_queue
unsigned long u64
Definition: types.h:89
uword unformat_ip6_address(unformat_input_t *input, va_list *args)
Definition: ip6_format.c:138
echo_fail_t
void echo_send_listen(echo_main_t *em)
Definition: vpp_echo_bapi.c:91
echo_session_t * echo_session_new(echo_main_t *em)
quic_session_type_t
u8 * echo_format_timing_event(u8 *s, va_list *args)
int wait_for_state_change(echo_main_t *em, connection_state_t state, f64 timeout)
void echo_send_attach(echo_main_t *em)
Definition: vpp_echo_bapi.c:28
volatile connection_state_t state
void echo_send_detach(echo_main_t *em)
Definition: vpp_echo_bapi.c:78
echo_session_t * echo_get_session_from_handle(echo_main_t *em, u64 handle)
unsigned char u8
Definition: types.h:56
foreach_app_session_field u64 vpp_session_handle
double f64
Definition: types.h:142
u8 * connect_test_data
echo_main_t echo_main
Definition: vpp_echo.c:24
volatile u32 n_clients_connected
connection_state_t
volatile u64 bytes_received
void echo_api_hookup(echo_main_t *em)
void echo_send_connect(u8 *uri, u32 opaque)
#define foreach_echo_fail_code
u8 * format_api_error(u8 *s, va_list *args)
clib_spinlock_t segment_handles_lock
vhost_vring_state_t state
Definition: vhost_user.h:146
unsigned int u32
Definition: types.h:88
struct teardown_stat_ teardown_stat_t
void init_error_string_table()
data_source_t
struct _unformat_input_t unformat_input_t
pthread_t mq_thread_handle
uword echo_unformat_timing_event(unformat_input_t *input, va_list *args)
uword unformat_ip4_address(unformat_input_t *input, va_list *args)
Definition: ip4_format.c:76
uword echo_unformat_close(unformat_input_t *input, va_list *args)
u8 * format_transport_proto(u8 *s, va_list *args)
Definition: transport.c:46
uword * error_string_by_error_number
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
Definition: transport.c:156
fifo_segment_main_t segment_main
data_source_t data_source
u8 * format_ip4_address(u8 *s, va_list *args)
Definition: ip4_format.c:44
enum echo_test_evt_ echo_test_evt_t
svm_msg_q_t * our_event_queue
int echo_send_rpc(echo_main_t *em, void *fp, void *arg, u32 opaque)
u8 * format_ip6_address(u8 *s, va_list *args)
Definition: ip6_format.c:44
uword * shared_segment_handles
u32 *volatile data_thread_args
volatile u8 time_to_stop
void echo_session_handle_add_del(echo_main_t *em, u64 handle, u32 sid)
union session_connected_bundled_msg_ session_connected_bundled_msg_t
teardown_stat_t reset_count
void echo_notify_event(echo_main_t *em, echo_test_evt_t e)
volatile u32 nxt_available_sidx
echo_close_f_t
char * echo_fail_code_str[]
int wait_for_segment_allocation(u64 segment_handle)
struct echo_proto_cb_vft_ echo_proto_cb_vft_t
void echo_send_unbind(echo_main_t *em)
void echo_send_disconnect_session(u64 handle, u32 opaque)
teardown_stat_t close_count
volatile u64 bytes_to_receive
void echo_session_print_stats(echo_main_t *em, echo_session_t *session)
ip46_address_t ip
u64 uword
Definition: types.h:112
teardown_stat_t active_count
uword * session_index_by_vpp_handles
echo_test_evt_
struct _svm_queue svm_queue_t
svm_msg_q_t * rpc_msq_queue
echo_proto_cb_vft_t * proto_cb_vft
pthread_t * data_thread_handles
test_return_packets_t
void(* echo_rpc_t)(void *arg, u32 opaque)
session_connected_msg_t * mp
u8 send_stream_disconnects
u8 * echo_format_app_state(u8 *s, va_list *args)
quic_session_state_t