Line data Source code
1 : #ifndef HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h 2 : #define HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h 3 : 4 : #include "../fd_quic.h" 5 : #include "../../aio/fd_aio_pcapng.h" 6 : #include "../../udpsock/fd_udpsock.h" 7 : #include "../../tls/test_tls_helper.h" 8 : #include "../../../ballet/txn/fd_txn.h" /* FD_TXN_MTU */ 9 : 10 : #include <stdio.h> 11 : 12 : /* Common helpers for QUIC tests. The tests using these gain the 13 : following command-line options: 14 : 15 : --pcap <path> Append test traffic to pcapng 1.0 at given file 16 : path (encryption secrets included) */ 17 : 18 : /* fd_quic_virtual_pair_t is used to connect two local QUICs via 19 : direct fd_aio. Optionally supports packet capture. */ 20 : 21 : struct fd_quic_virtual_pair { 22 : fd_quic_t * quic_a; 23 : fd_quic_t * quic_b; 24 : 25 : /* aio_{a2b,b2a} point to the first hop of each aio chain */ 26 : fd_aio_t const * aio_a2b; 27 : fd_aio_t const * aio_b2a; 28 : 29 : fd_aio_pcapng_t pcapng_a2b; 30 : fd_aio_pcapng_t pcapng_b2a; 31 : }; 32 : typedef struct fd_quic_virtual_pair fd_quic_virtual_pair_t; 33 : 34 : FD_PROTOTYPES_BEGIN 35 : 36 : extern FILE * fd_quic_test_pcap; 37 : 38 : /* fd_quic_test_boot boots the QUIC test environment. 39 : Should be called after fd_boot(). 40 : 41 : fd_quic_test_halt halts the QUIC test environment. 42 : Should be called before fd_halt(). */ 43 : 44 : void 45 : fd_quic_test_boot( int * pargc, 46 : char *** pargv ); 47 : void 48 : fd_quic_test_halt( void ); 49 : 50 : void 51 : fd_quic_config_anonymous( fd_quic_t * quic, 52 : int role ); 53 : 54 : void 55 : fd_quic_config_test_signer( fd_quic_t * quic, 56 : fd_tls_test_sign_ctx_t * sign_ctx ); 57 : 58 : /* fd_quic_new_anonymous creates an anonymous QUIC instance with the 59 : given limits. Vacant config fields are auto-generated, except for 60 : role (server or client). Returns QUIC instance without local join on 61 : success. Halts program on error. Caller is responsible for cleaning 62 : up QUIC. */ 63 : 64 : fd_quic_t * 65 : fd_quic_new_anonymous( fd_wksp_t * wksp, 66 : fd_quic_limits_t const * limits, 67 : int role, 68 : fd_rng_t * rng ); 69 : 70 : /* fd_quic_new_anonymous_small is like fd_quic_new_anonymous but with 71 : arbitrary small limits for convenience. */ 72 : 73 : fd_quic_t * 74 : fd_quic_new_anonymous_small( fd_wksp_t * wksp, 75 : int role, 76 : fd_rng_t * rng ); 77 : 78 : /* fd_quic_sync_clocks sets the clock of two QUICs to 'now'. */ 79 : 80 : void 81 : fd_quic_sync_clocks( fd_quic_t * quicA, 82 : fd_quic_t * quicB, 83 : long now ); 84 : 85 : /* fd_quic_virtual_pair_init sets up an aio loop between the two given QUIC 86 : objects. That is, an fd_aio_send() call by quicA will trigger 87 : a synchronous callback to the aio receive to the quicB. (FIXME This 88 : assumes no reentrancy in QUIC) If user requested pcap, causes 89 : packets to get logged. May only be called once per thread. Any 90 : allocated resources get released at halt. */ 91 : 92 : void 93 : fd_quic_virtual_pair_init( fd_quic_virtual_pair_t * pair, 94 : fd_quic_t * quicA, 95 : fd_quic_t * quicB ); 96 : 97 : /* fd_quic_virtual_pair_fini destroys an aio loop between the two given 98 : QUIC objects. */ 99 : 100 : void 101 : fd_quic_virtual_pair_fini( fd_quic_virtual_pair_t * pair ); 102 : 103 : void 104 : fd_quic_test_cb_tls_keylog( void * quic_ctx, 105 : char const * line ); 106 : 107 : FD_PROTOTYPES_END 108 : 109 : /* fd_quic_udpsock is a command-line helper for creating an UDP channel 110 : over AF_XDP or UDP sockets. */ 111 : 112 : struct fd_quic_udpsock { 113 : int type; 114 0 : # define FD_QUIC_UDPSOCK_TYPE_UDPSOCK 2 115 : 116 : uint listen_ip; 117 : ushort listen_port; 118 : 119 : fd_wksp_t * wksp; /* Handle to the workspace owning the objects */ 120 : union { 121 : struct { 122 : fd_udpsock_t * sock; 123 : int sock_fd; 124 : } udpsock; 125 : }; 126 : 127 : fd_aio_t const * aio; 128 : }; 129 : typedef struct fd_quic_udpsock fd_quic_udpsock_t; 130 : 131 : FD_PROTOTYPES_BEGIN 132 : 133 : fd_quic_udpsock_t * 134 : fd_quic_client_create_udpsock(fd_quic_udpsock_t * udpsock, 135 : fd_wksp_t * wksp, 136 : fd_aio_t const * rx_aio, 137 : uint listen_ip); 138 : 139 : fd_quic_udpsock_t * 140 : fd_quic_udpsock_create( void * _sock, 141 : int * argc, 142 : char *** argv, 143 : fd_wksp_t * wksp, 144 : fd_aio_t const * rx_aio ); 145 : 146 : void * 147 : fd_quic_udpsock_destroy( fd_quic_udpsock_t * udpsock ); 148 : 149 : void 150 : fd_quic_udpsock_service( fd_quic_udpsock_t const * udpsock ); 151 : 152 : 153 : /* fd_quic_netem injects packet loss and reordering into an aio link. */ 154 : 155 : struct fd_quic_netem_reorder_buf { 156 : ulong sz; 157 : uchar buf[2048]; 158 : }; 159 : 160 : struct fd_quic_netem { 161 : fd_aio_t local; 162 : fd_aio_t const * dst; 163 : float thresh_drop; 164 : float thresh_reorder; 165 : 166 : struct fd_quic_netem_reorder_buf reorder_buf[2]; 167 : int reorder_mru; /* most recently written reorder buf */ 168 : 169 : ulong drop_sequence; /* defines a drop-sequence for next 64 outgoing packets */ 170 : 171 : long * now_ptr; /* points to test 'now' */ 172 : long one_way_latency; 173 : }; 174 : 175 : typedef struct fd_quic_netem fd_quic_netem_t; 176 : 177 : fd_quic_netem_t * 178 : fd_quic_netem_init( fd_quic_netem_t * netem, 179 : float thres_drop, 180 : float thres_reorder, 181 : long * now_ptr ); 182 : 183 : /* fd_quic_netem_set_drop sets a drop sequence for outgoing packets. 184 : 'drop_sequence' is an ordered bitset interpreted from right to left, 185 : where 1 signals a drop. This function can specify behavior for at most 186 : the next 64 packets. Subsequent calls to this function overwrite the 187 : previous call. Non-zero thres_drop and/or thres_reorder only apply if 188 : packet is not dropped by the deterministic drop_sequence. 189 : To get only deterministic drops, set thres_drop and thres_reorder to 0. */ 190 : 191 : void 192 : fd_quic_netem_set_drop( fd_quic_netem_t * netem, 193 : ulong drop_sequence ); 194 : 195 : /* fd_quic_netem_set_one_way_latency sets the one_way_latency 196 : for the network emulation. Each outgoing packet will increment 197 : *now_ptr by one_way_latency. */ 198 : 199 : void 200 : fd_quic_netem_set_one_way_latency( fd_quic_netem_t * netem, 201 : long one_way_latency ); 202 : 203 : /* fd_quic_netem_send implements fd_aio_send for fd_quic_netem_t. */ 204 : 205 : int 206 : fd_quic_netem_send( void * ctx, /* fd_quic_net_em_t */ 207 : fd_aio_pkt_info_t const * batch, 208 : ulong batch_cnt, 209 : ulong * opt_batch_idx, 210 : int flush ); 211 : 212 : FD_PROTOTYPES_END 213 : 214 : #endif /* HEADER_fd_src_waltz_quic_tests_fd_quic_test_helpers_h */