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