test_common.h revision 9a690580
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * Test client's and server's common components.
4 */
5
6#ifndef TEST_COMMON_H
7#define TEST_COMMON_H 1
8
9#if __linux__
10#   include <net/if.h>  /* For IFNAMSIZ */
11#endif
12
13struct lsquic_engine;
14struct lsquic_engine_settings;
15struct lsquic_out_spec;
16struct event_base;
17struct event;
18struct packets_in;
19struct lsquic_conn;
20struct prog;
21struct reader_ctx;
22
23enum sport_flags
24{
25#if LSQUIC_DONTFRAG_SUPPORTED
26    SPORT_FRAGMENT_OK       = (1 << 0),
27#endif
28    SPORT_SET_SNDBUF        = (1 << 1), /* SO_SNDBUF */
29    SPORT_SET_RCVBUF        = (1 << 2), /* SO_RCVBUF */
30    SPORT_SERVER            = (1 << 3),
31    SPORT_CONNECT           = (1 << 4),
32};
33
34struct service_port {
35    TAILQ_ENTRY(service_port)  next_sport;
36#ifndef WIN32
37    int                        fd;
38#else
39    SOCKET                        fd;
40#endif
41#if __linux__
42    uint32_t                   n_dropped;
43    int                        drop_init;
44    char                       if_name[IFNAMSIZ];
45#endif
46    struct event              *ev;
47    struct lsquic_engine      *engine;
48    void                      *conn_ctx;
49    char                       host[80];
50    struct sockaddr_storage    sas;
51    struct sockaddr_storage    sp_local_addr;
52    struct packets_in         *packs_in;
53    enum sport_flags           sp_flags;
54    int                        sp_sndbuf;   /* If SPORT_SET_SNDBUF is set */
55    int                        sp_rcvbuf;   /* If SPORT_SET_RCVBUF is set */
56    struct prog               *sp_prog;
57    unsigned char             *sp_token_buf;
58    size_t                     sp_token_sz;
59};
60
61TAILQ_HEAD(sport_head, service_port);
62
63struct service_port *
64sport_new (const char *optarg, struct prog *);
65
66void
67sport_destroy (struct service_port *);
68
69int
70sport_init_server (struct service_port *, struct lsquic_engine *,
71                   struct event_base *);
72
73int
74sport_init_client (struct service_port *, struct lsquic_engine *,
75                   struct event_base *);
76
77int
78sport_packets_out (void *ctx, const struct lsquic_out_spec *, unsigned count);
79
80int
81sport_set_token (struct service_port *, const char *);
82
83int
84set_engine_option (struct lsquic_engine_settings *,
85                   int *version_cleared, const char *name_value);
86
87struct packout_buf;
88
89struct packout_buf_allocator
90{
91    unsigned                    n_out,      /* Number of buffers outstanding */
92                                max;        /* Maximum outstanding.  Zero mean no limit */
93    SLIST_HEAD(, packout_buf)   free_packout_bufs;
94};
95
96void
97pba_init (struct packout_buf_allocator *, unsigned max);
98
99void *
100pba_allocate (void *packout_buf_allocator, void*, unsigned short, char);
101
102void
103pba_release (void *packout_buf_allocator, void *, void *obj, char);
104
105void
106pba_cleanup (struct packout_buf_allocator *);
107
108void
109print_conn_info (const struct lsquic_conn *conn);
110
111size_t
112test_reader_size (void *void_ctx);
113
114size_t
115test_reader_read (void *void_ctx, void *buf, size_t count);
116
117struct reader_ctx *
118create_lsquic_reader_ctx (const char *filename);
119
120void
121destroy_lsquic_reader_ctx (struct reader_ctx *ctx);
122
123#define STRINGIFY(x) #x
124#define TOSTRING(x) STRINGIFY(x)
125#define LITESPEED_ID "lsquic" "/" TOSTRING(LSQUIC_MAJOR_VERSION) "." \
126            TOSTRING(LSQUIC_MINOR_VERSION) "." TOSTRING(LSQUIC_PATCH_VERSION)
127
128#endif
129