tcp: fix cc algo name parsing
[vpp.git] / src / plugins / hs_apps / sapi / quic_echo.h
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
19 #include <vnet/session/application_interface.h>
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;
64   foreach_app_session_field
65 #undef _
66   u64 vpp_session_handle;
67   u64 bytes_sent;
68   u64 bytes_to_send;
69   volatile u64 bytes_received;
70   volatile u64 bytes_to_receive;
71   f64 start;
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 */
75 } echo_session_t;
76
77 typedef enum
78 {
79   ECHO_NO_DATA_SOURCE,
80   ECHO_TEST_DATA_SOURCE,
81   ECHO_RX_DATA_SOURCE,
82   ECHO_INVALID_DATA_SOURCE
83 } data_source_t;
84
85 enum echo_close_f_t
86 {
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 */
91 };
92
93 enum quic_session_type_t
94 {
95   QUIC_SESSION_TYPE_QUIC,
96   QUIC_SESSION_TYPE_STREAM,
97   QUIC_SESSION_TYPE_LISTEN,
98 };
99
100 enum quic_session_state_t
101 {
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 */
108 };
109
110 typedef enum
111 {
112   STATE_START,
113   STATE_ATTACHED,
114   STATE_LISTEN,
115   STATE_READY,
116   STATE_DATA_DONE,
117   STATE_DISCONNECTED,
118   STATE_DETACHED
119 } connection_state_t;
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 */
130 } echo_test_evt_t;
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);
144 } quic_echo_cb_vft_t;
145
146
147 typedef enum
148 {
149   RETURN_PACKETS_NOTEST,
150   RETURN_PACKETS_LOG_WRONG,
151   RETURN_PACKETS_ASSERT,
152 } test_return_packets_t;
153
154 typedef struct teardown_stat_
155 {
156   u32 q; /* quic sessions */
157   u32 s; /* stream sessions */
158 } teardown_stat_t;
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 */
168   u8 *socket_name;
169   int i_am_master;
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 */
179   fifo_segment_main_t segment_main;
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. */
189   u8 use_sock_api;
190
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 */
195   u32 fifo_size;
196   u32 rx_buf_size;
197   u32 tx_buf_size;
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
205   u8 *appns_id;
206   u64 appns_flags;
207   u64 appns_secret;
208
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;
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 {
221     u64 tx_total;
222     u64 rx_total;
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   {
231     f64 start_time;
232     f64 end_time;
233     u8 events_sent;
234     u8 start_event;
235     u8 end_event;
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;
245   u32 opaque;
246 } echo_rpc_msg_t;