Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 1 | #!/bin/sh |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 2 | # Copyright (c) 2014-2015 Oracle and/or its affiliates. All Rights Reserved. |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 3 | # |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the GNU General Public License as |
| 6 | # published by the Free Software Foundation; either version 2 of |
| 7 | # the License, or (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it would be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program; if not, write the Free Software Foundation, |
| 16 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | # |
| 18 | # Author: Alexey Kodanev <alexey.kodanev@oracle.com> |
| 19 | # |
| 20 | |
| 21 | [ -z "$TST_LIB_LOADED" ] && . test.sh |
| 22 | |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 23 | init_ltp_netspace() |
| 24 | { |
| 25 | if [ ! -f /var/run/netns/ltp_ns ]; then |
| 26 | ROD ip net add ltp_ns |
| 27 | ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2 |
| 28 | ROD ip li set dev ltp_ns_veth1 netns ltp_ns |
Alexey Kodanev | 0a55aff | 2016-12-21 00:07:46 +0300 | [diff] [blame] | 29 | ROD ip netns exec ltp_ns ip li set lo up |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 30 | fi |
| 31 | |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 32 | LHOST_IFACES="${LHOST_IFACES:-ltp_ns_veth2}" |
| 33 | RHOST_IFACES="${RHOST_IFACES:-ltp_ns_veth1}" |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 34 | |
| 35 | export TST_INIT_NETNS="no" |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 36 | export LTP_NETNS="${LTP_NETNS:-ip netns exec ltp_ns}" |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 37 | |
Alexey Kodanev | 3224c57 | 2017-01-19 19:37:56 +0300 | [diff] [blame] | 38 | tst_restore_ipaddr |
| 39 | tst_restore_ipaddr rhost |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 40 | } |
| 41 | |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 42 | # Run command on remote host. |
| 43 | # Options: |
| 44 | # -b run in background |
| 45 | # -s safe option, if something goes wrong, will exit with TBROK |
| 46 | # -c specify command to run |
| 47 | |
| 48 | tst_rhost_run() |
| 49 | { |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 50 | local pre_cmd= |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 51 | local post_cmd=' || echo RTERR' |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 52 | local out= |
| 53 | local user="root" |
| 54 | local cmd= |
| 55 | local safe=0 |
| 56 | |
| 57 | OPTIND=0 |
| 58 | |
| 59 | while getopts :bsc:u: opt; do |
| 60 | case "$opt" in |
Alexey Kodanev | 6902dd9 | 2016-12-17 15:29:19 +0300 | [diff] [blame^] | 61 | b) [ "$TST_USE_NETNS" ] && pre_cmd="" || pre_cmd="nohup" |
| 62 | post_cmd=" > /dev/null 2>&1 &" |
| 63 | out="1> /dev/null" |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 64 | ;; |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 65 | s) safe=1 ;; |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 66 | c) cmd="$OPTARG" ;; |
| 67 | u) user="$OPTARG" ;; |
Alexey Kodanev | 6902dd9 | 2016-12-17 15:29:19 +0300 | [diff] [blame^] | 68 | *) tst_brkm TBROK "tst_rhost_run: unknown option: $OPTARG" ;; |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 69 | esac |
| 70 | done |
| 71 | |
| 72 | OPTIND=0 |
| 73 | |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 74 | if [ -z "$cmd" ]; then |
| 75 | [ "$safe" -eq 1 ] && \ |
| 76 | tst_brkm TBROK "tst_rhost_run: command not defined" |
| 77 | tst_resm TWARN "tst_rhost_run: command not defined" |
| 78 | return 1 |
| 79 | fi |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 80 | |
| 81 | local output= |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 82 | local ret=0 |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 83 | if [ -n "$TST_USE_SSH" ]; then |
| 84 | output=`ssh -n -q $user@$RHOST "sh -c \ |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 85 | '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'` |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 86 | elif [ -n "$TST_USE_NETNS" ]; then |
| 87 | output=`$LTP_NETNS sh -c \ |
| 88 | "$pre_cmd $cmd $post_cmd" $out 2>&1 || echo 'RTERR'` |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 89 | else |
| 90 | output=`rsh -n -l $user $RHOST "sh -c \ |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 91 | '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'` |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 92 | fi |
Alexey Kodanev | eb92f55 | 2015-02-06 12:14:48 +0300 | [diff] [blame] | 93 | echo "$output" | grep -q 'RTERR$' && ret=1 |
| 94 | if [ $ret -eq 1 ]; then |
| 95 | output=$(echo "$output" | sed 's/RTERR//') |
| 96 | [ "$safe" -eq 1 ] && \ |
| 97 | tst_brkm TBROK "'$cmd' failed on '$RHOST': '$output'" |
| 98 | fi |
Alexey Kodanev | 18739ff | 2014-04-03 12:36:23 +0400 | [diff] [blame] | 99 | |
| 100 | [ -z "$out" -a -n "$output" ] && echo "$output" |
| 101 | |
| 102 | return $ret |
| 103 | } |
Alexey Kodanev | 50c8ec3 | 2014-09-16 18:15:55 +0400 | [diff] [blame] | 104 | |
| 105 | # Get test interface names for local/remote host. |
| 106 | # tst_get_ifaces [TYPE] |
| 107 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 108 | tst_get_ifaces() |
| 109 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 110 | local type="${1:-lhost}" |
Alexey Kodanev | 50c8ec3 | 2014-09-16 18:15:55 +0400 | [diff] [blame] | 111 | if [ "$type" = "lhost" ]; then |
| 112 | echo "$LHOST_IFACES" |
| 113 | else |
| 114 | echo "$RHOST_IFACES" |
| 115 | fi |
| 116 | } |
| 117 | |
| 118 | # Get HW addresses from defined test interface names. |
| 119 | # tst_get_hwaddrs [TYPE] |
| 120 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 121 | tst_get_hwaddrs() |
| 122 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 123 | local type="${1:-lhost}" |
Alexey Kodanev | 50c8ec3 | 2014-09-16 18:15:55 +0400 | [diff] [blame] | 124 | local addr= |
| 125 | local list= |
| 126 | |
| 127 | for eth in $(tst_get_ifaces $type); do |
| 128 | |
| 129 | local addr_path="/sys/class/net/${eth}/address" |
| 130 | |
| 131 | case $type in |
| 132 | lhost) addr=$(cat $addr_path) ;; |
| 133 | rhost) addr=$(tst_rhost_run -s -c "cat $addr_path") |
| 134 | esac |
| 135 | |
| 136 | [ -z "$list" ] && list="$addr" || list="$list $addr" |
| 137 | done |
| 138 | echo "$list" |
| 139 | } |
| 140 | |
| 141 | # Get test HW address. |
| 142 | # tst_hwaddr [TYPE] [LINK] |
| 143 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 144 | # LINK: link number starting from 0. Default value is '0'. |
| 145 | tst_hwaddr() |
| 146 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 147 | local type="${1:-lhost}" |
| 148 | local link_num="${2:-0}" |
Alexey Kodanev | 50c8ec3 | 2014-09-16 18:15:55 +0400 | [diff] [blame] | 149 | local hwaddrs= |
| 150 | link_num=$(( $link_num + 1 )) |
| 151 | [ "$type" = "lhost" ] && hwaddrs=$LHOST_HWADDRS || hwaddrs=$RHOST_HWADDRS |
| 152 | echo "$hwaddrs" | awk '{ print $'"$link_num"' }' |
| 153 | } |
| 154 | |
| 155 | # Get test interface name. |
| 156 | # tst_iface [TYPE] [LINK] |
| 157 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 158 | # LINK: link number starting from 0. Default value is '0'. |
| 159 | tst_iface() |
| 160 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 161 | local type="${1:-lhost}" |
| 162 | local link_num="${2:-0}" |
| 163 | link_num="$(( $link_num + 1 ))" |
Alexey Kodanev | 50c8ec3 | 2014-09-16 18:15:55 +0400 | [diff] [blame] | 164 | echo "$(tst_get_ifaces $type)" | awk '{ print $'"$link_num"' }' |
| 165 | } |
Alexey Kodanev | a9ed4f9 | 2014-09-23 14:15:04 +0400 | [diff] [blame] | 166 | |
| 167 | # Blank for an IPV4 test; 6 for an IPV6 test. |
| 168 | TST_IPV6= |
| 169 | |
| 170 | tst_read_opts() |
| 171 | { |
| 172 | OPTIND=0 |
| 173 | while getopts ":6" opt; do |
| 174 | case "$opt" in |
| 175 | 6) |
| 176 | TST_IPV6=6;; |
| 177 | esac |
| 178 | done |
| 179 | OPTIND=0 |
| 180 | } |
| 181 | |
| 182 | tst_read_opts $* |
Alexey Kodanev | 36bf986 | 2014-09-23 17:49:02 +0400 | [diff] [blame] | 183 | |
| 184 | # Get IP address |
| 185 | # tst_ipaddr [TYPE] |
| 186 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 187 | tst_ipaddr() |
| 188 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 189 | local type="${1:-lhost}" |
| 190 | local ipv="${TST_IPV6:-4}" |
Alexey Kodanev | 36bf986 | 2014-09-23 17:49:02 +0400 | [diff] [blame] | 191 | local tst_host= |
| 192 | |
| 193 | if [ "$type" = "lhost" ]; then |
| 194 | eval "tst_host=\$LHOST_IPV${ipv}_HOST" |
| 195 | else |
| 196 | eval "tst_host=\$RHOST_IPV${ipv}_HOST" |
| 197 | fi |
| 198 | |
| 199 | if [ "$TST_IPV6" ]; then |
| 200 | echo "${IPV6_NETWORK}:${tst_host}" |
| 201 | else |
| 202 | echo "${IPV4_NETWORK}.${tst_host}" |
| 203 | fi |
| 204 | } |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 205 | |
| 206 | # tst_init_iface [TYPE] [LINK] |
| 207 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 208 | # LINK: link number starting from 0. Default value is '0'. |
| 209 | tst_init_iface() |
| 210 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 211 | local type="${1:-lhost}" |
| 212 | local link_num="${2:-0}" |
| 213 | local iface="$(tst_iface $type $link_num)" |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 214 | tst_resm TINFO "initialize '$type' '$iface' interface" |
| 215 | |
| 216 | if [ "$type" = "lhost" ]; then |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 217 | ip link set $iface down || return $? |
| 218 | ip route flush dev $iface || return $? |
| 219 | ip addr flush dev $iface || return $? |
| 220 | ip link set $iface up |
| 221 | return $? |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 222 | fi |
| 223 | |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 224 | tst_rhost_run -c "ip link set $iface down" || return $? |
| 225 | tst_rhost_run -c "ip route flush dev $iface" || return $? |
| 226 | tst_rhost_run -c "ip addr flush dev $iface" || return $? |
| 227 | tst_rhost_run -c "ip link set $iface up" |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | # tst_add_ipaddr [TYPE] [LINK] |
| 231 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 232 | # LINK: link number starting from 0. Default value is '0'. |
| 233 | tst_add_ipaddr() |
| 234 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 235 | local type="${1:-lhost}" |
| 236 | local link_num="${2:-0}" |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 237 | |
| 238 | local mask=24 |
| 239 | [ "$TST_IPV6" ] && mask=64 |
| 240 | |
Alexey Kodanev | 910bcd2 | 2015-02-02 19:50:39 +0300 | [diff] [blame] | 241 | local iface=$(tst_iface $type $link_num) |
| 242 | |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 243 | if [ $type = "lhost" ]; then |
| 244 | tst_resm TINFO "set local addr $(tst_ipaddr)/$mask" |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 245 | ip addr add $(tst_ipaddr)/$mask dev $iface |
| 246 | return $? |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 247 | fi |
| 248 | |
| 249 | tst_resm TINFO "set remote addr $(tst_ipaddr rhost)/$mask" |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 250 | tst_rhost_run -c "ip addr add $(tst_ipaddr rhost)/$mask dev $iface" |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | # tst_restore_ipaddr [TYPE] [LINK] |
| 254 | # Restore default ip addresses defined in network.sh |
| 255 | # TYPE: { lhost | rhost }; Default value is 'lhost'. |
| 256 | # LINK: link number starting from 0. Default value is '0'. |
| 257 | tst_restore_ipaddr() |
| 258 | { |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 259 | local type="${1:-lhost}" |
| 260 | local link_num="${2:-0}" |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 261 | |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 262 | tst_init_iface $type $link_num || return $? |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 263 | |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 264 | local ret=0 |
Alexey Kodanev | 910bcd2 | 2015-02-02 19:50:39 +0300 | [diff] [blame] | 265 | local backup_tst_ipv6=$TST_IPV6 |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 266 | TST_IPV6= tst_add_ipaddr $type $link_num || ret=$? |
| 267 | TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$? |
Alexey Kodanev | 910bcd2 | 2015-02-02 19:50:39 +0300 | [diff] [blame] | 268 | TST_IPV6=$backup_tst_ipv6 |
Alexey Kodanev | 27c9302 | 2015-02-02 20:12:47 +0300 | [diff] [blame] | 269 | |
| 270 | return $ret |
Alexey Kodanev | d7dbcef | 2014-10-07 15:01:21 +0400 | [diff] [blame] | 271 | } |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 272 | |
Alexey Kodanev | 1c6ed10 | 2015-08-24 23:15:59 +0300 | [diff] [blame] | 273 | # tst_netload ADDR [FILE] [TYPE] [OPTS] |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 274 | # Run network load test |
| 275 | # ADDR: IP address |
| 276 | # FILE: file with result time |
| 277 | # TYPE: PING or TFO (TCP traffic) |
Alexey Kodanev | 1c6ed10 | 2015-08-24 23:15:59 +0300 | [diff] [blame] | 278 | # OPTS: additional options |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 279 | tst_netload() |
| 280 | { |
| 281 | local ip_addr="$1" |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 282 | local rfile="${2:-netload.res}" |
| 283 | local type="${3:-TFO}" |
| 284 | local addopts="${@:4}" |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 285 | local ret=0 |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 286 | clients_num="${clients_num:-2}" |
| 287 | client_requests="${client_requests:-500000}" |
| 288 | max_requests="${max_requests:-3}" |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 289 | |
| 290 | case "$type" in |
| 291 | PING) |
| 292 | local ipv6= |
| 293 | echo "$ip_addr" | grep ":" > /dev/null |
| 294 | [ $? -eq 0 ] && ipv6=6 |
| 295 | tst_resm TINFO "run ping${ipv6} test with rhost '$ip_addr'..." |
| 296 | local res= |
| 297 | res=$(ping${ipv6} -f -c $client_requests $ip_addr -w 600 2>&1) |
| 298 | [ $? -ne 0 ] && return 1 |
| 299 | echo $res | sed -nE 's/.*time ([0-9]+)ms.*/\1/p' > $rfile |
| 300 | ;; |
| 301 | TFO) |
| 302 | local port= |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 303 | port="$(tst_rhost_run -c 'tst_get_unused_port ipv6 stream')" |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 304 | [ $? -ne 0 ] && tst_brkm TBROK "failed to get unused port" |
| 305 | |
Alexey Kodanev | 85e298f | 2016-10-06 10:25:44 +0300 | [diff] [blame] | 306 | tst_resm TINFO "run netstress with '$ip_addr', port '$port'" |
| 307 | tst_rhost_run -s -b -c "netstress -R $max_requests \ |
Alexey Kodanev | 1c6ed10 | 2015-08-24 23:15:59 +0300 | [diff] [blame] | 308 | -g $port $addopts" |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 309 | |
Alexey Kodanev | 85e298f | 2016-10-06 10:25:44 +0300 | [diff] [blame] | 310 | # check that netstress on rhost in 'Listening' state |
Alexey Kodanev | f8d6f19 | 2015-08-24 19:53:12 +0300 | [diff] [blame] | 311 | local sec_waited= |
| 312 | for sec_waited in $(seq 1 60); do |
Alexey Kodanev | 02bbf72 | 2016-06-30 18:55:56 +0300 | [diff] [blame] | 313 | tst_rhost_run -c "ss -lutn | grep -q $port" && break |
Alexey Kodanev | f8d6f19 | 2015-08-24 19:53:12 +0300 | [diff] [blame] | 314 | if [ $sec_waited -eq 60 ]; then |
| 315 | tst_resm TINFO "rhost not in LISTEN state" |
| 316 | return 1 |
| 317 | fi |
| 318 | sleep 1 |
| 319 | done |
| 320 | |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 321 | # run local tcp client |
Alexey Kodanev | 85e298f | 2016-10-06 10:25:44 +0300 | [diff] [blame] | 322 | netstress -a $clients_num -r $client_requests -l -H $ip_addr\ |
Alexey Kodanev | 6902dd9 | 2016-12-17 15:29:19 +0300 | [diff] [blame^] | 323 | -g $port -d $rfile $addopts || ret=1 |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 324 | |
| 325 | if [ $ret -eq 0 -a ! -f $rfile ]; then |
| 326 | tst_brkm TBROK "can't read $rfile" |
| 327 | fi |
| 328 | |
Alexey Kodanev | 85e298f | 2016-10-06 10:25:44 +0300 | [diff] [blame] | 329 | tst_rhost_run -c "pkill -9 netstress\$" |
Alexey Kodanev | 592ac3c | 2015-07-01 19:28:46 +0300 | [diff] [blame] | 330 | ;; |
| 331 | *) tst_brkm TBROK "invalid net_load type '$type'" ;; |
| 332 | esac |
| 333 | |
| 334 | return $ret |
| 335 | } |
Hangbin Liu | 6c42b44 | 2016-04-27 20:54:34 +0800 | [diff] [blame] | 336 | |
| 337 | # tst_ping [IFACE] [DST ADDR] [MESSAGE SIZE ARRAY] |
| 338 | # Check icmp connectivity |
| 339 | # IFACE: source interface name |
| 340 | # DST ADDR: destination IPv4 or IPv6 address |
| 341 | # MESSAGE SIZE ARRAY: message size array |
| 342 | tst_ping() |
| 343 | { |
| 344 | # The max number of ICMP echo request |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 345 | PING_MAX="${PING_MAX:-500}" |
Hangbin Liu | 6c42b44 | 2016-04-27 20:54:34 +0800 | [diff] [blame] | 346 | |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 347 | local src_iface="${1:-$(tst_iface)}" |
| 348 | local dst_addr="${2:-$(tst_ipaddr rhost)}"; shift 2 |
| 349 | local msg_sizes="$@" |
Hangbin Liu | 6c42b44 | 2016-04-27 20:54:34 +0800 | [diff] [blame] | 350 | local ret=0 |
| 351 | |
| 352 | # ping cmd use 56 as default message size |
| 353 | for size in ${msg_sizes:-"56"}; do |
| 354 | ping$TST_IPV6 -I $src_iface -c $PING_MAX $dst_addr \ |
Alexey Kodanev | 9272a23 | 2016-09-30 21:32:17 +0300 | [diff] [blame] | 355 | -s $size -i 0 > /dev/null 2>&1 |
Hangbin Liu | 6c42b44 | 2016-04-27 20:54:34 +0800 | [diff] [blame] | 356 | ret=$? |
| 357 | if [ $ret -eq 0 ]; then |
| 358 | tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size pass" |
| 359 | else |
| 360 | tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size fail" |
| 361 | break |
| 362 | fi |
| 363 | done |
| 364 | return $ret |
| 365 | } |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 366 | |
| 367 | # Management Link |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 368 | [ -z "$RHOST" ] && TST_USE_NETNS="yes" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 369 | export RHOST="$RHOST" |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 370 | export PASSWD="${PASSWD:-}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 371 | # Don't use it in new tests, use tst_rhost_run() from test_net.sh instead. |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 372 | export LTP_RSH="${LTP_RSH:-rsh -n}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 373 | |
| 374 | # Test Links |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 375 | # Set first three octets of the network address, default is '10.0.0' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 376 | export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 377 | # Set local host last octet, default is '2' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 378 | export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 379 | # Set remote host last octet, default is '1' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 380 | export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 381 | # Set the reverse of IPV4_NETWORK |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 382 | export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 383 | # Set first three octets of the network address, default is 'fd00:1:1:1' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 384 | export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 385 | # Set local host last octet, default is '2' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 386 | export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 387 | # Set remote host last octet, default is '1' |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 388 | export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 389 | # Reverse network portion of the IPv6 address |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 390 | export IPV6_NET_REV="${IPV6_NET_REV:-1.0.0.0.1.0.0.0.1.0.0.0.0.0.d.f}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 391 | # Reverse host portion of the IPv6 address of the local host |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 392 | export LHOST_IPV6_REV="${LHOST_IPV6_REV:-2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 393 | # Reverse host portion of the IPv6 address of the remote host |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 394 | export RHOST_IPV6_REV="${RHOST_IPV6_REV:-1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 395 | |
| 396 | # Networks that aren't reachable through the test links |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 397 | export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}" |
| 398 | export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 399 | |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 400 | export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}" |
| 401 | export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}" |
| 402 | export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}" |
| 403 | export FTP_UPLOAD_URLDIR="${FTP_UPLOAD_URLDIR:-pub}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 404 | |
| 405 | # network/stress tests require additional parameters |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 406 | export NS_DURATION="${NS_DURATION:-3600}" |
| 407 | export NS_TIMES="${NS_TIMES:-10000}" |
| 408 | export CONNECTION_TOTAL="${CONNECTION_TOTAL:-4000}" |
| 409 | export IP_TOTAL="${IP_TOTAL:-10000}" |
| 410 | export IP_TOTAL_FOR_TCPIP="${IP_TOTAL_FOR_TCPIP:-100}" |
| 411 | export ROUTE_TOTAL="${ROUTE_TOTAL:-10000}" |
| 412 | export MTU_CHANGE_TIMES="${MTU_CHANGE_TIMES:-1000}" |
| 413 | export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-10000}" |
| 414 | export DOWNLOAD_BIGFILESIZE="${DOWNLOAD_BIGFILESIZE:-2147483647}" |
| 415 | export DOWNLOAD_REGFILESIZE="${DOWNLOAD_REGFILESIZE:-1048576}" |
| 416 | export UPLOAD_BIGFILESIZE="${UPLOAD_BIGFILESIZE:-2147483647}" |
| 417 | export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}" |
| 418 | export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}" |
| 419 | export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-40000}" |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 420 | |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 421 | [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace |
| 422 | |
| 423 | # Warning: make sure to set valid interface names and IP addresses below. |
| 424 | # Set names for test interfaces, e.g. "eth0 eth1" |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 425 | export LHOST_IFACES="${LHOST_IFACES:-eth0}" |
| 426 | export RHOST_IFACES="${RHOST_IFACES:-eth0}" |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 427 | # Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02" |
Petr Vorel | f61ceb4 | 2017-01-23 15:02:58 +0100 | [diff] [blame] | 428 | export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}" |
| 429 | export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}" |
Alexey Kodanev | 5f8ca6c | 2016-11-11 18:44:08 +0300 | [diff] [blame] | 430 | |
Alexey Kodanev | 6538f7a | 2016-05-06 15:52:44 +0300 | [diff] [blame] | 431 | # More information about network parameters can be found |
| 432 | # in the following document: testcases/network/stress/README |