1#!/bin/sh 2# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz> 3# Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved. 4# Copyright (c) International Business Machines Corp., 2006 5# 6# This program is free software; you can redistribute it and/or 7# modify it under the terms of the GNU General Public License as 8# published by the Free Software Foundation; either version 2 of 9# the License, or (at your option) any later version. 10# 11# This program is distributed in the hope that it would be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <http://www.gnu.org/licenses/>. 18# 19# Author: Petr Vorel <pvorel@suse.cz> 20# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 21# 22# Library for all network/stress/ tests. 23# NOTE: More information about network variables can be found 24# in tst_net.sh and testcases/network/stress/README. 25 26. tst_net.sh 27 28# Netmask of for the tested network 29IPV4_NETMASK="255.255.255.0" 30IPV4_NETMASK_NUM=24 31 32# Multicast address and it's prefix 33MCAST_IPV4_ADDR_PREFIX="224.10" 34MCAST_IPV4_ADDR="${MCAST_IPV4_ADDR_PREFIX}.10.1" 35MCAST_IPV6_ADDR_PREFIX="ff0e::1111" 36MCAST_IPV6_ADDR="${MCAST_IPV6_ADDR_PREFIX}:1" 37 38# Setup for tests using netstress. 39netstress_setup() 40{ 41 TST_NEEDS_ROOT=1 42 tst_test_cmds pgrep pkill 43} 44 45# Cleanup for tests using netstress. 46netstress_cleanup() 47{ 48 # Stop the background TCP traffic 49 pkill -13 -x netstress 50 tst_rhost_run -c "pkill -13 -x netstress" 51} 52 53# restore_ipaddr [TYPE] [LINK] [LOCAL_IFACE] [REMOTE_IFACE] 54# TYPE: { lhost | rhost }; Default value is 'lhost'. 55# LINK: link number starting from 0. Default value is '0'. 56# LOCAL_IFACE: local iface name. 57# REMOTE_IFACE: local iface name. 58restore_ipaddr() 59{ 60 local type="${1:-lhost}" 61 local link_num="${2:-0}" 62 local iface_loc=${3:-$(tst_iface lhost $link_num)} 63 local iface_rmt=${4:-$(tst_iface rhost $link_num)} 64 65 tst_restore_ipaddr $type $link_num || return $? 66 [ $type = "lhost" ] && tst_wait_ipv6_dad $iface_loc $iface_rmt 67} 68 69# Check connectivity with tst_ping. 70# check_connectivity SRC_IFACE DST_ADDR [CNT] 71# SRC_IFACE: source interface name. 72# DST_ADDR: destination IPv4 or IPv6 address. 73# CNT: loop step. 74check_connectivity() 75{ 76 local src_iface="${1}" 77 local dst_addr="${2}" 78 local cnt="${3:-}" 79 local cnt_msg 80 81 [ -n "$cnt" ] && cnt_msg=" (step $cnt)" 82 83 tst_res TINFO "ping through $src_iface iface to ${dst_addr}$cnt_msg" 84 85 tst_ping $src_iface $dst_addr 86} 87 88# check_connectivity_interval CNT [RESTORE] [SRC_IFACE] [DST_ADDR] 89# CNT: loop step. 90# RESTORE: whether restore ip addr. 91# SRC_IFACE: source interface name. 92# DST_ADDR: destination IPv4 or IPv6 address. 93check_connectivity_interval() 94{ 95 local cnt="$1" 96 local restore="${2:-false}" 97 local src_iface="${3:-$(tst_iface)}" 98 local dst_addr="${4:-$(tst_ipaddr rhost)}" 99 100 [ $CHECK_INTERVAL -eq 0 ] && return 101 102 [ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && return 103 104 [ "$restore" != "false" ] && restore_ipaddr 105 106 check_connectivity $src_iface $dst_addr $cnt 107} 108 109# Run netstress process on both lhost and rhost. 110# make_background_tcp_traffic [IP] 111# IP: server IP; Default value is $(tst_ipaddr). 112make_background_tcp_traffic() 113{ 114 pgrep -x netstress > /dev/null && return 115 116 local ip="${1:-$(tst_ipaddr)}" 117 local port=$(tst_get_unused_port ipv${TST_IPVER} stream) 118 119 netstress -R 3 -g $port > /dev/null 2>&1 & 120 tst_rhost_run -b -c "netstress -l -H $ip -g $port" 121} 122 123test_if_ip() 124{ 125 case $1 in 126 1) test_body 'if_cmd';; 127 2) test_body 'ip_cmd';; 128 esac 129} 130 131test_rt_ip() 132{ 133 case $1 in 134 1) test_body 'rt_cmd';; 135 2) test_body 'ip_cmd';; 136 esac 137} 138