litespeed-quic/bin/test_common.h

158 lines
3.9 KiB
C
Raw Normal View History

/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */
2017-09-22 21:00:03 +00:00
/*
* Test client's and server's common components.
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H 1
#if __linux__
# include <net/if.h> /* For IFNAMSIZ */
2017-09-22 21:00:03 +00:00
#endif
2020-06-03 04:13:30 +00:00
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
2017-09-22 21:00:03 +00:00
struct lsquic_engine;
struct lsquic_engine_settings;
struct lsquic_out_spec;
struct event_base;
struct event;
struct packets_in;
struct lsquic_conn;
struct prog;
Latest changes - [API Change] Sendfile-like functionality is gone. The stream no longer opens files and deals with file descriptors. (Among other things, this makes the code more portable.) Three writing functions are provided: lsquic_stream_write lsquic_stream_writev lsquic_stream_writef (NEW) lsquic_stream_writef() is given an abstract reader that has function pointers for size() and read() functions which the user can implement. This is the most flexible way. lsquic_stream_write() and lsquic_stream_writev() are now both implemented as wrappers around lsquic_stream_writef(). - [OPTIMIZATION] When writing to stream, be it within or without the on_write() callback, place data directly into packet buffer, bypassing auxiliary data structures. This reduces amount of memory required, for the amount of data that can be written is limited by the congestion window. To support writes outside the on_write() callback, we keep N outgoing packet buffers per connection which can be written to by any stream. One half of these are reserved for the highest priority stream(s), the other half for all other streams. This way, low-priority streams cannot write instead of high-priority streams and, on the other hand, low-priority streams get a chance to send their packets out. The algorithm is as follows: - When user writes to stream outside of the callback: - If this is the highest priority stream, place it onto the reserved N/2 queue or fail. (The actual size of this queue is dynamic -- MAX(N/2, CWND) -- rather than N/2, allowing high-priority streams to write as much as can be sent.) - If the stream is not the highest priority, try to place the data onto the reserved N/2 queue or fail. - When tick occurs *and* more packets can be scheduled: - Transfer packets from the high N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for highest-priority streams, placing resulting packets directly onto the scheduled queue. - If more scheduling is allowed: - Transfer packets from the low N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for non-highest-priority streams, placing resulting packets directly onto the scheduled queue The number N is currently 20, but it could be varied based on resource usage. - If stream is created due to incoming headers, make headers readable from on_new. - Outgoing packets are no longer marked non-writeable to prevent placing more than one STREAM frame from the same stream into a single packet. This property is maintained via code flow and an explicit check. Packets for stream data are allocated using a special function. - STREAM frame elision is cheaper, as we only perform it if a reset stream has outgoing packets referencing it. - lsquic_packet_out_t is smaller, as stream_rec elements are now inside a union.
2017-10-31 13:35:58 +00:00
struct reader_ctx;
2020-06-03 04:13:30 +00:00
struct lsxpack_header;
#ifndef WIN32
# define SOCKOPT_VAL int
# define SOCKET_TYPE int
# define CLOSE_SOCKET close
# define CHAR_CAST
#else
# define SOCKOPT_VAL DWORD
# define SOCKET_TYPE SOCKET
# define CLOSE_SOCKET closesocket
# define CHAR_CAST (char *)
#endif
2017-09-22 21:00:03 +00:00
enum sport_flags
{
#if LSQUIC_DONTFRAG_SUPPORTED
SPORT_FRAGMENT_OK = (1 << 0),
#endif
2017-09-22 21:00:03 +00:00
SPORT_SET_SNDBUF = (1 << 1), /* SO_SNDBUF */
SPORT_SET_RCVBUF = (1 << 2), /* SO_RCVBUF */
SPORT_SERVER = (1 << 3),
SPORT_CONNECT = (1 << 4),
2017-09-22 21:00:03 +00:00
};
struct service_port {
TAILQ_ENTRY(service_port) next_sport;
#ifndef WIN32
2017-09-22 21:00:03 +00:00
int fd;
#else
SOCKET fd;
#endif
2017-09-22 21:00:03 +00:00
#if __linux__
uint32_t n_dropped;
int drop_init;
char if_name[IFNAMSIZ];
#endif
struct event *ev;
struct lsquic_engine *engine;
void *conn_ctx;
char host[80];
struct sockaddr_storage sas;
struct sockaddr_storage sp_local_addr;
2017-09-22 21:00:03 +00:00
struct packets_in *packs_in;
enum sport_flags sp_flags;
2020-06-03 04:13:30 +00:00
SOCKOPT_VAL sp_sndbuf; /* If SPORT_SET_SNDBUF is set */
SOCKOPT_VAL sp_rcvbuf; /* If SPORT_SET_RCVBUF is set */
2017-09-22 21:00:03 +00:00
struct prog *sp_prog;
unsigned char *sp_token_buf;
size_t sp_token_sz;
2017-09-22 21:00:03 +00:00
};
TAILQ_HEAD(sport_head, service_port);
struct service_port *
sport_new (const char *optarg, struct prog *);
void
sport_destroy (struct service_port *);
int
sport_init_server (struct service_port *, struct lsquic_engine *,
struct event_base *);
2017-09-22 21:00:03 +00:00
int
sport_init_client (struct service_port *, struct lsquic_engine *,
struct event_base *);
int
sport_packets_out (void *ctx, const struct lsquic_out_spec *, unsigned count);
int
sport_set_token (struct service_port *, const char *);
2017-09-22 21:00:03 +00:00
int
set_engine_option (struct lsquic_engine_settings *,
int *version_cleared, const char *name_value);
struct packout_buf;
struct packout_buf_allocator
{
unsigned n_out, /* Number of buffers outstanding */
max; /* Maximum outstanding. Zero mean no limit */
SLIST_HEAD(, packout_buf) free_packout_bufs;
};
void
pba_init (struct packout_buf_allocator *, unsigned max);
void *
pba_allocate (void *packout_buf_allocator, void*, unsigned short, char);
2017-09-22 21:00:03 +00:00
void
pba_release (void *packout_buf_allocator, void *, void *obj, char);
2017-09-22 21:00:03 +00:00
void
pba_cleanup (struct packout_buf_allocator *);
void
print_conn_info (const struct lsquic_conn *conn);
Latest changes - [API Change] Sendfile-like functionality is gone. The stream no longer opens files and deals with file descriptors. (Among other things, this makes the code more portable.) Three writing functions are provided: lsquic_stream_write lsquic_stream_writev lsquic_stream_writef (NEW) lsquic_stream_writef() is given an abstract reader that has function pointers for size() and read() functions which the user can implement. This is the most flexible way. lsquic_stream_write() and lsquic_stream_writev() are now both implemented as wrappers around lsquic_stream_writef(). - [OPTIMIZATION] When writing to stream, be it within or without the on_write() callback, place data directly into packet buffer, bypassing auxiliary data structures. This reduces amount of memory required, for the amount of data that can be written is limited by the congestion window. To support writes outside the on_write() callback, we keep N outgoing packet buffers per connection which can be written to by any stream. One half of these are reserved for the highest priority stream(s), the other half for all other streams. This way, low-priority streams cannot write instead of high-priority streams and, on the other hand, low-priority streams get a chance to send their packets out. The algorithm is as follows: - When user writes to stream outside of the callback: - If this is the highest priority stream, place it onto the reserved N/2 queue or fail. (The actual size of this queue is dynamic -- MAX(N/2, CWND) -- rather than N/2, allowing high-priority streams to write as much as can be sent.) - If the stream is not the highest priority, try to place the data onto the reserved N/2 queue or fail. - When tick occurs *and* more packets can be scheduled: - Transfer packets from the high N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for highest-priority streams, placing resulting packets directly onto the scheduled queue. - If more scheduling is allowed: - Transfer packets from the low N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for non-highest-priority streams, placing resulting packets directly onto the scheduled queue The number N is currently 20, but it could be varied based on resource usage. - If stream is created due to incoming headers, make headers readable from on_new. - Outgoing packets are no longer marked non-writeable to prevent placing more than one STREAM frame from the same stream into a single packet. This property is maintained via code flow and an explicit check. Packets for stream data are allocated using a special function. - STREAM frame elision is cheaper, as we only perform it if a reset stream has outgoing packets referencing it. - lsquic_packet_out_t is smaller, as stream_rec elements are now inside a union.
2017-10-31 13:35:58 +00:00
size_t
test_reader_size (void *void_ctx);
size_t
test_reader_read (void *void_ctx, void *buf, size_t count);
struct reader_ctx *
create_lsquic_reader_ctx (const char *filename);
void
destroy_lsquic_reader_ctx (struct reader_ctx *ctx);
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define LITESPEED_ID "lsquic" "/" TOSTRING(LSQUIC_MAJOR_VERSION) "." \
TOSTRING(LSQUIC_MINOR_VERSION) "." TOSTRING(LSQUIC_PATCH_VERSION)
2020-06-03 04:13:30 +00:00
struct header_buf
{
unsigned off;
char buf[UINT16_MAX];
};
int
header_set_ptr (struct lsxpack_header *hdr, struct header_buf *header_buf,
const char *name, size_t name_len,
const char *val, size_t val_len);
2017-09-22 21:00:03 +00:00
#endif