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