FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
quic_echo.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 #include <stdio.h>
17 #include <signal.h>
18 
20 
21 #define vl_typedefs /* define message structures */
22 #include <vpp/api/vpe_all_api_h.h>
23 #undef vl_typedefs
24 
25 /* declare message handlers for each api */
26 
27 #define vl_endianfun /* define message structures */
28 #include <vpp/api/vpe_all_api_h.h>
29 #undef vl_endianfun
30 
31 /* instantiate all the print functions we know about */
32 #define vl_print(handle, ...)
33 #define vl_printfun
34 #include <vpp/api/vpe_all_api_h.h>
35 #undef vl_printfun
36 
37 #define NITER 4000000
38 #define TIMEOUT 10.0
39 
40 #define CHECK(expected, result, _fmt, _args...) \
41  if (expected != result) \
42  ECHO_FAIL ("expected %d, got %d : " _fmt, expected, result, ##_args);
43 
44 #define ECHO_FAIL(_fmt,_args...) \
45  { \
46  echo_main_t *em = &echo_main; \
47  em->has_failed = 1; \
48  em->time_to_stop = 1; \
49  if (em->log_lvl > 0) \
50  clib_warning ("ECHO-ERROR: "_fmt, ##_args); \
51  }
52 
53 #define ECHO_LOG(lvl, _fmt,_args...) \
54  { \
55  echo_main_t *em = &echo_main; \
56  if (em->log_lvl > lvl) \
57  clib_warning (_fmt, ##_args); \
58  }
59 
60 typedef struct
61 {
62  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
63 #define _(type, name) type name;
65 #undef _
69  volatile u64 bytes_received;
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 */
76 
77 typedef enum
78 {
84 
86 {
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 */
91 };
92 
94 {
98 };
99 
101 {
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 */
108 };
109 
110 typedef enum
111 {
120 
121 typedef enum echo_test_evt_
122 {
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 */
131 
132 typedef struct _quic_echo_cb_vft
133 {
134  void (*quic_connected_cb) (session_connected_msg_t * mp, u32 session_index);
135  void (*client_stream_connected_cb) (session_connected_msg_t * mp,
136  u32 session_index);
137  void (*server_stream_connected_cb) (session_connected_msg_t * mp,
138  u32 session_index);
139  void (*quic_accepted_cb) (session_accepted_msg_t * mp, u32 session_index);
140  void (*client_stream_accepted_cb) (session_accepted_msg_t * mp,
141  u32 session_index);
142  void (*server_stream_accepted_cb) (session_accepted_msg_t * mp,
143  u32 session_index);
145 
146 
147 typedef enum
148 {
153 
154 typedef struct teardown_stat_
155 {
156  u32 q; /* quic sessions */
157  u32 s; /* stream sessions */
159 
160 typedef struct
161 {
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 */
171 
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 */
174 
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 */
180 
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 */
185 
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. */
190 
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 */
204 
208 
209  pthread_t *data_thread_handles; /* vec of data thread handles */
210  pthread_t mq_thread_handle; /* Message queue thread handle */
212 
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 */
219 
220  struct {
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 */
227  } stats;
228 
229  struct /* Event based timing : start & end depend on CLI specified events */
230  {
236  } timing;
237 } echo_main_t;
238 
239 typedef void (*echo_rpc_t) (void *arg, u32 opaque);
240 
241 typedef struct
242 {
243  void *fp;
244  void *arg;
#define foreach_app_session_field
flag for dgram mode
volatile u64 accepted_session_count
Definition: quic_echo.h:74
clib_time_t clib_time
Definition: quic_echo.h:167
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
teardown_stat_t clean_count
Definition: quic_echo.h:226
u32 listen_session_index
Definition: quic_echo.h:170
u32 listener_index
Definition: quic_echo.h:72
int i_am_master
Definition: quic_echo.h:169
clib_spinlock_t sid_vpp_handles_lock
Definition: quic_echo.h:173
int max_test_msg
Definition: quic_echo.h:203
u8 use_sock_api
Flag that decides if socket, instead of svm, api is used to connect to vpp.
Definition: quic_echo.h:189
unsigned long u64
Definition: types.h:89
u32 tx_buf_size
Definition: quic_echo.h:197
volatile connection_state_t state
Definition: quic_echo.h:182
u8 start_event
Definition: quic_echo.h:234
test_return_packets_t
Definition: quic_echo.h:147
unsigned char u8
Definition: types.h:56
foreach_app_session_field u64 vpp_session_handle
Definition: quic_echo.h:66
double f64
Definition: types.h:142
quic_session_state_t
Definition: quic_echo.h:100
u8 output_json
Definition: quic_echo.h:201
volatile u32 n_clients_connected
Definition: quic_echo.h:216
quic_session_type_t
Definition: quic_echo.h:93
volatile u64 bytes_received
Definition: quic_echo.h:69
u8 * appns_id
Definition: quic_echo.h:205
u32 n_rx_threads
Definition: quic_echo.h:217
clib_spinlock_t segment_handles_lock
Definition: quic_echo.h:176
connection_state_t
Definition: quic_echo.h:110
unsigned int u32
Definition: types.h:88
u32 my_client_index
Definition: quic_echo.h:163
f64 start_time
Definition: quic_echo.h:231
u32 fifo_size
Definition: quic_echo.h:195
u32 * data_thread_args
Definition: quic_echo.h:211
quic_echo_cb_vft_t cb_vft
Definition: quic_echo.h:177
volatile u32 n_quic_clients_connected
Definition: quic_echo.h:215
uword * session_index_by_vpp_handles
Definition: quic_echo.h:172
u64 bytes_to_send
Definition: quic_echo.h:68
pthread_t mq_thread_handle
Definition: quic_echo.h:210
fifo_segment_main_t segment_main
Definition: quic_echo.h:179
u8 events_sent
Definition: quic_echo.h:233
data_source_t data_source
Definition: quic_echo.h:198
u64 bytes_to_send
Definition: quic_echo.h:193
u8 test_return_packets
Definition: quic_echo.h:192
echo_session_t * sessions
Definition: quic_echo.h:165
u64 appns_secret
Definition: quic_echo.h:207
uword * shared_segment_handles
Definition: quic_echo.h:175
data_source_t
Definition: quic_echo.h:77
volatile u8 time_to_stop
Definition: quic_echo.h:183
teardown_stat_t reset_count
Definition: quic_echo.h:223
f64 end_time
Definition: quic_echo.h:232
volatile u32 nxt_available_sidx
Definition: quic_echo.h:218
echo_close_f_t
Definition: quic_echo.h:85
u32 n_clients
Definition: quic_echo.h:213
void(* echo_rpc_t)(void *arg, u32 opaque)
Definition: quic_echo.h:239
echo_test_evt_
Definition: quic_echo.h:121
enum echo_test_evt_ echo_test_evt_t
u32 n_stream_clients
Definition: quic_echo.h:214
teardown_stat_t close_count
Definition: quic_echo.h:224
struct teardown_stat_ teardown_stat_t
struct _quic_echo_cb_vft quic_echo_cb_vft_t
volatile u64 bytes_to_receive
Definition: quic_echo.h:70
svm_msg_q_t * our_event_queue
Definition: quic_echo.h:166
u64 rx_total
Definition: quic_echo.h:222
u8 * connect_test_data
Definition: quic_echo.h:191
u64 uword
Definition: types.h:112
teardown_stat_t active_count
Definition: quic_echo.h:225
u64 appns_flags
Definition: quic_echo.h:206
struct _svm_queue svm_queue_t
svm_msg_q_t * rpc_msq_queue
Definition: quic_echo.h:178
u64 tx_total
Definition: quic_echo.h:221
pthread_t * data_thread_handles
Definition: quic_echo.h:209
svm_queue_t * vl_input_queue
Definition: quic_echo.h:162
u8 send_quic_disconnects
Definition: quic_echo.h:199
u32 rx_buf_size
Definition: quic_echo.h:196
u8 send_stream_disconnects
Definition: quic_echo.h:200
u64 bytes_to_receive
Definition: quic_echo.h:194
u8 * socket_name
Definition: quic_echo.h:168