EXAMPLES.txt revision b8fa6195
1# Copyright (c) 2017 - 2020 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 bin/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 bin/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 bin/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 - Specify maximum packet size using -o base_plpmtu=$number. 109 Valid sizes are up to 65535. 110 - Use the -W flag for http_client and http_server for the ability 111 to send packets of large size. 112 - On the client side, use the -z flag to specify the maximum size 113 of packet that the client will accept. 114 115Example Usage 116 ./http_client -p /file-1M -H www.litespeedtech.com -s 192.168.0.85:5443 117 -o version=FF000014 118 ./http_server -c www.litespeedtech.com,certschain,privkey 119 -s 0.0.0.0:5443 -W -o base_plpmtu=65535 120 121Additional Notes 122 Since this feature does not have MTU discovery enabled at the time of 123 writing, make sure to use client and server machines that share a path 124 with the intended MTU. 125 126Control QUIC Settings via -o Flag 127--------------------------------- 128 129Most of the settings in struct squic_engine_settings can be controlled 130via -o flag. With exception of es_versions, which is a bit mask, other 131es_* options can be mapped to corresponding -o value via s/^es_//: 132 133 es_cfcw => -o cwcf=12345 134 es_max_streams_in => -o max_streams_in=123 135 136And so on. 137 138For example, to test version negotiation: 139 140 ./http_server -c www.litespeedtech.com,certschain,privkey \ 141 -o version=Q035 -L debug 2>server.out & 142 ./http_client -H www.litespeedtech.com -p Makefile -L debug 2>client.out 143 144Above, the client will start with the default, which is the highest supported 145QUIC version, which the server should negotiate down. You should see it from 146the log files. 147 148The code to set options via -o flag lives in set_engine_option(). It is good 149to update this function at the same time as member fields are added to struct 150lsquic_engine_settings. 151 152Control LSQUIC Behavior via Environment Variables 153------------------------------------------------- 154 155LSQUIC_PACKET_OUT_LIMIT 156 157 If set, the value of this environment variable is the maximum number 158 of packets that can be sent out in one shot. The limit is in the test 159 program framework's ea_packets_out() callback. 160 161 It is not applicable when sendmmsg(2) is used. 162 163 Note 1: sendmmsg can be enabled using -g option, if available for your 164 platform. 165 166 Note 2: see -m option for a related packet-out limitation. 167 168LSQUIC_LOSE_PACKETS_RE 169 170 If set, this regular expression specifies the numbers of packets which 171 the sender will lose on purpose. For example: 172 173 export LSQUIC_LOSE_PACKETS_RE='^(3|5|10)$' 174 175 The act of losing a packet is performed by changing its payload to 176 zero-filled buffer of the same size, which is almost as good as 177 not sending anything. The latter is difficult to implement without 178 negatively affecting the regular code flow. 179 180 Only available in debug builds. 181 182LSQUIC_PACER_INTERTICK 183 184 Number of microsecods to use as constant intertick time in lieu of the 185 pacer's dynamic intertick time approximation. 186 187 Only available in debug builds. 188 189LSQUIC_CUBIC_SAMPLING_RATE 190 191 Number of microseconds between times CWND is logged at info level. 192 193 Only available in debug builds. 194 195LSQUIC_RANDOM_SEND_FAILURE 196 197 Frequency with which sending of packets fails: one out of this many 198 times on average. 199 200 Only available when compiled with -DLSQUIC_RANDOM_SEND_FAILURE=1 201 202LSQUIC_LOG_SECRETS 203 204 If set to true value, crypto secrets will be logged. Applies to 205 IETF QUIC only. 206 207LSQUIC_COALESCE 208 209 If set to false, packets are not coalesced. Defaults to true. 210 211LSQUIC_USE_POOLS 212 213 If set to false, all memory pooling code is replaced with calls to 214 malloc() and free(). This facilitates debugging memory issues. 215 The default is true. 216 217LSQUIC_ACK_ATTACK 218 219 If set to true, generate optimistic ACKs. 220 221Control Network-Related Stuff 222----------------------------- 223 224 -D Set `do not fragment' flag on outgoing UDP packets. 225 226 -z BYTES Maximum size of outgoing UDP packets. The default is 1370 227 bytes for IPv4 socket and 1350 bytes for IPv6 socket. 228 229 -S opt=val Socket options. Supported options: 230 sndbuf=12345 # Sets SO_SNDBUF 231 rcvbuf=12345 # Sets SO_RCVBUF 232 233 -g Use sendmmsg() to send packets. This is only compiled in 234 if available. 235 236More Compilation Options 237------------------------ 238 239-DLSQUIC_CONN_STATS=1 240 241 Track some statistics about connections -- packets in, sent, delayed, 242 stream payload per packet size ratio, and some others -- and print them 243 at NOTICE level when connection is destroyed. 244 245 Cumulative connections statistics are printed by the engine when it is 246 destroyed if lsquic_engine_api.ea_stats_fh is set. The HTTP client 247 programs sets it when -t or -T command-line option is used. 248 249-DLSQUIC_PACKINTS_SANITY_CHECK=1 250 251 Turn on sanity checking for packet interval code. The packet interval 252 code, shared by both send and receive history modules, contained a bug 253 which prompted me to add a checking function. 254 255-DLSQUIC_SEND_STATS=0 256 257 Turn off statistics collection performed by the send controller: number 258 of packets sent, resent, and delayed. 259 260-DLOG_PACKET_CHECKSUM=1 261 262 When turned on, CRC32 checksum of each sent and received packet is 263 logged as an event. 264 265-DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_WARN 266 267 If you want to go even faster: compile out some log levels entirely. 268 269-DLSQUIC_EXTRA_CHECKS=1 270 271 Add relatively expensive run-time sanity checks 272 273-DLSQUIC_RANDOM_SEND_FAILURE=1 274 275 Simulate failure to send packets to test send resumption logic. When 276 this flag is specified, sending of packets will randomly fail, about 277 one out of every 10 attempts. Set environment variable 278 LSQUIC_RANDOM_SEND_FAILURE to change this frequency. 279 280-DLSQUIC_ECN_BLACK_HOLE=1 281 282 When compiled with this flag, setting environment variable 283 LSQUIC_ECN_BLACK_HOLE to 1 will emulate ECN black hole: all received 284 packets with ECN markings are dropped on the floor. 285 286-DLSQUIC_ACK_ATTACK=1 287 288 Enable ACK attack mode. See LSQUIC_ACK_ATTACK environment variable 289 entry above. 290