]> git.meshlink.io Git - meshlink/blob - test/utcp-benchmark-stream
Move UTCP into the MeshLink repository.
[meshlink] / test / utcp-benchmark-stream
1 #!/bin/bash
2 set -e
3
4 # Require root permissions
5 test "$(id -u)" = "0" || exit 77
6
7 # Configuration
8 LOG_PREFIX=/dev/shm/utcp-benchmark-log
9
10 # Size in bytes
11 SIZE=2e6
12
13 # Rate of generated stream in bits/s
14 STREAMRATE=10e6
15
16 # Network parameters
17 # Some realistic values:
18 # - Gbit LAN connection: RATE=1gbit DELAY=0.4ms JITTER=0.04ms LOSS=0%
19 # - Fast WAN connection: RATE=100mbit DELAY=50ms JITTER=3ms LOSS=0%
20 # - 5GHz WiFi connection: RATE=90mbit DELAY=5ms JITTER=1ms LOSS=0%
21 RATE=100mbit
22 DELAY=10ms
23 JITTER=1ms
24 LOSS=0.1%
25
26 # Maximum achievable bandwidth is limited to BUFSIZE / (2 * DELAY)
27 # The Linux kernel has a default maximum send buffer of 4 MiB
28 #export BUFSIZE=4194304
29
30 # Remove old log files
31 rm -f $LOG_PREFIX-* 2>/dev/null
32
33 # Clean up old namespaces
34 ip link del utcp-left 2>/dev/null || true
35 ip link del utcp-right 2>/dev/null || true
36 ip netns delete utcp-left 2>/dev/null || true
37 ip netns delete utcp-right 2>/dev/null || true
38
39 # Set up the left namespace
40 ip netns add utcp-left
41 ip link add name utcp-left type veth peer name utcp-right
42 ip link set utcp-left netns utcp-left
43
44 ip netns exec utcp-left ethtool -K utcp-left tso off
45 ip netns exec utcp-left ip link set dev lo up
46 ip netns exec utcp-left ip addr add dev utcp-left 192.168.1.1/24
47 ip netns exec utcp-left ip link set utcp-left up
48
49 #ip netns exec utcp-left tc qdisc del dev utcp-left root
50 ip netns exec utcp-left tc qdisc add dev utcp-left root netem rate $RATE delay $DELAY $JITTER loss random $LOSS
51
52 # Set up the right namespace
53 ip netns add utcp-right
54 ip link set utcp-right netns utcp-right
55
56 ip netns exec utcp-right ethtool -K utcp-right tso off
57 ip netns exec utcp-right ip link set dev lo up
58 ip netns exec utcp-right ip addr add dev utcp-right 192.168.1.2/24
59 ip netns exec utcp-right ip link set utcp-right up
60
61 #ip netns exec utcp-right tc qdisc del dev utcp-right root
62 ip netns exec utcp-right tc qdisc add dev utcp-right root netem rate $RATE delay $DELAY $JITTER loss random $LOSS
63 # Test using kernel TCP
64 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-socat.pcap port 9999 2>/dev/null &
65 ip netns exec utcp-left socat TCP4-LISTEN:9999 - </dev/null | ./stream -r $STREAMRATE -t $SIZE -v &
66 sleep 0.1
67 ./stream -r $STREAMRATE -t $SIZE | ip netns exec utcp-right time socat - TCP4:192.168.1.1:9999 2>$LOG_PREFIX-socat-client.txt >/dev/null
68 sleep 0.1
69 kill $(jobs -p) 2>/dev/null
70
71 # Test using UTCP
72 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-utcp.pcap udp port 9999 2>/dev/null &
73 ip netns exec utcp-left ./test 9999 2>$LOG_PREFIX-server.txt </dev/null | ./stream -r $STREAMRATE -t $SIZE -v &
74 sleep 0.1
75 ./stream -r $STREAMRATE -t $SIZE | ip netns exec utcp-right time ./test 192.168.1.1 9999 2>$LOG_PREFIX-client.txt >/dev/null
76 sleep 0.1
77 kill $(jobs -p) 2>/dev/null
78
79 # Print timing statistics
80 echo "Regular TCP:"
81 tail -2 $LOG_PREFIX-socat-client.txt
82
83 echo
84 echo "UTCP:"
85 tail -3 $LOG_PREFIX-client.txt