LCOV - code coverage report
Current view: top level - waltz/quic/tests - fd_quic_test_helpers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 2 0.0 %
Date: 2025-01-08 12:08:44 Functions: 0 0 -

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

Generated by: LCOV version 1.14