Commit | Line | Data |
---|---|---|
17fe0490 CB |
1 | #!/bin/bash |
2 | # | |
9d16b343 MJ |
3 | # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com> |
4 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> | |
17fe0490 | 5 | # |
9d16b343 | 6 | # SPDX-License-Identifier: LGPL-2.1-only |
b2068598 DG |
7 | |
8 | TEST_DESC="Streaming - High throughput with bandwidth limits" | |
17fe0490 CB |
9 | |
10 | CURDIR=$(dirname $0)/ | |
9ac429ef | 11 | TESTDIR=$CURDIR/../../.. |
17fe0490 CB |
12 | NR_APP_ITER=10 |
13 | NR_ITER=1000000 | |
ea3a3cae CB |
14 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
15 | TESTAPP_NAME="gen-ust-events" | |
16 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
17fe0490 CB |
17 | SESSION_NAME="high-throughput" |
18 | EVENT_NAME="tp:tptest" | |
19 | SESSIOND_CTRL_PORT=5342 | |
20 | SESSIOND_DATA_PORT=5343 | |
21 | DEFAULT_IF="lo" | |
22 | ||
7539dcec | 23 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX) |
17fe0490 | 24 | |
5dca3876 | 25 | NUM_TESTS=104 |
d346ccad | 26 | |
9ac429ef | 27 | source $TESTDIR/utils/utils.sh |
17fe0490 | 28 | |
ea3a3cae CB |
29 | if [ ! -x "$TESTAPP_BIN" ]; then |
30 | BAIL_OUT "No UST events binary detected." | |
17fe0490 CB |
31 | fi |
32 | ||
24e59479 MD |
33 | function reset_bw_limit |
34 | { | |
35 | tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 | |
36 | return $? | |
37 | } | |
38 | ||
17fe0490 CB |
39 | function set_bw_limit |
40 | { | |
41 | limit=$1 | |
ffaed7f7 JD |
42 | ctrlportlimit=$(($limit/10)) |
43 | # failsafe to have at least 1kbit/s for control (in the case where $1 < 10) | |
44 | [ $ctrlportlimit = 0 ] && ctrlportlimit=1 | |
45 | # if $1 < 10, we might bust the limit set here, but the | |
46 | # parent qdisc (1:) will always limit us to the right max value | |
47 | dataportlimit=$((9*${ctrlportlimit})) | |
48 | ||
24e59479 | 49 | diag "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data" |
d346ccad | 50 | |
17fe0490 | 51 | tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 |
24e59479 MD |
52 | if [ $? -ne 0 ]; then |
53 | reset_bw_limit | |
54 | return 1 | |
55 | fi | |
17fe0490 | 56 | |
ffaed7f7 JD |
57 | # the total bandwidth is the limit set by the user |
58 | tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1 | |
24e59479 MD |
59 | if [ $? -ne 0 ]; then |
60 | reset_bw_limit | |
61 | return 1 | |
62 | fi | |
ffaed7f7 JD |
63 | # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port |
64 | tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1 | |
24e59479 MD |
65 | if [ $? -ne 0 ]; then |
66 | reset_bw_limit | |
67 | return 1 | |
68 | fi | |
ffaed7f7 JD |
69 | # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused) |
70 | tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1 | |
24e59479 MD |
71 | if [ $? -ne 0 ]; then |
72 | reset_bw_limit | |
73 | return 1 | |
74 | fi | |
17fe0490 | 75 | |
ffaed7f7 JD |
76 | # filter to assign control traffic to the 1:10 class |
77 | tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1 | |
24e59479 MD |
78 | if [ $? -ne 0 ]; then |
79 | reset_bw_limit | |
80 | return 1 | |
81 | fi | |
ffaed7f7 JD |
82 | # filter to assign data traffic to the 1:11 class |
83 | tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1 | |
24e59479 MD |
84 | if [ $? -ne 0 ]; then |
85 | reset_bw_limit | |
86 | return 1 | |
87 | fi | |
d346ccad | 88 | |
24e59479 | 89 | return 0 |
17fe0490 CB |
90 | } |
91 | ||
92 | function create_lttng_session_with_uri | |
93 | { | |
94 | sess_name=$1 | |
95 | uri=$2 | |
96 | # Create session with custom URI | |
97 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1 | |
d346ccad | 98 | ok $? "Create session with uri $uri" |
17fe0490 CB |
99 | } |
100 | ||
17fe0490 CB |
101 | function run_apps |
102 | { | |
103 | for i in `seq 1 $NR_APP_ITER`; do | |
b2068598 DG |
104 | # With bandwidth limitation, unfortunately, application easily timeout |
105 | # due to very slow communication between the consumer and relayd making | |
106 | # the status reply from the consumer quite slow thus delaying the | |
107 | # registration done message. | |
6c4a91d6 | 108 | LTTNG_UST_REGISTER_TIMEOUT=-1 $TESTAPP_BIN -i $NR_ITER & >/dev/null 2>&1 |
17fe0490 CB |
109 | done |
110 | } | |
111 | ||
17fe0490 CB |
112 | function test_high_throughput |
113 | { | |
114 | NETWORK_URI="net://localhost" | |
115 | create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI | |
c4926bb5 | 116 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
e563bbdb | 117 | start_lttng_tracing_ok $SESSION_NAME |
17fe0490 | 118 | run_apps |
5dca3876 MD |
119 | diag "Waiting for applications to end" |
120 | wait | |
121 | pass "waiting done" | |
96340a01 | 122 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 123 | destroy_lttng_session_ok $SESSION_NAME |
17fe0490 CB |
124 | validate_event_count |
125 | } | |
126 | ||
127 | function validate_event_count | |
128 | { | |
7539dcec FD |
129 | TEMP_FILE=$(mktemp --tmpdir tmp.streaming_high_throughput_limit_file1.XXXXXX) |
130 | TEMP_FILE_2=$(mktemp --tmpdir tmp.streaming_high_throughput_limit_file2.XXXXXX) | |
17fe0490 CB |
131 | |
132 | traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) | |
133 | babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 | |
134 | ||
135 | cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE | |
136 | ||
137 | dropped=0 | |
138 | while read line; | |
139 | do | |
140 | let dropped=$dropped+$line | |
141 | done < $TEMP_FILE | |
142 | ||
143 | let total=$dropped+$traced | |
144 | let wanted=$NR_APP_ITER*$NR_ITER | |
145 | ||
17fe0490 | 146 | if [ $wanted -ne $total ]; then |
d346ccad CB |
147 | fail "Validate trace event count" |
148 | diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " | |
17fe0490 CB |
149 | return 1 |
150 | else | |
d346ccad CB |
151 | pass "Validate trace event count" |
152 | diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " | |
b2068598 | 153 | |
b2068598 DG |
154 | rm -rf $TRACE_PATH |
155 | rm $TEMP_FILE $TEMP_FILE_2 | |
156 | ||
17fe0490 CB |
157 | return 0 |
158 | fi | |
159 | } | |
160 | ||
161 | function interrupt_cleanup() | |
162 | { | |
d346ccad | 163 | diag "*** Exiting ***" |
17fe0490 | 164 | reset_bw_limit |
24e59479 MD |
165 | # invoke utils cleanup |
166 | full_cleanup | |
17fe0490 CB |
167 | } |
168 | ||
d346ccad | 169 | plan_tests $NUM_TESTS |
17fe0490 | 170 | |
e3bef725 CB |
171 | print_test_banner "$TEST_DESC" |
172 | ||
d346ccad CB |
173 | if [ "$(id -u)" == "0" ]; then |
174 | isroot=1 | |
175 | else | |
176 | isroot=0 | |
177 | fi | |
17fe0490 | 178 | |
d346ccad CB |
179 | skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS || |
180 | { | |
17fe0490 | 181 | |
d346ccad | 182 | # Catch sigint and try to cleanup limits |
24e59479 | 183 | trap interrupt_cleanup SIGTERM SIGINT |
d346ccad CB |
184 | |
185 | BW_LIMITS=(3200 1600 800 400 200 100 50 25) | |
186 | for BW in ${BW_LIMITS[@]}; | |
187 | do | |
188 | diag "Test high-throughput with bandwidth limit set to ${BW}kbits" | |
491c49eb | 189 | |
d346ccad | 190 | set_bw_limit $BW |
24e59479 | 191 | ok $? "Setting bandwidth limit" |
d346ccad CB |
192 | |
193 | start_lttng_sessiond | |
194 | start_lttng_relayd "-o $TRACE_PATH" | |
195 | test_high_throughput | |
196 | result=$? | |
197 | stop_lttng_relayd | |
198 | stop_lttng_sessiond | |
199 | reset_bw_limit | |
24e59479 | 200 | ok $? "Reset bandwith limits" |
d346ccad CB |
201 | done |
202 | } |