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.
19 #include <vnet/session/application_interface.h>
21 #define vl_typedefs /* define message structures */
22 #include <vpp/api/vpe_all_api_h.h>
25 /* declare message handlers for each api */
27 #define vl_endianfun /* define message structures */
28 #include <vpp/api/vpe_all_api_h.h>
31 /* instantiate all the print functions we know about */
32 #define vl_print(handle, ...)
34 #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); \
62 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
63 #define _(type, name) type name;
64 foreach_app_session_field
66 u64 vpp_session_handle;
69 volatile u64 bytes_received;
70 volatile u64 bytes_to_receive;
72 u32 listener_index; /* listener index in echo session pool */
73 u32 idle_cycles; /* consecutive enq/deq with no data */
74 volatile u64 accepted_session_count; /* sessions we accepted */
80 ECHO_TEST_DATA_SOURCE,
82 ECHO_INVALID_DATA_SOURCE
87 ECHO_CLOSE_F_INVALID = 0,
88 ECHO_CLOSE_F_PASSIVE, /* wait for close msg */
89 ECHO_CLOSE_F_ACTIVE, /* send close msg */
90 ECHO_CLOSE_F_NONE, /* don't bother sending close msg */
93 enum quic_session_type_t
95 QUIC_SESSION_TYPE_QUIC,
96 QUIC_SESSION_TYPE_STREAM,
97 QUIC_SESSION_TYPE_LISTEN,
100 enum quic_session_state_t
102 QUIC_SESSION_STATE_INITIAL,
103 QUIC_SESSION_STATE_READY,
104 QUIC_SESSION_STATE_AWAIT_CLOSING, /* Data transfer is done, wait for close evt */
105 QUIC_SESSION_STATE_AWAIT_DATA, /* Peer closed, wait for outstanding data */
106 QUIC_SESSION_STATE_CLOSING, /* told vpp to close */
107 QUIC_SESSION_STATE_CLOSED, /* closed in vpp */
119 } connection_state_t;
121 typedef enum echo_test_evt_
123 ECHO_EVT_START = 1, /* app starts */
124 ECHO_EVT_FIRST_QCONNECT = (1 << 1), /* First connect Quic session sent */
125 ECHO_EVT_LAST_QCONNECTED = (1 << 2), /* All Quic session are connected */
126 ECHO_EVT_FIRST_SCONNECT = (1 << 3), /* First connect Stream session sent */
127 ECHO_EVT_LAST_SCONNECTED = (1 << 4), /* All Stream session are connected */
128 ECHO_EVT_LAST_BYTE = (1 << 5), /* Last byte received */
129 ECHO_EVT_EXIT = (1 << 6), /* app exits */
132 typedef struct _quic_echo_cb_vft
134 void (*quic_connected_cb) (session_connected_msg_t * mp, u32 session_index);
135 void (*client_stream_connected_cb) (session_connected_msg_t * mp,
137 void (*server_stream_connected_cb) (session_connected_msg_t * mp,
139 void (*quic_accepted_cb) (session_accepted_msg_t * mp, u32 session_index);
140 void (*client_stream_accepted_cb) (session_accepted_msg_t * mp,
142 void (*server_stream_accepted_cb) (session_accepted_msg_t * mp,
144 } quic_echo_cb_vft_t;
149 RETURN_PACKETS_NOTEST,
150 RETURN_PACKETS_LOG_WRONG,
151 RETURN_PACKETS_ASSERT,
152 } test_return_packets_t;
154 typedef struct teardown_stat_
156 u32 q; /* quic sessions */
157 u32 s; /* stream sessions */
162 svm_queue_t *vl_input_queue; /* vpe input queue */
163 u32 my_client_index; /* API client handle */
164 u8 *uri; /* The URI we're playing with */
165 echo_session_t *sessions; /* Session pool */
166 svm_msg_q_t *our_event_queue; /* Our event queue */
167 clib_time_t clib_time; /* For deadman timers */
170 u32 listen_session_index; /* Index of vpp listener session */
172 uword *session_index_by_vpp_handles; /* Hash table : quic_echo s_id -> vpp s_handle */
173 clib_spinlock_t sid_vpp_handles_lock; /* Hash table lock */
175 uword *shared_segment_handles; /* Hash table : segment_names -> 1*/
176 clib_spinlock_t segment_handles_lock; /* Hash table lock */
177 quic_echo_cb_vft_t cb_vft; /* cb vft for QUIC scenarios */
178 svm_msg_q_t *rpc_msq_queue; /* MQ between quic_echo threads */
179 fifo_segment_main_t segment_main;
181 /* State of the connection, shared between msg RX thread and main thread */
182 volatile connection_state_t state;
183 volatile u8 time_to_stop; /* Signal variables */
184 u8 has_failed; /* stores the exit code */
186 /** Flag that decides if socket, instead of svm, api is used to connect to
187 * vpp. If sock api is used, shm binary api is subsequently bootstrapped
188 * and all other messages are exchanged using shm IPC. */
191 u8 *connect_test_data;
192 u8 test_return_packets;
193 u64 bytes_to_send; /* target per stream */
194 u64 bytes_to_receive; /* target per stream */
198 data_source_t data_source; /* Use no/dummy/mirrored data */
199 u8 send_quic_disconnects; /* actively send disconnect */
200 u8 send_stream_disconnects; /* actively send disconnect */
201 u8 output_json; /* Output stats as JSON */
202 u8 log_lvl; /* Verbosity of the logging */
203 int max_test_msg; /* Limit the number of incorrect data messages */
209 pthread_t *data_thread_handles; /* vec of data thread handles */
210 pthread_t mq_thread_handle; /* Message queue thread handle */
211 u32 *data_thread_args;
213 u32 n_clients; /* Target number of QUIC sessions */
214 u32 n_stream_clients; /* Target Number of STREAM sessions per QUIC session */
215 volatile u32 n_quic_clients_connected; /* Number of connected QUIC sessions */
216 volatile u32 n_clients_connected; /* Number of STREAM sessions connected */
217 u32 n_rx_threads; /* Number of data threads */
218 volatile u32 nxt_available_sidx; /* next unused prealloced session_index */
223 teardown_stat_t reset_count; /* received reset from vpp */
224 teardown_stat_t close_count; /* received close from vpp */
225 teardown_stat_t active_count; /* sent close to vpp */
226 teardown_stat_t clean_count; /* cleaned up stale session */
229 struct /* Event based timing : start & end depend on CLI specified events */
239 typedef void (*echo_rpc_t) (void *arg, u32 opaque);