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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __included_vpp_echo_common_h__
17 #define __included_vpp_echo_common_h__
19 #include <vnet/session/application_interface.h>
20 #include <vpp/api/vpe_msg_enum.h>
22 #define vl_typedefs /* define message structures */
23 #include <vpp/api/vpe_all_api_h.h>
26 /* declare message handlers for each api */
28 #define vl_endianfun /* define message structures */
29 #include <vpp/api/vpe_all_api_h.h>
32 /* instantiate all the print functions we know about */
33 #define vl_print(handle, ...)
35 #include <vpp/api/vpe_all_api_h.h>
40 #define CHECK(expected, result, _fmt, _args...) \
41 if (expected != result) \
42 ECHO_FAIL ("expected %d, got %d : " _fmt, expected, result, ##_args);
44 #define ECHO_FAIL(_fmt,_args...) \
46 echo_main_t *em = &echo_main; \
48 em->time_to_stop = 1; \
49 if (em->log_lvl > 0) \
50 clib_warning ("ECHO-ERROR: "_fmt, ##_args); \
53 #define ECHO_LOG(lvl, _fmt,_args...) \
55 echo_main_t *em = &echo_main; \
56 if (em->log_lvl > lvl) \
57 clib_warning (_fmt, ##_args); \
60 #define ECHO_REGISTER_PROTO(proto, vft) \
61 static void __clib_constructor \
62 vpp_echo_init_##proto () \
64 echo_main_t *em = &echo_main; \
65 em->available_proto_cb_vft[proto] = &vft; \
70 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
71 #define _(type, name) type name;
72 foreach_app_session_field
74 u64 vpp_session_handle;
77 volatile u64 bytes_received;
78 volatile u64 bytes_to_receive;
80 u32 listener_index; /* listener index in echo session pool */
81 u32 idle_cycles; /* consecutive enq/deq with no data */
82 volatile u64 accepted_session_count; /* sessions we accepted (as a listener) */
88 ECHO_TEST_DATA_SOURCE,
90 ECHO_INVALID_DATA_SOURCE
95 ECHO_CLOSE_F_INVALID = 0,
96 ECHO_CLOSE_F_PASSIVE, /* wait for close msg */
97 ECHO_CLOSE_F_ACTIVE, /* send close msg */
98 ECHO_CLOSE_F_NONE, /* don't bother sending close msg */
101 enum quic_session_type_t
103 ECHO_SESSION_TYPE_QUIC,
104 ECHO_SESSION_TYPE_STREAM,
105 ECHO_SESSION_TYPE_LISTEN,
108 enum quic_session_state_t
110 ECHO_SESSION_STATE_INITIAL,
111 ECHO_SESSION_STATE_READY,
112 ECHO_SESSION_STATE_AWAIT_CLOSING, /* Data transfer is done, wait for close evt */
113 ECHO_SESSION_STATE_AWAIT_DATA, /* Peer closed, wait for outstanding data */
114 ECHO_SESSION_STATE_CLOSING, /* told vpp to close */
115 ECHO_SESSION_STATE_CLOSED, /* closed in vpp */
127 } connection_state_t;
129 typedef enum echo_test_evt_
131 ECHO_EVT_START = 1, /* app starts */
132 ECHO_EVT_FIRST_QCONNECT = (1 << 1), /* First connect Quic session sent */
133 ECHO_EVT_LAST_QCONNECTED = (1 << 2), /* All Quic session are connected */
134 ECHO_EVT_FIRST_SCONNECT = (1 << 3), /* First connect Stream session sent */
135 ECHO_EVT_LAST_SCONNECTED = (1 << 4), /* All Stream session are connected */
136 ECHO_EVT_LAST_BYTE = (1 << 5), /* Last byte received */
137 ECHO_EVT_EXIT = (1 << 6), /* app exits */
140 typedef union session_connected_bundled_msg_
142 session_connected_msg_t *mp;
143 vl_api_connect_uri_reply_t *bmp;
144 } session_connected_bundled_msg_t;
146 typedef struct echo_proto_cb_vft_
148 void (*connected_cb) (session_connected_bundled_msg_t * mp, u32 session_index, u8 is_failed); /* Session is connected */
149 void (*accepted_cb) (session_accepted_msg_t * mp, echo_session_t * session); /* Session got accepted */
150 void (*bound_uri_cb) (session_bound_msg_t * mp, echo_session_t * session); /* Session got bound */
151 void (*reset_cb) (session_reset_msg_t * mp, echo_session_t * s); /* Received RESET on session */
152 void (*disconnected_cb) (session_disconnected_msg_t * mp, echo_session_t * s); /* Received DISCONNECT on session */
153 void (*disconnected_reply_cb) (echo_session_t * s); /* ACK disconnect we sent to vpp */
154 void (*cleanup_cb) (echo_session_t * s, u8 parent_died); /* Session should be cleaned up (parent listener may be dead) */
155 /* Add CLI options */
156 int (*process_opts_cb) (unformat_input_t * a);
157 void (*set_defaults_before_opts_cb) (void);
158 void (*set_defaults_after_opts_cb) (void);
159 void (*print_usage_cb) (void);
160 } echo_proto_cb_vft_t;
164 RETURN_PACKETS_NOTEST,
165 RETURN_PACKETS_LOG_WRONG,
166 RETURN_PACKETS_ASSERT,
167 } test_return_packets_t;
169 typedef struct teardown_stat_
171 u32 q; /* quic sessions */
172 u32 s; /* stream sessions */
177 svm_queue_t *vl_input_queue; /* vpe input queue */
178 u32 my_client_index; /* API client handle */
179 u8 *uri; /* The URI we're playing with */
180 echo_session_t *sessions; /* Session pool */
181 svm_msg_q_t *our_event_queue; /* Our event queue */
182 clib_time_t clib_time; /* For deadman timers */
185 u32 listen_session_index; /* Index of vpp listener session */
187 uword *session_index_by_vpp_handles; /* Hash table : quic_echo s_id -> vpp s_handle */
188 clib_spinlock_t sid_vpp_handles_lock; /* Hash table lock */
190 uword *shared_segment_handles; /* Hash table : segment_names -> 1 */
191 clib_spinlock_t segment_handles_lock; /* Hash table lock */
192 echo_proto_cb_vft_t *proto_cb_vft;
193 svm_msg_q_t *rpc_msq_queue; /* MQ between quic_echo threads */
194 fifo_segment_main_t segment_main;
196 /* State of the connection, shared between msg RX thread and main thread */
197 volatile connection_state_t state;
198 volatile u8 time_to_stop; /* Signal variables */
199 u8 has_failed; /* stores the exit code */
201 /** Flag that decides if socket, instead of svm, api is used to connect to
202 * vpp. If sock api is used, shm binary api is subsequently bootstrapped
203 * and all other messages are exchanged using shm IPC. */
206 u8 *connect_test_data;
207 u8 test_return_packets;
208 u64 bytes_to_send; /* target per stream */
209 u64 bytes_to_receive; /* target per stream */
213 data_source_t data_source; /* Use no/dummy/mirrored data */
214 u8 send_stream_disconnects; /* actively send disconnect */
215 u8 output_json; /* Output stats as JSON */
216 u8 log_lvl; /* Verbosity of the logging */
217 int max_test_msg; /* Limit the number of incorrect data messages */
223 pthread_t *data_thread_handles; /* vec of data thread handles */
224 pthread_t mq_thread_handle; /* Message queue thread handle */
225 u32 *volatile data_thread_args;
227 u32 n_connects; /* Target number of connects to send */
228 u32 n_sessions; /* Number of sessions to prealloc */
229 u32 n_clients; /* Target number of clients doing RX/TX */
230 u32 n_rx_threads; /* Number of data threads */
232 volatile u32 n_clients_connected; /* Number of STREAM sessions connected */
233 volatile u32 nxt_available_sidx; /* next unused prealloced session_index */
235 /* VNET_API_ERROR_FOO -> "Foo" hash table */
236 uword *error_string_by_error_number;
237 echo_proto_cb_vft_t *available_proto_cb_vft[TRANSPORT_N_PROTO];
243 teardown_stat_t reset_count; /* received reset from vpp */
244 teardown_stat_t close_count; /* received close from vpp */
245 teardown_stat_t active_count; /* sent close to vpp */
246 teardown_stat_t clean_count; /* cleaned up stale session */
249 struct /* Event based timing : start & end depend on CLI specified events */
267 extern echo_main_t echo_main;
269 typedef void (*echo_rpc_t) (void *arg, u32 opaque);
278 u8 *format_ip4_address (u8 * s, va_list * args);
279 u8 *format_ip6_address (u8 * s, va_list * args);
280 u8 *format_ip46_address (u8 * s, va_list * args);
281 uword unformat_data (unformat_input_t * input, va_list * args);
282 u8 *format_api_error (u8 * s, va_list * args);
283 void init_error_string_table ();
284 u8 *echo_format_app_state (u8 * s, va_list * args);
285 uword echo_unformat_close (unformat_input_t * input, va_list * args);
286 uword echo_unformat_timing_event (unformat_input_t * input, va_list * args);
287 u8 *echo_format_timing_event (u8 * s, va_list * args);
288 uword unformat_transport_proto (unformat_input_t * input, va_list * args);
289 u8 *format_transport_proto (u8 * s, va_list * args);
290 uword unformat_ip4_address (unformat_input_t * input, va_list * args);
291 uword unformat_ip6_address (unformat_input_t * input, va_list * args);
293 void echo_session_handle_add_del (echo_main_t * em, u64 handle, u32 sid);
294 echo_session_t *echo_session_new (echo_main_t * em);
295 int echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque);
296 echo_session_t *echo_get_session_from_handle (echo_main_t * em, u64 handle);
297 int wait_for_segment_allocation (u64 segment_handle);
298 int wait_for_state_change (echo_main_t * em, connection_state_t state,
300 void echo_notify_event (echo_main_t * em, echo_test_evt_t e);
301 void echo_session_print_stats (echo_main_t * em, echo_session_t * session);
305 void echo_send_attach (echo_main_t * em);
306 void echo_send_detach (echo_main_t * em);
307 void echo_send_listen (echo_main_t * em);
308 void echo_send_unbind (echo_main_t * em);
309 void echo_send_connect (u8 * uri, u32 opaque);
310 void echo_send_disconnect_session (u64 handle, u32 opaque);
311 void echo_api_hookup (echo_main_t * em);
313 #endif /* __included_vpp_echo_common_h__ */
316 * fd.io coding-style-patch-verification: ON
319 * eval: (c-set-style "gnu")