3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
6 # SPDX-License-Identifier: LGPL-2.1-only
8 TEST_DESC
="Streaming - High throughput with bandwidth limits"
11 TESTDIR
=$CURDIR/..
/..
/..
14 TESTAPP_PATH
="$TESTDIR/utils/testapp"
15 TESTAPP_NAME
="gen-ust-events"
16 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17 SESSION_NAME
="high-throughput"
18 EVENT_NAME
="tp:tptest"
19 SESSIOND_CTRL_PORT
=5342
20 SESSIOND_DATA_PORT
=5343
23 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX
)
27 source $TESTDIR/utils
/utils.sh
29 if [ ! -x "$TESTAPP_BIN" ]; then
30 BAIL_OUT
"No UST events binary detected."
33 function reset_bw_limit
35 tc qdisc del dev
$DEFAULT_IF root
>/dev
/null
2>&1
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}))
49 diag
"Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
51 tc qdisc add dev
$DEFAULT_IF root handle
1: htb default
15 >/dev
/null
2>&1
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
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
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
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
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
92 function create_lttng_session_with_uri
96 # Create session with custom URI
97 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
-U $uri $sess_name >/dev
/null
2>&1
98 ok $?
"Create session with uri $uri"
103 for i
in `seq 1 $NR_APP_ITER`; do
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.
108 LTTNG_UST_REGISTER_TIMEOUT
=-1 $TESTAPP_BIN -i $NR_ITER & >/dev
/null
2>&1
112 function test_high_throughput
114 NETWORK_URI
="net://localhost"
115 create_lttng_session_with_uri
$SESSION_NAME $NETWORK_URI
116 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
117 start_lttng_tracing_ok
$SESSION_NAME
119 diag
"Waiting for applications to end"
122 stop_lttng_tracing_ok
$SESSION_NAME
123 destroy_lttng_session_ok
$SESSION_NAME
127 function validate_event_count
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
)
132 traced
=$
("$BABELTRACE_BIN" $TRACE_PATH 2>/dev
/null |
wc -l)
133 "$BABELTRACE_BIN" $TRACE_PATH >/dev
/null
2>$TEMP_FILE_2
135 cat $TEMP_FILE_2 | cut
-f4 -d " " >$TEMP_FILE
140 let dropped
=$dropped+$line
143 let total
=$dropped+$traced
144 let wanted
=$NR_APP_ITER*$NR_ITER
146 if [ $wanted -ne $total ]; then
147 fail
"Validate trace event count"
148 diag
"Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
151 pass
"Validate trace event count"
152 diag
"Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
155 rm $TEMP_FILE $TEMP_FILE_2
161 function interrupt_cleanup
()
163 diag
"*** Exiting ***"
165 # invoke utils cleanup
169 plan_tests
$NUM_TESTS
171 print_test_banner
"$TEST_DESC"
173 bail_out_if_no_babeltrace
175 if [ "$(id -u)" == "0" ]; then
181 skip
$isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS ||
184 # Catch sigint and try to cleanup limits
185 trap interrupt_cleanup SIGTERM SIGINT
187 BW_LIMITS
=(3200 1600 800 400 200 100 50 25)
188 for BW
in ${BW_LIMITS[@]};
190 diag
"Test high-throughput with bandwidth limit set to ${BW}kbits"
193 ok $?
"Setting bandwidth limit"
196 start_lttng_relayd
"-o $TRACE_PATH"
202 ok $?
"Reset bandwith limits"