]> git.meshlink.io Git - utcp/blob - benchmark
Add a benchmark script.
[utcp] / benchmark
1 #!/bin/bash
2 set -e
3
4 # Configuration
5 LOG_PREFIX=/dev/shm/benchmark-log
6 SIZE=10000000
7 RATE=100mbit
8 DELAY=10ms
9 JITTER=0ms
10
11 # Require root permissions
12 if [ "$USER" != "root" ]; then
13         exec sudo "$0" "$@"
14 fi
15
16 # Clean up old namespaces
17 ip link del utcp-left 2>/dev/null || true
18 ip link del utcp-right 2>/dev/null || true
19 ip netns delete utcp-left 2>/dev/null || true
20 ip netns delete utcp-right 2>/dev/null || true
21
22 # Set up the left namespace
23 ip netns add utcp-left
24 ip link add name utcp-left type veth peer name utcp-right
25 ip link set utcp-left netns utcp-left
26
27 ip netns exec utcp-left ethtool -K utcp-left tso off
28 ip netns exec utcp-left ip link set dev lo up
29 ip netns exec utcp-left ip addr add dev utcp-left 192.168.1.1/24
30 ip netns exec utcp-left ip link set utcp-left up
31
32 #ip netns exec utcp-left tc qdisc del dev utcp-left root
33 ip netns exec utcp-left tc qdisc add dev utcp-left root netem rate $RATE delay $DELAY $JITTER
34
35 # Set up the right namespace
36 ip netns add utcp-right
37 ip link set utcp-right netns utcp-right
38
39 ip netns exec utcp-right ethtool -K utcp-right tso off
40 ip netns exec utcp-right ip link set dev lo up
41 ip netns exec utcp-right ip addr add dev utcp-right 192.168.1.2/24
42 ip netns exec utcp-right ip link set utcp-right up
43
44 #ip netns exec utcp-right tc qdisc del dev utcp-right root
45 ip netns exec utcp-right tc qdisc add dev utcp-right root netem rate $RATE delay $DELAY $JITTER
46
47 # Test using kernel TCP
48 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-socat.pcap port 9999 2>/dev/null &
49 ip netns exec utcp-left socat TCP4-LISTEN:9999 - >/dev/null &
50 sleep 0.1
51 head -c $SIZE /dev/zero | ip netns exec utcp-right time socat - TCP4:192.168.1.1:9999 2>$LOG_PREFIX-socat-client.txt >/dev/null
52 sleep 0.1
53 kill $(jobs -p) 2>/dev/null
54
55 # Test using UTCP
56 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-utcp.pcap udp port 9999 2>/dev/null &
57 ip netns exec utcp-left ./test 9999 2>$LOG_PREFIX-server.txt >/dev/null &
58 sleep 0.1
59 head -c $SIZE /dev/zero | ip netns exec utcp-right time ./test 192.168.1.1 9999 2>$LOG_PREFIX-client.txt >/dev/null
60 sleep 0.1
61 kill $(jobs -p) 2>/dev/null
62
63 # Print timing statistics
64 echo "Regular TCP:"
65 tail -2 $LOG_PREFIX-socat-client.txt
66
67 echo
68 echo "UTCP:"
69 tail -2 $LOG_PREFIX-client.txt
70
71 # If sudo was used, ensure the log files can be read by the user
72 if [ -n "$SUDO_USER" ]; then
73         chown $SUDO_USER $LOG_PREFIX-*
74 fi