EXAMPLES.txt revision 0adf085a
1# Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. 2LSQUIC Examples 3=============== 4 5LSQUIC comes with several examples of how the library is used. 6 7The client and server programs described below are built on a common 8framework and share many options. 9 10Echo client and server 11---------------------- 12 13Echo client and server (see test/echo_{client,server}.c) are for simple 14line-based request and reply communication. Only one stream per connection 15is supported for simplicity. The client reads input from stdin. 16 17MD5 client and server 18--------------------- 19 20See test/md5_{client,server}.c 21 22MD5 server accepts connections, computes MD5 sum of streams' (one or more) 23payload, and sends back the checksum. MD5 client sends one or more file 24contents to the server. Both client and server support various options to 25exercise different aspects of LSQUIC. 26 27HTTP client and server 28---------------------- 29 30See test/http_{client,server}.c 31 32This pair of programs is to demonstrate how to use HTTP features of QUIC. 33HTTP server is interoperable with proto-quic's quic_client. 34 35Usage Examples 36-------------- 37 38Fetch Google's home page: 39 40 ./http_client -s www.google.com -p / 41 42The default port number is 443, but it can be specified after colon 43using the -s flag. The value of the `host' header as well as the SNI 44value defaults to the host part of the -s option. -H option can be 45used to override it. For example: 46 47 ./http_client -H www.youtube.com -s www.google.com:443 -p / -M HEAD 48 49The host part can be an IP address. Both IPv4 and IPv6 are supported. 50See ./http_client -h for a (long) list of different flags. 51 52POST a file to calculate its CRC32 checksum: 53 54 ./http_client -H www.litespeedtech.com -s 443 \ 55 -p /cgi-bin/crc32.cgi -P file-256M -M POST 56 57 HTTP/1.1 200 OK 58 content-type: text/plain 59 date: Fri, 09 Jun 2017 08:40:45 GMT 60 server: LiteSpeed 61 alt-svc: quic=":443"; v="35,37" 62 63 CRC32: 2A0E7DBB 64 65This is a good way to check that the payload gets to the other side 66correctly. The CGI script is: 67 68 #!/usr/bin/perl 69 use String::CRC32; 70 printf "Content-type: text/plain\r\n\r\nCRC32: %X\n", crc32(*STDIN) 71 72On the command line, I do 73 74 alias crc32="perl -MString::CRC32 -e'printf qq(%X\n), crc32(<>)'" 75 76To submit several requests concurrently, one can use -n and -r options: 77 78 ./http_client -H www.litespeedtech.com -s 443 \ 79 -p /cgi-bin/crc32.cgi -P file-256M -M POST -n 3 -r 10 80 81This will open three parallel connections which will make ten POST 82requests together. 83 84To perform load testing, it is good to mix sending and receiving data: 85 86 for i in {1..100}; do 87 ./http_client $COMMON_OPTS -p /cgi-bin/crc32.cgi -P file-256M \ 88 -M POST >out-post.$i & 89 ./http_client $COMMON_OPTS -p /docs/file-256M >out-get.$i & 90 sleep 1 91 done 92 93If you don't want to create a hundred 256-megabyte out-get.* files, use -K 94flag to discard output. 95 96Testing Large Packet Sizes 97--------------------------------- 98 99IETF QUIC supports all valid UDP packet sizes. This section outlines the 100environment setup and testing parameters necessary to test this feature. 101 102Compilation 103 - Make sure to compile the library in DEBUG mode so that the NDEBUG 104 define is off. 105 - Build both the http_client and http_server test programs. 106 107Running Instructions 108 - On the server side, define the environment variable 109 LSQUIC_CN_PACK_SIZE and set it to the intended packet size. 110 Valid sizes are up to 65507 (IPv4). 111 - Use the -W flag for http_client and http_server for the ability 112 to send packets of large size. 113 - On the client side, use the -z flag to specify the maximum size 114 of packet that the client will accept. 115 116Example Usage 117 ./http_client -p /file-1M -H www.litespeedtech.com -s 192.168.0.85:5443 118 -o version=FF000014 -z 65507 -W 119 ./http_server -c www.litespeedtech.com,certschain,privkey 120 -s 0.0.0.0:5443 -W 121 122Additional Notes 123 Since this feature does not have MTU discovery enabled at the time of 124 writing, make sure to use client and server machines that share a path 125 with the intended MTU. 126 127Control QUIC Settings via -o Flag 128--------------------------------- 129 130Most of the settings in struct squic_engine_settings can be controlled 131via -o flag. With exception of es_versions, which is a bit mask, other 132es_* options can be mapped to corresponding -o value via s/^es_//: 133 134 es_cfcw => -o cwcf=12345 135 es_max_streams_in => -o max_streams_in=123 136 137And so on. 138 139For example, to test version negotiation: 140 141 ./http_server -c www.litespeedtech.com,certschain,privkey \ 142 -o version=Q035 -L debug 2>server.out & 143 ./http_client -H www.litespeedtech.com -p Makefile -L debug 2>client.out 144 145Above, the client will start with the default, which is the highest supported 146QUIC version, which the server should negotiate down. You should see it from 147the log files. 148 149The code to set options via -o flag lives in set_engine_option(). It is good 150to update this function at the same time as member fields are added to struct 151lsquic_engine_settings. 152 153Control LSQUIC Behavior via Environment Variables 154------------------------------------------------- 155 156LSQUIC_PACKET_OUT_LIMIT 157 158 If set, the value of this environment variable is the maximum number 159 of packets that can be sent out in one shot. The limit is in the test 160 program framework's ea_packets_out() callback. 161 162 It is not applicable when sendmmsg(2) is used. 163 164 Note 1: sendmmsg can be enabled using -g option, if available for your 165 platform. 166 167 Note 2: see -m option for a related packet-out limitation. 168 169LSQUIC_DISABLE_HANDSHAKE 170 171 If set (to anything, not any particular value), the QUIC handshake is 172 disabled and packets are not encrypted. This can be useful to: 173 a) profile functions in LSQUIC without accounting for crypto stuff, 174 which tends to dwarf everything else; 175 b) see bytes in the clear on the wire; and 176 c) compare throughput performance to TCP without crypto. 177 178 This functionality is compiled in if the somewhat-awkwardly named 179 LSQUIC_ENABLE_HANDSHAKE_DISABLE is set to 1. By default, it is enabled 180 in debug builds and disabled in optimized builds. 181 182LSQUIC_LOSE_PACKETS_RE 183 184 If set, this regular expression specifies the numbers of packets which 185 the sender will lose on purpose. For example: 186 187 export LSQUIC_LOSE_PACKETS_RE='^(3|5|10)$' 188 189 The act of losing a packet is performed by changing its payload to 190 zero-filled buffer of the same size, which is almost as good as 191 not sending anything. The latter is difficult to implement without 192 negatively affecting the regular code flow. 193 194 Only available in debug builds. 195 196LSQUIC_PACER_INTERTICK 197 198 Number of microsecods to use as constant intertick time in lieu of the 199 pacer's dynamic intertick time approximation. 200 201 Only available in debug builds. 202 203LSQUIC_CUBIC_SAMPLING_RATE 204 205 Number of microseconds between times CWND is logged at info level. 206 207 Only available in debug builds. 208 209LSQUIC_RANDOM_SEND_FAILURE 210 211 Frequency with which sending of packets fails: one out of this many 212 times on average. 213 214 Only available when compiled with -DLSQUIC_RANDOM_SEND_FAILURE=1 215 216LSQUIC_LOG_SECRETS 217 218 If set to true value, crypto secrets will be logged. Applies to 219 IETF QUIC only. 220 221LSQUIC_COALESCE 222 223 If set to false, packets are not coalesced. Defaults to true. 224 225LSQUIC_USE_POOLS 226 227 If set to false, all memory pooling code is replaced with calls to 228 malloc() and free(). This facilitates debugging memory issues. 229 The default is true. 230 231Control Network-Related Stuff 232----------------------------- 233 234 -D Set `do not fragment' flag on outgoing UDP packets. 235 236 -z BYTES Maximum size of outgoing UDP packets. The default is 1370 237 bytes for IPv4 socket and 1350 bytes for IPv6 socket. 238 239 -S opt=val Socket options. Supported options: 240 sndbuf=12345 # Sets SO_SNDBUF 241 rcvbuf=12345 # Sets SO_RCVBUF 242 243 -g Use sendmmsg() to send packets. This is only compiled in 244 if available. 245 246More Compilation Options 247------------------------ 248 249-DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1 250 251 Support disabling of handshake. See above. 252 253-DLSQUIC_CONN_STATS=1 254 255 Track some statistics about connections -- packets in, sent, delayed, 256 stream payload per packet size ratio, and some others -- and print them 257 at NOTICE level when connection is destroyed. 258 259 Cumulative connections statistics are printed by the engine when it is 260 destroyed if lsquic_engine_api.ea_stats_fh is set. The HTTP client 261 programs sets it when -t or -T command-line option is used. 262 263-DLSQUIC_PACKINTS_SANITY_CHECK=1 264 265 Turn on sanity checking for packet interval code. The packet interval 266 code, shared by both send and receive history modules, contained a bug 267 which prompted me to add a checking function. 268 269-DLSQUIC_SEND_STATS=0 270 271 Turn off statistics collection performed by the send controller: number 272 of packets sent, resent, and delayed. 273 274-DLOG_PACKET_CHECKSUM=1 275 276 When turned on, CRC32 checksum of each sent and received packet is 277 logged as an event. 278 279-DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_WARN 280 281 If you want to go even faster: compile out some log levels entirely. 282 283-DLSQUIC_EXTRA_CHECKS=1 284 285 Add relatively expensive run-time sanity checks 286 287-DLSQUIC_RANDOM_SEND_FAILURE=1 288 289 Simulate failure to send packets to test send resumption logic. When 290 this flag is specified, sending of packets will randomly fail, about 291 one out of every 10 attempts. Set environment variable 292 LSQUIC_RANDOM_SEND_FAILURE to change this frequency. 293 294-DLSQUIC_ECN_BLACK_HOLE=1 295 296 When compiled with this flag, setting environment variable 297 LSQUIC_ECN_BLACK_HOLE to 1 will emulate ECN black hole: all received 298 packets with ECN markings are dropped on the floor. 299