All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests
@ 2017-08-18 16:44 Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions Petr Vorel
                   ` (10 more replies)
  0 siblings, 11 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

This is full version of v8 (please ignore 2 patches introduced yesterday in
"[LTP] [RFC PATCH 0/2] Simplify network setup: Add unused IP address helper
functions + test_net_stress.sh")

It's also on https://github.com/pevik/ltp/tree/tst_net_vars.v8

Changes v7->v8:

* Fix all problems you mentioned.
* Add tst_ipaddr_un_host and tst_ipaddr_un_ip
* Fix reset_ltp_netspace() implementation (patch [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace())
* Fix and simplify route "change" tests (route_test_change())

Petr Vorel (11):
  lib/test_net.sh: Add unused IP address helper functions
  network/stress: Add library helper for stress testing
  network/stress: Simplify make_background_tcp_traffic usage
  network/stress: Reduce the default number of cycles for various tests
  lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for
    SSH/RSH
  network/stress: Fix and cleanup part of multicast IPv4 tests
  lib/test_net.sh: Add function reset_ltp_netspace()
  network/stress: Fix and cleanup route IPv4 tests
  network/stress: Further enhancements for route4-rmmod
  network: Add tools for setup IP related environment variables
  network: Use tools to set up IPv4 and IPv6 related variables

 include/tst_net.h                                  | 140 +++++
 testcases/lib/.gitignore                           |   3 +
 testcases/lib/Makefile                             |   2 +-
 testcases/lib/test_net.sh                          | 207 +++++--
 testcases/lib/tst_net_iface_prefix.c               | 173 ++++++
 testcases/lib/tst_net_ip_prefix.c                  | 112 ++++
 testcases/lib/tst_net_vars.c                       | 637 +++++++++++++++++++++
 testcases/network/stress/interface/if-addr-adddel  |  21 +-
 .../network/stress/interface/if-addr-addlarge      |  22 +-
 testcases/network/stress/interface/if-lib.sh       |  73 ---
 testcases/network/stress/interface/if-mtu-change   |  30 +-
 testcases/network/stress/interface/if-route-adddel |  26 +-
 .../network/stress/interface/if-route-addlarge     |  21 +-
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |  21 +-
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 +------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 +-------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 +------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 +-------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 ++++
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_net_stress.sh     | 170 ++++++
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 283 +--------
 testcases/network/stress/route/route4-change-gw    | 305 ++--------
 testcases/network/stress/route/route4-change-if    | 341 ++---------
 testcases/network/stress/route/route4-ifdown       | 284 ++-------
 testcases/network/stress/route/route4-lib.sh       | 145 +++++
 testcases/network/stress/route/route4-redirect     | 223 ++------
 testcases/network/stress/route/route4-rmmod        | 311 +++-------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 31 files changed, 2082 insertions(+), 2526 deletions(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh
 create mode 100644 testcases/network/stress/route/route4-lib.sh

-- 
2.13.2


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-21 13:31   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 02/11] network/stress: Add library helper for stress testing Petr Vorel
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 3 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index c11747a27..6575c77f4 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -219,7 +219,7 @@ tst_ipaddr()
 {
 	local type="${1:-lhost}"
 	local ipv="${TST_IPV6:-4}"
-	local tst_host=
+	local tst_host
 
 	if [ "$type" = "lhost" ]; then
 		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
@@ -234,6 +234,77 @@ tst_ipaddr()
 	fi
 }
 
+# Get IP address of unused network, specified by type and counter.
+# This is useful for generating row of unique addresses based on lhost/rhost.
+# tst_ipaddr_un_host [TYPE] [COUNTER]
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+# COUNTER: Integer value for counting 4th octet and 3rd octet; Default is 1.
+tst_ipaddr_un_host()
+{
+	local type="${1:-lhost}"
+	local counter="${2:-1}"
+	local octet_3 octet_4 max_octet_3 max_octet_4 tmp
+
+	[ $counter -lt 1 ] && counter=1
+	[ "$TST_IPV6" ] && max_octet_3=65535 || max_octet_3=255
+	max_octet_4=$((max_octet_3 - 1))
+	tmp=$((counter * 2))
+	[ "$type" = "rhost" ] && tmp=$((tmp - 1))
+
+	octet_4=$((tmp % max_octet_4))
+	octet_3=$((tmp / max_octet_4))
+
+	if [ $octet_4 -eq 0 ]; then
+		octet_4=$max_octet_4
+		octet_3=$((octet_3 - 1))
+	fi
+
+	[ $octet_3 -gt $max_octet_3 ] && octet_3=$max_octet_3
+	[ $octet_4 -gt $max_octet_4 ] && octet_4=$max_octet_4
+
+	if [ "$TST_IPV6" ]; then
+		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
+		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
+		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
+		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"
+	else
+		echo "${IPV4_NET16_UNUSED}.${octet_3}.${octet_4}"
+	fi
+}
+
+# Get IP address of unused network, specified by 3rd and 4th octet.
+# This is useful when 3rd and/or 4th octet are needed to be defined.
+# tst_ipaddr_un_ip [OCTET_3] [OCTET_4]
+# OCTET_3: Integer or hex value of 3rd octet; Default value is 0.
+# OCTET_4: Integer or hex value of 4th octet; Default value is 0.
+tst_ipaddr_un_ip()
+{
+	local octet_3="${1:-0}"
+	local octet_4="${2:-0}"
+	local max
+
+	[ "$TST_IPV6" ] && max=65535 || max=255
+
+	if [ "$TST_IPV6" ]; then
+		octet_3=$(printf %d $octet_3)
+		octet_4=$(printf %d $octet_4)
+	fi
+
+	[ $octet_3 -lt 0 ] && octet_3=0
+	[ $octet_4 -lt 0 ] && octet_4=1
+	[ $octet_3 -gt $max ] && octet_3=$max
+	[ $octet_4 -gt $max ] && octet_4=$max
+
+	if [ "$TST_IPV6" ]; then
+		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
+		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
+		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
+		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"
+	else
+		echo "${IPV4_NET16_UNUSED}.${octet_3}.${octet_4}"
+	fi
+}
+
 # tst_init_iface [TYPE] [LINK]
 # TYPE: { lhost | rhost }; Default value is 'lhost'.
 # LINK: link number starting from 0. Default value is '0'.
@@ -436,6 +507,7 @@ tst_ping()
 	local src_iface="${1:-$(tst_iface)}"
 	local dst_addr="${2:-$(tst_ipaddr rhost)}"; shift $(( $# >= 2 ? 2 : 0 ))
 	local msg_sizes="$*"
+	local msg="tst_ping IPv${TST_IPV6:-4} iface $src_iface, msg_size"
 	local ret=0
 
 	# ping cmd use 56 as default message size
@@ -444,9 +516,9 @@ tst_ping()
 			-s $size -i 0 > /dev/null 2>&1
 		ret=$?
 		if [ $ret -eq 0 ]; then
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size pass"
+			tst_resm TINFO "$msg $size: pass"
 		else
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size fail"
+			tst_resm TINFO "$msg $size: fail"
 			break
 		fi
 	done
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 02/11] network/stress: Add library helper for stress testing
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

+ use it in interface stress tests

test_net_stress.sh:
* test_net_stress.sh library is intended to be used throughout all
  stress tests reduce duplicity and use code from test_net.sh where
  possible instead of legacy scripts in testcases/network/stress/ns-tools/.
* TCID set automatically from basename.
* Add "unused network" related variables. So far used only IPv4 ones.
* Functions from if-lib.sh moved and (and some renamed) to
  test_net_stress.sh as they are going to be reused in other tests (not
  just interface stress tests).

Interfaces stress tests:
* Interfaces tests use test_net_stress.sh.
* Remove restore_ipaddr from cleanup functions as these functions would
  break netns testing with RTNETLINK errors. Use them just in setup during
  if-mtu-change where are really needed.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/interface/if-addr-adddel  |  15 +-
 .../network/stress/interface/if-addr-addlarge      |  16 +-
 testcases/network/stress/interface/if-lib.sh       |  73 ---------
 testcases/network/stress/interface/if-mtu-change   |  23 +--
 testcases/network/stress/interface/if-route-adddel |  19 +--
 .../network/stress/interface/if-route-addlarge     |  15 +-
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |   4 +-
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_net_stress.sh     | 168 +++++++++++++++++++++
 10 files changed, 208 insertions(+), 136 deletions(-)
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh

diff --git a/testcases/network/stress/interface/if-addr-adddel b/testcases/network/stress/interface/if-addr-adddel
index dcc018a48..42c2d5afa 100644
--- a/testcases/network/stress/interface/if-addr-adddel
+++ b/testcases/network/stress/interface/if-addr-adddel
@@ -18,20 +18,13 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-addr-adddel
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 # The interval of the check interface activity
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -88,7 +81,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		cnt=$(($cnt + 1))
 
@@ -122,7 +115,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
diff --git a/testcases/network/stress/interface/if-addr-addlarge b/testcases/network/stress/interface/if-addr-addlarge
index 9e550068b..e667d9138 100644
--- a/testcases/network/stress/interface/if-addr-addlarge
+++ b/testcases/network/stress/interface/if-addr-addlarge
@@ -18,20 +18,13 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-addr-addlarge
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 # The interval of the check interface activity
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -100,8 +93,7 @@ test_body()
 			return
 		fi
 
-		# Check the connectivity
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -143,7 +135,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
diff --git a/testcases/network/stress/interface/if-lib.sh b/testcases/network/stress/interface/if-lib.sh
deleted file mode 100644
index 4168dd09f..000000000
--- a/testcases/network/stress/interface/if-lib.sh
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
-
-TST_CLEANUP="cleanup"
-
-. test_net.sh
-
-ipver=${TST_IPV6:-4}
-
-IPV4_NET16_UNUSED=${IPV4_NET16_UNUSED:-"10.23"}
-IPV6_NET32_UNUSED=${IPV6_NET32_UNUSED:-"fd00:23"}
-
-setup()
-{
-	tst_require_root
-	tst_check_cmds ip pgrep pkill
-	trap "tst_brkm TBROK 'test interrupted'" INT
-}
-
-cleanup()
-{
-	# Stop the background TCP traffic
-	pkill -13 -x netstress
-	tst_rhost_run -c "pkill -13 -x netstress"
-}
-
-make_background_tcp_traffic()
-{
-	port=$(tst_get_unused_port ipv${ipver} stream)
-	netstress -R 3 -g $port > /dev/null 2>&1 &
-	tst_rhost_run -b -c "netstress -l -H $(tst_ipaddr) -g $port"
-}
-
-check_connectivity()
-{
-	local cnt="$1"
-	local restore="$2"
-
-	[ $CHECK_INTERVAL -eq 0 ] && return
-	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && return
-
-	tst_resm TINFO "check connectivity through $(tst_iface) on step $cnt"
-
-	[ -n "$restore" ] && restore_ipaddr
-
-	tst_ping
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "$(tst_iface) is broken"
-		return 1
-	fi
-	return 0
-}
-
-restore_ipaddr()
-{
-	tst_restore_ipaddr || return $?
-	tst_wait_ipv6_dad
-}
diff --git a/testcases/network/stress/interface/if-mtu-change b/testcases/network/stress/interface/if-mtu-change
index 637fa6389..5900f546a 100644
--- a/testcases/network/stress/interface/if-mtu-change
+++ b/testcases/network/stress/interface/if-mtu-change
@@ -18,9 +18,6 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-mtu-change
-
-. if-lib.sh
 
 TST_CLEANUP="do_cleanup"
 
@@ -33,16 +30,22 @@ CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
 [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
 saved_mtu=
 
+. test_net_stress.sh
+
+do_setup()
+{
+	tst_restore_ipaddr
+	tst_restore_ipaddr rhost
+	tst_wait_ipv6_dad
+}
+
 do_cleanup()
 {
-	cleanup
+	netstress_cleanup
 	if [ "$saved_mtu" ]; then
 		ip li set $(tst_iface) mtu $saved_mtu
 		tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
 	fi
-	tst_restore_ipaddr
-	tst_restore_ipaddr rhost
-	tst_wait_ipv6_dad
 }
 
 test_body()
@@ -59,7 +62,7 @@ test_body()
 	local iface_rmt=$(tst_iface rhost)
 	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
 
-	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times " \
+	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times" \
 	               "every $CHANGE_INTERVAL seconds"
 
 	make_background_tcp_traffic
@@ -98,12 +101,14 @@ test_body()
 	done
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
 saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
 
+do_setup
+
 test_body 'if_cmd'
 test_body 'ip_cmd'
 
diff --git a/testcases/network/stress/interface/if-route-adddel b/testcases/network/stress/interface/if-route-adddel
index 451674178..700e852a8 100644
--- a/testcases/network/stress/interface/if-route-adddel
+++ b/testcases/network/stress/interface/if-route-adddel
@@ -18,19 +18,12 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-route-adddel
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -47,10 +40,10 @@ test_body()
 	local new_rt=
 	local opt_rt=
 	if [ "$TST_IPV6" ]; then
-		new_rt=${IPV6_NET32_UNUSED}::
+		new_rt="$(TST_IPV6=6 tst_ipaddr_un_ip)"
 		opt_rt="/64"
 	else
-		new_rt="${IPV4_NET16_UNUSED}.23.0"
+		new_rt="$(tst_ipaddr_un_ip 23)"
 		case $cmd_type in
 		rt_cmd) ;;
 		ip_cmd) opt_rt='/24' ;;
@@ -86,7 +79,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -97,7 +90,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds route
 
diff --git a/testcases/network/stress/interface/if-route-addlarge b/testcases/network/stress/interface/if-route-addlarge
index e83cf60a7..3337b7225 100644
--- a/testcases/network/stress/interface/if-route-addlarge
+++ b/testcases/network/stress/interface/if-route-addlarge
@@ -18,19 +18,12 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-route-addlarge
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -93,7 +86,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -112,7 +105,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds route
 
diff --git a/testcases/network/stress/interface/if-updown b/testcases/network/stress/interface/if-updown
index deefef639..5ab54a1f8 100644
--- a/testcases/network/stress/interface/if-updown
+++ b/testcases/network/stress/interface/if-updown
@@ -18,12 +18,13 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TOTAL=2
-TCID=if-updown
 
-. if-lib.sh
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 20))}
 
+. test_net_stress.sh
+
 test_body()
 {
 	local cmd_type=$1
@@ -59,7 +60,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt restore_ip || return
+		check_connectivity_interval $cnt restore_ip || return
 
 		cnt=$(($cnt + 1))
 	done
@@ -67,7 +68,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
diff --git a/testcases/network/stress/interface/if4-addr-change b/testcases/network/stress/interface/if4-addr-change
index 54b8fd5fb..567f86643 100644
--- a/testcases/network/stress/interface/if4-addr-change
+++ b/testcases/network/stress/interface/if4-addr-change
@@ -21,12 +21,12 @@ TST_TOTAL=1
 TCID=if4-addr-change
 TST_CLEANUP="do_cleanup"
 
-. test_net.sh
-
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 # Maximum host portion of the IPv4 address on the local host
 LHOST_IPV4_HOST_MAX="254"
 
+. test_net.sh
+
 do_cleanup()
 {
 	tst_restore_ipaddr
diff --git a/testcases/network/stress/ns-tools/Makefile b/testcases/network/stress/ns-tools/Makefile
index 61f85634a..1c186b232 100644
--- a/testcases/network/stress/ns-tools/Makefile
+++ b/testcases/network/stress/ns-tools/Makefile
@@ -29,7 +29,7 @@ INSTALL_TARGETS		:= check_envval get_ifname initialize_if set_ipv4addr \
 			   check_icmpv6_connectivity check_netem check_setkey \
 			   create_file find_portbundle killall_icmp_traffic \
 			   killall_tcp_traffic killall_udp_traffic output_ipsec_conf \
-			   ns-echoclient
+			   ns-echoclient test_net_stress.sh
 
 FILTER_OUT_MAKE_TARGETS	:= ns-common
 
diff --git a/testcases/network/stress/ns-tools/test_net_stress.sh b/testcases/network/stress/ns-tools/test_net_stress.sh
new file mode 100644
index 000000000..6173cc9bc
--- /dev/null
+++ b/testcases/network/stress/ns-tools/test_net_stress.sh
@@ -0,0 +1,168 @@
+#!/bin/sh
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Petr Vorel <pvorel@suse.cz>
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+#
+# Library for all network/stress/ tests.
+# NOTE: More information about network variables can be found
+# in test_net.sh and testcases/network/stress/README.
+
+export TCID="${TCID:-$(basename $0)}"
+
+# using variables IPV4_NET16_UNUSED and various functions
+. test_net.sh
+
+# Netmask of for the tested network
+IPV4_NETMASK="255.255.255.0"
+IPV4_NETMASK_NUM=24
+
+# Prefix of the Multicast Address
+MCAST_IPV4_ADDR_PREFIX="224.10"
+# Multicast Address
+MCAST_IPV4_ADDR="${MCAST_IPV4_ADDR_PREFIX}.10.1"
+
+LINK_TOTAL=$(echo $LHOST_HWADDRS | wc -w)
+RHOST_LINK_TOTAL=$(echo $RHOST_HWADDRS | wc -w)
+[ $LINK_TOTAL -ne $RHOST_LINK_TOTAL ] && \
+	tst_brkm TBROK "the number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" \
+	"($LINK_TOTAL vs. $RHOST_LINK_TOTAL," \
+	"LHOST_HWADDRS: '$LHOST_HWADDRS' RHOST_HWADDRS: '$RHOST_HWADDRS')"
+
+ipver=${TST_IPV6:-4}
+
+# Setup for tests using netstress.
+netstress_setup()
+{
+	tst_require_root
+	tst_check_cmds ip pgrep pkill
+	trap "tst_brkm TBROK 'test interrupted'" INT
+}
+
+# Cleanup for tests using netstress.
+netstress_cleanup()
+{
+	# Stop the background TCP traffic
+	pkill -13 -x netstress
+	tst_rhost_run -c "pkill -13 -x netstress"
+}
+
+# Set an IPv4 address on local/remote interface.
+# tst_add_ipaddr_stress [TYPE] [IP] [LINK]
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+# IP: IP address to be set; Default value is from tst_ipaddr_un_host().
+# LINK: link number starting from 0. Default value is '0'.
+tst_add_ipaddr_stress()
+{
+	local type="${1:-lhost}"
+	local ip="${2:-}"
+	local link_num="${3:-0}"
+	local mask=$IPV4_NETMASK_NUM
+	local iface=$(tst_iface $type $link_num)
+
+	if [ -z "$ip" ]; then
+		[ $type = "lhost" ] && ip=$(tst_ipaddr_un_host) || ip=$(tst_ipaddr_un_host rhost)
+	fi
+
+	cmd="ip addr add $ip/$mask dev $iface"
+	[ $type = "lhost" ] && ROD "$cmd" || tst_rhost_run -s -c "$cmd"
+}
+
+# restore_ipaddr [TYPE] [LINK] [LOCAL_IFACE] [REMOTE_IFACE]
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+# LINK: link number starting from 0. Default value is '0'.
+# LOCAL_IFACE: local iface name.
+# REMOTE_IFACE: local iface name.
+restore_ipaddr()
+{
+	local type="${1:-lhost}"
+	local link_num="${2:-0}"
+	local iface_loc=${3:-$(tst_iface lhost $link_num)}
+	local iface_rmt=${4:-$(tst_iface rhost $link_num)}
+
+	tst_restore_ipaddr $type $link_num || return $?
+	[ $type = "lhost" ] && tst_wait_ipv6_dad $iface_loc $iface_rmt
+}
+
+# Check connectivity with tst_ping.
+# check_connectivity SRC_IFACE DST_ADDR [CNT]
+# SRC_IFACE: source interface name.
+# DST_ADDR: destination IPv4 or IPv6 address.
+# CNT: loop step.
+check_connectivity()
+{
+	local src_iface="${1}"
+	local dst_addr="${2}"
+	local cnt="${3:-}"
+	local cnt_msg
+
+	[ -n "$cnt" ] && cnt_msg=" (step $cnt)"
+
+	tst_resm TINFO "check connectivity through $src_iface iface to ${dst_addr}$cnt_msg"
+
+	tst_ping $src_iface $dst_addr
+	if [ $? -ne 0 ]; then
+		tst_resm TFAIL "$src_iface is broken"
+		return 1
+	fi
+	return 0
+}
+
+# check_connectivity_interval CNT [RESTORE] [SRC_IFACE] [DST_ADDR]
+# CNT: loop step.
+# RESTORE: whether restore ip addr.
+# SRC_IFACE: source interface name.
+# DST_ADDR: destination IPv4 or IPv6 address.
+check_connectivity_interval()
+{
+	local cnt="$1"
+	local restore="${2:-false}"
+	local src_iface="${3:-$(tst_iface)}"
+	local dst_addr="${4:-$(tst_ipaddr rhost)}"
+
+	[ $CHECK_INTERVAL -eq 0 ] && return
+
+	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && return
+
+	[ "$restore" != "false" ] && restore_ipaddr
+
+	check_connectivity $src_iface $dst_addr $cnt
+}
+
+# Run netstress process on both lhost and rhost.
+# make_background_tcp_traffic [IP]
+# IP: server IP; Default value is $(tst_ipaddr).
+make_background_tcp_traffic()
+{
+	local ip="${1:-$(tst_ipaddr)}"
+	local port=$(tst_get_unused_port ipv${ipver} stream)
+
+	netstress -R 3 -g $port > /dev/null 2>&1 &
+	tst_rhost_run -b -c "netstress -l -H $ip -g $port"
+}
+
+# Kill process on local/remote host.
+# kill_daemon CMD [TYPE]
+# CMD: command to kill.
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+kill_daemon()
+{
+	local cmd="pkill -SIGHUP -x $1; tst_sleep 10ms; pkill -9 -x $1"
+	local type="${2:-lhost}"
+	[ $type = "lhost" ] && sh -c "$cmd" || tst_rhost_run -c "$cmd"
+}
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 03/11] network/stress: Simplify make_background_tcp_traffic usage
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 02/11] network/stress: Add library helper for stress testing Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 04/11] network/stress: Reduce the default number of cycles for various tests Petr Vorel
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/interface/if-addr-adddel    | 6 +-----
 testcases/network/stress/interface/if-addr-addlarge  | 6 +-----
 testcases/network/stress/interface/if-mtu-change     | 7 ++-----
 testcases/network/stress/interface/if-route-adddel   | 7 ++-----
 testcases/network/stress/interface/if-route-addlarge | 6 +-----
 testcases/network/stress/ns-tools/test_net_stress.sh | 2 ++
 6 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/testcases/network/stress/interface/if-addr-adddel b/testcases/network/stress/interface/if-addr-adddel
index 42c2d5afa..3b1ab50bb 100644
--- a/testcases/network/stress/interface/if-addr-adddel
+++ b/testcases/network/stress/interface/if-addr-adddel
@@ -53,10 +53,9 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local cnt=1
 	while [ $cnt -le $NS_TIMES ]; do
+		make_background_tcp_traffic
 
 		case $cmd_type in
 		if_cmd)
@@ -85,9 +84,6 @@ test_body()
 
 		cnt=$(($cnt + 1))
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		case $cmd_type in
 		if_cmd)
 			if [ "$TST_IPV6" ]; then
diff --git a/testcases/network/stress/interface/if-addr-addlarge b/testcases/network/stress/interface/if-addr-addlarge
index e667d9138..c3cdb8fa9 100644
--- a/testcases/network/stress/interface/if-addr-addlarge
+++ b/testcases/network/stress/interface/if-addr-addlarge
@@ -47,8 +47,6 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local x=1
 	local y=1
 	local cnt=1
@@ -61,6 +59,7 @@ test_body()
 	fi
 
 	while [ $cnt -le $IP_TOTAL ]; do
+		make_background_tcp_traffic
 
 		if [ "$TST_IPV6" ]; then
 			local hex_x=$(printf '%x' $x)
@@ -95,9 +94,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		case $cmd_type in
 		if_cmd)
 			if [ "$TST_IPV6" ]; then
diff --git a/testcases/network/stress/interface/if-mtu-change b/testcases/network/stress/interface/if-mtu-change
index 5900f546a..62837ae74 100644
--- a/testcases/network/stress/interface/if-mtu-change
+++ b/testcases/network/stress/interface/if-mtu-change
@@ -65,8 +65,6 @@ test_body()
 	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times" \
 	               "every $CHANGE_INTERVAL seconds"
 
-	make_background_tcp_traffic
-
 	mtu_array_len=$(echo $CHANGE_VALUES | wc -w)
 	local cnt=0
 	while [ $cnt -lt $MTU_CHANGE_TIMES ]; do
@@ -76,6 +74,8 @@ test_body()
 		mtu=$(echo $CHANGE_VALUES | cut -d ' ' -f $field)
 		[ $cnt -eq $MTU_CHANGE_TIMES ] && mtu="$saved_mtu"
 
+		make_background_tcp_traffic
+
 		tst_resm TINFO "set MTU to $mtu $cnt/$MTU_CHANGE_TIMES"
 		local ret=0
 		case $cmd_type in
@@ -95,9 +95,6 @@ test_body()
 		tst_sleep $CHANGE_INTERVAL
 
 		EXPECT_PASS tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
-
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
 	done
 }
 
diff --git a/testcases/network/stress/interface/if-route-adddel b/testcases/network/stress/interface/if-route-adddel
index 700e852a8..5189ea597 100644
--- a/testcases/network/stress/interface/if-route-adddel
+++ b/testcases/network/stress/interface/if-route-adddel
@@ -57,10 +57,10 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local cnt=1
 	while [ $cnt -le $NS_TIMES ]; do
+		make_background_tcp_traffic
+
 		case $cmd_type in
 		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
 		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
@@ -81,9 +81,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		cnt=$(($cnt + 1))
 	done
 
diff --git a/testcases/network/stress/interface/if-route-addlarge b/testcases/network/stress/interface/if-route-addlarge
index 3337b7225..b7e6952c2 100644
--- a/testcases/network/stress/interface/if-route-addlarge
+++ b/testcases/network/stress/interface/if-route-addlarge
@@ -54,8 +54,6 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local x=1
 	local y=1
 	local cnt=1
@@ -68,6 +66,7 @@ test_body()
 	fi
 
 	while [ $cnt -le $ROUTE_TOTAL ]; do
+		make_background_tcp_traffic
 
 		if [ "$TST_IPV6" ]; then
 			local hex_x=$(printf '%x' $x)
@@ -88,9 +87,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		cnt=$(($cnt + 1))
 		y=$(($y + 1))
 		if [ $y -gt $xymax ]; then
diff --git a/testcases/network/stress/ns-tools/test_net_stress.sh b/testcases/network/stress/ns-tools/test_net_stress.sh
index 6173cc9bc..d7d082599 100644
--- a/testcases/network/stress/ns-tools/test_net_stress.sh
+++ b/testcases/network/stress/ns-tools/test_net_stress.sh
@@ -149,6 +149,8 @@ check_connectivity_interval()
 # IP: server IP; Default value is $(tst_ipaddr).
 make_background_tcp_traffic()
 {
+	pgrep -x netstress > /dev/null && return
+
 	local ip="${1:-$(tst_ipaddr)}"
 	local port=$(tst_get_unused_port ipv${ipver} stream)
 
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 04/11] network/stress: Reduce the default number of cycles for various tests
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (2 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

Reducing value to one fifth resp. one tenth should be enough even for
stress testing.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 6575c77f4..1357ea5b5 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -621,20 +621,20 @@ export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
 export FTP_UPLOAD_URLDIR="${FTP_UPLOAD_URLDIR:-pub}"
 
 # network/stress tests require additional parameters
-export NS_DURATION="${NS_DURATION:-3600}"
-export NS_TIMES="${NS_TIMES:-10000}"
+export NS_DURATION="${NS_DURATION:-720}"
+export NS_TIMES="${NS_TIMES:-2000}"
 export CONNECTION_TOTAL="${CONNECTION_TOTAL:-4000}"
-export IP_TOTAL="${IP_TOTAL:-10000}"
+export IP_TOTAL="${IP_TOTAL:-2000}"
 export IP_TOTAL_FOR_TCPIP="${IP_TOTAL_FOR_TCPIP:-100}"
-export ROUTE_TOTAL="${ROUTE_TOTAL:-10000}"
+export ROUTE_TOTAL="${ROUTE_TOTAL:-2000}"
 export MTU_CHANGE_TIMES="${MTU_CHANGE_TIMES:-1000}"
-export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-10000}"
+export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-2000}"
 export DOWNLOAD_BIGFILESIZE="${DOWNLOAD_BIGFILESIZE:-2147483647}"
 export DOWNLOAD_REGFILESIZE="${DOWNLOAD_REGFILESIZE:-1048576}"
 export UPLOAD_BIGFILESIZE="${UPLOAD_BIGFILESIZE:-2147483647}"
 export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
-export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-40000}"
+export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
 [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
 
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (3 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 04/11] network/stress: Reduce the default number of cycles for various tests Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-21 13:42   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 1357ea5b5..c4399f637 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -55,7 +55,6 @@ init_ltp_netspace()
 # -b run in background
 # -s safe option, if something goes wrong, will exit with TBROK
 # -c specify command to run
-
 tst_rhost_run()
 {
 	local pre_cmd=
@@ -91,15 +90,16 @@ tst_rhost_run()
 
 	local output=
 	local ret=0
+	local newpath="$LTPROOT/testcases/bin"
 	if [ -n "${TST_USE_SSH:-}" ]; then
-		output=`ssh -n -q $user@$RHOST "sh -c \
-			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
+		output=`ssh -n -q $user@$RHOST "PATH=$newpath:\$PATH \
+			sh -c '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
 	elif [ -n "$TST_USE_NETNS" ]; then
 		output=`$LTP_NETNS sh -c \
 			"$pre_cmd $cmd $post_cmd" $out 2>&1 || echo 'RTERR'`
 	else
-		output=`rsh -n -l $user $RHOST "sh -c \
-			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
+		output=`rsh -n -l $user $RHOST "PATH=$newpath:\$PATH \
+			sh -c '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
 	fi
 	echo "$output" | grep -q 'RTERR$' && ret=1
 	if [ $ret -eq 1 ]; then
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (4 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-21 13:52   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

* Fix test for SSH and netns based testing.
* Remove hardcoded rsh dependency.
* Create shell library mcast4-lib.sh (multicast IPv4 specific)
  to reduce duplicity in tests. Library uses test_stress_net.sh
  (and therefore test_net.sh).
* Cleanup code + fixed typos.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 ++------------------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 ++-------------------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 +++++++++++
 5 files changed, 196 insertions(+), 826 deletions(-)
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh

diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope01 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
index b03ff626b..086ecb1f9 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
@@ -1,211 +1,32 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   mcast4-grpope01
-#
-# Description:
-#   Verify that the kernel is not crashed when joining lots of IPv4 multicast
-#   groups on a single socket
-#
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	May 1 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# The test case ID, the test case count and the total number of test case
-TCID=mcast4-grpope01
-TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# Number of the group
-MCASTNUM_HEAVY=${MCASTNUM_HEAVY:-40000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of the IPv4 network
-NETWORK_MASK=24
-
-# Host portion of the IPv4 address
-LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
-RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
-
-# Prefix of the Multicast Address
-MCAST_ADDR_PREFIX=224.10
-
-
-#-----------------------------------------------------------------------
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Function: do_cleanup
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Recover the system configuration
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to kill the multicast receiver and sender
-    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
-
-    # Clean up each interface
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Function: do_setup
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
 # Description:
-#   Configure the ssystem for the test
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Initialize the system configuration
-    do_cleanup
-
-    # Call do_cleanup function before exit
-    trap do_cleanup 0
-
-    # name of interface of the local/remote host
-    lhost_ifname=`get_ifname lhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set IPv4 addresses to the interfaces
-    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the local host"
-	exit 1
-    fi
-
-    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the remote host"
-	exit 1
-    fi
-
-    # IPv4 address of the local/remote host
-    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
-    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
-
-    # Make sure the connectvity
-    check_icmpv4_connectivity $lhost_ifname $rhost_addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "There is no IPv4 connectivity."
-	exit 1
-    fi
-
-    # Make sure the sysctl values
-    sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_HEAVY >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
-	exit $TST_TOTAL
-    fi
-
-    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
-    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-#
-
-# Test description
-tst_resm TINFO "Verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"
-
-do_setup
-
-# Run a multicast join tool
-tmpfile=$TMPDIR/ns-mcast_join.$$
-ns-mcast_join -f 4 -I $lhost_ifname -n $MCASTNUM_HEAVY -p $MCAST_ADDR_PREFIX > $tmpfile
-if [ $? -ne 0 ]; then
-    tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
-    rm -f $tmpfile
-    exit 1
-fi
-msg=`cat $tmpfile | grep groups`
-tst_resm TINFO "Joined $msg"
-rm -f $tmpfile
-
-# Send IGMP General Query from the remote host
-ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -o -r 1' ; echo $?'`
-if [ $ret -ne 0 ]; then
-    tst_resm TBROK "Failed to start IGMP querier"
-    exit 1
-fi
-
-#-----------------------------------------------------------------------
+# Verify that the kernel is not crashed when joining lots of IPv4 multicast
+# groups on a single socket.
 #
-# Clean up
+# Setup: testcases/network/stress/README
 #
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-while true ; do
-    ps auxw | grep -v grep | grep ns-mcast_join > /dev/null
-    if [ $? -ne 0 ] ; then
-  	break
-    fi
-done
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"
 
-exit 0
+mcast_setup $MCASTNUM_HEAVY
+do_multicast_test_multiple_join $MCASTNUM_HEAVY
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
index 67efac73c..73d244f2a 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
@@ -1,220 +1,28 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   mcast4-grpope02
-#
-# Description:
-#   Verify that the kernel is not crashed when joining lots of IPv4 multicast
-#   groups on lots of sockets
-#
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	May 1 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# The test case ID, the test case count and the total number of test case
-TCID=mcast4-grpope02
-TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# Number of the group
-MCASTNUM_HEAVY=${MCASTNUM_HEAVY:-40000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of the IPv4 network
-NETWORK_MASK=24
-
-# Host portion of the IPv4 address
-LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
-RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
-
-# Prefix of the Multicast Address
-MCAST_ADDR_PREFIX=224.10
-
-
-#-----------------------------------------------------------------------
-#
-# Function: do_cleanup
-#
-# Description:
-#   Recover the system configuration
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to kill the multicast receiver and sender
-    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
-
-    # Clean up each interface
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Function: do_setup
-#
-# Description:
-#   Configure the ssystem for the test
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Initialize the system configuration
-    do_cleanup
-
-    # Call do_cleanup function before exit
-    trap do_cleanup 0
-
-    # Increase the maximum number of open file descriptors
-    fd_num=`ulimit -n`
-    if [ $fd_num -lt $MCASTNUM_HEAVY ]; then
-	ulimit -n $MCASTNUM_HEAVY
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "$MCASTNUM_HEAVY is too many for the file descriptor"
-	fi
-    fi
-
-    # name of interface of the local/remote host
-    lhost_ifname=`get_ifname lhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set IPv4 addresses to the interfaces
-    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the local host"
-	exit 1
-    fi
-
-    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the remote host"
-	exit 1
-    fi
-
-    # IPv4 address of the local/remote host
-    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
-    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
-
-    # Make sure the connectvity
-    check_icmpv4_connectivity $lhost_ifname $rhost_addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "There is no IPv4 connectivity."
-	exit 1
-    fi
-
-    # Make sure the sysctl values
-    sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_HEAVY >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
-	exit $TST_TOTAL
-    fi
-
-    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
-    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
-}
-
-
-#-----------------------------------------------------------------------
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Main
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-
-# Test description
-tst_resm TINFO "Verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on separate sockets"
-
-do_setup
-
-# Run a multicast join tool
-tmpfile=$TMPDIR/ns-mcast_join.$$
-ns-mcast_join -m -f 4 -I $lhost_ifname -n $MCASTNUM_HEAVY -p $MCAST_ADDR_PREFIX > $tmpfile
-if [ $? -ne 0 ]; then
-    tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
-    rm -f $tmpfile
-    exit 1
-fi
-msg=`cat $tmpfile | grep groups`
-tst_resm TINFO "Joined $msg"
-rm -f $tmpfile
-
-# Send IGMP General Query from the remote host
-ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -o -r 1' ; echo $?'`
-if [ $ret -ne 0 ]; then
-    tst_resm TBROK "Failed to start IGMP querier"
-    exit 1
-fi
-
-#-----------------------------------------------------------------------
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Clean up
+# Setup: testcases/network/stress/README
 #
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-while true ; do
-    ps auxw | grep -v grep | grep ns-mcast_join > /dev/null
-    if [ $? -ne 0 ] ; then
-	break
-    fi
-done
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining $MCASTNUM_HEAVY IPv4 multicast groups on separate sockets"
 
-exit 0
+mcast_setup $MCASTNUM_HEAVY true
+do_multicast_test_multiple_join $MCASTNUM_HEAVY true
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope03 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope03
index c44ec2170..15e6d4a2f 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope03
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope03
@@ -1,207 +1,28 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   mcast4-grpope03
-#
-# Description:
-#   Verify that the kernel is not crashed when joining and leaving the same
-#   IPv4 multicast group on multiple sockets lots of times
-#
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	May 2 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# The test case ID, the test case count and the total number of test case
-TCID=mcast4-grpope03
-TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# Number of the socket
-MCASTNUM_NORMAL=${MCASTNUM_NORMAL:-20}
-
-# The number of the join/leave groups
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of the IPv4 network
-NETWORK_MASK=24
-
-# Host portion of the IPv4 address
-LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
-RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
-
-# Multicast Address
-MCAST_ADDR=224.10.10.1
-
-
-#-----------------------------------------------------------------------
-#
-# Function: do_cleanup
-#
-# Description:
-#   Recover the system configuration
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to kill the multicast receiver and sender
-    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
-
-    # Clean up each interface
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Function: do_setup
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Configure the ssystem for the test
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Initialize the system configuration
-    do_cleanup
-
-    # Call do_cleanup function before exit
-    trap do_cleanup 0
-
-    # name of interface of the local/remote host
-    lhost_ifname=`get_ifname lhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set IPv4 addresses to the interfaces
-    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the local host"
-	exit 1
-    fi
-
-    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the remote host"
-	exit 1
-    fi
-
-    # IPv4 address of the local/remote host
-    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
-    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
-
-    # Make sure the connectvity
-    check_icmpv4_connectivity $lhost_ifname $rhost_addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "There is no IPv4 connectivity."
-	exit 1
-    fi
-
-    # Make sure the sysctl values
-    sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_NORMAL >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
-	exit $TST_TOTAL
-    fi
-
-    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
-    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
-}
-
-
-#-----------------------------------------------------------------------
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Main
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
+# Setup: testcases/network/stress/README
 #
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Test description
-tst_resm TINFO "Verify that the kernel is not crashed when joining and leaving the same IPv4 multicast group on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
-
-do_setup
-
-# Send IGMP General Query from the remote host
-ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -i 1000000000 -r 1 -b' ; echo $?'`
-if [ $ret -ne 0 ]; then
-    tst_resm TBROK "Failed to start IGMP querier"
-    exit 1
-fi
-
-# Run a multicast join tool
-num=0
-while [ $num -lt $MCASTNUM_NORMAL ]; do
-    ns-mcast_join -f 4 -I $lhost_ifname -l $NS_TIMES -a $MCAST_ADDR &
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
-	exit 1
-    fi
-    num=`expr $num + 1`
-done
-
-wait
-
-#-----------------------------------------------------------------------
-#
-# Clean up
-#
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining and leaving the same IPv4 multicast group on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
 
-exit 0
+mcast_setup $MCASTNUM_NORMAL
+do_multicast_test_join_leave
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
index 8783928f3..56a066ba4 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
@@ -1,226 +1,28 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   mcast4-grpope04
-#
-# Description:
-#   Verify that the kernel is not crashed when joining and leaving the same
-#   IPv4 multicast group with the different source filter on multiple sockets
-#   lots of times
-#
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	May 2 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# The test case ID, the test case count and the total number of test case
-TCID=mcast4-grpope04
-TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# Number of the socket
-MCASTNUM_NORMAL=${MCASTNUM_NORMAL:-20}
-
-# The number of the join/leave groups
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of the IPv4 network
-NETWORK_MASK=24
-
-# Host portion of the IPv4 address
-LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
-RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
-
-# Multicast Address
-MCAST_ADDR=224.10.10.1
-
-# Prefix of the filter souce adddress
-SOURCE_ADDR_PREFIX="10.10"	# 10.10.x.y
-
-
-#-----------------------------------------------------------------------
-#
-# Function: do_cleanup
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Description:
-#   Recover the system configuration
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to kill the multicast receiver and sender
-    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
-
-    # Clean up each interface
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Function: do_setup
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Description:
-#   Configure the ssystem for the test
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Initialize the system configuration
-    do_cleanup
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-    # Call do_cleanup function before exit
-    trap do_cleanup 0
-
-    # name of interface of the local/remote host
-    lhost_ifname=`get_ifname lhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set IPv4 addresses to the interfaces
-    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the local host"
-	exit 1
-    fi
-
-    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the remote host"
-	exit 1
-    fi
-
-    # IPv4 address of the local/remote host
-    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
-    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
-
-    # Make sure the connectvity
-    check_icmpv4_connectivity $lhost_ifname $rhost_addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "There is no IPv4 connectivity."
-	exit 1
-    fi
-
-    # Make sure the sysctl values
-    sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_NORMAL >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
-	exit $TST_TOTAL
-    fi
-
-    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
-    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-#
-
-# Test description
-tst_resm TINFO "Verify that the kernel is not crashed when joining and leaving ame IPv4 multicast group with different source filters on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
-
-do_setup
-
-# Send IGMP General Query from the remote host
-ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -i 1000000000 -r 1 -b' ; echo $?'`
-if [ $ret -ne 0 ]; then
-    tst_resm TBROK "Failed to start IGMP querier"
-    exit 1
-fi
-
-# Run a multicast join tool
-num=0
-while [ $num -lt $MCASTNUM_NORMAL ]; do
-    # Define the source address
-    x=`expr $num \/ 254`
-    y=`expr $num % 254 + 1`
-    if [ $x -gt 254 ]; then
-	tst_resm TINFO "The number of the connection is less than $num"
-	break
-    fi
-    source_addr="${SOURCE_ADDR_PREFIX}.${x}.${y}"
-
-    if [ `expr $num % 5` -ne 2 ]; then
-	filter="include"
-    else
-	filter="exclude"
-    fi
-
-    ns-mcast_join -f 4 -I $lhost_ifname -l $NS_TIMES -a $MCAST_ADDR -F $filter -s $source_addr &
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
-	exit 1
-    fi
-    num=`expr $num + 1`
-done
-
-wait
-
-#-----------------------------------------------------------------------
-#
-# Clean up
-#
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining and leaving the same IPv4 multicast group with a different source filter on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
 
-exit 0
+mcast_setup $MCASTNUM_NORMAL
+do_multicast_test_join_leave true
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
new file mode 100644
index 000000000..0c74969cf
--- /dev/null
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
@@ -0,0 +1,118 @@
+#!/bin/sh
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Petr Vorel <pvorel@suse.cz>
+#
+# Setup script for mcast4-grpope* tests.
+
+TST_TOTAL=1
+TST_CLEANUP="mcast_cleanup"
+
+. test_net_stress.sh
+
+mcast_setup()
+{
+	local igmp_max_memberships="$1"
+	local increase_max="${2:-}"
+
+	netstress_setup
+	tst_tmpdir
+
+	SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships)
+	SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf)
+	SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version)
+	SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version)
+
+	if [ "$increase_max" ]; then
+		# Increase the maximum number of open file descriptors
+		[ `ulimit -n` -lt $igmp_max_memberships ] && ROD ulimit -n $igmp_max_memberships
+	fi
+
+	ROD sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
+	ROD sysctl -qw net.ipv4.igmp_max_msf=10
+	ROD sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=0
+	ROD sysctl -qw net.ipv4.conf.all.force_igmp_version=0
+}
+
+mcast_cleanup()
+{
+	[ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -qw net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS
+	[ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -qw net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF
+	[ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION
+	[ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION
+
+	pkill -SIGHUP -x ns-mcast_join
+	tst_sleep 10ms
+	pkill -9 -x ns-mcast_join
+
+	tst_rhost_run -c "pkill -SIGHUP -x ns-igmp_querier"
+
+	restore_ipaddr
+	restore_ipaddr rhost
+}
+
+do_multicast_test_multiple_join()
+{
+	local igmp_max_memberships="$1"
+	local param_multi_socket ret tmpfile
+
+	[ "${2:-}" = true ] && param_multi_socket="-m"
+
+	# Run a multicast join tool
+	tmpfile=ns-mcast_join.$$
+
+	EXPECT_PASS ns-mcast_join $param_multi_socket -f 4 -I $(tst_iface) -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX \> $tmpfile
+
+	tst_resm TINFO "joined $(grep groups $tmpfile)"
+
+	# Send IGMP General Query from the remote host
+	EXPECT_RHOST_PASS ns-igmp_querier -I $(tst_iface rhost) -o -r 1 -m $MCAST_IPV4_ADDR
+}
+
+do_multicast_test_join_leave()
+{
+	local define_source_address filter num ret source_addr x y
+
+	[ "$1" = true ] && define_source_address=true
+
+	# Send IGMP General Query from the remote host
+	tst_rhost_run -s -c "ns-igmp_querier -I $(tst_iface rhost) -i 1000000000 -r 1 -b"
+
+	# Run a multicast join tool
+	num=0
+	while [ $num -lt $MCASTNUM_NORMAL ]; do
+		if [ "$define_source_address" ]; then
+			x=$(($num / 254))
+			y=$(($num % 254 + 1))
+			if [ $x -gt 254 ]; then
+				tst_resm TINFO "the number of the connection is less than $num"
+				break
+			fi
+			source_addr="${IPV4_NET16_UNUSED}.${x}.${y}"
+
+			[ $(($num % 5)) -ne 2 ] && filter="include" || filter="exclude"
+			params="-F $filter -s $source_addr"
+		fi
+
+		ns-mcast_join -f 4 -I $(tst_iface) -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &
+		num=$(($num + 1))
+	done
+
+	wait
+
+	tst_resm TPASS "test is finished successfully"
+}
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (5 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-21 15:31   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

This function is useful when we know we broke netns (e.g. by unloading
network driver).

It was necessary to introduce new variable LTP_NETNS_CUSTOM, as after
resetting network namespace there is no way to reset LTP_NETNS variable
for subsequent tests and therefore is (for non-custom variant) always
needed to set it even if netns itself is setup.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index c4399f637..6c2fb6803 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -21,6 +21,16 @@
 
 [ -z "$TST_LIB_LOADED" ] && . test.sh
 
+set_ltp_netns_var()
+{
+	if [ -z "$LTP_NETNS_CUSTOM" ]; then
+		pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
+		export LTP_NETNS="ns_exec $pid net,mnt"
+	else
+		export LTP_NETNS="$LTP_NETNS_CUSTOM"
+	fi
+}
+
 init_ltp_netspace()
 {
 	local pid=
@@ -41,8 +51,7 @@ init_ltp_netspace()
 
 	export TST_INIT_NETNS="no"
 
-	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
-	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
+	set_ltp_netns_var
 
 	tst_restore_ipaddr
 	tst_restore_ipaddr rhost
@@ -50,6 +59,18 @@ init_ltp_netspace()
 	tst_wait_ipv6_dad
 }
 
+# Force to reset netns.
+reset_ltp_netspace()
+{
+	[ -n "$TST_USE_NETNS" ] || return
+
+	tst_resm TINFO "reset netns"
+	ip link delete ltp_ns_veth2 2> /dev/null
+	rm -f /var/run/netns/ltp_ns
+	pkill ns_create
+	init_ltp_netspace
+}
+
 # Run command on remote host.
 # Options:
 # -b run in background
@@ -636,7 +657,9 @@ export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
 export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
-[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
+if [ -n "$TST_USE_NETNS" ]; then
+	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
+fi
 
 # Warning: make sure to set valid interface names and IP addresses below.
 # Set names for test interfaces, e.g. "eth0 eth1"
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (6 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-22 11:46   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

* Fix test for netns based testing (route4-change-if requires to have
  manually set another pair of interfaces).
* Remove rsh dependency.
* Create shell library route4-lib.sh (route IPv4 specific) to reduce
  duplicity in tests. Library uses test_stress_net.sh (and therefore test_net.sh).
* Stop using TST_COUNT, simplify TCID
* Cleanup code, fix typos, update doc.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Tests using route_test_change() use background traffic instead of ns-udpsender
but I fixed it that it uses route. Is it too much overhead? The reason is I'd
like to get rid of all ugly scripts and binaries in
testcases/network/stress/ns-tools, including ns-udpsender.c.
---
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 283 ++---------------
 testcases/network/stress/route/route4-change-gw    | 305 ++----------------
 testcases/network/stress/route/route4-change-if    | 341 +++------------------
 testcases/network/stress/route/route4-ifdown       | 284 +++--------------
 testcases/network/stress/route/route4-lib.sh       | 145 +++++++++
 testcases/network/stress/route/route4-redirect     | 223 +++-----------
 testcases/network/stress/route/route4-rmmod        | 307 ++++---------------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 9 files changed, 424 insertions(+), 1489 deletions(-)
 create mode 100644 testcases/network/stress/route/route4-lib.sh

diff --git a/testcases/network/stress/route/00_Descriptions.txt b/testcases/network/stress/route/00_Descriptions.txt
index 9bcbc5f05..3d3d26999 100644
--- a/testcases/network/stress/route/00_Descriptions.txt
+++ b/testcases/network/stress/route/00_Descriptions.txt
@@ -1,48 +1,47 @@
-route4-change-dst01
+route4-change-dst 1
 	Verify the kernel is not crashed when the destination of an IPv4 route
 	is changed frequently by route command
 
-route4-change-dst02
+route4-change-dst 2
 	Verify the kernel is not crashed when the destination of an IPv4 route
 	is changed frequently by ip command
 
-route4-change-gw01
+route4-change-gw 1
 	Verify the kernel is not crashed when the gateway of an IPv4 route is
 	changed frequently by route command
 
-route4-change-gw02
+route4-change-gw 2
 	Verify the kernel is not crashed when the gateway of an IPv4 route is
 	changed frequently by ip command
 
-route4-change-if01
+route4-change-if 1
 	Verify the kernel is not crashed when the interface of an IPv4 route is
 	changed frequently by route command
 
-route4-change-if02
+route4-change-if 2
 	Verify the kernel is not crashed when the interface of an IPv4 route is
 	changed frequently by ip command
 
-route4-redirect01
+route4-redirect 1
 	Verify the kernel is not crashed when the IPv4 route is modified by
 	ICMP Redirects frequently
 
-route4-ifdown01
+route4-ifdown 1
 	Verify the kernel is not crashed when IPv4 route is add by route command
 	then it is deleted by the interface down with ifconfig command
 
-route4-ifdown02
+route4-ifdown 2
 	Verify the kernel is not crashed when IPv4 route is add by ip command
 	then it is deleted by the interface down with ip command
 
-route4-rmmod01
+route4-rmmod 1
 	Verify the kernel is not crashed when IPv4 route is add by route command
 	then it is deleted by the removing network driver
 
-route4-rmmod02
+route4-rmmod 2
 	Verify the kernel is not crashed when IPv4 route is add by ip command
 	then it is deleted by the removing network driver
 
-
 route6-change-dst01
 	Verify the kernel is not crashed when the destination of an IPv6 route
 	is changed frequently by route command
diff --git a/testcases/network/stress/route/route4-change-dst b/testcases/network/stress/route/route4-change-dst
index 3c85555be..e33d79fa4 100644
--- a/testcases/network/stress/route/route4-change-dst
+++ b/testcases/network/stress/route/route4-change-dst
@@ -1,276 +1,45 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-dst
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the destination of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the destination of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 16 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-dst
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
 
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+TST_CLEANUP="route_cleanup"
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+RHOST_GW=$(tst_ipaddr_un_ip $DST_NETWORK_OCTET_3 1)
 
-# The destination network
-DST_NETWORK_PREFIX="10.10"	# destination network would be 10.10.n.0/24
-DST_HOST="5"
-DST_PORT="7"
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-# SET VALUES:
-#   rhost_ipv4addr	- IPv4 Address of the remote host
-#   lhost_ifname	- Interface name of the local host
-#   rhost_ifname	- Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    TCID=route4-change-dst
-    TST_COUNT=0
-
-    # Initialize the interfaces of the remote host
-    initialize_if rhost ${LINK_NUM}
-
-    # Set IPv4 address to the interfaces
-    set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add an IPv4 address the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # IPv4 address of the remote host (gateway)
-    rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
-
-    # Get the Interface name of local host
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the Interface name of remote host
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-}
-
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	route_setup
+	tst_add_ipaddr_stress lhost $RHOST_GW
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-dst0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the destination of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    # Initialize the interface of the local host
-    initialize_if lhost ${LINK_NUM}
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-    lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-
-    # Check the connectivity to the gateway
-    check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	return 1
-    fi
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Define the destination IP address
-	dst_network_postfix=`expr $cnt % 255`
-	dst_addr=${DST_NETWORK_PREFIX}.${dst_network_postfix}.${DST_HOST}
-	dst_network=${DST_NETWORK_PREFIX}.${dst_network_postfix}.0
-
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
-
-	# Load the route with UDP datagram
-	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Delete the route
-	case $test_type in
-	    1)
-	    route del -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route del ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Cannot delte the route to ${ADDDEL_ROUTE}"
-	    return 1
-	fi
-
-	cnt=`expr $cnt + 1`
-    done
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
 
-exit $RC
+for cmd_name in 'rt_cmd' 'ip_cmd'; do
+	route_test_change "dst" $cmd_name $RHOST_GW
+done
+
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-gw b/testcases/network/stress/route/route4-change-gw
index a9a91cca6..9ab12fad7 100644
--- a/testcases/network/stress/route/route4-change-gw
+++ b/testcases/network/stress/route/route4-change-gw
@@ -1,292 +1,55 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-gw
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the gateway of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the gateway of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 16 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-gw
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
 
-# Netmask of for the tested network
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+TST_CLEANUP="route_cleanup"
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
-RHOST_IPV4_HOST_TOP="10"	# gateway
-RHOST_IPV4_HOST_LAST=19
+RHOST_COUNTER_START=5
+RHOST_COUNTER_COUNT=10
+RHOST_DST_ADDR=$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $RHOST_COUNTER_COUNT)))
 
-# The destination network
-DST_NETWORK="10.10.0"	# destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-# SET VALUES:
-#   rhost_ipv4addr	- IPv4 Address of the remote host
-#   lhost_ifname	- Interface name of the local host
-#   rhost_ifname	- Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    TCID=route4-change-gw
-    TST_COUNT=0
-
-    # Get the Interface name of local host
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the Interface name of remote host
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Initialize the interfaces of the remote host
-    initialize_if rhost ${LINK_NUM}
-
-    # Set IPv4 address to the interface of the remote host
-    rhost_part=$RHOST_IPV4_HOST_TOP
-    while [ $rhost_part -le $RHOST_IPV4_HOST_LAST ]; do
-	ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ip addr add '${IPV4_NETWORK}.${rhost_part}/${IPV4_NETMASK_NUM}' broadcast '${IPV4_NETWORK}'.255 dev '$rhost_ifname' ) > /dev/null ; echo $?'`
-	if [ $ret -ne 0 ]; then
-	    tst_resm TBROK "Failed to assign IP address to the interface at the remote host"
-	    exit $TST_TOTAL
-	fi
-	rhost_part=`expr $rhost_part + 1`
-    done
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    killall -SIGHUP ns-udpsender >/dev/null 2>&1
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-gw0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the gateway of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    # Initialize the interface of the local host
-    initialize_if lhost ${LINK_NUM}
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-
-    # Check the connectivity to the gateway
-    rhost_part=$RHOST_IPV4_HOST_TOP
-    check_icmpv4_connectivity $lhost_ifname ${IPV4_NETWORK}.${rhost_part}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	return 1
-    fi
+	local cnt=0
 
-    # Set the variables regarding the destination host
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+	route_setup
+	tst_add_ipaddr_stress
 
-    # Set the first route
-    case $test_type in
-	1)
-	route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	;;
-	2)
-	ip route add ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	;;
-    esac
-
-    # Load the route with UDP traffic
-    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-    if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Failed to run a UDP datagram sender"
-	return 1
-    fi
-
-    # Loop for changing the route
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	pre_rhost_part=$rhost_part
-	rhost_part=`expr $rhost_part + 1`
-	if [ $rhost_part -gt $RHOST_IPV4_HOST_LAST ]; then
-	    rhost_part=$RHOST_IPV4_HOST_TOP
-	fi
-
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	    route del -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${pre_rhost_part} dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route change ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to change the gateway to ${IPV4_NETWORK}.${rhost_part}"
-	    return 1
-	fi
-
-	# Rerun if udp datagram sender is dead
-	ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null
-	if [ $? -ne 0 ]; then
-	    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-	    if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Failed to run a UDP datagram sender"
-		return 1
-	    fi
-	fi
-
-	cnt=`expr $cnt + 1`
-    done
-
-    # Kill the udp datagram sender
-    killall -SIGHUP ns-udpsender >/dev/null 2>&1
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
+	while [ $cnt -lt $RHOST_COUNTER_COUNT ]; do
+		tst_add_ipaddr_stress rhost $(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt)))
+		cnt=$(($cnt + 1))
+	done
+	tst_add_ipaddr_stress rhost $RHOST_DST_ADDR
 }
 
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
 
-exit $RC
+for cmd_name in 'rt_cmd' 'ip_cmd'; do
+	route_test_change "gw" $cmd_name $RHOST_DST_ADDR
+done
+
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-if b/testcases/network/stress/route/route4-change-if
index 33fc3755c..e2075d304 100644
--- a/testcases/network/stress/route/route4-change-if
+++ b/testcases/network/stress/route/route4-change-if
@@ -1,324 +1,77 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-if
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the interface of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the interface of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 17 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-if
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The first 2 ocnted of the Network portion of the gateway address
-IPV4_NETWORK_PRE=${IPV4_NETWORK_PRE:-"10.0"}
 
-# Netmask of for the gateway
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+TST_CLEANUP="do_cleanup"
 
-# The destination network
-DST_NETWORK="10.10.0"	# destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
+RHOST_DST_ADDR=$(tst_ipaddr_un_ip $DST_NETWORK_OCTET_3 5)
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-# SET VALUES:
-#   rhost_ipv4addr	- IPv4 Address of the remote host
-#   lhost_ifname	- Interface name of the local host
-#   rhost_ifname	- Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    TCID=route4-change-if
-    TST_COUNT=0
-
-    # Get the number of the test links
-    link_total=`echo $LHOST_HWADDRS | wc -w`
-    rhost_link_total=`echo $RHOST_HWADDRS | wc -w`
-    if [ $link_total -ne $rhost_link_total ]; then
-	tst_resm TBROK "The number of element in LHOST_HWADDRS differs from RHOST_HWADDRS"
-	exit $TST_TOTAL
-    fi
-    if [ $link_total -lt 2 ]; then
-	tst_resm TBROK "This test case requires plural Test Links"
-	exit $TST_TOTAL
-    fi
+	local link_num=0
+	local lhost_ip rhost_ip
 
-    lhost_ifname_array=""
-    rhost_ifname_array=""
-    link_num=0
-    while [ $link_num -lt $link_total ]; do
-	# Get the Interface names of the local host
-	lhost_ifname=`get_ifname lhost ${link_num}`
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to get the interface name at the local host"
-	    exit $TST_TOTAL
-	fi
-	lhost_ifname_array="$lhost_ifname_array $lhost_ifname"
+	route_setup
 
-	# Get the Interface names of the remote host
-	rhost_ifname=`get_ifname rhost ${link_num}`
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to get the interface name at the remote host"
-	    exit $TST_TOTAL
-	fi
-	rhost_ifname_array="$rhost_ifname_array $rhost_ifname"
+	[ $LINK_TOTAL -lt 2 ] && \
+		tst_brkm TCONF "this test case requires more than one test link in LHOST_HWADDRS variable"
 
-	# Initialize the interfaces of the remote host
-	initialize_if rhost ${link_num}
+	while [ $link_num -lt $LINK_TOTAL ]; do
+		lhost_ip=$(tst_ipaddr_un_ip $link_num $LHOST_IPV4_HOST)
+		rhost_ip=$(tst_ipaddr_un_ip $link_num $RHOST_IPV4_HOST)
+		tst_add_ipaddr_stress lhost $lhost_ip $link_num
+		tst_add_ipaddr_stress rhost $rhost_ip $link_num
 
-	# Set IPv4 address to the interface of the remote host
-	set_ipv4addr rhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${RHOST_IPV4_HOST}
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to assign IP address to the interface $rhost_ifname at the remote host"
-	    exit $TST_TOTAL
-	fi
+		check_connectivity $(tst_iface lhost $link_num) $rhost_ip
+		link_num=$(($link_num + 1))
+	done
 
-	link_num=`expr $link_num + 1`
-    done
+	tst_add_ipaddr_stress rhost $RHOST_DST_ADDR
 }
 
-
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Make sure to kill the udp datagram sender
-    killall -SIGHUP ns-udpsender >/dev/null 2>&1
-
-    # Initialize the interfaces
-    link_num=0
-    while [ $link_num -lt $link_total ]; do
-	initialize_if lhost ${link_num}
-	initialize_if rhost ${link_num}
-	link_num=`expr $link_num + 1`
-    done
-}
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-if0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the interface of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    link_num=0
-    while [ $link_num -lt $link_total ]; do
-	# Initialize the interface of the local host
-	initialize_if lhost ${link_num}
-
-	# Assign IPv4 address to the interface of the local host
-	set_ipv4addr lhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${LHOST_IPV4_HOST}
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	    return 1
-	fi
-
-	# Check the connectivity to the gateway
-	field=`expr $link_num + 1`
-	lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field`
-	check_icmpv4_connectivity $lhost_ifname "${IPV4_NETWORK_PRE}.${link_num}.${LHOST_IPV4_HOST}"
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $link_num is somthing wrong."
-	    return 1
-	fi
-	link_num=`expr $link_num + 1`
-    done
-
-    # Set the variables regarding the destination host
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
-
-    # Set the first route
-    link_num=0
-    field=`expr $link_num + 1`
-    lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field`
-    gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
-    case $test_type in
-	1)
-	route add -net $dst_network netmask 255.255.255.0 gw $gateway dev $lhost_ifname
-	;;
-	2)
-	ip route add ${dst_network}/24 via $gateway dev $lhost_ifname
-	;;
-    esac
-
-    # Load the route with UDP traffic
-    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-    if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Failed to run a UDP datagram sender"
-	return 1
-    fi
+	local link_num=0
 
-    # Loop for changing the route
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	link_num=`expr $link_num + 1`
-	if [ $link_num -ge $link_total ]; then
-	    link_num=0
-	fi
+	netstress_cleanup
 
-	pre_lhost_ifname=$lhost_ifname
-	pre_gateway=$gateway
-
-	field=`expr $link_num + 1`
-	lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field`
-	gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
-
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $gateway dev $lhost_ifname
-	    route del -net $dst_network netmask 255.255.255.0 gw $pre_gateway dev $pre_lhost_ifname
-	    ;;
-	    2)
-	    ip route change ${dst_network}/24 via $gateway dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to change the gateway to $gateway"
-	    return 1
-	fi
-
-	# Rerun if udp datagram sender is dead
-	ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null
-	if [ $? -ne 0 ]; then
-	    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-	    if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Failed to run a UDP datagram sender"
-		return 1
-	    fi
-	fi
-
-	cnt=`expr $cnt + 1`
-    done
-
-    # Kill the udp datagram sender
-    killall -SIGHUP ns-udpsender
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
+	while [ $link_num -lt $LINK_TOTAL ]; do
+		lhost_ip=$(tst_ipaddr_un_ip $link_num $LHOST_IPV4_HOST)
+		rhost_ip=$(tst_ipaddr_un_ip $link_num $RHOST_IPV4_HOST)
+		ip addr del $lhost_ip/$IPV4_NETMASK_NUM dev $(tst_iface lhost $link_num)
+		tst_rhost_run -c "ip addr del $rhost_ip/$IPV4_NETMASK_NUM dev $(tst_iface rhost $link_num)"
+		link_num=$(($link_num + 1))
+	done
 }
 
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
 
-exit $RC
+for cmd_name in 'rt_cmd' 'ip_cmd'; do
+	route_test_change "if" $cmd_name $RHOST_DST_ADDR
+done
+
+tst_exit
diff --git a/testcases/network/stress/route/route4-ifdown b/testcases/network/stress/route/route4-ifdown
index e7ce1b4fe..275273efa 100644
--- a/testcases/network/stress/route/route4-ifdown
+++ b/testcases/network/stress/route/route4-ifdown
@@ -1,261 +1,79 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route4-ifdown
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Description:
-#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
-#   by the interface down
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-ifdown
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv4 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
-
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
-
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+. route4-lib.sh
 
+TST_CLEANUP="route_cleanup"
 
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-# SET VALUES:
-#   rhost_ipv4addr	- IPv4 Address of the remote host
-#   lhost_ifname	- Interface name of the local host
-#   rhost_ifname	- Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Make sure to clean up
-    do_cleanup
+	route_setup
 
-    # Set IPv4 address to the interfaces of the remote host
-    set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add an IPv4 address the remote host"
-	exit $TST_TOTAL
-    fi
-    rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-    lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-
-    # Get the Interface names
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+	tst_add_ipaddr_stress
+	tst_add_ipaddr_stress rhost
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    test_type=$1
-
-    TCID=route4-ifdown0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by the interface down with ifconfing command in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by the interface down with ip command in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
+	local cmd_type=$1
+	local cmd_name="$(get_cmd $cmd_type)"
+	local cnt=0
+	local cmd cmd2
+
+	if [ "$cmd_type" = 'ifconfig_cmd' ]; then
+		cmd="$cmd_name $(tst_iface) down"
+		cmd2="$cmd_name $(tst_iface) up"
+	else
+		cmd="$cmd_name link set down dev $(tst_iface)"
+		cmd2="$cmd_name link set up dev $(tst_iface)"
 	fi
 
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
+	tst_resm TINFO "IPv4 route is added and deleted by '$cmd_name' command $NS_TIMES times"
 
-	# Load the route with UDP datagram
-	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Down then up the interface
-	case $test_type in
-	    1)
-	    ifconfig $lhost_ifname down && ifconfig $lhost_ifname up
-	    ;;
-	    2)
-	    ip link set down dev $lhost_ifname && ip link set up dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to down/up the interface"
-	    return 1
-	fi
+	while [ $cnt -lt $NS_TIMES ]; do
+		make_background_tcp_traffic $(tst_ipaddr_un_host)
+		check_connectivity_interval $cnt false $(tst_iface) $(tst_ipaddr_un_host rhost)
 
-	cnt=`expr $cnt + 1`
-    done
+		$cmd
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to down the interface"
+			return
+		fi
 
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
+		$cmd2
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to up the interface"
+			return
+		fi
 
+		cnt=$(($cnt + 1))
+	done
 
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
+	tst_resm TPASS "test is finished correctly"
+}
 
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
+test_body 'ifconfig_cmd'
+test_body 'ip_cmd'
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
new file mode 100644
index 000000000..66a96320c
--- /dev/null
+++ b/testcases/network/stress/route/route4-lib.sh
@@ -0,0 +1,145 @@
+#!/bin/sh
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Setup script for route4-* tests.
+#
+# More information about network parameters can be found
+# in the following document: testcases/network/stress/README
+#
+# Author: Petr Vorel <pvorel@suse.cz>
+
+. test_net_stress.sh
+
+tst_check_cmds ip pgrep route
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
+
+DST_NETWORK_OCTET_3=23
+DST_HOST=5
+
+route_cleanup()
+{
+	netstress_cleanup
+	restore_ipaddr
+	restore_ipaddr rhost
+}
+
+route_setup()
+{
+	netstress_setup
+	tst_check_cmds route
+	route_cleanup
+}
+
+manipulate_route()
+{
+	local cmd_name=$1
+	local task=$2
+	local network=$3
+	local prefix=$4
+	local netmask=$5
+	local gateway=$6
+	local ifname=$7
+
+	[ "$task" = "add" ] || [ "$task" = "del" ] || tst_brkm TBROK "wrong task: '$task'"
+
+	if [ "$cmd_name" = "ip" ]; then
+		ROD "$cmd_name route $task $network/$prefix via $gateway dev $ifname"
+	elif [ "$cmd_name" = "route" ]; then
+		ROD "$cmd_name $task -net $network netmask $netmask gw $gateway dev $ifname"
+	else
+		tst_brkm TBROK "wrong command: '$task'"
+	fi
+}
+
+get_cmd()
+{
+	local cmd_type=$1
+
+	case $cmd_type in
+	rt_cmd) echo 'route' ;;
+	ip_cmd) echo 'ip' ;;
+	ifconfig_cmd) echo 'ifconfig' ;;
+	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
+	esac
+}
+
+# helper function for route4-change-{dst,gw,if} tests
+route_test_change()
+{
+	local test_field="$1"
+	local cmd_type="$2"
+	local ip="$3"
+	local dst_network="$(tst_ipaddr_un_ip $DST_NETWORK_OCTET_3)"
+	local gateway="$(tst_ipaddr_un_host rhost)"
+	local lhost_ifname="$(tst_iface)"
+	local cmd_name="$(get_cmd $cmd_type)"
+	local cnt=0 link_num=0
+	local gateway2 lhost_ifname2 pre_dst_network test_field_name
+
+	case $test_field in
+	dst) test_field_name='destination' ;;
+	gw) test_field_name='gateway' ;;
+	if) test_field_name='interface' ;;
+	*) tst_brkm TBROK "Unknown test parameter '$test_field'"
+	esac
+
+	tst_resm TINFO "the $test_field_name of an IPv4 route is changed by '$cmd_name' command $NS_TIMES times"
+
+	if [ "$test_field" = 'dst' ]; then
+		gateway="$ip"
+		gateway2="$gateway"
+	else
+		dst_addr="$ip"
+	fi
+
+	while [ $cnt -lt $NS_TIMES ]; do
+		lhost_ifname2="$lhost_ifname"
+		gateway2="$gateway"
+
+		pre_dst_network="$dst_network"
+		if [ "$test_field" = 'dst' ]; then
+			dst_addr="$(tst_ipaddr_un_ip $(($cnt % 255)) $DST_HOST)"
+			dst_network="$(tst_ipaddr_un_ip $(($cnt % 255)))"
+			netstress_cleanup
+		elif [ "$test_field" = 'gw' ]; then
+			gateway2="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt)))"
+			local cnt2=$(($cnt + 1))
+			[ $cnt2 -eq $RHOST_COUNTER_COUNT ] && cnt2=$RHOST_COUNTER_START
+			gateway="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt2)))"
+		elif [ "$test_field" = 'if' ]; then
+			[ $link_num -ge $LINK_TOTAL ] && link_num=0
+			lhost_ifname="$(tst_iface lhost $link_num)"
+			gateway="$(tst_ipaddr_un_ip $link_num 1)"
+			link_num=$(($link_num + 1))
+		fi
+
+		if [ $cnt -gt 0 ]; then
+			manipulate_route $cmd_name 'del' $pre_dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
+		fi
+
+		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+		make_background_tcp_traffic $(tst_ipaddr_un_host)
+		check_connectivity_interval $cnt false $lhost_ifname $dst_addr || return
+
+		cnt=$(($cnt + 1))
+	done
+
+	manipulate_route $cmd_name 'del' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+
+	tst_resm TPASS "test is finished correctly"
+}
diff --git a/testcases/network/stress/route/route4-redirect b/testcases/network/stress/route/route4-redirect
index 9eb8a4624..578a2c01a 100644
--- a/testcases/network/stress/route/route4-redirect
+++ b/testcases/network/stress/route/route4-redirect
@@ -1,212 +1,73 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-redirect
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the IPv4 route is modified by
-#   ICMP Redirects frequently
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the IPv4 route is modified by
+# ICMP Redirects frequently.
 #
-# History:
-#	Apr 07 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# The test case ID, the test case count and the total number of test case
-TCID=route4-redirect01
 TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Test description
-tst_resm TINFO "Verify the kernel is not crashed when the IPv4 route is modified by  ICMP Redirects frequently"
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK_NUM=24
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+. route4-lib.sh
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
-RHOST_IPV4_HOST="2"	# gateway
+TST_CLEANUP="do_cleanup"
 
-# The destination network
-DST_NETWORK="10.10.0"   # destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
+SYSFS_ACCEPT_REDIRECTS=
+SYSFS_SECURE_REDIRECTS=
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Kill the redirector utility
-    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
+	kill_daemon ns-udpsender
+	restore_ipaddr
+	restore_ipaddr rhost
 
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	kill_daemon ns-icmp_redirector remote
+	[ -n "$SYSFS_ACCEPT_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).accept_redirects=$SYSFS_ACCEPT_REDIRECTS
+	[ -n "$SYSFS_SECURE_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).secure_redirects=$SYSFS_SECURE_REDIRECTS
 }
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Set the initial route and start icmp redirect on the remote host
-#
-# SET VALUES:
-#   rhost_ipv4addr      - IPv4 Address of the remote host
-#   lhost_ifname        - Interface name of the local host
-#   rhost_ifname        - Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Make sure to clean up
-    do_cleanup
-
-    # Get the Interface name of local host
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the Interface name of remote host
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Remove the link-local address of the remote host
-    sleep 3
-    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
+	netstress_setup
 
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
+	SYSFS_ACCEPT_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).accept_redirects)
+	SYSFS_SECURE_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).secure_redirects)
 
-    # Add route to the initial gateway
-    route add -net ${DST_NETWORK}.0 netmask 255.255.255.0 gw ${IPV4_NETWORK}.${RHOST_IPV4_HOST} dev $lhost_ifname
+	tst_add_ipaddr_stress
 
-    # Make sure the sysctl value is set for accepting the redirect
-    sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null
-
-    # Run the redirector utility at the remote host
-    ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
-    if [ $ret -ne 0 ]; then
-	tst_resm TBROK "Failed to run icmp redirector at the remote host"
-	exit $TST_TOTAL
-    fi
+	# Run the redirector utility at the remote host
+	tst_rhost_run -s -c "ns-icmp_redirector -I $(tst_iface rhost) -b"
 }
 
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   None
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    # Loop for changing the route
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to run udp packet sender"
-	    return 1
-	fi
-	cnt=`expr $cnt + 1`
-    done
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
+	local cnt=0
+	tst_resm TINFO "changing IPv4 route by sending UDP packets with ns-udpsender $NS_TIMES times"
+	while [ $cnt -lt $NS_TIMES ]; do
+		ROD ns-udpsender -f 4 -D $(tst_ipaddr_un_host rhost 2) -p 7 -o -s 8
+		cnt=$(($cnt + 1))
+	done
+
+	tst_resm TPASS "test is finished correctly"
 }
 
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-RC=0
 do_setup
-test_body || RC=`expr $RC + 1`
-do_cleanup
+test_body
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 36c8c970d..9c1eade81 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -1,280 +1,107 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route4-rmmod
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Description:
-#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
-#   by the removing network driver
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-rmmod
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv4 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
-
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+. route4-lib.sh
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+TST_CLEANUP="do_cleanup"
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Make sure to load the network driver
-    if [ x${lhost_module} != x ]; then
-	modprobe $lhost_module
-    fi
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	if [ -n "$MODULE" ]; then
+		modprobe $MODULE
+		tst_sleep 100ms
+	fi
+	netstress_cleanup
+	restore_ipaddr
 }
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Check the local host has ethtool utility
-    which ethtool >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "This test case requires ethtool utility"
-	exit $TST_TOTAL
-    fi
+	local ifname module
 
-    # Make sure to clean up
-    do_cleanup
+	route_setup
 
-    # Set IPv4 address to the interfaces of the remote host
-    set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add an IPv4 address the remote host"
-	exit $TST_TOTAL
-    fi
-    rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	tst_check_cmds ethtool
 
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-    lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
+	tst_add_ipaddr_stress
 
-    # Get the Interface names
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
+	# module driver of tested interface
+	MODULE="$(ethtool -i $(tst_iface) | grep driver | sed 's/driver:[[:blank:]]*//')"
 
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
+	# Check the other active interface uses the same driver
+	for ifname in $(ifconfig | grep ^eth | awk '{ print $1}'); do
+		[ "$(tst_iface)" = "$ifname" ] && continue
+		[ "$ifname" = 'lo' ] && continue
 
-    # Get the module name of the interface at the local host
-    lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-
-    # Chack the other active interface uses the same driver
-    for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do
-	if [ $lhost_ifname = $ifname ]; then
-	    continue
-	fi
-
-	module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-	if [ $lhost_module = $module ]; then
-	    tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface."
-	    exit $TST_TOTAL
-	fi
-    done
-
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+		module="$(ethtool -i $ifname | grep driver | sed 's/driver:[[:blank:]]*//')"
+		[ "$module" = "$MODULE" ] && \
+			tst_brkm TCONF "an active interface '$ifname' uses the same network driver '$MODULE' with the test interface '$(tst_iface)'"
+	done
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    test_type=$1
+	local cmd_type=$1
+	local cmd_name="$(get_cmd $cmd_type)"
+	local dst_addr=${DST_NETWORK}.${DST_HOST}
+	local dst_network=${DST_NETWORK}.0
+	local cnt=0
 
-    TCID=route4-rmmod0${test_type}
-    TST_COUNT=$test_type
+	tst_resm TINFO "IPv4 route is added by '$cmd_name' command and then deleted by removing network driver $NS_TIMES times"
 
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
+	while [ $cnt -lt $NS_TIMES ]; do
+		make_background_tcp_traffic $(tst_ipaddr_un_ip)
 
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
-	fi
+		check_connectivity_interval $cnt false $(tst_iface) $(tst_ipaddr_un_host rhost) || return
 
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
+		# Remove and reload the network driver
+		modprobe -r $MODULE
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to remove the network driver '$MODULE'"
+			return
+		fi
 
-	# Load the route with UDP datagram
-	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Remove and reload the network driver
-	rmmod $lhost_module && modprobe $lhost_module
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to unload/reload the network driver"
-	    return 1
-	fi
+		modprobe $MODULE
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to load the network driver '$MODULE'"
+			return
+		fi
 
-	# Make sure to assing the IPv4 address
-	set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1
+		tst_sleep 100ms
 
-	cnt=`expr $cnt + 1`
-    done
+		# If we use netns we need to reset it as unloading kernel module breaks it
+		reset_ltp_netspace
 
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
+		tst_add_ipaddr_stress
 
+		cnt=$(($cnt + 1))
+	done
 
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
+	tst_resm TPASS "test is finished correctly"
+}
 
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
+test_body 'rt_cmd'
+test_body 'ip_cmd'
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route6-change-dst b/testcases/network/stress/route/route6-change-dst
index 33e89e985..649f0cc00 100644
--- a/testcases/network/stress/route/route6-change-dst
+++ b/testcases/network/stress/route/route6-change-dst
@@ -242,7 +242,7 @@ test_body()
 	    ;;
 	esac
 	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Cannot delte the route to ${ADDDEL_ROUTE}"
+	    tst_resm TFAIL "Cannot delete the route to ${ADDDEL_ROUTE}"
 	    return 1
 	fi
 
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 09/11] network/stress: Further enhancements for route4-rmmod
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (7 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables Petr Vorel
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
  10 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

* Remove dependency to ifconfig.
* Use TCONF when test would break other interface.
* Raise TCONF only if the other device is in different than 'down' mode.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/route/route4-rmmod | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 9c1eade81..8cba6a9c1 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -41,20 +41,24 @@ do_setup()
 
 	route_setup
 
+	# NOTE: we have to use ethtool as
+	# /sys/class/net/<iface>/device/driver/module doesn't exist
+	# for virtual drivers (e.g. veth)
 	tst_check_cmds ethtool
 
 	tst_add_ipaddr_stress
 
 	# module driver of tested interface
 	MODULE="$(ethtool -i $(tst_iface) | grep driver | sed 's/driver:[[:blank:]]*//')"
+	[ -z "$MODULE" ] && tst_resm TBROK "module for interface '$(tst_iface)' not found"
 
 	# Check the other active interface uses the same driver
-	for ifname in $(ifconfig | grep ^eth | awk '{ print $1}'); do
+	for ifname in $(basename -a /sys/class/net/*); do
 		[ "$(tst_iface)" = "$ifname" ] && continue
 		[ "$ifname" = 'lo' ] && continue
 
 		module="$(ethtool -i $ifname | grep driver | sed 's/driver:[[:blank:]]*//')"
-		[ "$module" = "$MODULE" ] && \
+		[ "$module" = "$MODULE" -a "$(cat /sys/class/net/$ifname/operstate)" != "down" ] && \
 			tst_brkm TCONF "an active interface '$ifname' uses the same network driver '$MODULE' with the test interface '$(tst_iface)'"
 	done
 }
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (8 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-21  6:10   ` Petr Vorel
  2017-08-22 12:23   ` Alexey Kodanev
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
  10 siblings, 2 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of
test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK
IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX,
IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch
and give feedback and pointed out errors, as well as to Cyril Hrubis who
reviewed orignal version of tst_net_vars.c.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_net.h                    | 140 ++++++++
 testcases/lib/.gitignore             |   3 +
 testcases/lib/Makefile               |   2 +-
 testcases/lib/tst_net_iface_prefix.c | 173 ++++++++++
 testcases/lib/tst_net_ip_prefix.c    | 112 ++++++
 testcases/lib/tst_net_vars.c         | 637 +++++++++++++++++++++++++++++++++++
 6 files changed, 1066 insertions(+), 1 deletion(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c

diff --git a/include/tst_net.h b/include/tst_net.h
new file mode 100644
index 000000000..07ca79825
--- /dev/null
+++ b/include/tst_net.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <arpa/inet.h>
+#include <errno.h>
+
+#define MAX_IPV4_PREFIX 32
+#define MAX_IPV6_PREFIX 128
+
+#define tst_res_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_res(__VA_ARGS__); } \
+
+
+#define tst_brk_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_brk(__VA_ARGS__); } \
+
+static inline void print_svar(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"%s\"\n", name, val);
+}
+
+static inline void print_svar_change(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"${%s:-%s}\"\n", name, name, val);
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc.c.
+ */
+static int bit_count(uint32_t i)
+{
+	int c = 0;
+	unsigned int seen_one = 0;
+
+	while (i > 0) {
+		if (i & 1) {
+			seen_one = 1;
+			c++;
+		} else {
+			if (seen_one)
+				return -1;
+		}
+		i >>= 1;
+	}
+
+	return c;
+}
+
+/*
+ * Function mask2prefix is from ipcalc project, ipcalc.c.
+ */
+static int mask2prefix(struct in_addr mask)
+{
+	return bit_count(ntohl(mask.s_addr));
+}
+
+/*
+ * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
+ */
+static int ipv4_mask_to_int(const char *prefix)
+{
+	int ret;
+	struct in_addr in;
+
+	ret = inet_pton(AF_INET, prefix, &in);
+	if (ret == 0)
+		return -1;
+
+	return mask2prefix(in);
+}
+
+/*
+ * Function safe_atoi is from ipcalc project, ipcalc.c.
+ */
+static int safe_atoi(const char *s, int *ret_i)
+{
+	char *x = NULL;
+	long l;
+
+	errno = 0;
+	l = strtol(s, &x, 0);
+
+	if (!x || x == s || *x || errno)
+		return errno > 0 ? -errno : -EINVAL;
+
+	if ((long)(int)l != l)
+		return -ERANGE;
+
+	*ret_i = (int)l;
+
+	return 0;
+}
+
+/*
+ * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
+ */
+static int get_prefix(const char *ip_str, int is_ipv6)
+{
+	char *prefix_str = NULL;
+	int prefix = -1, r;
+
+	prefix_str = strchr(ip_str, '/');
+	if (!prefix_str)
+		return -1;
+
+	*(prefix_str++) = '\0';
+
+	if (!is_ipv6 && strchr(prefix_str, '.'))
+		prefix = ipv4_mask_to_int(prefix_str);
+	else {
+		r = safe_atoi(prefix_str, &prefix);
+		if (r != 0)
+			tst_brk(TBROK, "conversion error");
+	}
+
+	if (prefix < 0 || ((is_ipv6 && prefix > MAX_IPV6_PREFIX) ||
+		(!is_ipv6 && prefix > MAX_IPV4_PREFIX)))
+		tst_brk(TBROK, "bad %s prefix: %s", is_ipv6 ? "IPv6" : "IPv4",
+			prefix_str);
+
+	return prefix;
+}
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 522889bed..f36ed99fa 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -4,3 +4,6 @@
 /tst_rod
 /tst_kvcmp
 /tst_device
+/tst_net_iface_prefix
+/tst_net_ip_prefix
+/tst_net_vars
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index 1127a59fe..398150ae0 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk
 INSTALL_TARGETS		:= *.sh
 
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
-			   tst_device
+			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_net_iface_prefix.c b/testcases/lib/tst_net_iface_prefix.c
new file mode 100644
index 000000000..7a90b1d9e
--- /dev/null
+++ b/testcases/lib/tst_net_iface_prefix.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+#include "tst_net.h"
+
+typedef struct data {
+	char *ifname;
+	int prefix;
+} data;
+
+static data vars;
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPV4_LHOST/IPV4_LPREFIX\n"
+		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"
+		"%s IPV6_LHOST/IPV6_LPREFIX\n"
+		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
+		"%s IPV4_LHOST\n"
+		"%s -r IPV4_RHOST\n\n"
+		"%s IPV6_LHOST\n"
+		"%s -r IPV6_RHOST\n\n"
+		"%s -h\n\n"
+		"Set prefix and interface name for given IP.\n"
+		"Tries to find prefix and interface from kernel exported info (rtnetlink).\n\n"
+		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"
+		"EXPORTED VARIABLES:\n"
+		"Export one of following variables:\n"
+		"Export one of following variables:\n"
+		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
+		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK\n"
+		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
+		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK\n"
+		"Export one of following variables (if found):\n"
+		"LHOST_IFACES: iface name of the local host (*)\n"
+		"RHOST_IFACES: iface name of the remote host (*)\n\n"
+		"(*): respect user settings\n"
+		"Iface (LHOST_IFACES, RHOST_IFACES) as user might want to use more ifaces.\n\n"
+		"PARAMS:\n"
+		"-h this help\n"
+		"-r export remote environment variables\n",
+		cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd);
+}
+
+static int read_iface_prefix(const char *ip_str, int is_ipv6)
+{
+	uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;
+
+	char buf[16384];
+	int len;
+
+	struct {
+		struct nlmsghdr nlhdr;
+		struct ifaddrmsg addrmsg;
+	} msg;
+
+	struct nlmsghdr *retmsg;
+
+	int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+
+	memset(&msg, 0, sizeof(msg));
+	msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+	msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
+	msg.nlhdr.nlmsg_type = RTM_GETADDR;
+	msg.addrmsg.ifa_family = family;
+
+	send(sock, &msg, msg.nlhdr.nlmsg_len, 0);
+	len = recv(sock, buf, sizeof(buf), 0);
+	retmsg = (struct nlmsghdr *)buf;
+
+	while NLMSG_OK(retmsg, len) {
+		char ifname[IFNAMSIZ];
+		struct ifaddrmsg *retaddr;
+		struct rtattr *retrta;
+		char pradd[128];
+		int attlen;
+
+		retaddr = (struct ifaddrmsg *)NLMSG_DATA(retmsg);
+		retrta = (struct rtattr *)IFA_RTA(retaddr);
+		attlen = IFA_PAYLOAD(retmsg);
+
+		while RTA_OK(retrta, attlen) {
+			if (retrta->rta_type == IFA_ADDRESS) {
+				inet_ntop(family, RTA_DATA(retrta), pradd,
+					  sizeof(pradd));
+
+				if_indextoname(retaddr->ifa_index, ifname);
+
+				if (!strcmp(pradd, ip_str)) {
+					vars.prefix = retaddr->ifa_prefixlen;
+					vars.ifname = strdup(ifname);
+					return 0;
+				}
+			}
+			retrta = RTA_NEXT(retrta, attlen);
+
+		}
+		retmsg = NLMSG_NEXT(retmsg, len);
+	}
+
+	return -1;
+}
+
+static void print_ivar(const char *name, unsigned int val)
+{
+	if (name)
+		printf("export %s=%d\n", name, val);
+}
+
+int main(int argc, char *argv[])
+{
+	char *ip_str = NULL, *prefix_str = NULL;
+	int is_ipv6, is_rhost = 0;
+
+	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
+		!strcmp(argv[1], "--help"));
+	if (argc < 2 || is_usage) {
+		usage(argv[0]);
+		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
+	}
+	if (!strcmp(argv[1], "-r"))
+		is_rhost = 1;
+
+	ip_str = argv[is_rhost ? 2 : 1];
+	is_ipv6 = !!strchr(ip_str, ':');
+
+	prefix_str = strchr(ip_str, '/');
+	if (prefix_str) {
+		vars.prefix = get_prefix(ip_str, is_ipv6);
+		tst_res_comment(TINFO,
+			"IP address '%s' contains prefix %d, using it and don't search for iface.\n",
+			ip_str, vars.prefix);
+	} else if (read_iface_prefix(ip_str, is_ipv6)) {
+		tst_res_comment(TINFO,
+			"prefix and interface not found for '%s'.\n", ip_str);
+		exit(EXIT_SUCCESS);
+	}
+
+	if (is_ipv6) {
+		print_svar_change("LHOST_IFACES", vars.ifname);
+		print_ivar(is_rhost ? "IPV6_RPREFIX" : "IPV6_LPREFIX",
+			vars.prefix);
+	} else {
+		print_svar_change("RHOST_IFACES", vars.ifname);
+		print_ivar(is_rhost ? "IPV4_RPREFIX" : "IPV4_LPREFIX",
+			vars.prefix);
+	}
+
+	exit(EXIT_SUCCESS);
+}
diff --git a/testcases/lib/tst_net_ip_prefix.c b/testcases/lib/tst_net_ip_prefix.c
new file mode 100644
index 000000000..c001641fc
--- /dev/null
+++ b/testcases/lib/tst_net_ip_prefix.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+#include "tst_net.h"
+
+#define DEFAULT_IPV4_PREFIX 24
+#define DEFAULT_IPV6_PREFIX 64
+
+typedef struct data {
+	int prefix;
+} data;
+
+static data vars;
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPV4_LHOST/IPV4_LPREFIX\n"
+		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"
+		"%s IPV6_LHOST/IPV6_LPREFIX\n"
+		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
+		"%s IPV4_LHOST\n"
+		"%s -r IPV4_RHOST\n\n"
+		"%s IPV6_LHOST\n"
+		"%s -r IPV6_RHOST\n\n"
+		"%s -h\n\n"
+		"Set IP without prefix and prefix for given IP.\n"
+		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"
+		"EXPORTED VARIABLES:\n"
+		"Export one of following variables:\n"
+		"IPV4_LHOST: IPv4 address of the local host (without /prefix)\n"
+		"IPV4_RHOST: IPv4 address of the remote host (without /prefix)\n"
+		"IPV6_LHOST: IPv6 address of the local host (without /prefix)\n"
+		"IPV6_RHOST: IPv6 address of the remote host (without /prefix)\n"
+		"Export one of following variables:\n"
+		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
+		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK\n"
+		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
+		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK\n"
+		"Export one of following variables (if found):\n"
+		"Default IPv4 prefix: %d.\n"
+		"Default IPv6 prefix: %d.\n\n"
+		"PARAMS:\n"
+		"-h this help\n"
+		"-r export remote environment variables\n",
+		cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd,
+		DEFAULT_IPV4_PREFIX, DEFAULT_IPV6_PREFIX);
+}
+
+static void print_ivar(const char *name, unsigned int val)
+{
+	if (name)
+		printf("export %s=%d\n", name, val);
+}
+
+int main(int argc, char *argv[])
+{
+	char *ip_str = NULL, *prefix_str = NULL;
+	int is_ipv6, is_rhost = 0;
+
+	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
+		!strcmp(argv[1], "--help"));
+	if (argc < 2 || is_usage) {
+		usage(argv[0]);
+		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
+	}
+	if (!strcmp(argv[1], "-r"))
+		is_rhost = 1;
+
+	ip_str = argv[is_rhost ? 2 : 1];
+	is_ipv6 = !!strchr(ip_str, ':');
+
+	prefix_str = strchr(ip_str, '/');
+	if (prefix_str)
+		vars.prefix = get_prefix(ip_str, is_ipv6);
+	else
+		vars.prefix = is_ipv6 ? DEFAULT_IPV6_PREFIX : DEFAULT_IPV4_PREFIX;
+
+	if (is_ipv6) {
+		print_ivar(is_rhost ? "IPV6_RPREFIX" : "IPV6_LPREFIX",
+			vars.prefix);
+		print_svar(is_rhost ? "IPV6_RHOST" : "IPV6_LHOST", ip_str);
+	} else {
+		print_ivar(is_rhost ? "IPV4_RPREFIX" : "IPV4_LPREFIX",
+			vars.prefix);
+		print_svar(is_rhost ? "IPV4_RHOST" : "IPV4_LHOST", ip_str);
+	}
+
+	exit(EXIT_SUCCESS);
+}
diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
new file mode 100644
index 000000000..17fa03268
--- /dev/null
+++ b/testcases/lib/tst_net_vars.c
@@ -0,0 +1,637 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) 1997-2015 Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2011-2013 Rich Felker, et al.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <assert.h>
+#include <errno.h>
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <stdarg.h>
+
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+#include "tst_net.h"
+
+#define BASE_IPV4_PREFIX 8
+#define BASE_IPV6_PREFIX 16
+
+#define MAX_IPV4_PREFIX 32
+#define MAX_IPV6_PREFIX 128
+
+#define DEFAULT_IPV4_UNUSED_PART1 10
+#define DEFAULT_IPV6_UNUSED_PART1 0xfd
+
+#define DEFAULT_IPV4_UNUSED_PART2 23
+#define DEFAULT_IPV6_UNUSED_PART2 0x23
+
+typedef struct ltp_net_variables {
+	char *ipv4_lbroadcast;
+	char *ipv4_rbroadcast;
+	char *ipv4_lnetmask;
+	char *ipv4_rnetmask;
+	char *ipv4_lnetwork;
+	char *ipv4_rnetwork;
+	char *lhost_ipv4_host;
+	char *rhost_ipv4_host;
+	char *ipv6_lnetmask;
+	char *ipv6_rnetmask;
+	char *ipv6_lnetwork;
+	char *ipv6_rnetwork;
+	char *lhost_ipv6_host;
+	char *rhost_ipv6_host;
+	char *ipv4_net16_unused;
+	char *ipv6_net32_unused;
+	char *lhost_ifaces;
+} ltp_net_variables;
+
+
+static ltp_net_variables vars;
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPV4_LHOST/IPV4_LPREFIX IPV4_RHOST/IPV4_RPREFIX\n"
+		"%s IPV6_LHOST/IPV6_LPREFIX IPV6_RHOST/IPV6_RPREFIX\n\n"
+		"%s IPV4_LHOST IPV4_RHOST\n"
+		"%s IPV6_LHOST IPV6_RHOST\n"
+		"%s -h\n\n"
+		"IP addresses must be different\n"
+		"Exported variables:\n"
+		"IPV4_LBROADCAST: IPv4 broadcast of the local host\n"
+		"IPV4_RBROADCAST: IPv4 broadcast of the remote host\n"
+		"IPV4_LNETMASK: IPv4 netmask of the local host\n"
+		"IPV4_RNETMASK: IPv4 netmask of the remote host\n"
+		"IPV4_LNETWORK: IPv4 network part of IPV4_LHOST\n"
+		"IPV4_RNETWORK: IPv4 network part of IPV4_RHOST\n"
+		"LHOST_IPV4_HOST IPv4 host part of IPV4_LHOST\n"
+		"RHOST_IPV4_HOST IPv4 host part of IPV4_RHOST\n"
+		"IPV4_NET16_UNUSED: IPv4 16 bit unused subnet\n"
+		"IPV6_LNETMASK: IPv6 netmask of the local host\n"
+		"IPV6_RNETMASK: IPv6 netmask of the remote host (*)\n"
+		"IPV6_LNETWORK: IPv6 network part of IPV6_LHOST\n"
+		"IPV6_RNETWORK: IPv6 network part of IPV6_LHOST\n"
+		"LHOST_IPV6_HOST: IPv6 unique part of IPV6_LHOST\n"
+		"RHOST_IPV6_HOST: IPv6 unique part of IPV6_RHOST\n"
+		"IPV6_NET32_UNUSED: IPv6 32 bit unused subnet\n"
+		"(*): respect user settings:\n"
+		"NOTE: Prefixes, ifaces and lhosts are expected to be set by tst_net_iface_prefix.\n"
+		"OPTIONS:\n"
+		"-h this help\n",
+		cmd, cmd, cmd, cmd, cmd);
+}
+
+static void get_in_addr(const char *ip_str, struct in_addr *ip)
+{
+	if (inet_pton(AF_INET, ip_str, ip) <= 0)
+		tst_brk_comment(TCONF, "bad IPv4 address: '%s'", ip_str);
+}
+
+static void get_in6_addr(const char *ip_str, struct in6_addr *ip6)
+{
+	if (inet_pton(AF_INET6, ip_str, ip6) <= 0)
+		tst_brk_comment(TCONF, "bad IPv6 address: '%s'", ip_str);
+}
+
+/*
+ * Function prefix2mask is from ipcalc project, ipcalc.c.
+ */
+static struct in_addr prefix2mask(unsigned int prefix)
+{
+	struct in_addr mask = {0};
+
+	if (prefix)
+		mask.s_addr = htonl(~((1 << (32 - prefix)) - 1));
+	else
+		mask.s_addr = htonl(0);
+
+	return mask;
+}
+
+/*
+ * Function calc_network is based on ipcalc project,
+ * calc_network/ipcalc.c.
+ */
+static struct in_addr calc_network(const struct in_addr *ip, struct in_addr *mask)
+{
+	struct in_addr network = {0};
+
+	network.s_addr = ip->s_addr & mask->s_addr;
+	return network;
+}
+
+static int is_in_subnet_ipv4(const struct in_addr *network,
+	const struct in_addr *mask, const struct in_addr *ip)
+{
+	return (ip->s_addr & mask->s_addr) ==
+		(network->s_addr & mask->s_addr);
+}
+
+static int is_in_subnet_ipv6(const struct in6_addr *network,
+	const struct in6_addr *mask, const struct in6_addr *ip6)
+{
+	unsigned int i;
+
+	for (i = 0; i < sizeof(struct in6_addr) / sizeof(int); i++) {
+		if (((((int *) ip6)[i] & ((int *) mask)[i])) !=
+			(((int *) network)[i] & ((int *) mask)[i]))
+			return 0;
+	}
+	return 1;
+}
+
+/*
+ * Function get_ipv4_netmask uses code from calc_network, which is from
+ * ipcalc project, ipcalc.c.
+ */
+static char *get_ipv4_netmask(unsigned int prefix)
+{
+	char buf[INET_ADDRSTRLEN + 1];
+	struct in_addr mask = prefix2mask(prefix);
+
+	if (prefix > MAX_IPV4_PREFIX)
+		return NULL;
+
+	if (!inet_ntop(AF_INET, &mask, buf, sizeof(buf)))
+		tst_brk_comment(TCONF, "error calculating IPv4 address");
+
+	return strdup(buf);
+}
+
+/*
+ * Function get_ipv4_netmask uses code from ipv6_prefix_to_mask and
+ * ipv6_mask_to_str, which are from ipcalc project, ipcalc.c.
+ */
+static char *get_ipv6_netmask(unsigned int prefix)
+{
+	struct in6_addr in6;
+	char buf[128];
+	int i, j;
+
+	if (prefix > MAX_IPV6_PREFIX)
+		return NULL;
+
+	memset(&in6, 0x0, sizeof(in6));
+	for (i = prefix, j = 0; i > 0; i -= 8, j++) {
+		if (i >= 8)
+			in6.s6_addr[j] = 0xff;
+		else
+			in6.s6_addr[j] = (unsigned long)(0xffU << (8 - i));
+	}
+
+	if (!inet_ntop(AF_INET6, &in6, buf, sizeof(buf)))
+		tst_brk_comment(TCONF, "error calculating IPv6 address");
+
+	return strdup(buf);
+}
+
+/*
+ * Function get_ipv4_broadcast uses code from calc_broadcast, which is from
+ * ipcalc project, ipcalc.c.
+ */
+static char *get_ipv4_broadcast(struct in_addr ip, unsigned int prefix)
+{
+	struct in_addr mask = prefix2mask(prefix);
+	struct in_addr broadcast;
+	char buf[INET_ADDRSTRLEN + 1];
+
+	memset(&broadcast, 0, sizeof(broadcast));
+	broadcast.s_addr = (ip.s_addr & mask.s_addr) | ~mask.s_addr;
+
+	if (!inet_ntop(AF_INET, &broadcast, buf, sizeof(buf)))
+		tst_brk_comment(TCONF, "error calculating IPv4 address");
+
+	return strdup(buf);
+}
+
+/*
+ * For unused network we use
+ * DEFAULT_IPV4_UNUSED_PART1:DEFAULT_IPV4_UNUSED_PART2 or
+ * {DEFAULT_IPV4_UNUSED_PART1}.XY, when there is a collision with IP.
+ */
+static char *get_ipv4_net16_unused(const struct in_addr *ip,
+	unsigned int prefix)
+{
+	struct in_addr mask, network;
+	char buf[128], net_unused[128];
+
+	mask = prefix2mask(prefix);
+	network = calc_network(ip, &mask);
+
+	sprintf(net_unused, "%d.%d", DEFAULT_IPV4_UNUSED_PART1,
+			DEFAULT_IPV4_UNUSED_PART2);
+	sprintf(buf, "%s.0.0", net_unused);
+
+	get_in_addr(buf, &network);
+
+	if (!is_in_subnet_ipv4(ip, &mask, &network))
+		return strdup(net_unused);
+
+	srand(time(NULL));
+
+	/* try to randomize second group */
+	sprintf(net_unused, "%d.%d", DEFAULT_IPV4_UNUSED_PART1,
+		(rand() % 128) + (((ip->s_addr >> 8) & 0xff) < 128 ? 128 : 0));
+	sprintf(buf, "%s.0.0", net_unused);
+
+	get_in_addr(buf, &network);
+
+	if (!is_in_subnet_ipv4(ip, &mask, &network))
+		return strdup(net_unused);
+
+	/* try to randomize first group */
+	sprintf(net_unused, "%d.%d", (rand() % 128) + (((ip->s_addr) & 0xff)
+			< 128 ? 128 : 0), DEFAULT_IPV4_UNUSED_PART2);
+	sprintf(buf, "%s.0.0", net_unused);
+
+	get_in_addr(buf, &network);
+
+	if (!is_in_subnet_ipv4(ip, &mask, &network))
+		return strdup(net_unused);
+
+	return NULL;
+}
+
+/*
+ * Function get_ipv6_net32_unused is inspired by ipcalc project,
+ * get_ipv6_info/ipcalc.c.
+ *
+ * For unused network we use DEFAULT_IPV6_UNUSED_PART1:DEFAULT_IPV6_UNUSED_PART2
+ * if no collision with existing IP range.
+ * Otherwise we try to use
+ * {DEFAULT_IPV6_UNUSED_PART1}XY:DEFAULT_IPV6_UNUSED_PART2 or
+ * XY:DEFAULT_IPV6_UNUSED_PART2.
+ */
+static char *get_ipv6_net32_unused(const struct in6_addr *ip6,
+	unsigned int prefix)
+{
+	int i, j;
+	struct in6_addr mask = {0}, network;
+	char buf[128], net_unused[128];
+
+	if (prefix > 128)
+		return NULL;
+
+
+	for (i = prefix, j = 0; i > 0; i -= 8, j++) {
+		if (i >= 8)
+			mask.s6_addr[j] = 0xff;
+		else
+			mask.s6_addr[j] = (unsigned long)(0xffU << (8 - i));
+	}
+
+	sprintf(net_unused, "%x:%x", 256 * DEFAULT_IPV6_UNUSED_PART1,
+			DEFAULT_IPV6_UNUSED_PART2);
+	sprintf(buf, "%s::", net_unused);
+
+	get_in6_addr(buf, &network);
+
+	if (!is_in_subnet_ipv6(ip6, &mask, &network))
+		return strdup(net_unused);
+
+	srand(time(NULL));
+
+	/* try to randomize second group */
+	sprintf(net_unused, "%x:%x", 256 * DEFAULT_IPV6_UNUSED_PART1 +
+			(rand() % 128) + (ip6->s6_addr[1] < 128 ? 128 : 0),
+			DEFAULT_IPV6_UNUSED_PART2);
+	sprintf(buf, "%s::", net_unused);
+
+	get_in6_addr(buf, &network);
+
+	if (!is_in_subnet_ipv6(ip6, &mask, &network))
+		return strdup(net_unused);
+
+	/* try to randomize first group */
+	sprintf(net_unused, "%x:%x",
+			256 * (rand() % 128) + (256 * ip6->s6_addr[0] < 128 ?
+			128 : 0), DEFAULT_IPV6_UNUSED_PART2);
+	sprintf(buf, "%s::", net_unused);
+
+	get_in6_addr(buf, &network);
+
+	if (!is_in_subnet_ipv6(ip6, &mask, &network))
+		return strdup(net_unused);
+
+	return NULL;
+}
+
+/*
+ * Function get_ipv6_network is based on musl libc project,
+ * inet_ntop/inet_ntop.c.
+ */
+static char *get_ipv6_network(const unsigned char *a0, unsigned int prefix)
+{
+	const unsigned char *a = a0;
+	unsigned int i, j, max, best, border = 0;
+	char buf[100];
+	char ret[100];
+	char tmp[100];
+	char *p_ret = ret;
+	char *p_tmp = tmp;
+	size_t offset;
+
+	if (prefix > MAX_IPV6_PREFIX)
+		return NULL;
+
+	if (prefix == MAX_IPV6_PREFIX)
+		return strdup("\0");
+
+	snprintf(buf, sizeof(buf),
+		"%x:%x:%x:%x:%x:%x:%x:%x",
+		256 * a[0] + a[1], 256 * a[2] + a[3],
+		256 * a[4] + a[5], 256 * a[6] + a[7],
+		256 * a[8] + a[9], 256 * a[10] + a[11],
+		256 * a[12] + a[13], 256 * a[14] + a[15]);
+
+	for (i = 0; i < 8; i++) {
+		if (i < prefix >> 4) {
+			border += sprintf(p_tmp, "%x", 256 * a[2 * i] +
+				a[2 * i + 1]);
+			if (i > 0)
+				border++;
+		}
+
+		if (i >= prefix >> 4)
+			break;
+
+		/* ':' only if no leading in host or ending in net */
+		if (i > 0)
+			*p_ret++ = ':';
+
+		offset = sprintf(p_ret, "%x", 256 * a[2 * i] + a[2 * i + 1]);
+		p_ret += offset;
+	}
+
+	*p_ret = '\0';
+
+	/* Find longest /(^0|:)[:0]{2,}/ */
+	for (i = best = 0, max = 2; buf[i]; i++) {
+		if (i && buf[i] != ':')
+			continue;
+		j = strspn(buf + i, ":0");
+
+		if (j > max)
+			best = i, max = j;
+	}
+
+	size_t length = strlen(ret);
+	size_t best_end = best + max - 1;
+
+	if (max > 2 && best < border) {
+		p_ret = ret;
+		/* Replace longest /(^0|:)[:0]{2,}/ with "::" */
+		if (best == 0 && best_end >= border) {
+			/* zeros in whole net part or continue to host */
+			ret[0] = ':';
+			ret[1] = '\0';
+		} else if (best == 0 && best_end < border) {
+			/* zeros on beginning, not whole part */
+			ret[0] = ':';
+			memmove(p_ret + 1, p_ret + best_end, border - best_end
+				+ 1);
+		} else if (best > 0 && best_end >= border) {
+			/* zeros not from beginning to border or continue to host */
+			ret[best] = ':';
+			ret[best + 1] = '\0';
+		} else {
+			/* zeros somewhere in the middle */
+			ret[best] = ':';
+			memmove(p_ret + best + 1, p_ret + best_end,
+					border - best + 1);
+		}
+	}
+
+	if (length < INET6_ADDRSTRLEN)
+		return strdup(ret);
+
+	return NULL;
+}
+
+/*
+ * Strip host part from ip address.
+ */
+static char *get_host_from_ip(const char *ip, const char *net)
+{
+	if (ip == NULL || net == NULL)
+		return NULL;
+
+	char *result = strstr(ip, net);
+
+	if (!result || result != ip)
+		return NULL;
+
+	char *buf = strdup(ip);
+	unsigned int index = strlen(net);
+
+	/* prefix < 8 (IPv4) or 128 (IPv6) */
+	if (index == strlen(ip))
+		return strdup("\0");
+
+	/* prefix > 0 && prefix < 32 (IPv4) or 128 (IPv6) */
+	if (index > 0 && index < strlen(ip)) {
+		int len = strlen(ip) - index - 1;
+		assert(ip[index] == ':' || ip[index] == '.');
+		memmove(buf, buf + index + 1, len);
+		buf[len] = '\0';
+	}
+
+	return buf;
+}
+
+static void check_prefix_range(unsigned int prefix, int is_ipv6, int is_lhost)
+{
+	unsigned int base_prefix = is_ipv6 ? BASE_IPV6_PREFIX :
+		BASE_IPV4_PREFIX;
+	unsigned int max_prefix = is_ipv6 ? MAX_IPV6_PREFIX : MAX_IPV4_PREFIX;
+
+	if (prefix < base_prefix || (is_ipv6 && prefix == 128) ||
+		(!is_ipv6 && prefix == 32))
+		tst_res_comment(TWARN,
+			"prefix %d for %s will be unsuitable for some stress tests which needs %s variable."
+			" To avoid this use prefix >= %d and prefix < %d.",
+			prefix, is_ipv6 ?  "IPv6" : "IPv4",
+			is_ipv6 ? (is_lhost ? "IPV6_LNETWORK" : "IPV6_RNETWORK")
+				: (is_lhost ? "IPV4_LNETWORK" : "IPV4_RNETWORK"),
+			base_prefix, max_prefix);
+}
+
+static char *get_ipv4_network(int ip, unsigned int prefix)
+{
+	char buf[INET_ADDRSTRLEN + 1];
+	char *p_buf = buf;
+	unsigned char byte;
+	unsigned int i;
+
+	if (prefix > MAX_IPV4_PREFIX)
+		return NULL;
+
+	if (prefix == MAX_IPV4_PREFIX)
+		return strdup("\0");
+
+	prefix &= 0x18;
+
+	for (i = 0; i < MAX_IPV4_PREFIX && (prefix == 0 || i < prefix); i += 8) {
+		if (i == 0) {
+			byte = ip & 0xff;
+			sprintf(p_buf, "%d", byte);
+		} else {
+			byte = (ip >> i) & 0xff;
+			sprintf(p_buf, ".%d", byte);
+		}
+		p_buf += strlen(p_buf);
+	}
+
+	return strdup(buf);
+}
+
+/*
+ * Round down prefix.
+ */
+static int round_down_prefix(unsigned int prefix, int is_ipv6)
+{
+	unsigned int base_prefix = is_ipv6 ? BASE_IPV6_PREFIX :
+		BASE_IPV4_PREFIX;
+
+	return prefix / base_prefix * base_prefix;
+}
+
+static void get_ipv4_info(const char *lip_str, const char *rip_str, int lprefix,
+	int rprefix)
+{
+	struct in_addr lip, rip;
+	int lprefix_round, rprefix_round;
+
+	lprefix_round = round_down_prefix(lprefix, 0);
+	rprefix_round = round_down_prefix(rprefix, 0);
+
+	get_in_addr(lip_str, &lip);
+	get_in_addr(rip_str, &rip);
+
+	vars.ipv4_lbroadcast = get_ipv4_broadcast(lip, lprefix);
+	vars.ipv4_rbroadcast = get_ipv4_broadcast(rip, rprefix);
+
+	vars.ipv4_lnetmask = get_ipv4_netmask(lprefix);
+	vars.ipv4_rnetmask = get_ipv4_netmask(rprefix);
+
+	vars.ipv4_lnetwork = get_ipv4_network(lip.s_addr, lprefix_round);
+	vars.ipv4_rnetwork = get_ipv4_network(rip.s_addr, rprefix_round);
+
+	vars.lhost_ipv4_host = get_host_from_ip(lip_str, vars.ipv4_lnetwork);
+	vars.rhost_ipv4_host = get_host_from_ip(rip_str, vars.ipv4_rnetwork);
+
+	vars.ipv4_net16_unused = get_ipv4_net16_unused(&lip, lprefix_round);
+}
+
+static void get_ipv6_info(const char *lip_str, const char *rip_str,
+	int lprefix, int rprefix)
+{
+	struct in6_addr lip, rip;
+	int lprefix_round, rprefix_round;
+
+	lprefix_round = round_down_prefix(lprefix, 1);
+	rprefix_round = round_down_prefix(rprefix, 1);
+
+	get_in6_addr(lip_str, &lip);
+	get_in6_addr(rip_str, &rip);
+
+	vars.ipv6_lnetmask = get_ipv6_netmask(lprefix);
+	vars.ipv6_rnetmask = get_ipv6_netmask(rprefix);
+
+	vars.ipv6_lnetwork = get_ipv6_network(lip.s6_addr, lprefix_round);
+	vars.ipv6_rnetwork = get_ipv6_network(rip.s6_addr, rprefix_round);
+
+	vars.lhost_ipv6_host = get_host_from_ip(lip_str, vars.ipv6_lnetwork);
+	vars.rhost_ipv6_host = get_host_from_ip(rip_str, vars.ipv6_rnetwork);
+
+	vars.ipv6_net32_unused = get_ipv6_net32_unused(&lip, lprefix_round);
+}
+
+static void print_vars(int is_ipv6)
+{
+	if (is_ipv6) {
+		print_svar("IPV6_LNETMASK", vars.ipv6_lnetmask);
+		print_svar_change("IPV6_RNETMASK", vars.ipv6_rnetmask);
+		print_svar("IPV6_LNETWORK", vars.ipv6_lnetwork);
+		print_svar("IPV6_RNETWORK", vars.ipv6_rnetwork);
+		print_svar("LHOST_IPV6_HOST", vars.lhost_ipv6_host);
+		print_svar("RHOST_IPV6_HOST", vars.rhost_ipv6_host);
+		print_svar("IPV6_NET32_UNUSED", vars.ipv6_net32_unused);
+	} else {
+		print_svar("IPV4_LBROADCAST", vars.ipv4_lbroadcast);
+		print_svar_change("IPV4_RBROADCAST", vars.ipv4_rbroadcast);
+		print_svar("IPV4_LNETMASK", vars.ipv4_lnetmask);
+		print_svar_change("IPV4_RNETMASK", vars.ipv4_rnetmask);
+		print_svar("IPV4_LNETWORK", vars.ipv4_lnetwork);
+		print_svar("IPV4_RNETWORK", vars.ipv4_rnetwork);
+		print_svar("LHOST_IPV4_HOST", vars.lhost_ipv4_host);
+		print_svar("RHOST_IPV4_HOST", vars.rhost_ipv4_host);
+		print_svar("IPV4_NET16_UNUSED", vars.ipv4_net16_unused);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	char *lip_str = NULL, *rip_str = NULL;
+	int is_ipv6, lprefix, rprefix;
+
+	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
+		!strcmp(argv[1], "--help"));
+	if (argc < 3 || is_usage) {
+		usage(argv[0]);
+		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
+	}
+
+	lip_str = argv[1];
+	rip_str = argv[2];
+
+	is_ipv6 = !!strchr(lip_str, ':');
+	if (is_ipv6 != !(strchr(rip_str, ':') == NULL))
+		tst_brk_comment(TBROK, "mixed IPv4 and IPv6 addresses");
+
+	lprefix = get_prefix(lip_str, is_ipv6);
+	rprefix = get_prefix(rip_str, is_ipv6);
+
+	if (lprefix < 0)
+		tst_brk_comment(TBROK, "wrong lprefix");
+
+	if (rprefix < 0)
+		tst_brk_comment(TBROK, "wrong rprefix");
+
+	check_prefix_range(lprefix, is_ipv6, 1);
+	check_prefix_range(rprefix, is_ipv6, 0);
+
+	if (!strcmp(lip_str, rip_str))
+		tst_brk_comment(TBROK, "IP addresses cannot be the same");
+
+	if (is_ipv6)
+		get_ipv6_info(lip_str, rip_str, lprefix, rprefix);
+	else
+		get_ipv4_info(lip_str, rip_str, lprefix, rprefix);
+
+	print_vars(is_ipv6);
+
+	exit(EXIT_SUCCESS);
+}
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (9 preceding siblings ...)
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-08-18 16:44 ` Petr Vorel
  2017-08-22 12:49   ` Alexey Kodanev
  10 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-18 16:44 UTC (permalink / raw)
  To: ltp

Tools (tst_net_ip_prefix, tst_net_iface_prefix, tst_net_vars)
simplify setup as it only needs to have passed 4 IP addresses
(IPv4 lhost + rhost and IPv6 lhost + rhost).

It's possible to define different network part for local
and remote hosts.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I don't like we don't warn on exit, when error during parsing variables with
tst_net_vars/tst_net_ip_prefix/tst_net_iface_prefix.
---
 testcases/lib/test_net.sh                          | 94 ++++++++++++++--------
 testcases/network/stress/interface/if4-addr-change | 17 ++--
 2 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 6c2fb6803..655045f95 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -239,19 +239,10 @@ tst_read_opts $*
 tst_ipaddr()
 {
 	local type="${1:-lhost}"
-	local ipv="${TST_IPV6:-4}"
-	local tst_host
-
-	if [ "$type" = "lhost" ]; then
-		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
-	else
-		eval "tst_host=\$RHOST_IPV${ipv}_HOST"
-	fi
-
 	if [ "$TST_IPV6" ]; then
-		echo "${IPV6_NETWORK}:${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV6_LHOST" || echo "$IPV6_RHOST"
 	else
-		echo "${IPV4_NETWORK}.${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV4_LHOST" || echo "$IPV4_RHOST"
 	fi
 }
 
@@ -361,9 +352,13 @@ tst_add_ipaddr()
 {
 	local type="${1:-lhost}"
 	local link_num="${2:-0}"
+	local mask
 
-	local mask=24
-	[ "$TST_IPV6" ] && mask=64
+	if [ "$TST_IPV6" ]; then
+		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
+	else
+		[ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX
+	fi
 
 	local iface=$(tst_iface $type $link_num)
 
@@ -617,24 +612,54 @@ export PASSWD="${PASSWD:-}"
 export LTP_RSH="${LTP_RSH:-rsh -n}"
 
 # Test Links
-# Set first three octets of the network address, default is '10.0.0'
-export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
-# Set local host last octet, default is '2'
-export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
-# Set the reverse of IPV4_NETWORK
-export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
-# Set first three octets of the network address, default is 'fd00:1:1:1'
-export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
-# Set local host last octet, default is '2'
-export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
-
-# Networks that aren't reachable through the test links
-export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
-export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
+# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
+# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
+IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
+
+# tst_net_ip_prefix
+# Strip prefix from IP address and save both If no prefix found sets
+# default prefix.
+#
+# tst_net_iface_prefix reads prefix and interface from rtnetlink.
+# If nothing found sets default prefix value.
+#
+# tst_net_vars exports environment variables related to test links and
+# networks that aren't reachable through the test links.
+#
+# For full list of exported environment variables see:
+# tst_net_ip_prefix -h
+# tst_net_iface_prefix -h
+# tst_net_vars -h
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing IP and prefixes from IPv4 lhost: '$IPV4_LHOST'," \
+		"rhost: '$IPV4_RHOST', IPv6 lhost: '$IPV6_LHOST', rhost: '$IPV6_RHOST'"
+	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
+fi
+
+if [ -n "$TST_USE_NETNS" ]; then
+	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
+fi
+
+
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
+	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST || echo "exit $?")
+	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST || echo "exit $?")
+
+	tst_resm TINFO "Parsing all remaining variables"
+	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
+	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
+
+	export TST_PARSE_VARIABLES="yes"
+fi
 
 export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
 export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
@@ -657,14 +682,13 @@ export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
 export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
-if [ -n "$TST_USE_NETNS" ]; then
-	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
-fi
-
 # Warning: make sure to set valid interface names and IP addresses below.
 # Set names for test interfaces, e.g. "eth0 eth1"
+# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
+# want to use more ifaces.
 export LHOST_IFACES="${LHOST_IFACES:-eth0}"
 export RHOST_IFACES="${RHOST_IFACES:-eth0}"
+
 # Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02"
 export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}"
 export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}"
diff --git a/testcases/network/stress/interface/if4-addr-change b/testcases/network/stress/interface/if4-addr-change
index 567f86643..a7469c252 100644
--- a/testcases/network/stress/interface/if4-addr-change
+++ b/testcases/network/stress/interface/if4-addr-change
@@ -48,12 +48,19 @@ while [ $cnt -lt $NS_TIMES ]; do
 
 	[ $num -eq $RHOST_IPV4_HOST ] && continue
 
-	# Change IPv4 address
-	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
+	# check prefix and fix values for prefix != 24
+	add_to_net=
+	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
+		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
+	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
+		add_to_net=".0.1"
+	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
+		add_to_net=".1"
+	fi
 
-	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
-		broadcast 255.255.255.255 || \
-		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
+	# Change IPv4 address
+	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
+		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
 
 	cnt=$(($cnt + 1))
 
-- 
2.13.2


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-08-21  6:10   ` Petr Vorel
  2017-08-22 12:23   ` Alexey Kodanev
  1 sibling, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-21  6:10 UTC (permalink / raw)
  To: ltp

> New tools:
> * tst_net_ip_prefix
> Strip prefix from IP address and save both
> If no prefix found sets default prefix.
...
> +++ b/testcases/lib/tst_net_vars.c
> @@ -0,0 +1,637 @@
> +/*
> + * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> + * Copyright (c) 1997-2015 Red Hat, Inc. All rights reserved.
> + * Copyright (c) 2011-2013 Rich Felker, et al.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <arpa/inet.h>
> +#include <arpa/nameser.h>
> +#include <assert.h>
> +#include <errno.h>
> +#include <linux/rtnetlink.h>
> +#include <net/if.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <time.h>
> +#include <stdarg.h>
> +
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +#include "tst_net.h"
> +
> +#define BASE_IPV4_PREFIX 8
> +#define BASE_IPV6_PREFIX 16
> +
> +#define MAX_IPV4_PREFIX 32
> +#define MAX_IPV6_PREFIX 128
> +
> +#define DEFAULT_IPV4_UNUSED_PART1 10
> +#define DEFAULT_IPV6_UNUSED_PART1 0xfd
> +
> +#define DEFAULT_IPV4_UNUSED_PART2 23
> +#define DEFAULT_IPV6_UNUSED_PART2 0x23
> +
> +typedef struct ltp_net_variables {
> +	char *ipv4_lbroadcast;
> +	char *ipv4_rbroadcast;
> +	char *ipv4_lnetmask;
> +	char *ipv4_rnetmask;
> +	char *ipv4_lnetwork;
> +	char *ipv4_rnetwork;
> +	char *lhost_ipv4_host;
> +	char *rhost_ipv4_host;
> +	char *ipv6_lnetmask;
> +	char *ipv6_rnetmask;
> +	char *ipv6_lnetwork;
> +	char *ipv6_rnetwork;
> +	char *lhost_ipv6_host;
> +	char *rhost_ipv6_host;
> +	char *ipv4_net16_unused;
> +	char *ipv6_net32_unused;
> +	char *lhost_ifaces;
I left unused struct member lhost_ifaces :-(.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions Petr Vorel
@ 2017-08-21 13:31   ` Alexey Kodanev
  2017-08-22 17:18     ` Petr Vorel
  0 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-21 13:31 UTC (permalink / raw)
  To: ltp

Hi Petr,
On 08/18/2017 07:44 PM, Petr Vorel wrote:
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 75 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index c11747a27..6575c77f4 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -219,7 +219,7 @@ tst_ipaddr()
>  {
>  	local type="${1:-lhost}"
>  	local ipv="${TST_IPV6:-4}"
> -	local tst_host=
> +	local tst_host
>  
>  	if [ "$type" = "lhost" ]; then
>  		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
> @@ -234,6 +234,77 @@ tst_ipaddr()
>  	fi
>  }
>  
> +# Get IP address of unused network, specified by type and counter.
> +# This is useful for generating row of unique addresses based on lhost/rhost.
> +# tst_ipaddr_un_host [TYPE] [COUNTER]
> +# TYPE: { lhost | rhost }; Default value is 'lhost'.
> +# COUNTER: Integer value for counting 4th octet and 3rd octet; Default is 1.
> +tst_ipaddr_un_host()
> +{
> +	local type="${1:-lhost}"
> +	local counter="${2:-1}"
> +	local octet_3 octet_4 max_octet_3 max_octet_4 tmp
> +
> +	[ $counter -lt 1 ] && counter=1
> +	[ "$TST_IPV6" ] && max_octet_3=65535 || max_octet_3=255
> +	max_octet_4=$((max_octet_3 - 1))
> +	tmp=$((counter * 2))
> +	[ "$type" = "rhost" ] && tmp=$((tmp - 1))
> +
> +	octet_4=$((tmp % max_octet_4))
> +	octet_3=$((tmp / max_octet_4))
> +
> +	if [ $octet_4 -eq 0 ]; then
> +		octet_4=$max_octet_4
> +		octet_3=$((octet_3 - 1))
> +	fi
> +
> +	[ $octet_3 -gt $max_octet_3 ] && octet_3=$max_octet_3
> +	[ $octet_4 -gt $max_octet_4 ] && octet_4=$max_octet_4
> +
> +	if [ "$TST_IPV6" ]; then
> +		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
> +		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
> +		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
> +		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"
> +	else
> +		echo "${IPV4_NET16_UNUSED}.${octet_3}.${octet_4}"
> +	fi
> +}
> +
> +# Get IP address of unused network, specified by 3rd and 4th octet.
> +# This is useful when 3rd and/or 4th octet are needed to be defined.
> +# tst_ipaddr_un_ip [OCTET_3] [OCTET_4]

3rd and 4th octet are only meaningful for IPv4, what about 'net_id' and
'host_id' instead?

> +# OCTET_3: Integer or hex value of 3rd octet; Default value is 0.
> +# OCTET_4: Integer or hex value of 4th octet; Default value is 0.
> +tst_ipaddr_un_ip()
> +{
> +	local octet_3="${1:-0}"
> +	local octet_4="${2:-0}"
> +	local max
> +
> +	[ "$TST_IPV6" ] && max=65535 || max=255
> +
> +	if [ "$TST_IPV6" ]; then
> +		octet_3=$(printf %d $octet_3)
> +		octet_4=$(printf %d $octet_4)
> +	fi
> +
> +	[ $octet_3 -lt 0 ] && octet_3=0
> +	[ $octet_4 -lt 0 ] && octet_4=1
> +	[ $octet_3 -gt $max ] && octet_3=$max
> +	[ $octet_4 -gt $max ] && octet_4=$max
> +
> +	if [ "$TST_IPV6" ]; then
> +		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
> +		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
> +		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
> +		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"

'${octet_3}${octet_4}' - if max is 65K, it's 4 bytes, ':' missed?


I assume this is needed for getting subnets/routes, in most cases we would
have 64-bit netmask that's why I would move one parameter before '::'

echo "${IPV6_NET32_UNUSED}:${octet_3}::${octet_4}"


> +	else
> +		echo "${IPV4_NET16_UNUSED}.${octet_3}.${octet_4}"
> +	fi
> +}


Can we have getopts in a single function to prevent code duplication?

Best regards,
Alexey

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
@ 2017-08-21 13:42   ` Alexey Kodanev
  2017-08-22 17:21     ` Petr Vorel
  0 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-21 13:42 UTC (permalink / raw)
  To: ltp

On 08/18/2017 07:44 PM, Petr Vorel wrote:
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

We already discussed it here:
http://lists.linux.it/pipermail/ltp/2017-July/005113.html

Thanks,
Alexey


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
@ 2017-08-21 13:52   ` Alexey Kodanev
  0 siblings, 0 replies; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-21 13:52 UTC (permalink / raw)
  To: ltp

On 08/18/2017 07:44 PM, Petr Vorel wrote:
> * Fix test for SSH and netns based testing.
> * Remove hardcoded rsh dependency.
> * Create shell library mcast4-lib.sh (multicast IPv4 specific)
>   to reduce duplicity in tests. Library uses test_stress_net.sh
>   (and therefore test_net.sh).
> * Cleanup code + fixed typos.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  .../stress/multicast/grp-operation/mcast4-grpope01 | 221 ++-----------------
>  .../stress/multicast/grp-operation/mcast4-grpope02 | 230 ++------------------
>  .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
>  .../stress/multicast/grp-operation/mcast4-grpope04 | 236 ++-------------------
>  .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 +++++++++++
>  5 files changed, 196 insertions(+), 826 deletions(-)
>  create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
...
> -
> -wait
> -
> -#-----------------------------------------------------------------------
> -#
> -# Clean up
> -#
> +. mcast4-lib.sh
>  
> -tst_resm TPASS "Test is finished successfully."
> +tst_resm TINFO "joining and leaving the same IPv4 multicast group with a different source filter on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
>  
> -exit 0
> +mcast_setup $MCASTNUM_NORMAL
> +do_multicast_test_join_leave true
> +tst_exit
> diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
> new file mode 100644
> index 000000000..0c74969cf
> --- /dev/null
> +++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
> @@ -0,0 +1,118 @@
> +#!/bin/sh
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation; either version 2 of
> +# the License, or (at your option) any later version.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Author: Petr Vorel <pvorel@suse.cz>
> +#
> +# Setup script for mcast4-grpope* tests.
> +
> +TST_TOTAL=1
> +TST_CLEANUP="mcast_cleanup"
> +
> +. test_net_stress.sh
> +
> +mcast_setup()
> +{
> +	local igmp_max_memberships="$1"
> +	local increase_max="${2:-}"
> +
> +	netstress_setup
> +	tst_tmpdir
> +
> +	SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships)
> +	SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf)
> +	SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version)
> +	SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version)
> +
> +	if [ "$increase_max" ]; then

"$increase_max" = "true"

> +		# Increase the maximum number of open file descriptors
> +		[ `ulimit -n` -lt $igmp_max_memberships ] && ROD ulimit -n $igmp_max_memberships
> +	fi
> +
> +	ROD sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
> +	ROD sysctl -qw net.ipv4.igmp_max_msf=10
> +	ROD sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=0
> +	ROD sysctl -qw net.ipv4.conf.all.force_igmp_version=0
> +}
> +
> +mcast_cleanup()
> +{
> +	[ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -qw net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS
> +	[ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -qw net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF
> +	[ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION
> +	[ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION
> +
> +	pkill -SIGHUP -x ns-mcast_join
> +	tst_sleep 10ms
> +	pkill -9 -x ns-mcast_join
> +
> +	tst_rhost_run -c "pkill -SIGHUP -x ns-igmp_querier"
> +
> +	restore_ipaddr
> +	restore_ipaddr rhost
> +}
> +
> +do_multicast_test_multiple_join()
> +{
> +	local igmp_max_memberships="$1"
> +	local param_multi_socket ret tmpfile
> +
> +	[ "${2:-}" = true ] && param_multi_socket="-m"
> +
> +	# Run a multicast join tool
> +	tmpfile=ns-mcast_join.$$
> +
> +	EXPECT_PASS ns-mcast_join $param_multi_socket -f 4 -I $(tst_iface) -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX \> $tmpfile
> +
> +	tst_resm TINFO "joined $(grep groups $tmpfile)"
> +
> +	# Send IGMP General Query from the remote host
> +	EXPECT_RHOST_PASS ns-igmp_querier -I $(tst_iface rhost) -o -r 1 -m $MCAST_IPV4_ADDR
> +}
> +
> +do_multicast_test_join_leave()
> +{
> +	local define_source_address filter num ret source_addr x y
> +
> +	[ "$1" = true ] && define_source_address=true
> +
> +	# Send IGMP General Query from the remote host
> +	tst_rhost_run -s -c "ns-igmp_querier -I $(tst_iface rhost) -i 1000000000 -r 1 -b"
> +
> +	# Run a multicast join tool
> +	num=0
> +	while [ $num -lt $MCASTNUM_NORMAL ]; do
> +		if [ "$define_source_address" ]; then
> +			x=$(($num / 254))
> +			y=$(($num % 254 + 1))
> +			if [ $x -gt 254 ]; then
> +				tst_resm TINFO "the number of the connection is less than $num"
> +				break
> +			fi
> +			source_addr="${IPV4_NET16_UNUSED}.${x}.${y}"

tst_ipaddr_un()?


> +
> +			[ $(($num % 5)) -ne 2 ] && filter="include" || filter="exclude"
> +			params="-F $filter -s $source_addr"
> +		fi
> +
> +		ns-mcast_join -f 4 -I $(tst_iface) -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &
> +		num=$(($num + 1))
> +	done
> +
> +	wait
> +
> +	tst_resm TPASS "test is finished successfully"
> +}

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
@ 2017-08-21 15:31   ` Alexey Kodanev
  2017-08-22 20:13     ` Petr Vorel
  0 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-21 15:31 UTC (permalink / raw)
  To: ltp

On 08/18/2017 07:44 PM, Petr Vorel wrote:
> This function is useful when we know we broke netns (e.g. by unloading
> network driver).
>
> It was necessary to introduce new variable LTP_NETNS_CUSTOM, as after
> resetting network namespace there is no way to reset LTP_NETNS variable
> for subsequent tests and therefore is (for non-custom variant) always
> needed to set it even if netns itself is setup.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 29 ++++++++++++++++++++++++++---
>  1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index c4399f637..6c2fb6803 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -21,6 +21,16 @@
>  
>  [ -z "$TST_LIB_LOADED" ] && . test.sh
>  
> +set_ltp_netns_var()
> +{
> +	if [ -z "$LTP_NETNS_CUSTOM" ]; then
> +		pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
> +		export LTP_NETNS="ns_exec $pid net,mnt"
> +	else
> +		export LTP_NETNS="$LTP_NETNS_CUSTOM"
> +	fi
> +}
> +
>  init_ltp_netspace()
>  {
>  	local pid=
> @@ -41,8 +51,7 @@ init_ltp_netspace()
>  
>  	export TST_INIT_NETNS="no"
>  
> -	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
> -	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
> +	set_ltp_netns_var
>  
>  	tst_restore_ipaddr
>  	tst_restore_ipaddr rhost
> @@ -50,6 +59,18 @@ init_ltp_netspace()
>  	tst_wait_ipv6_dad
>  }
>  
> +# Force to reset netns.
> +reset_ltp_netspace()
> +{
> +	[ -n "$TST_USE_NETNS" ] || return
> +
> +	tst_resm TINFO "reset netns"
> +	ip link delete ltp_ns_veth2 2> /dev/null
> +	rm -f /var/run/netns/ltp_ns
> +	pkill ns_create

Hmm, if there was custom netns you would break it anyway with this
function and change to LTP one.

I guess we should leave it unsupported for route rmmod test unless we
figure out the right solution.

Also, what if we reset only ltp veth pair, i.e.:

reset_ltp_netspace()
{
    ...
    [ "$(tst_iface)" != "ltp_ns_veth2" ] || return
    ip li del ltp_ns_veth2 2>/dev/null
}

init_ltp_netspace()
{
    ...

    pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
    export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"

    if ! ip li sh $LHOST_IFACES > /dev/null 2>&1; then
        ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
        ROD ns_ifmove ltp_ns_veth1 $pid
    fi
    ...
}

> +	init_ltp_netspace
> +}
> +
>  # Run command on remote host.
>  # Options:
>  # -b run in background
> @@ -636,7 +657,9 @@ export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
>  export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
>  export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
>  
> -[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
> +if [ -n "$TST_USE_NETNS" ]; then
> +	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
> +fi

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
@ 2017-08-22 11:46   ` Alexey Kodanev
  2017-08-22 21:22     ` Petr Vorel
  0 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-22 11:46 UTC (permalink / raw)
  To: ltp

Hi,
On 08/18/2017 07:44 PM, Petr Vorel wrote:
> * Fix test for netns based testing (route4-change-if requires to have
>   manually set another pair of interfaces).
> * Remove rsh dependency.
> * Create shell library route4-lib.sh (route IPv4 specific) to reduce
>   duplicity in tests. Library uses test_stress_net.sh (and therefore test_net.sh).
> * Stop using TST_COUNT, simplify TCID
> * Cleanup code, fix typos, update doc.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Tests using route_test_change() use background traffic instead of ns-udpsender
> but I fixed it that it uses route. Is it too much overhead? The reason is I'd

How do you use it to make a background traffic if you change route on
every loop iteration?

> like to get rid of all ugly scripts and binaries in
> testcases/network/stress/ns-tools, including ns-udpsender.c.

ns-udpsender can send a single UDP datagram over the new route without
waiting for answer but unfortunately we don't know for sure whether it
actually sent datagram and/or destination received it.

> ---
>  testcases/network/stress/route/00_Descriptions.txt |  23 +-
>  testcases/network/stress/route/route4-change-dst   | 283 ++---------------
>  testcases/network/stress/route/route4-change-gw    | 305 ++----------------
>  testcases/network/stress/route/route4-change-if    | 341 +++------------------
>  testcases/network/stress/route/route4-ifdown       | 284 +++--------------
>  testcases/network/stress/route/route4-lib.sh       | 145 +++++++++
>  testcases/network/stress/route/route4-redirect     | 223 +++-----------
>  testcases/network/stress/route/route4-rmmod        | 307 ++++---------------
>  testcases/network/stress/route/route6-change-dst   |   2 +-
>  9 files changed, 424 insertions(+), 1489 deletions(-)
>  create mode 100644 testcases/network/stress/route/route4-lib.sh
>

...



> -	    return 1
> +	local cmd_type=$1
> +	local cmd_name="$(get_cmd $cmd_type)"
> +	local cnt=0
> +	local cmd cmd2
> +
> +	if [ "$cmd_type" = 'ifconfig_cmd' ]; then
> +		cmd="$cmd_name $(tst_iface) down"
> +		cmd2="$cmd_name $(tst_iface) up"
> +	else
> +		cmd="$cmd_name link set down dev $(tst_iface)"
> +		cmd2="$cmd_name link set up dev $(tst_iface)"

This test-case looks like duplicate of if-updown


>  	fi
>  
> -	# Add the route
> -	case $test_type in
> -	    1)
> -	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	    2)
> -	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	esac
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
> -	    return 1
> -	fi
> +	tst_resm TINFO "IPv4 route is added and deleted by '$cmd_name' command $NS_TIMES times"
>  
> -	# Load the route with UDP datagram
> -	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to run a UDP datagram sender"
> -	    return 1
> -	fi
> -
> -	# Down then up the interface
> -	case $test_type in
> -	    1)
> -	    ifconfig $lhost_ifname down && ifconfig $lhost_ifname up
> -	    ;;
> -	    2)
> -	    ip link set down dev $lhost_ifname && ip link set up dev $lhost_ifname
> -	    ;;
> -	esac
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to down/up the interface"
> -	    return 1
> -	fi
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		make_background_tcp_traffic $(tst_ipaddr_un_host)
> +		check_connectivity_interval $cnt false $(tst_iface) $(tst_ipaddr_un_host rhost)
>  
> -	cnt=`expr $cnt + 1`
> -    done
> +		$cmd
> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "failed to down the interface"
> +			return
> +		fi
>  
> -    tst_resm TPASS "Test is finished correctly."
> -    return 0
> -}
> +		$cmd2
> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "failed to up the interface"
> +			return
> +		fi
>  
> +		cnt=$(($cnt + 1))
> +	done
>  
> -#-----------------------------------------------------------------------
> -#
> -# Main
> -#
> -# Exit Value:
> -#   The number of the failure
> -#
> -#-----------------------------------------------------------------------
> +	tst_resm TPASS "test is finished correctly"
> +}
>  
> -RC=0
>  do_setup
> -test_body 1 || RC=`expr $RC + 1`      # Case of route command
> -test_body 2 || RC=`expr $RC + 1`      # Case of ip command
> -do_cleanup
> +test_body 'ifconfig_cmd'
> +test_body 'ip_cmd'
>  
> -exit $RC
> +tst_exit
> diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
> new file mode 100644
> index 000000000..66a96320c
> --- /dev/null
> +++ b/testcases/network/stress/route/route4-lib.sh
> @@ -0,0 +1,145 @@
> +#!/bin/sh
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation; either version 2 of
> +# the License, or (at your option) any later version.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Setup script for route4-* tests.
> +#
> +# More information about network parameters can be found
> +# in the following document: testcases/network/stress/README
> +#
> +# Author: Petr Vorel <pvorel@suse.cz>
> +
> +. test_net_stress.sh
> +
> +tst_check_cmds ip pgrep route
> +
> +CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
> +
> +DST_NETWORK_OCTET_3=23
> +DST_HOST=5
> +
> +route_cleanup()
> +{
> +	netstress_cleanup
> +	restore_ipaddr
> +	restore_ipaddr rhost
> +}
> +
> +route_setup()
> +{
> +	netstress_setup
> +	tst_check_cmds route
> +	route_cleanup
> +}
> +
> +manipulate_route()
> +{
> +	local cmd_name=$1
> +	local task=$2
> +	local network=$3
> +	local prefix=$4
> +	local netmask=$5
> +	local gateway=$6
> +	local ifname=$7
> +
> +	[ "$task" = "add" ] || [ "$task" = "del" ] || tst_brkm TBROK "wrong task: '$task'"
> +
> +	if [ "$cmd_name" = "ip" ]; then
> +		ROD "$cmd_name route $task $network/$prefix via $gateway dev $ifname"
> +	elif [ "$cmd_name" = "route" ]; then
> +		ROD "$cmd_name $task -net $network netmask $netmask gw $gateway dev $ifname"
> +	else
> +		tst_brkm TBROK "wrong command: '$task'"
> +	fi
> +}
> +
> +get_cmd()
> +{
> +	local cmd_type=$1
> +
> +	case $cmd_type in
> +	rt_cmd) echo 'route' ;;
> +	ip_cmd) echo 'ip' ;;
> +	ifconfig_cmd) echo 'ifconfig' ;;
> +	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
> +	esac
> +}
> +
> +# helper function for route4-change-{dst,gw,if} tests
> +route_test_change()
> +{
> +	local test_field="$1"
> +	local cmd_type="$2"
> +	local ip="$3"
> +	local dst_network="$(tst_ipaddr_un_ip $DST_NETWORK_OCTET_3)"
> +	local gateway="$(tst_ipaddr_un_host rhost)"
> +	local lhost_ifname="$(tst_iface)"
> +	local cmd_name="$(get_cmd $cmd_type)"
> +	local cnt=0 link_num=0
> +	local gateway2 lhost_ifname2 pre_dst_network test_field_name
> +
> +	case $test_field in
> +	dst) test_field_name='destination' ;;
> +	gw) test_field_name='gateway' ;;
> +	if) test_field_name='interface' ;;
> +	*) tst_brkm TBROK "Unknown test parameter '$test_field'"
> +	esac
> +
> +	tst_resm TINFO "the $test_field_name of an IPv4 route is changed by '$cmd_name' command $NS_TIMES times"
> +
> +	if [ "$test_field" = 'dst' ]; then
> +		gateway="$ip"
> +		gateway2="$gateway"
> +	else
> +		dst_addr="$ip"
> +	fi
> +
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		lhost_ifname2="$lhost_ifname"
> +		gateway2="$gateway"
> +
> +		pre_dst_network="$dst_network"
> +		if [ "$test_field" = 'dst' ]; then
> +			dst_addr="$(tst_ipaddr_un_ip $(($cnt % 255)) $DST_HOST)"
> +			dst_network="$(tst_ipaddr_un_ip $(($cnt % 255)))"

tst_ipaddr_un() handles '$cnt' overrun already.

> +			netstress_cleanup

cleanup in the test on every loop iteration?

> +		elif [ "$test_field" = 'gw' ]; then
> +			gateway2="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt)))"
> +			local cnt2=$(($cnt + 1))
> +			[ $cnt2 -eq $RHOST_COUNTER_COUNT ] && cnt2=$RHOST_COUNTER_START
> +			gateway="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt2)))"

Why do you need RHOST_COUNTER_COUNT and RHOST_COUNTER_START variables?

> +		elif [ "$test_field" = 'if' ]; then
> +			[ $link_num -ge $LINK_TOTAL ] && link_num=0
> +			lhost_ifname="$(tst_iface lhost $link_num)"
> +			gateway="$(tst_ipaddr_un_ip $link_num 1)"
> +			link_num=$(($link_num + 1))
> +		fi


It's better to change 'if' structure to 'case' one


> +
> +		if [ $cnt -gt 0 ]; then
> +			manipulate_route $cmd_name 'del' $pre_dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
> +		fi
> +
> +		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
> +		make_background_tcp_traffic $(tst_ipaddr_un_host)

For generating traffic you're always using a single destination address,
why it can't be $(tst_ipaddr)?

> +		check_connectivity_interval $cnt false $lhost_ifname $dst_addr || return

Could you please clarify the traffic flow here? if I understand it
correctly ICMP goes over the new route/gw to an IP addresses on remote
host which was added in setup, correct?

I think ns-udpsender is the more appropriate choice for a one way traffic...


> +
> +		cnt=$(($cnt + 1))
> +	done
> +
> +	manipulate_route $cmd_name 'del' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
> +
> +	tst_resm TPASS "test is finished correctly"
> +}
> diff --git a/testcases/network/stress/route/route4-redirect b/testcases/network/stress/route/route4-redirect
> index 9eb8a4624..578a2c01a 100644
> --- a/testcases/network/stress/route/route4-redirect
> +++ b/testcases/network/stress/route/route4-redirect
> @@ -1,212 +1,73 @@
>  #!/bin/sh

...

>  
> -# The destination network
> -DST_NETWORK="10.10.0"   # destination network would be 10.10.0.0/24
> -DST_HOST="5"
> -DST_PORT="7"
> +SYSFS_ACCEPT_REDIRECTS=
> +SYSFS_SECURE_REDIRECTS=
>  
> -
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_cleanup
> -#
> -# DESCRIPTION:
> -#   Recover the tested interfaces
> -#
> -#-----------------------------------------------------------------------
>  do_cleanup()
>  {
> -    # Kill the redirector utility
> -    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
> +	kill_daemon ns-udpsender
> +	restore_ipaddr
> +	restore_ipaddr rhost
>  
> -    # Initialize the interfaces
> -    initialize_if lhost ${LINK_NUM}
> -    initialize_if rhost ${LINK_NUM}
> +	kill_daemon ns-icmp_redirector remote
> +	[ -n "$SYSFS_ACCEPT_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).accept_redirects=$SYSFS_ACCEPT_REDIRECTS
> +	[ -n "$SYSFS_SECURE_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).secure_redirects=$SYSFS_SECURE_REDIRECTS
>  }
>  
> -
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_setup
> -#
> -# DESCRIPTION:
> -#   Set the initial route and start icmp redirect on the remote host
> -#
> -# SET VALUES:
> -#   rhost_ipv4addr      - IPv4 Address of the remote host
> -#   lhost_ifname        - Interface name of the local host
> -#   rhost_ifname        - Interface name of the remote host
> -#
> -#-----------------------------------------------------------------------
>  do_setup()
>  {
> -    # Make sure to clean up
> -    do_cleanup
> -
> -    # Get the Interface name of local host
> -    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "Failed to get the interface name at the local host"
> -	exit $TST_TOTAL
> -    fi
> -
> -    # Get the Interface name of remote host
> -    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "Failed to get the interface name at the remote host"
> -	exit $TST_TOTAL
> -    fi
> -
> -    # Remove the link-local address of the remote host
> -    sleep 3
> -    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
> +	netstress_setup
>  
> -    # Assign IPv4 address to the interface of the local host
> -    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
> -	return 1
> -    fi
> +	SYSFS_ACCEPT_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).accept_redirects)
> +	SYSFS_SECURE_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).secure_redirects)
>  
> -    # Add route to the initial gateway
> -    route add -net ${DST_NETWORK}.0 netmask 255.255.255.0 gw ${IPV4_NETWORK}.${RHOST_IPV4_HOST} dev $lhost_ifname
> +	tst_add_ipaddr_stress
>  
> -    # Make sure the sysctl value is set for accepting the redirect
> -    sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
> -    sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null
> -
> -    # Run the redirector utility at the remote host
> -    ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
> -    if [ $ret -ne 0 ]; then
> -	tst_resm TBROK "Failed to run icmp redirector at the remote host"
> -	exit $TST_TOTAL
> -    fi
> +	# Run the redirector utility at the remote host
> +	tst_rhost_run -s -c "ns-icmp_redirector -I $(tst_iface rhost) -b"
>  }
>  
> -
> -
> -#-----------------------------------------------------------------------
> -#
> -# FUNCTION:
> -#   test_body
> -#
> -# DESCRIPTION:
> -#   main code of the test
> -#
> -# Arguments:
> -#   None
> -#
> -#-----------------------------------------------------------------------
>  test_body()
>  {
> -    # Loop for changing the route
> -    cnt=0
> -    while [ $cnt -lt $NS_TIMES ]; do
> -	ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TBROK "Failed to run udp packet sender"
> -	    return 1
> -	fi
> -	cnt=`expr $cnt + 1`
> -    done
> -
> -    tst_resm TPASS "Test is finished correctly."
> -    return 0
> +	local cnt=0
> +	tst_resm TINFO "changing IPv4 route by sending UDP packets with ns-udpsender $NS_TIMES times"
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		ROD ns-udpsender -f 4 -D $(tst_ipaddr_un_host rhost 2) -p 7 -o -s 8

...
> -exit $RC
> +tst_exit
> diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
> index 36c8c970d..9c1eade81 100644
> --- a/testcases/network/stress/route/route4-rmmod
> +++ b/testcases/network/stress/route/route4-rmmod

...

>  test_body()
>  {
> -    test_type=$1
> +	local cmd_type=$1
> +	local cmd_name="$(get_cmd $cmd_type)"
> +	local dst_addr=${DST_NETWORK}.${DST_HOST}
> +	local dst_network=${DST_NETWORK}.0
> +	local cnt=0
>  
> -    TCID=route4-rmmod0${test_type}
> -    TST_COUNT=$test_type
> +	tst_resm TINFO "IPv4 route is added by '$cmd_name' command and then deleted by removing network driver $NS_TIMES times"

This is not what the test does after the changes.

>  
> -    case $test_type in
> -	1)
> -	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
> -	;;
> -	2)
> -	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
> -	;;
> -	*)
> -	tst_resm TBROK "unspecified case"
> -	return 1
> -	;;
> -    esac
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		make_background_tcp_traffic $(tst_ipaddr_un_ip)
> -    # Start the loop
> -    cnt=0
> -    while [ $cnt -lt $NS_TIMES ]; do
> -	# Check the connectivity to the gateway
> -	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
> -	    return 1
> -	fi
> +		check_connectivity_interval $cnt false $(tst_iface) $(tst_ipaddr_un_host rhost) || return
>  
> -	# Add the route
> -	case $test_type in
> -	    1)
> -	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	    2)
> -	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	esac
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
> -	    return 1
> -	fi
> +		# Remove and reload the network driver
> +		modprobe -r $MODULE
> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "failed to remove the network driver '$MODULE'"
> +			return
> +		fi
>  
> -	# Load the route with UDP datagram
> -	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to run a UDP datagram sender"
> -	    return 1
> -	fi
> -
> -	# Remove and reload the network driver
> -	rmmod $lhost_module && modprobe $lhost_module
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to unload/reload the network driver"
> -	    return 1
> -	fi
> +		modprobe $MODULE
> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "failed to load the network driver '$MODULE'"
> +			return
> +		fi
>  
> -	# Make sure to assing the IPv4 address
> -	set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1
> +		tst_sleep 100ms
>  
> -	cnt=`expr $cnt + 1`
> -    done
> +		# If we use netns we need to reset it as unloading kernel module breaks it
> +		reset_ltp_netspace
>  
> -    tst_resm TPASS "Test is finished correctly."
> -    return 0
> -}
> +		tst_add_ipaddr_stress
>  
> +		cnt=$(($cnt + 1))
> +	done


With this implementation it should be moved to 'interface' group.


Best regards,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170822/e7f2ef3a/attachment-0001.html>

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables Petr Vorel
  2017-08-21  6:10   ` Petr Vorel
@ 2017-08-22 12:23   ` Alexey Kodanev
  2017-08-23 10:46     ` Petr Vorel
  1 sibling, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-22 12:23 UTC (permalink / raw)
  To: ltp

On 08/18/2017 07:44 PM, Petr Vorel wrote:
> New tools:
> * tst_net_ip_prefix
> Strip prefix from IP address and save both
> If no prefix found sets default prefix.
>
> * tst_net_iface_prefix
> tst_net_iface_prefix reads prefix and interface from rtnetlink.
>
> * tst_net_vars takes input of local and remote address and setup most of
> test link (IP related) environment variables.

Here is the thread with minor comments that still applicable to this
version:

http://lists.linux.it/pipermail/ltp/2017-June/004838.html

Thanks,
Alexey


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-08-18 16:44 ` [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
@ 2017-08-22 12:49   ` Alexey Kodanev
  0 siblings, 0 replies; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-22 12:49 UTC (permalink / raw)
  To: ltp

On 08/18/2017 07:44 PM, Petr Vorel wrote:
> Tools (tst_net_ip_prefix, tst_net_iface_prefix, tst_net_vars)
> simplify setup as it only needs to have passed 4 IP addresses
> (IPv4 lhost + rhost and IPv6 lhost + rhost).
>
> It's possible to define different network part for local
> and remote hosts.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> I don't like we don't warn on exit, when error during parsing variables with
> tst_net_vars/tst_net_ip_prefix/tst_net_iface_prefix.

What stops you from printing TWARN/TBROK on error inside these commands?

> ---
>  testcases/lib/test_net.sh                          | 94 ++++++++++++++--------
>  testcases/network/stress/interface/if4-addr-change | 17 ++--
>  2 files changed, 71 insertions(+), 40 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index 6c2fb6803..655045f95 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -239,19 +239,10 @@ tst_read_opts $*
>  tst_ipaddr()
>  {
>  	local type="${1:-lhost}"
> -	local ipv="${TST_IPV6:-4}"
> -	local tst_host
> -
> -	if [ "$type" = "lhost" ]; then
> -		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
> -	else
> -		eval "tst_host=\$RHOST_IPV${ipv}_HOST"
> -	fi
> -
>  	if [ "$TST_IPV6" ]; then
> -		echo "${IPV6_NETWORK}:${tst_host}"
> +		[ "$type" = "lhost" ] && echo "$IPV6_LHOST" || echo "$IPV6_RHOST"
>  	else
> -		echo "${IPV4_NETWORK}.${tst_host}"
> +		[ "$type" = "lhost" ] && echo "$IPV4_LHOST" || echo "$IPV4_RHOST"
>  	fi
>  }
>  
> @@ -361,9 +352,13 @@ tst_add_ipaddr()
>  {
>  	local type="${1:-lhost}"
>  	local link_num="${2:-0}"
> +	local mask
>  
> -	local mask=24
> -	[ "$TST_IPV6" ] && mask=64
> +	if [ "$TST_IPV6" ]; then
> +		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
> +	else
> +		[ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX
> +	fi
>  
>  	local iface=$(tst_iface $type $link_num)
>  
> @@ -617,24 +612,54 @@ export PASSWD="${PASSWD:-}"
>  export LTP_RSH="${LTP_RSH:-rsh -n}"
>  
>  # Test Links
> -# Set first three octets of the network address, default is '10.0.0'
> -export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
> -# Set local host last octet, default is '2'
> -export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
> -# Set remote host last octet, default is '1'
> -export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
> -# Set the reverse of IPV4_NETWORK
> -export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
> -# Set first three octets of the network address, default is 'fd00:1:1:1'
> -export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
> -# Set local host last octet, default is '2'
> -export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
> -# Set remote host last octet, default is '1'
> -export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
> -
> -# Networks that aren't reachable through the test links
> -export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
> -export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
> +# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
> +# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
> +IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
> +IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
> +IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
> +IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
> +
> +# tst_net_ip_prefix
> +# Strip prefix from IP address and save both If no prefix found sets
> +# default prefix.
> +#
> +# tst_net_iface_prefix reads prefix and interface from rtnetlink.
> +# If nothing found sets default prefix value.
> +#
> +# tst_net_vars exports environment variables related to test links and
> +# networks that aren't reachable through the test links.
> +#
> +# For full list of exported environment variables see:
> +# tst_net_ip_prefix -h
> +# tst_net_iface_prefix -h
> +# tst_net_vars -h
> +if [ -z "$TST_PARSE_VARIABLES" ]; then
> +	tst_resm TINFO "Parsing IP and prefixes from IPv4 lhost: '$IPV4_LHOST'," \
> +		"rhost: '$IPV4_RHOST', IPv6 lhost: '$IPV6_LHOST', rhost: '$IPV6_RHOST'"
> +	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
> +	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
> +	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
> +	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
> +fi
> +
> +if [ -n "$TST_USE_NETNS" ]; then
> +	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
> +fi
> +
> +
> +if [ -z "$TST_PARSE_VARIABLES" ]; then
> +	tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
> +	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
> +	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST || echo "exit $?")
> +	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
> +	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST || echo "exit $?")
> +
> +	tst_resm TINFO "Parsing all remaining variables"
> +	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
> +	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
> +
> +	export TST_PARSE_VARIABLES="yes"
> +fi
>  
>  export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
>  export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
> @@ -657,14 +682,13 @@ export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
>  export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
>  export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
>  
> -if [ -n "$TST_USE_NETNS" ]; then
> -	[ "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace || set_ltp_netns_var
> -fi
> -
>  # Warning: make sure to set valid interface names and IP addresses below.
>  # Set names for test interfaces, e.g. "eth0 eth1"
> +# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
> +# want to use more ifaces.
>  export LHOST_IFACES="${LHOST_IFACES:-eth0}"
>  export RHOST_IFACES="${RHOST_IFACES:-eth0}"
> +


Looks good. Could you also run checkpatch tool with this patch-set and
fix warnings/errors?

Thanks,
Alexey

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions
  2017-08-21 13:31   ` Alexey Kodanev
@ 2017-08-22 17:18     ` Petr Vorel
  2017-08-23  9:12       ` Alexey Kodanev
  0 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-22 17:18 UTC (permalink / raw)
  To: ltp

Hi Alexey,

again, thank you for your review!

> > +# Get IP address of unused network, specified by 3rd and 4th octet.
> > +# This is useful when 3rd and/or 4th octet are needed to be defined.
> > +# tst_ipaddr_un_ip [OCTET_3] [OCTET_4]

> 3rd and 4th octet are only meaningful for IPv4, what about 'net_id' and
> 'host_id' instead?
OK, no problem.

> > +# OCTET_3: Integer or hex value of 3rd octet; Default value is 0.
> > +# OCTET_4: Integer or hex value of 4th octet; Default value is 0.
> > +tst_ipaddr_un_ip()
> > +{
> > +	local octet_3="${1:-0}"
> > +	local octet_4="${2:-0}"
> > +	local max
> > +
> > +	[ "$TST_IPV6" ] && max=65535 || max=255
> > +
> > +	if [ "$TST_IPV6" ]; then
> > +		octet_3=$(printf %d $octet_3)
> > +		octet_4=$(printf %d $octet_4)
> > +	fi
> > +
> > +	[ $octet_3 -lt 0 ] && octet_3=0
> > +	[ $octet_4 -lt 0 ] && octet_4=1
> > +	[ $octet_3 -gt $max ] && octet_3=$max
> > +	[ $octet_4 -gt $max ] && octet_4=$max
> > +
> > +	if [ "$TST_IPV6" ]; then
> > +		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
> > +		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
> > +		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
> > +		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"

> '${octet_3}${octet_4}' - if max is 65K, it's 4 bytes, ':' missed?
Not sure if I get what you mean, I don't see missing ':'

$ TST_IPV6=6 tst_ipaddr_un_ip 65535
fd00:23::ffff:0

$ TST_IPV6=6 tst_ipaddr_un_ip 65535 65535
fd00:23::ffff:ffff

$ TST_IPV6=6 tst_ipaddr_un_ip 0 65535
fd00:23::ffff

But I'll use new version based on move one parameter before '::', as you suggested (see
bellow).


> I assume this is needed for getting subnets/routes, in most cases we would
> have 64-bit netmask that's why I would move one parameter before '::'

> echo "${IPV6_NET32_UNUSED}:${octet_3}::${octet_4}"
Right, changed:
if [ "$TST_IPV6" ]; then
	[ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id=
	[ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id=
	[ "$net_id" ] && net_id=":$net_id"
	echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}"
else
	echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}"
fi
i.e. don't print ':0', when host_id == 0 and don't print '0' at the end when host_id == 0.
I give up optimizations when IPV6_NET32_UNUSED contain ':' at the end (it shouldn't contain
it anyway).


> Can we have getopts in a single function to prevent code duplication?

OK, rewritten into single function:
# Get IP address of unused network, specified by either by type and
# counter or by net and host.
# tst_ipaddr_un -cCOUNTER [TYPE]
# tst_ipaddr_un [NET_ID] [HOST_ID]
# TYPE: { lhost | rhost }; Default value is 'lhost'.
# COUNTER: Integer value for counting HOST_ID and NET_ID. Default is 1.
# NET_ID: Integer or hex value of net. For IPv4 is 3rd octet, for IPv6 is 3rd
# hextet. Default value is 0.
# HOST_ID: Integer or hex value of host. For IPv4 is 4th octet, for IPv6 is the
# last hextet. Default value is 0.
tst_ipaddr_un()
{
	local counter host_id net_id max_host_id max_net_id tmp type
	local OPTIND

	while getopts "c:" opt; do
		case $opt in
			c) counter="$OPTARG";;
		esac
	done
	shift $(($OPTIND - 1))

	[ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255

	if [ "$counter" ]; then
		[ $counter -lt 1 ] && counter=1
		type="${1:-lhost}"
		max_host_id=$((max_net_id - 1))
		tmp=$((counter * 2))
		[ "$type" = "rhost" ] && tmp=$((tmp - 1))

		host_id=$((tmp % max_host_id))
		net_id=$((tmp / max_host_id))

		if [ $host_id -eq 0 ]; then
			host_id=$max_host_id
			net_id=$((net_id - 1))
		fi
	else
		net_id="${1:-0}"
		host_id="${2:-0}"
		max_host_id=$max_net_id
		if [ "$TST_IPV6" ]; then
			net_id=$(printf %d $net_id)
			host_id=$(printf %d $host_id)
		fi
		[ $net_id -lt 0 ] && net_id=0
		[ $host_id -lt 0 ] && host_id=1
	fi

	[ $net_id -gt $max_net_id ] && net_id=$max_net_id
	[ $host_id -gt $max_host_id ] && host_id=$max_host_id

	if [ "$TST_IPV6" ]; then
		[ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id=
		[ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id=
		[ "$net_id" ] && net_id=":$net_id"
		echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}"
	else
		echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}"
	fi
}

Any comments on it? (BTW I prefer in functions using OPTIND as local variable than
reseting it after use).

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH
  2017-08-21 13:42   ` Alexey Kodanev
@ 2017-08-22 17:21     ` Petr Vorel
  0 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-22 17:21 UTC (permalink / raw)
  To: ltp

> On 08/18/2017 07:44 PM, Petr Vorel wrote:
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> >  testcases/lib/test_net.sh | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)

> We already discussed it here:
> http://lists.linux.it/pipermail/ltp/2017-July/005113.html
I'm sorry, I had it in my TODO list to remove this patch, but forget on it. Will be in v9.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-08-21 15:31   ` Alexey Kodanev
@ 2017-08-22 20:13     ` Petr Vorel
  2017-08-23  9:39       ` Alexey Kodanev
  0 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-22 20:13 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > +# Force to reset netns.
> > +reset_ltp_netspace()
> > +{
> > +	[ -n "$TST_USE_NETNS" ] || return
> > +
> > +	tst_resm TINFO "reset netns"
> > +	ip link delete ltp_ns_veth2 2> /dev/null
> > +	rm -f /var/run/netns/ltp_ns
> > +	pkill ns_create

> Hmm, if there was custom netns you would break it anyway with this
> function and change to LTP one.

> I guess we should leave it unsupported for route rmmod test unless we
> figure out the right solution.

> Also, what if we reset only ltp veth pair, i.e.:

> reset_ltp_netspace()
> {
>     ...
>     [ "$(tst_iface)" != "ltp_ns_veth2" ] || return
Why this? I suppose it detects whether custom netns is used, but then I'd swap the
condition to:
	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return

>     ip li del ltp_ns_veth2 2>/dev/null
> }

> init_ltp_netspace()
> {
>     ...

>     pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>     export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"

>     if ! ip li sh $LHOST_IFACES > /dev/null 2>&1; then
>         ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
Code duplicity :-(.
>         ROD ns_ifmove ltp_ns_veth1 $pid
>     fi
>     ...
> }

It's working for me with this patch (turn over the condition in reset_ltp_netspace(), assuming
that custom netns would have different LHOST_IFACES, is that correct?):

+++ b/testcases/lib/test_net.sh
@@ -44,12 +44,26 @@ init_ltp_netspace()
 	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
 	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
 
+	if ! ip li show $LHOST_IFACES > /dev/null 2>&1; then
+		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
+		ROD ns_ifmove ltp_ns_veth1 $pid
+	fi
+
 	tst_restore_ipaddr
 	tst_restore_ipaddr rhost
 
 	tst_wait_ipv6_dad
 }
 
+# Force to reset netns.
+reset_ltp_netspace()
+{
+	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return
+	tst_resm TINFO "reset netns"
+	ip link delete ltp_ns_veth2 2> /dev/null
+	init_ltp_netspace
+}
+

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-22 11:46   ` Alexey Kodanev
@ 2017-08-22 21:22     ` Petr Vorel
  2017-08-23 13:17       ` Alexey Kodanev
                         ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-22 21:22 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > Tests using route_test_change() use background traffic instead of ns-udpsender
> > but I fixed it that it uses route. Is it too much overhead? The reason is I'd

> How do you use it to make a background traffic if you change route on
> every loop iteration?

> > like to get rid of all ugly scripts and binaries in
> > testcases/network/stress/ns-tools, including ns-udpsender.c.

> ns-udpsender can send a single UDP datagram over the new route without
> waiting for answer but unfortunately we don't know for sure whether it
> actually sent datagram and/or destination received it.
What would you suggest? I chose netstress as it's kind of client & server application. Do
we want to write something from scratch?
I don't like also the infinite loop in send_udp_datagram (I've caused one crash in local
network in previous tests by sending too many packets).



> > +	if [ "$cmd_type" = 'ifconfig_cmd' ]; then
> > +		cmd="$cmd_name $(tst_iface) down"
> > +		cmd2="$cmd_name $(tst_iface) up"
> > +	else
> > +		cmd="$cmd_name link set down dev $(tst_iface)"
> > +		cmd2="$cmd_name link set up dev $(tst_iface)"

> This test-case looks like duplicate of if-updown
OK, I'll delete testcases/network/stress/route/route4-ifdown and
testcases/network/stress/route/route6-ifdown. testcases/network/stress/interface/if-updown
looks cleaner anyway.
Anything else to delete? The more time I spend with route tests the more I doubt about
it's real value.

...
> > +# helper function for route4-change-{dst,gw,if} tests
> > +route_test_change()
> > +{
...
> > +	while [ $cnt -lt $NS_TIMES ]; do
> > +		lhost_ifname2="$lhost_ifname"
> > +		gateway2="$gateway"
> > +
> > +		pre_dst_network="$dst_network"
> > +		if [ "$test_field" = 'dst' ]; then
> > +			dst_addr="$(tst_ipaddr_un_ip $(($cnt % 255)) $DST_HOST)"
> > +			dst_network="$(tst_ipaddr_un_ip $(($cnt % 255)))"

> tst_ipaddr_un() handles '$cnt' overrun already.
Thanks, silly error.

> > +			netstress_cleanup

> cleanup in the test on every loop iteration?
That's used to kill netstress before calling make_background_tcp_traffic.

> > +		elif [ "$test_field" = 'gw' ]; then
> > +			gateway2="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt)))"
> > +			local cnt2=$(($cnt + 1))
> > +			[ $cnt2 -eq $RHOST_COUNTER_COUNT ] && cnt2=$RHOST_COUNTER_START
> > +			gateway="$(tst_ipaddr_un_host rhost $(($RHOST_COUNTER_START + $cnt2)))"

> Why do you need RHOST_COUNTER_COUNT and RHOST_COUNTER_START variables?
I create 10 unused addresses on rhost in route4-change-gw and then I'm using them in the
test. I use it also for RHOST_DST_ADDR (creating unique rhost address in route4-change-gw
used as destination address for check_connectivity_interval).

> > +		elif [ "$test_field" = 'if' ]; then
> > +			[ $link_num -ge $LINK_TOTAL ] && link_num=0
> > +			lhost_ifname="$(tst_iface lhost $link_num)"
> > +			gateway="$(tst_ipaddr_un_ip $link_num 1)"
> > +			link_num=$(($link_num + 1))
> > +		fi


> It's better to change 'if' structure to 'case' one
OK.


> > +
> > +		if [ $cnt -gt 0 ]; then
> > +			manipulate_route $cmd_name 'del' $pre_dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
> > +		fi
> > +
> > +		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
> > +		make_background_tcp_traffic $(tst_ipaddr_un_host)

> For generating traffic you're always using a single destination address,
> why it can't be $(tst_ipaddr)?
I thought it should be also on unused network, but as it's a simple check (not a new
route) I can change it to $(tst_ipaddr).

> > +		check_connectivity_interval $cnt false $lhost_ifname $dst_addr || return

> Could you please clarify the traffic flow here? if I understand it
> correctly ICMP goes over the new route/gw to an IP addresses on remote
> host which was added in setup, correct?
Yes.

> I think ns-udpsender is the more appropriate choice for a one way traffic...
OK. But we both don't like it's limitations (no guarantee of delivery and infinite loop)

> > --- a/testcases/network/stress/route/route4-rmmod
> > +++ b/testcases/network/stress/route/route4-rmmod

> ...

> >  test_body()
> >  {
> > -    test_type=$1
> > +	local cmd_type=$1
> > +	local cmd_name="$(get_cmd $cmd_type)"
> > +	local dst_addr=${DST_NETWORK}.${DST_HOST}
> > +	local dst_network=${DST_NETWORK}.0
Left unused variables, I remove them.

> > +	local cnt=0

> > -    TCID=route4-rmmod0${test_type}
> > -    TST_COUNT=$test_type
> > +	tst_resm TINFO "IPv4 route is added by '$cmd_name' command and then deleted by removing network driver $NS_TIMES times"

> This is not what the test does after the changes.
Yes, no route added, sorry. I removed it because it was already set by
tst_add_ipaddr_stress:
10.23.0.0/24 dev ltp_ns_veth2  proto kernel  scope link  src 10.23.0.2

> With this implementation it should be moved to 'interface' group.
I'll put it back to match the description and really test creating route, so I can keep it
here.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions
  2017-08-22 17:18     ` Petr Vorel
@ 2017-08-23  9:12       ` Alexey Kodanev
  0 siblings, 0 replies; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-23  9:12 UTC (permalink / raw)
  To: ltp

Hi Petr,
On 22.08.2017 20:18, Petr Vorel wrote:
> Hi Alexey,
>
> again, thank you for your review!
>
>>> +# Get IP address of unused network, specified by 3rd and 4th octet.
>>> +# This is useful when 3rd and/or 4th octet are needed to be defined.
>>> +# tst_ipaddr_un_ip [OCTET_3] [OCTET_4]
>> 3rd and 4th octet are only meaningful for IPv4, what about 'net_id' and
>> 'host_id' instead?
> OK, no problem.
>
>>> +# OCTET_3: Integer or hex value of 3rd octet; Default value is 0.
>>> +# OCTET_4: Integer or hex value of 4th octet; Default value is 0.
>>> +tst_ipaddr_un_ip()
>>> +{
>>> +	local octet_3="${1:-0}"
>>> +	local octet_4="${2:-0}"
>>> +	local max
>>> +
>>> +	[ "$TST_IPV6" ] && max=65535 || max=255
>>> +
>>> +	if [ "$TST_IPV6" ]; then
>>> +		octet_3=$(printf %d $octet_3)
>>> +		octet_4=$(printf %d $octet_4)
>>> +	fi
>>> +
>>> +	[ $octet_3 -lt 0 ] && octet_3=0
>>> +	[ $octet_4 -lt 0 ] && octet_4=1
>>> +	[ $octet_3 -gt $max ] && octet_3=$max
>>> +	[ $octet_4 -gt $max ] && octet_4=$max
>>> +
>>> +	if [ "$TST_IPV6" ]; then
>>> +		[ $octet_3 -gt 0 ] && octet_3="$(printf %x $octet_3)" || octet_3=
>>> +		[ $octet_4 -gt 0 -o "$octet_3" ] && octet_4="$(printf %x $octet_4)" || octet_4=
>>> +		[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"
>>> +		echo "${IPV6_NET32_UNUSED}::${octet_3}${octet_4}"
>> '${octet_3}${octet_4}' - if max is 65K, it's 4 bytes, ':' missed?
> Not sure if I get what you mean, I don't see missing ':'

Sorry,  now I see that you added it here:

[ "$octet_3" -a "$octet_4" ] && octet_4=":$octet_4"

>
> $ TST_IPV6=6 tst_ipaddr_un_ip 65535
> fd00:23::ffff:0
>
> $ TST_IPV6=6 tst_ipaddr_un_ip 65535 65535
> fd00:23::ffff:ffff
>
> $ TST_IPV6=6 tst_ipaddr_un_ip 0 65535
> fd00:23::ffff
>
> But I'll use new version based on move one parameter before '::', as you suggested (see
> bellow).
>
>
>> I assume this is needed for getting subnets/routes, in most cases we would
>> have 64-bit netmask that's why I would move one parameter before '::'
>> echo "${IPV6_NET32_UNUSED}:${octet_3}::${octet_4}"
> Right, changed:
> if [ "$TST_IPV6" ]; then
> 	[ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id=
> 	[ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id=
> 	[ "$net_id" ] && net_id=":$net_id"
> 	echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}"
> else
> 	echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}"
> fi
> i.e. don't print ':0', when host_id == 0 and don't print '0' at the end when host_id == 0.
> I give up optimizations when IPV6_NET32_UNUSED contain ':' at the end (it shouldn't contain
> it anyway).
>
>
>> Can we have getopts in a single function to prevent code duplication?
> OK, rewritten into single function:
> # Get IP address of unused network, specified by either by type and
> # counter or by net and host.
> # tst_ipaddr_un -cCOUNTER [TYPE]
> # tst_ipaddr_un [NET_ID] [HOST_ID]
> # TYPE: { lhost | rhost }; Default value is 'lhost'.
> # COUNTER: Integer value for counting HOST_ID and NET_ID. Default is 1.
> # NET_ID: Integer or hex value of net. For IPv4 is 3rd octet, for IPv6 is 3rd
> # hextet. Default value is 0.
> # HOST_ID: Integer or hex value of host. For IPv4 is 4th octet, for IPv6 is the
> # last hextet. Default value is 0.
> tst_ipaddr_un()
> {
> 	local counter host_id net_id max_host_id max_net_id tmp type
> 	local OPTIND
>
> 	while getopts "c:" opt; do
> 		case $opt in
> 			c) counter="$OPTARG";;
> 		esac
> 	done
> 	shift $(($OPTIND - 1))
>
> 	[ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255
>
> 	if [ "$counter" ]; then

What about handling the case here when no parameter specified or only
the type?

-    if [ "$counter" ]; then
+    if [ $# -eq 0 -o "$1" = "rhost" ]; then


Thanks,
Alexey

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-08-22 20:13     ` Petr Vorel
@ 2017-08-23  9:39       ` Alexey Kodanev
  2017-08-23 10:21         ` Petr Vorel
  0 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-23  9:39 UTC (permalink / raw)
  To: ltp

On 22.08.2017 23:13, Petr Vorel wrote:
> Hi Alexey,
>
>>> +# Force to reset netns.
>>> +reset_ltp_netspace()
>>> +{
>>> +	[ -n "$TST_USE_NETNS" ] || return
>>> +
>>> +	tst_resm TINFO "reset netns"
>>> +	ip link delete ltp_ns_veth2 2> /dev/null
>>> +	rm -f /var/run/netns/ltp_ns
>>> +	pkill ns_create
>> Hmm, if there was custom netns you would break it anyway with this
>> function and change to LTP one.
>> I guess we should leave it unsupported for route rmmod test unless we
>> figure out the right solution.
>> Also, what if we reset only ltp veth pair, i.e.:
>> reset_ltp_netspace()
>> {
>>     ...
>>     [ "$(tst_iface)" != "ltp_ns_veth2" ] || return
> Why this? I suppose it detects whether custom netns is used, but then I'd swap the
> condition to:
> 	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return

Right

>
>>     ip li del ltp_ns_veth2 2>/dev/null
>> }
>> init_ltp_netspace()
>> {
>>     ...
>>     pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>>     export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
>>     if ! ip li sh $LHOST_IFACES > /dev/null 2>&1; then
>>         ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
> Code duplicity :-(.

Why? it is moved here from the upper if block.

>>         ROD ns_ifmove ltp_ns_veth1 $pid
>>     fi
>>     ...
>> }
> It's working for me with this patch (turn over the condition in reset_ltp_netspace(), assuming
> that custom netns would have different LHOST_IFACES, is that correct?):

I'm not sure how to handle it correctly for rmmod test right now,
may be we should TCONF on the check inside the test:

$TST_USE_NETNS -a "$(tst_iface)" != "ltp_ns_veth2"


Thanks,
Alexey

>
> +++ b/testcases/lib/test_net.sh
> @@ -44,12 +44,26 @@ init_ltp_netspace()
>  	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>  	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
>  
> +	if ! ip li show $LHOST_IFACES > /dev/null 2>&1; then
> +		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
> +		ROD ns_ifmove ltp_ns_veth1 $pid
> +	fi
> +
>  	tst_restore_ipaddr
>  	tst_restore_ipaddr rhost
>  
>  	tst_wait_ipv6_dad
>  }
>  
> +# Force to reset netns.
> +reset_ltp_netspace()
> +{
> +	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return
> +	tst_resm TINFO "reset netns"
> +	ip link delete ltp_ns_veth2 2> /dev/null
> +	init_ltp_netspace
> +}
> +



^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-08-23  9:39       ` Alexey Kodanev
@ 2017-08-23 10:21         ` Petr Vorel
  0 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-23 10:21 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> >>     ip li del ltp_ns_veth2 2>/dev/null
> >> }
> >> init_ltp_netspace()
> >> {
> >>     ...
> >>     pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
> >>     export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
> >>     if ! ip li sh $LHOST_IFACES > /dev/null 2>&1; then
> >>         ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
> > Code duplicity :-(.

> Why? it is moved here from the upper if block.
OK :-).

Final version of reset_ltp_netspace() patch:

+++ b/testcases/lib/test_net.sh
@@ -26,13 +26,11 @@ init_ltp_netspace()
 	local pid=
 
 	if [ ! -f /var/run/netns/ltp_ns ]; then
-		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
 		pid="$(ROD ns_create net,mnt)"
 		mkdir -p /var/run/netns
 		ROD ln -s /proc/$pid/ns/net /var/run/netns/ltp_ns
 		ROD ns_exec $pid net,mnt mount --make-rprivate /sys
 		ROD ns_exec $pid net,mnt mount -t sysfs none /sys
-		ROD ns_ifmove ltp_ns_veth1 $pid
 		ROD ns_exec $pid net,mnt ip li set lo up
 	fi
 
@@ -44,12 +42,30 @@ init_ltp_netspace()
 	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
 	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
 
+	if ! ip li show $LHOST_IFACES > /dev/null 2>&1; then
+		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
+		ROD ns_ifmove ltp_ns_veth1 $pid
+	fi
+
 	tst_restore_ipaddr
 	tst_restore_ipaddr rhost
 
 	tst_wait_ipv6_dad
 }
 
+# Force to reset netns.
+reset_ltp_netspace()
+{
+	[ -n "$TST_USE_NETNS" ] || return
+
+	# resetting netns when using custom netns is not supported
+	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return
+
+	tst_resm TINFO "reset netns"
+	ip link delete ltp_ns_veth2 2> /dev/null
+	init_ltp_netspace
+}

> >>         ROD ns_ifmove ltp_ns_veth1 $pid
> >>     fi
> >>     ...
> >> }
> > It's working for me with this patch (turn over the condition in reset_ltp_netspace(), assuming
> > that custom netns would have different LHOST_IFACES, is that correct?):

> I'm not sure how to handle it correctly for rmmod test right now,
> may be we should TCONF on the check inside the test:

> $TST_USE_NETNS -a "$(tst_iface)" != "ltp_ns_veth2"

Right, tst_brkm TCONF added into setup of route4-rmmod test.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables
  2017-08-22 12:23   ` Alexey Kodanev
@ 2017-08-23 10:46     ` Petr Vorel
  0 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-23 10:46 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Here is the thread with minor comments that still applicable to this
> version:

> http://lists.linux.it/pipermail/ltp/2017-June/004838.html
Sorry for forgetting on it.
I've fixed warning for C sources (tst_net_vars.c, tst_net_ip_prefix.c,
tst_net_iface_prefix.c), except false positives ("do not add new typedefs" and "open brace
'{' following function declarations go on the next line" for NLMSG_OK() macro).

I haven't found any other usage for SAFE_* macros than SAFE_SOCKET() and SAFE_SEND().


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-22 21:22     ` Petr Vorel
@ 2017-08-23 13:17       ` Alexey Kodanev
  2017-08-23 13:49         ` Petr Vorel
  2017-08-23 13:34       ` Petr Vorel
  2017-08-23 13:57       ` Petr Vorel
  2 siblings, 1 reply; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-23 13:17 UTC (permalink / raw)
  To: ltp

On 23.08.2017 0:22, Petr Vorel wrote:
> Hi Alexey,
>
>>> Tests using route_test_change() use background traffic instead of ns-udpsender
>>> but I fixed it that it uses route. Is it too much overhead? The reason is I'd
>> How do you use it to make a background traffic if you change route on
>> every loop iteration?
>>> like to get rid of all ugly scripts and binaries in
>>> testcases/network/stress/ns-tools, including ns-udpsender.c.
>> ns-udpsender can send a single UDP datagram over the new route without
>> waiting for answer but unfortunately we don't know for sure whether it
>> actually sent datagram and/or destination received it.
> What would you suggest? I chose netstress as it's kind of client & server application. Do
> we want to write something from scratch?
> I don't like also the infinite loop in send_udp_datagram (I've caused one crash in local
> network in previous tests by sending too many packets).

I would convert to match the previous version for now, e.g.route-change-dst.

do_test()
{
        local new_rtaddrcnt
        local if=$(tst_iface)
        local inet="inet$TST_IPV6"

        tst_resm TINFO "change IPv$ipver route $NS_TIMES times"

        local udp_size=1472
        local mask=24
        if [ "$TST_IPV6" ]; then
            udp_size=1452
            mask=64
        fi

        cnt=1
        while [ $cnt -le $NS_TIMES ]; do

            new_rt="$(tst_ipaddr_un $cnt)/$mask"
            addr="$(tst_ipaddr_un $cnt 1)"
           
            ROD ip route add $new_rt dev $if
            ROD ip ne replace $addr lladdr $(tst_hwaddr rhost) nud
permanent dev $if

            # Load the route with one UDP datagram
            ROD ns-udpsender -f $ipver -D $addr -p $cnt -o -s $udp_size

            ROD ip neigh del $addr lladdr $(tst_hwaddr rhost)dev $if
            ROD ip route del $new_rt dev $if

            cnt=$(($cnt + 1))
        done

        tst_resm TPASS "Test is finished correctly"
}

For background traffic it's better to have 'netstress' running.

Thanks,
Alexey

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-22 21:22     ` Petr Vorel
  2017-08-23 13:17       ` Alexey Kodanev
@ 2017-08-23 13:34       ` Petr Vorel
  2017-08-23 13:38         ` Alexey Kodanev
  2017-08-23 13:57       ` Petr Vorel
  2 siblings, 1 reply; 33+ messages in thread
From: Petr Vorel @ 2017-08-23 13:34 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > > +	while [ $cnt -lt $NS_TIMES ]; do
> > > +		lhost_ifname2="$lhost_ifname"
> > > +		gateway2="$gateway"
> > > +
> > > +		pre_dst_network="$dst_network"
> > > +		if [ "$test_field" = 'dst' ]; then
> > > +			dst_addr="$(tst_ipaddr_un_ip $(($cnt % 255)) $DST_HOST)"
> > > +			dst_network="$(tst_ipaddr_un_ip $(($cnt % 255)))"

> > tst_ipaddr_un() handles '$cnt' overrun already.
> Thanks, silly error.
No, I'll keep it, without it addresses for cnt > 254 would be always 254 (no real
testing).

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-23 13:34       ` Petr Vorel
@ 2017-08-23 13:38         ` Alexey Kodanev
  0 siblings, 0 replies; 33+ messages in thread
From: Alexey Kodanev @ 2017-08-23 13:38 UTC (permalink / raw)
  To: ltp

On 23.08.2017 16:34, Petr Vorel wrote:
> Hi Alexey,
>
>>>> +	while [ $cnt -lt $NS_TIMES ]; do
>>>> +		lhost_ifname2="$lhost_ifname"
>>>> +		gateway2="$gateway"
>>>> +
>>>> +		pre_dst_network="$dst_network"
>>>> +		if [ "$test_field" = 'dst' ]; then
>>>> +			dst_addr="$(tst_ipaddr_un_ip $(($cnt % 255)) $DST_HOST)"
>>>> +			dst_network="$(tst_ipaddr_un_ip $(($cnt % 255)))"
>>> tst_ipaddr_un() handles '$cnt' overrun already.
>> Thanks, silly error.
> No, I'll keep it, without it addresses for cnt > 254 would be always 254 (no real
> testing).

If so, it should be added to tst_ipaddr_un.

Thanks,
Alexey

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-23 13:17       ` Alexey Kodanev
@ 2017-08-23 13:49         ` Petr Vorel
  0 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-23 13:49 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> >>> Tests using route_test_change() use background traffic instead of ns-udpsender
> >>> but I fixed it that it uses route. Is it too much overhead? The reason is I'd
> >> How do you use it to make a background traffic if you change route on
> >> every loop iteration?
> >>> like to get rid of all ugly scripts and binaries in
> >>> testcases/network/stress/ns-tools, including ns-udpsender.c.
> >> ns-udpsender can send a single UDP datagram over the new route without
> >> waiting for answer but unfortunately we don't know for sure whether it
> >> actually sent datagram and/or destination received it.
> > What would you suggest? I chose netstress as it's kind of client & server application. Do
> > we want to write something from scratch?
> > I don't like also the infinite loop in send_udp_datagram (I've caused one crash in local
> > network in previous tests by sending too many packets).

> I would convert to match the previous version for now, e.g.route-change-dst.
Sorry, do you to use ns-udpsender just in route-change-dst (as it's the only one which
kill netstress each time in loop by calling netstress_cleanup() ) or in all route tests
which are using it?

> do_test()
> {
>         local new_rtaddrcnt
>         local if=$(tst_iface)
>         local inet="inet$TST_IPV6"

>         tst_resm TINFO "change IPv$ipver route $NS_TIMES times"

>         local udp_size=1472
>         local mask=24
>         if [ "$TST_IPV6" ]; then
>             udp_size=1452
>             mask=64
>         fi

>         cnt=1
>         while [ $cnt -le $NS_TIMES ]; do

>             new_rt="$(tst_ipaddr_un $cnt)/$mask"
>             addr="$(tst_ipaddr_un $cnt 1)"

>             ROD ip route add $new_rt dev $if
>             ROD ip ne replace $addr lladdr $(tst_hwaddr rhost) nud
> permanent dev $if

>             # Load the route with one UDP datagram
>             ROD ns-udpsender -f $ipver -D $addr -p $cnt -o -s $udp_size

>             ROD ip neigh del $addr lladdr $(tst_hwaddr rhost)dev $if
>             ROD ip route del $new_rt dev $if

>             cnt=$(($cnt + 1))
>         done

>         tst_resm TPASS "Test is finished correctly"
> }

> For background traffic it's better to have 'netstress' running.
I see you probably don't like manipulate_route (the name is ugly - too long and I have to
admit that direct commands are more readable). If you want, I can replace it into direct
commands (as you mentioned some time ago). I just don't like many 'case' commands and
code repeating.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-08-22 21:22     ` Petr Vorel
  2017-08-23 13:17       ` Alexey Kodanev
  2017-08-23 13:34       ` Petr Vorel
@ 2017-08-23 13:57       ` Petr Vorel
  2 siblings, 0 replies; 33+ messages in thread
From: Petr Vorel @ 2017-08-23 13:57 UTC (permalink / raw)
  To: ltp

Hi Alexey,


> > > +	if [ "$cmd_type" = 'ifconfig_cmd' ]; then
> > > +		cmd="$cmd_name $(tst_iface) down"
> > > +		cmd2="$cmd_name $(tst_iface) up"
> > > +	else
> > > +		cmd="$cmd_name link set down dev $(tst_iface)"
> > > +		cmd2="$cmd_name link set up dev $(tst_iface)"

> > This test-case looks like duplicate of if-updown
> OK, I'll delete testcases/network/stress/route/route4-ifdown and
> testcases/network/stress/route/route6-ifdown. testcases/network/stress/interface/if-updown
> looks cleaner anyway.
Again, I didn't implement adding route before putting the interface down. This delete
route, so the use case is different from if-updown. I fix it and keep the test.

> Anything else to delete? The more time I spend with route tests the more I doubt about
> it's real value.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2017-08-23 13:57 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-18 16:44 [LTP] [RFC PATCH v8 00/11] Simplify network setup + fix some network stress tests Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 01/11] lib/test_net.sh: Add unused IP address helper functions Petr Vorel
2017-08-21 13:31   ` Alexey Kodanev
2017-08-22 17:18     ` Petr Vorel
2017-08-23  9:12       ` Alexey Kodanev
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 02/11] network/stress: Add library helper for stress testing Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 04/11] network/stress: Reduce the default number of cycles for various tests Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
2017-08-21 13:42   ` Alexey Kodanev
2017-08-22 17:21     ` Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
2017-08-21 13:52   ` Alexey Kodanev
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
2017-08-21 15:31   ` Alexey Kodanev
2017-08-22 20:13     ` Petr Vorel
2017-08-23  9:39       ` Alexey Kodanev
2017-08-23 10:21         ` Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
2017-08-22 11:46   ` Alexey Kodanev
2017-08-22 21:22     ` Petr Vorel
2017-08-23 13:17       ` Alexey Kodanev
2017-08-23 13:49         ` Petr Vorel
2017-08-23 13:34       ` Petr Vorel
2017-08-23 13:38         ` Alexey Kodanev
2017-08-23 13:57       ` Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 10/11] network: Add tools for setup IP related environment variables Petr Vorel
2017-08-21  6:10   ` Petr Vorel
2017-08-22 12:23   ` Alexey Kodanev
2017-08-23 10:46     ` Petr Vorel
2017-08-18 16:44 ` [LTP] [RFC PATCH v8 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
2017-08-22 12:49   ` Alexey Kodanev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.