2022-05-06 16:49:46 +00:00
|
|
|
/* Copyright (c) 2017 - 2022 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__
|
2019-09-11 15:27:58 +00:00
|
|
|
# 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
|
|
|
|
{
|
2017-09-26 15:26:05 +00:00
|
|
|
#if LSQUIC_DONTFRAG_SUPPORTED
|
2020-01-28 14:35:09 +00:00
|
|
|
SPORT_FRAGMENT_OK = (1 << 0),
|
2017-09-26 15:26:05 +00:00
|
|
|
#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),
|
2019-02-18 13:40:51 +00:00
|
|
|
SPORT_CONNECT = (1 << 4),
|
2017-09-22 21:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct service_port {
|
|
|
|
TAILQ_ENTRY(service_port) next_sport;
|
2018-03-12 22:25:01 +00:00
|
|
|
#ifndef WIN32
|
2017-09-22 21:00:03 +00:00
|
|
|
int fd;
|
2018-03-12 22:25:01 +00:00
|
|
|
#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;
|
2018-05-30 04:15:35 +00:00
|
|
|
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;
|
2019-09-11 15:27:58 +00:00
|
|
|
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 *);
|
|
|
|
|
2019-09-11 15:27:58 +00:00
|
|
|
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);
|
|
|
|
|
2019-09-11 15:27:58 +00:00
|
|
|
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 *
|
2020-10-07 13:41:26 +00:00
|
|
|
pba_allocate (void *packout_buf_allocator, void*, lsquic_conn_ctx_t *, unsigned short, char);
|
2017-09-22 21:00:03 +00:00
|
|
|
|
|
|
|
void
|
2018-10-16 13:03:33 +00:00
|
|
|
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 *);
|
|
|
|
|
2019-09-11 15:27:58 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-11 12:24:24 +00:00
|
|
|
#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
|