1#!/bin/bash
2
3CURLRC=~/testcase_curlrc
4
5# Set up the routing needed for the simulation
6/setup.sh
7
8# The following variables are available for use:
9# - ROLE contains the role of this execution context, client or server
10# - SERVER_PARAMS contains user-supplied command line parameters
11# - CLIENT_PARAMS contains user-supplied command line parameters
12
13generate_outputs_http3() {
14    for i in $REQUESTS
15    do
16        OUTFILE=$(basename $i)
17        echo -e "--http3-only\n-o /downloads/$OUTFILE\n--url $i" >> $CURLRC
18        echo "--next" >> $CURLRC
19    done
20    # Remove the last --next
21    head -n -1 $CURLRC > $CURLRC.tmp
22    mv $CURLRC.tmp $CURLRC
23}
24
25dump_curlrc() {
26    echo "Using curlrc:"
27    cat $CURLRC
28}
29
30if [ "$ROLE" == "client" ]; then
31    # Wait for the simulator to start up.
32    echo "Waiting for simulator"
33    /wait-for-it.sh sim:57832 -s -t 30
34    echo "TESTCASE is $TESTCASE"
35    rm -f $CURLRC
36
37    case "$TESTCASE" in
38    "http3")
39        echo -e "--verbose\n--parallel" >> $CURLRC
40        generate_outputs_http3
41        dump_curlrc
42        SSL_CERT_FILE=/certs/ca.pem curl --config $CURLRC || exit 1
43        exit 0
44        ;;
45    "handshake"|"transfer"|"retry")
46       HOSTNAME=none
47       for req in $REQUESTS
48       do
49           OUTFILE=$(basename $req)
50           if [ "$HOSTNAME" == "none" ]
51           then
52               HOSTNAME=$(printf "%s\n" "$req" | sed -ne 's,^https://\([^/:]*\).*,\1,p')
53               HOSTPORT=$(printf "%s\n" "$req" | sed -ne 's,^https://[^:/]*:\([^/]*\).*,\1,p')
54           fi
55           echo -n "$OUTFILE " >> ./reqfile.txt
56       done
57       SSLKEYLOGFILE=/logs/keys.log SSL_CERT_FILE=/certs/ca.pem SSL_CERT_DIR=/certs quic-hq-interop $HOSTNAME $HOSTPORT ./reqfile.txt || exit 1
58       exit 0
59       ;;
60    "resumption")
61       for req in $REQUESTS
62       do
63           OUTFILE=$(basename $req)
64           echo -n "$OUTFILE " > ./reqfile.txt
65           HOSTNAME=$(printf "%s\n" "$req" | sed -ne 's,^https://\([^/:]*\).*,\1,p')
66           HOSTPORT=$(printf "%s\n" "$req" | sed -ne 's,^https://[^:/]*:\([^/]*\).*,\1,p')
67           SSL_SESSION_FILE=./session.db SSLKEYLOGFILE=/logs/keys.log SSL_CERT_FILE=/certs/ca.pem SSL_CERT_DIR=/certs quic-hq-interop $HOSTNAME $HOSTPORT ./reqfile.txt || exit 1
68       done
69       exit 0
70       ;;
71    "chacha20")
72       OUTFILE=$(basename $REQUESTS)
73       SSL_CERT_FILE=/certs/ca.pem curl --verbose --tlsv1.3 --tls13-ciphers TLS_CHACHA20_POLY1305_SHA256 --http3 -o /downloads/$OUTFILE $REQUESTS || exit 1
74       exit 0
75       ;;
76    *)
77        echo "UNSUPPORTED TESTCASE $TESTCASE"
78        exit 127
79        ;;
80    esac
81elif [ "$ROLE" == "server" ]; then
82    echo "UNSUPPORTED"
83    exit 127
84else
85    echo "Unknown ROLE $ROLE"
86    exit 127
87fi
88
89