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