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 1 0.0 %
Date: 2025-03-20 12:08:36 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             : /* 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_aio_eth_wrap is an fd_aio middleware that translates between a L2 (Ethernet) and L3 fd_aio.
     102             :    Provides a simplistic Ethernet layer with hardcoded MAC addresses. */
     103             : 
     104             : struct fd_aio_eth_wrap {
     105             :   fd_aio_t     wrap_self;
     106             :   fd_aio_t     unwrap_self;
     107             :   fd_aio_t     wrap_next;
     108             :   fd_aio_t     unwrap_next;
     109             :   fd_eth_hdr_t template;
     110             : };
     111             : 
     112             : typedef struct fd_aio_eth_wrap fd_aio_eth_wrap_t;
     113             : 
     114             : FD_PROTOTYPES_BEGIN
     115             : 
     116             : fd_aio_t *
     117             : fd_aio_eth_wrap( fd_aio_eth_wrap_t * wrap );
     118             : 
     119             : fd_aio_t *
     120             : fd_aio_eth_unwrap( fd_aio_eth_wrap_t * wrap );
     121             : 
     122             : FD_PROTOTYPES_END
     123             : 
     124             : /* fd_quic_udpsock is a command-line helper for creating an UDP channel
     125             :    over AF_XDP or UDP sockets. */
     126             : 
     127             : struct fd_quic_udpsock {
     128             :   int type;
     129           0 : # define FD_QUIC_UDPSOCK_TYPE_UDPSOCK 2
     130             : 
     131             :   uint   listen_ip;
     132             :   ushort listen_port;
     133             : 
     134             :   fd_wksp_t * wksp;  /* Handle to the workspace owning the objects */
     135             :   union {
     136             :     struct {
     137             :       fd_udpsock_t * sock;
     138             :       int            sock_fd;
     139             :     } udpsock;
     140             :   };
     141             : 
     142             :   fd_aio_t const * aio;
     143             : };
     144             : typedef struct fd_quic_udpsock fd_quic_udpsock_t;
     145             : 
     146             : FD_PROTOTYPES_BEGIN
     147             : 
     148             : fd_quic_udpsock_t *
     149             : fd_quic_client_create_udpsock(fd_quic_udpsock_t * udpsock,
     150             :                               fd_wksp_t *      wksp,
     151             :                               fd_aio_t const * rx_aio,
     152             :                               uint listen_ip);
     153             : 
     154             : fd_quic_udpsock_t *
     155             : fd_quic_udpsock_create( void *           _sock,
     156             :                         int *            argc,
     157             :                         char ***         argv,
     158             :                         fd_wksp_t *      wksp,
     159             :                         fd_aio_t const * rx_aio );
     160             : 
     161             : void *
     162             : fd_quic_udpsock_destroy( fd_quic_udpsock_t * udpsock );
     163             : 
     164             : void
     165             : fd_quic_udpsock_service( fd_quic_udpsock_t const * udpsock );
     166             : 
     167             : 
     168             : /* fd_quic_netem injects packet loss and reordering into an aio link. */
     169             : 
     170             : struct fd_quic_netem_reorder_buf {
     171             :   ulong sz;
     172             :   uchar buf[2048];
     173             : };
     174             : 
     175             : struct fd_quic_netem {
     176             :   fd_aio_t         local;
     177             :   fd_aio_t const * dst;
     178             :   float            thresh_drop;
     179             :   float            thresh_reorder;
     180             : 
     181             :   struct fd_quic_netem_reorder_buf reorder_buf[2];
     182             :   int                              reorder_mru; /* most recently written reorder buf */
     183             : };
     184             : 
     185             : typedef struct fd_quic_netem fd_quic_netem_t;
     186             : 
     187             : fd_quic_netem_t *
     188             : fd_quic_netem_init( fd_quic_netem_t * netem,
     189             :                     float             thres_drop,
     190             :                     float             thres_reorder );
     191             : 
     192             : /* fd_quic_netem_send implements fd_aio_send for fd_quic_netem_t. */
     193             : 
     194             : int
     195             : fd_quic_netem_send( void *                    ctx, /* fd_quic_net_em_t */
     196             :                     fd_aio_pkt_info_t const * batch,
     197             :                     ulong                     batch_cnt,
     198             :                     ulong *                   opt_batch_idx,
     199             :                     int                       flush );
     200             : 
     201             : FD_PROTOTYPES_END
     202             : 
     203             : #endif /* HEADER_fd_src_waltz_quic_tests_fd_quic_helpers_h */

Generated by: LCOV version 1.14