All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests
@ 2017-06-03 12:00 Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 01/11] gitignore: Prefixing filenames Petr Vorel
                   ` (11 more replies)
  0 siblings, 12 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

Hi,

as it might be uncomfortable to see patches on mailing list, you can also see
them on github: https://github.com/pevik/ltp/tree/tst_net_vars.v6

changes v5->v6:

Changes in network setup (testcases/lib/tst_net_vars.c):
* Simplify parsing network and host part of IP. Now it calculate just network
  part and set host as the rest of what is left from IP.
* Try to lookup local iface name and prefix in rtnetlink data if prefix not
  provided in setup (in form of IP/PREFIX). Don't look up for remote prefix and
  iface name as we would need to setup connection first, but this requires to
  know them (remote prefix and iface name) for remote connection (or am I
  missing something?).
* When rtnetlink find local prefix and remote prefix isn't provided, use the
  local one.

Changes in shell libraries:
* test_net.sh: Add reset_ltp_netspace() function (required by route4-rmmod test).
* Create general library test_stress_net.sh (for all stress tests) and
  mcast4-lib.sh (multicast IPv4 tests) and route4-lib.sh (route IPv4 tests).
* Fix 'unbound variable' error in shell libraries.

Changes in tests:
* Fixed part of IPv4 multicast and route and use variables parsed with
  tst_net_vars for them + cleanup. Lots of tests in
  testcases/network/stress/multicast and testcases/network/stress/route isn't
  working at least for netns. There is also great duplicity in the code. It
  would be great to get rid of all scripts in testcases/network/stress/ns-tools
  and use functions from test_net.sh or other libraries (also remove a lot of
  code duplicity) => TODO: cleanup all tests.
* tst_net_vars simplifies setup as it only needs to have passed 4 IP
  addresses (2x IPv4 and 2 IPv6) and alows to define different network part for
  local and remote hosts.
* Rename variables in rewritten tests to use variables defined by
  tst_net_vars. These scripts are run by testscripts/network.sh script which
  defined these variables by setting test_net.sh, so it makes a sense to use
  them. Old tests still use IPV4_NETWORK variable instead of IPV4_LNETWORK and
  IPV4_RNETWORK and have it defined locally.
* Various cleanup.

Petr Vorel (11):
  gitignore: Prefixing filenames
  lib: Fix 'unbound variable' error in shell libraries
  network/stress: Fix typo
  network/stress: Use correct reporting function
  network/stress: Remove bg_tcp_traffic script
  network/stress: Add library test_stress_net.sh for general usage
  network/stress: Fix and cleanup part of multicast IPv4 tests
  lib/test_net.sh: reset_ltp_netspace()
  network/stress: Fix and cleanup route IPv4 tests
  network: Add tools for setup IP related environment variables
  network: Use tst_net_vars to set up IPv4 and IPv6 related variables

 testcases/lib/.gitignore                           |  13 +-
 testcases/lib/Makefile                             |   4 +-
 testcases/lib/test.sh                              |   4 +-
 testcases/lib/test_net.sh                          |  70 +-
 testcases/lib/tst_net_vars.c                       | 802 +++++++++++++++++++++
 testcases/network/stress/README                    |   6 +-
 .../stress/icmp/multi-diffip/icmp4-multi-diffip01  |   2 +-
 testcases/network/stress/interface/if-addr-adddel  |   2 +-
 .../network/stress/interface/if-addr-addlarge      |   3 +-
 testcases/network/stress/interface/if-lib.sh       |  32 +-
 testcases/network/stress/interface/if-route-adddel |   2 +-
 .../network/stress/interface/if-route-addlarge     |   2 +-
 testcases/network/stress/interface/if-updown       |   2 +-
 testcases/network/stress/interface/if4-addr-change |   2 +-
 .../stress/multicast/grp-operation/mcast4-grpope01 | 222 +-----
 .../stress/multicast/grp-operation/mcast4-grpope02 | 231 +-----
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 +-----
 .../stress/multicast/grp-operation/mcast4-grpope04 | 233 +-----
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 143 ++++
 .../network/stress/ns-tools/00_Descriptions.txt    |   3 -
 testcases/network/stress/ns-tools/Makefile         |   8 +-
 testcases/network/stress/ns-tools/bg_tcp_traffic   | 275 -------
 testcases/network/stress/ns-tools/initialize_if    |   3 -
 testcases/network/stress/ns-tools/ns-tcpserver.c   |   2 +-
 .../network/stress/ns-tools/test_stress_net.sh     | 138 ++++
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 287 +-------
 testcases/network/stress/route/route4-change-gw    | 308 +-------
 testcases/network/stress/route/route4-change-if    | 348 ++-------
 testcases/network/stress/route/route4-ifdown       | 298 ++------
 testcases/network/stress/route/route4-lib.sh       | 252 +++++++
 testcases/network/stress/route/route4-redirect     | 232 ++----
 testcases/network/stress/route/route4-rmmod        | 329 +++------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 testcases/network/stress/route/route6-rmmod        |   2 +-
 .../stress/tcp/multi-diffip/tcp4-multi-diffip01    |   2 +-
 .../stress/udp/multi-diffip/udp4-multi-diffip01    |   2 +-
 37 files changed, 1829 insertions(+), 2677 deletions(-)
 create mode 100644 testcases/lib/tst_net_vars.c
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
 delete mode 100644 testcases/network/stress/ns-tools/bg_tcp_traffic
 create mode 100644 testcases/network/stress/ns-tools/test_stress_net.sh
 create mode 100644 testcases/network/stress/route/route4-lib.sh

-- 
2.12.2


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

* [LTP] [RFC PATCH v6 01/11] gitignore: Prefixing filenames
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 02/11] lib: Fix 'unbound variable' error in shell libraries Petr Vorel
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

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

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 920817cac..522889bed 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,6 +1,6 @@
-tst_sleep
-tst_random
-tst_checkpoint
-tst_rod
-tst_kvcmp
-tst_device
+/tst_sleep
+/tst_random
+/tst_checkpoint
+/tst_rod
+/tst_kvcmp
+/tst_device
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 02/11] lib: Fix 'unbound variable' error in shell libraries
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 01/11] gitignore: Prefixing filenames Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 03/11] network/stress: Fix typo Petr Vorel
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

Some distros have set shell option 'nounset' as default, which requires
to fix testing optional variables.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test.sh     | 4 ++--
 testcases/lib/test_net.sh | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 2e4d86809..642f7eacf 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -103,11 +103,11 @@ tst_require_root()
 
 tst_exit()
 {
-	if [ -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
+	if [ -n "${TST_CLEANUP:-}" -a -z "${TST_NO_CLEANUP:-}" ]; then
 		$TST_CLEANUP
 	fi
 
-	if [ -n "$LTP_IPC_PATH" -a -f "$LTP_IPC_PATH" ]; then
+	if [ -n "${LTP_IPC_PATH:-}" -a -f "${LTP_IPC_PATH:-}" ]; then
 		rm -f "$LTP_IPC_PATH"
 	fi
 
diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 08493558b..f93f67411 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -83,7 +83,7 @@ tst_rhost_run()
 
 	local output=
 	local ret=0
-	if [ -n "$TST_USE_SSH" ]; then
+	if [ -n "${TST_USE_SSH:-}" ]; then
 		output=`ssh -n -q $user@$RHOST "sh -c \
 			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
 	elif [ -n "$TST_USE_NETNS" ]; then
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 03/11] network/stress: Fix typo
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 01/11] gitignore: Prefixing filenames Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 02/11] lib: Fix 'unbound variable' error in shell libraries Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 04/11] network/stress: Use correct reporting function Petr Vorel
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/README                  | 6 +++---
 testcases/network/stress/ns-tools/ns-tcpserver.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/testcases/network/stress/README b/testcases/network/stress/README
index fbfbc1cc0..c0d0ad374 100644
--- a/testcases/network/stress/README
+++ b/testcases/network/stress/README
@@ -23,7 +23,7 @@ control link is never changed.
 
 Test Links are the place where the stress tests run. For example, test packets
 flow those links. The number of test links must be at least 1. The setting of
-the interfaces connectted to the test links would be changed by the tests.
+the interfaces connected to the test links would be changed by the tests.
 Therefore, each test link should not belong to any external network. It is
 recommended to connect each pair of interfaces with the ether cross cables.
 
@@ -136,13 +136,13 @@ Required environment variables
 
  o LHOST_HWADDRS
    The blank-separated hardware address list of the interfaces which are
-   connectted to a test link at the local host.
+   connected to a test link at the local host.
    This value have to have at least one address. The sequence of the hardware
    address have to be same to the test link sequence.
 
  o RHOST_HWADDRS
    The blank-separated hardware address list of the interfaces which are
-   connectted to a test link at the remote host.
+   connected to a test link at the remote host.
    This value have to have at least one address. The sequence of the hardware
    address have to be same to the test link sequence.
 
diff --git a/testcases/network/stress/ns-tools/ns-tcpserver.c b/testcases/network/stress/ns-tools/ns-tcpserver.c
index 4ac51a9ee..bfbcc0d4e 100644
--- a/testcases/network/stress/ns-tools/ns-tcpserver.c
+++ b/testcases/network/stress/ns-tools/ns-tcpserver.c
@@ -276,7 +276,7 @@ void create_listen_socket(struct server_info *info_p)
  * Function: communicate_client()
  *
  * Descripton:
- *  Communicate with the connectted client.
+ *  Communicate with the connected client.
  *  Currently, this function sends tcp segment in the specified second
  *  or recevie SIGHUP
  *
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 04/11] network/stress: Use correct reporting function
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (2 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 03/11] network/stress: Fix typo Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script Petr Vorel
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

as tst_info dosn't exist.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/icmp/multi-diffip/icmp4-multi-diffip01 | 2 +-
 testcases/network/stress/route/route4-rmmod                     | 2 +-
 testcases/network/stress/route/route6-rmmod                     | 2 +-
 testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01   | 2 +-
 testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/testcases/network/stress/icmp/multi-diffip/icmp4-multi-diffip01 b/testcases/network/stress/icmp/multi-diffip/icmp4-multi-diffip01
index ad2da16b0..fe70f0041 100644
--- a/testcases/network/stress/icmp/multi-diffip/icmp4-multi-diffip01
+++ b/testcases/network/stress/icmp/multi-diffip/icmp4-multi-diffip01
@@ -177,7 +177,7 @@ while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
     x=`expr $ipaddr_pair_num \/ 255 % 255`
     y=`expr $ipaddr_pair_num % 255`
     if [ $x -ge 255 ]; then
-	tst_info TINFO "This script cannot add more than $ipaddr_pair_num addresses"
+	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
 	break
     fi
 
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 11c9711ad..36c8c970d 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -121,7 +121,7 @@ do_setup()
     # Check the local host has ethtool utility
     which ethtool >/dev/null
     if [ $? -ne 0 ]; then
-	tst_info TBROK "This test case requires ethtool utility"
+	tst_resm TBROK "This test case requires ethtool utility"
 	exit $TST_TOTAL
     fi
 
diff --git a/testcases/network/stress/route/route6-rmmod b/testcases/network/stress/route/route6-rmmod
index 164cf2663..640cc065f 100644
--- a/testcases/network/stress/route/route6-rmmod
+++ b/testcases/network/stress/route/route6-rmmod
@@ -117,7 +117,7 @@ do_setup()
     # Check the local host has ethtool utility
     which ethtool >/dev/null
     if [ $? -ne 0 ]; then
-	tst_info TBROK "This test case requires ethtool utility"
+	tst_resm TBROK "This test case requires ethtool utility"
 	exit $TST_TOTAL
     fi
 
diff --git a/testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01 b/testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01
index 8b9652c9f..999597735 100644
--- a/testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01
+++ b/testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01
@@ -205,7 +205,7 @@ while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
     x=`expr $ipaddr_pair_num \/ 255 % 255`
     y=`expr $ipaddr_pair_num % 255`
     if [ $x -ge 255 ]; then
-	tst_info TINFO "This script cannot add more than $ipaddr_pair_num addresses"
+	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
 	break
     fi
 
diff --git a/testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01 b/testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01
index 33d226515..63783d16e 100644
--- a/testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01
+++ b/testcases/network/stress/udp/multi-diffip/udp4-multi-diffip01
@@ -171,7 +171,7 @@ while [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
     x=`expr $ipaddr_pair_num \/ 255 % 255`
     y=`expr $ipaddr_pair_num % 255`
     if [ $x -ge 255 ]; then
-	tst_info TINFO "This script cannot add more than $ipaddr_pair_num addresses"
+	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
 	break
     fi
 
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (3 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 04/11] network/stress: Use correct reporting function Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-06 13:12   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage Petr Vorel
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

Script has been unused since:
commit 5fe27d6a193d12e265509d04f1d7fab980ba5fae
Author: Alexey Kodanev <alexey.kodanev@oracle.com>
Date:   Sun Feb 1 13:10:36 2015 +0300

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 .../network/stress/ns-tools/00_Descriptions.txt    |   3 -
 testcases/network/stress/ns-tools/Makefile         |   8 +-
 testcases/network/stress/ns-tools/bg_tcp_traffic   | 275 ---------------------
 3 files changed, 4 insertions(+), 282 deletions(-)
 delete mode 100644 testcases/network/stress/ns-tools/bg_tcp_traffic

diff --git a/testcases/network/stress/ns-tools/00_Descriptions.txt b/testcases/network/stress/ns-tools/00_Descriptions.txt
index 85f69ad59..ab9c3ce8e 100644
--- a/testcases/network/stress/ns-tools/00_Descriptions.txt
+++ b/testcases/network/stress/ns-tools/00_Descriptions.txt
@@ -37,9 +37,6 @@ create_file
 find_portbundle
 	Find a bundle of consecutive ports
 
-bg_tcp_traffic
-	Control the background TCP traffic
-
 killall_icmp_traffic
 	Kill all of the icmp traffic utilities (ping or ping6)
 
diff --git a/testcases/network/stress/ns-tools/Makefile b/testcases/network/stress/ns-tools/Makefile
index df9ba42e3..61f85634a 100644
--- a/testcases/network/stress/ns-tools/Makefile
+++ b/testcases/network/stress/ns-tools/Makefile
@@ -25,11 +25,11 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/env_pre.mk
 
 INSTALL_TARGETS		:= check_envval get_ifname initialize_if set_ipv4addr \
-		   	   add_ipv6addr check_icmpv4_connectivity \
+			   add_ipv6addr check_icmpv4_connectivity \
 			   check_icmpv6_connectivity check_netem check_setkey \
-			   create_file find_portbundle bg_tcp_traffic \
-			   killall_icmp_traffic killall_tcp_traffic \
-			   killall_udp_traffic output_ipsec_conf ns-echoclient
+			   create_file find_portbundle killall_icmp_traffic \
+			   killall_tcp_traffic killall_udp_traffic output_ipsec_conf \
+			   ns-echoclient
 
 FILTER_OUT_MAKE_TARGETS	:= ns-common
 
diff --git a/testcases/network/stress/ns-tools/bg_tcp_traffic b/testcases/network/stress/ns-tools/bg_tcp_traffic
deleted file mode 100644
index 630378c9d..000000000
--- a/testcases/network/stress/ns-tools/bg_tcp_traffic
+++ /dev/null
@@ -1,275 +0,0 @@
-#!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2005                 ##
-##                                                                            ##
-## 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:
-#   bg_tcp_traffic
-#
-# Description:
-#   Control the background TCP traffic
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# Arguments:
-#   $1: command (make/check/kill/killall)
-#   $2: IP address when the command is make
-#       Process ID when the command is check or kill
-#
-# Outputs:
-#   Process ID of the TCP traffic server when the command is make
-#
-# Exit Value:
-#    0: Exit normally
-#   >0: Exit abnormally
-#
-# History:
-#   Oct 19 2005 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-#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
-
-# Check the environmanet variable for the test
-. check_envval || exit 1
-
-# Timeout till client starts up [sec]
-CLIENT_TIMEOUT=10
-
-
-#-----------------------------------------------------------------------
-#
-# Function: usage
-#
-# Description:
-#   Print the usage of this script, then exit
-#
-#-----------------------------------------------------------------------
-usage(){
-    cat << EOD >&2
-bg_tcp_traffic command [argument]
-  command:  make / check / kill / killall
-  argument: IP address of the server (if command is make)
-            Process ID (if command is check/kill)
-            (none)  (if command is killall)
-EOD
-
-    exit 1
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Function: make_traffic
-#
-# Description:
-#   Make a background tcp traffic.
-#   The local host will be a server, and the remote host will be a client
-#
-# Arguments:
-#   $1: IP address of the server
-#
-# Exit Value:
-#   0: Success
-#   1: Fail
-#
-#-----------------------------------------------------------------------
-make_traffic() {
-    server_ipaddr=$1
-
-    # Identify the family is ipv4 or ipv6
-    family=0
-    echo $server_ipaddr | fgrep "." >/dev/null 2>&1
-    if [ $? -eq 0 ]; then
-	family=4
-    else
-	echo $server_ipaddr | fgrep ":" >/dev/null 2>&1
-	if [ $? -eq 0 ]; then
-	    family=6
-	fi
-    fi
-
-    if [ $family -eq 0 ]; then
-	echo "The IP address of the server is something wrong." >&2
-	exit 1
-    fi
-
-    # Find the available consecutive ports
-    server_port=`find_portbundle tcp 1025 1`
-    if [ $? -ne 0 ]; then
-	echo "No port is available." >&2
-	exit 1
-    fi
-
-    # Start up a server
-    infofile=`mktemp -p $TMPDIR`
-    ns-tcpserver -b -f $family -p ${server_port} -o $infofile
-
-    while true ; do	# Wait till ns-tcpserver outputs the information
-	if [ -s $infofile ]; then
-	    break
-	fi
-    done
-
-    server_pid=`fgrep PID: $infofile | awk '{ print $2 }'`
-
-    rm -f $infofile
-
-    if [ x$server_pid = x ]; then
-	echo "TCP traffic server does not run" >&2
-	exit 1
-    fi
-
-    # Start up a client
-    $LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-tcpclient -b -S $server_ipaddr -f $family -p $server_port"
-
-    count=0
-    while true ; do
-	$LTP_RSH $RHOST "ps auxw | fgrep -v grep | fgrep -l ns-tcpclient >/dev/null 2>&1"
-	if [ $? -ne 0 ]; then
-	    if [ $count -lt $CLIENT_TIMEOUT ]; then
-		count=`expr $count + 1`
-		sleep 1
-		continue
-	    else
-		echo "TCP traffic client does not run" >&2
-		kill -SIGHUP $server_pid
-		exit 1
-	    fi
-	else
-	    # Output the process ID of the server, the finished
-	    echo $server_pid
-	    exit 0
-	fi
-    done
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Function: check_traffic
-#
-# Description:
-#   Check the TCP traffic exists
-#
-# Arguments:
-#   $1: Process ID of the TCP traffic server
-#
-# Exit Value:
-#   0: The connectivity is good.
-#   1: The connectivity is something wrong.
-#
-#-----------------------------------------------------------------------
-check_traffic()
-{
-    server_pid=$1
-
-    if [ ! -d /proc/$server_pid ]; then
-	echo "TCP traffic server has gone." >&2
-	exit 1
-    fi
-    exit 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Function: kill_traffic
-#
-# Description:
-#   Kill the TCP traffic
-#
-# Arguments:
-#   $1: Process ID of the TCP traffic server
-#
-# Exit Value:
-#   Always 0
-#
-#-----------------------------------------------------------------------
-kill_traffic()
-{
-    server_pid=$1
-
-    kill -SIGHUP $server_pid >/dev/null 2>&1
-    exit 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Function: killall_traffic
-#
-# Description:
-#   Kill all of the TCP traffic
-#
-# Exit Value:
-#   Always 0
-#
-#-----------------------------------------------------------------------
-killall_traffic()
-{
-    killall_tcp_traffic
-}
-
-#
-# Main
-#
-command=$1
-
-case $command in
-    make)
-    if [ $# -ne 2 ]; then
-	usage
-    fi
-    make_traffic $2
-    ;;
-
-    check)
-    if [ $# -ne 2 ]; then
-	usage
-    fi
-    check_traffic $2
-    ;;
-
-    kill)
-    if [ $# -ne 2 ]; then
-	usage
-    fi
-    kill_traffic $2
-    ;;
-
-    killall)
-    if [ $# -ne 1 ]; then
-	usage
-    fi
-    killall_traffic $2
-    ;;
-
-    *)
-    usage
-    ;;
-esac
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (4 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-06 13:15   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

* This library is intended to be used throughout all stress tests reduce
duplicity and use code test_net.sh where possible instead of legacy
scripts in testcases/network/stress/ns-tools/.

* check_connectivity() is split into general part (in test_stress_net.sh)
ment as replacement of check_icmpv4_connectivity script and loop part
wrapper check_connectivity_loop() (in if-lib.sh).

* if-lib.sh sources test_stress_net.sh.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/interface/if-addr-adddel  |   2 +-
 .../network/stress/interface/if-addr-addlarge      |   3 +-
 testcases/network/stress/interface/if-lib.sh       |  32 +++--
 testcases/network/stress/interface/if-route-adddel |   2 +-
 .../network/stress/interface/if-route-addlarge     |   2 +-
 testcases/network/stress/interface/if-updown       |   2 +-
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_stress_net.sh     | 136 +++++++++++++++++++++
 8 files changed, 157 insertions(+), 24 deletions(-)
 create mode 100644 testcases/network/stress/ns-tools/test_stress_net.sh

diff --git a/testcases/network/stress/interface/if-addr-adddel b/testcases/network/stress/interface/if-addr-adddel
index dcc018a48..1e80368c9 100644
--- a/testcases/network/stress/interface/if-addr-adddel
+++ b/testcases/network/stress/interface/if-addr-adddel
@@ -88,7 +88,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		cnt=$(($cnt + 1))
 
diff --git a/testcases/network/stress/interface/if-addr-addlarge b/testcases/network/stress/interface/if-addr-addlarge
index 9e550068b..1bfa1b761 100644
--- a/testcases/network/stress/interface/if-addr-addlarge
+++ b/testcases/network/stress/interface/if-addr-addlarge
@@ -100,8 +100,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
diff --git a/testcases/network/stress/interface/if-lib.sh b/testcases/network/stress/interface/if-lib.sh
index 4168dd09f..831b65209 100644
--- a/testcases/network/stress/interface/if-lib.sh
+++ b/testcases/network/stress/interface/if-lib.sh
@@ -18,7 +18,7 @@
 
 TST_CLEANUP="cleanup"
 
-. test_net.sh
+. test_stress_net.sh
 
 ipver=${TST_IPV6:-4}
 
@@ -46,28 +46,26 @@ make_background_tcp_traffic()
 	tst_rhost_run -b -c "netstress -l -H $(tst_ipaddr) -g $port"
 }
 
-check_connectivity()
+restore_ipaddr()
+{
+	tst_restore_ipaddr || return $?
+	tst_wait_ipv6_dad
+}
+
+# check_connectivity_interval [CNT] [RESTORE]
+# CNT: loop step
+# RESTORE: whether restore ip addr (not required, default false)
+check_connectivity_interval()
 {
 	local cnt="$1"
-	local restore="$2"
+	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"
-
+	tst_resm TINFO "check connectivity 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
+	check_connectivity
+	return $?
 }
diff --git a/testcases/network/stress/interface/if-route-adddel b/testcases/network/stress/interface/if-route-adddel
index 451674178..6f45f4e03 100644
--- a/testcases/network/stress/interface/if-route-adddel
+++ b/testcases/network/stress/interface/if-route-adddel
@@ -86,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
diff --git a/testcases/network/stress/interface/if-route-addlarge b/testcases/network/stress/interface/if-route-addlarge
index e83cf60a7..2ea30e461 100644
--- a/testcases/network/stress/interface/if-route-addlarge
+++ b/testcases/network/stress/interface/if-route-addlarge
@@ -93,7 +93,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
diff --git a/testcases/network/stress/interface/if-updown b/testcases/network/stress/interface/if-updown
index deefef639..681d3989a 100644
--- a/testcases/network/stress/interface/if-updown
+++ b/testcases/network/stress/interface/if-updown
@@ -59,7 +59,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt restore_ip || return
+		check_connectivity_interval $cnt restore_ip || return
 
 		cnt=$(($cnt + 1))
 	done
diff --git a/testcases/network/stress/ns-tools/Makefile b/testcases/network/stress/ns-tools/Makefile
index 61f85634a..5316efae7 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_stress_net.sh
 
 FILTER_OUT_MAKE_TARGETS	:= ns-common
 
diff --git a/testcases/network/stress/ns-tools/test_stress_net.sh b/testcases/network/stress/ns-tools/test_stress_net.sh
new file mode 100644
index 000000000..3c890fe47
--- /dev/null
+++ b/testcases/network/stress/ns-tools/test_stress_net.sh
@@ -0,0 +1,136 @@
+#!/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>
+
+# Library for all network/stress/ tests.
+
+# using variables IPV4_NETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST and some functions
+. test_net.sh
+
+tst_check_cmds ifconfig killall
+
+# NOTE: More information about these network variables can be found
+# in testcases/network/stress/README
+
+# TODO: Test expects prefix to be 24, which can get wrong when called
+# with different prefix for IPV4_NETWORK.
+
+# 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
+# Prefix of the Multicast Address
+MCAST_IPV4_ADDR_PREFIX="224.10"
+# Multicast Address
+MCAST_IPV4_ADDR="${MCAST_IPV4_ADDR_PREFIX}.10.1"
+
+LINK_NUM=${LINK_NUM:-0}
+
+init_if_lhost_rhost()
+{
+	local link_num="$1"
+	tst_init_iface lhost $link_num
+	tst_init_iface rhost $link_num
+}
+
+# Set an IPv4 address on local/remote interface.
+# TYPE: { lhost | rhost }.
+# LINK_NUM: link number starting from 0. Default value is '0'.
+# NETWORK_PART: network part of local and remote IP address
+# HOST_PART: host part of local and remote IP address
+set_ipv4addr_check()
+{
+	local type="${1}"
+	local link_num="$2"
+	local network_part="$3"
+	local host_part="$4"
+	local addr broadcast cmd ifname netmask ret
+
+	addr=${network_part}.${host_part}
+	netmask=$(echo $network_part | sed "s/[[:digit:]]*/255/g").$(echo $host_part | sed "s/[[:digit:]]*/0/g")
+	broadcast=${network_part}.$(echo $host_part | sed "s/[[:digit:]]*/255/g")
+	ifname=$(tst_iface $type $link_num)
+
+	# TODO: use tst_init_iface and tst_add_ipaddr (tst_add_ipaddr must be
+	# adjusted to take mask as parameter).
+	for cmd in "ifconfig $ifname up" \
+		"ifconfig $ifname $addr netmask $netmask broadcast $broadcast"; do
+		[ $type = "lhost" ] && sh -c "$cmd" || tst_rhost_run -c "$cmd"
+		ret=$?
+		[ $ret -ne 0 ] && tst_brkm TBROK "failed to set IP '$addr' to '$ifname' at $type ('$cmd': $ret)"
+	done
+}
+
+# Set an IPv4 address on local and remote interfaces.
+# LINK_NUM: link number starting from 0. Default value is '0'.
+# NETWORK_PART: network part of local and remote IP address
+# LHOST_PART: host part of local IP address
+# RHOST_PART: host part of remote IP address
+set_lhost_rhost_ipv4addr()
+{
+	local link_num="$1"
+	local network_part="$2"
+	local lhost_part="$3"
+	local rhost_part="$4"
+
+	set_ipv4addr_check lhost $link_num $network_part $lhost_part
+	set_ipv4addr_check rhost $link_num $network_part $rhost_part
+}
+
+# Check connectivity with tst_ping.
+# check_connectivity [IFACE] [DST ADDR]
+# IFACE: source interface name
+# DST ADDR: destination IPv4 or IPv6 address
+# CNT: loop step (not required)
+check_connectivity()
+{
+	local src_iface="${1:-$(tst_iface)}"
+	local dst_addr="${2:-$(tst_ipaddr rhost)}"
+	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
+}
+
+# Kill process on local/remote host.
+# CMD: command to kill.
+# TYPE: { lhost | rhost }; Default value is 'lhost'.
+killall_sighup()
+{
+	local cmd="killall -q -SIGHUP $1"
+	local type="${2:-lhost}"
+	[ $type = "lhost" ] && $cmd || tst_rhost_run -c "$cmd"
+}
+
+# Kill process on remote host.
+# CMD: command to kill.
+killall_sighup_rhost()
+{
+	killall_sighup $1 rhost
+}
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (5 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-07 11:04   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace() Petr Vorel
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

* Fix test for netns based testing.
* Remove rsh dependency.
* Create shell library mcast4-lib.sh (mcast4 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 | 222 ++------------------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 231 ++------------------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 233 ++-------------------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 143 +++++++++++++
 5 files changed, 223 insertions(+), 823 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..b80cd86f5 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
@@ -1,211 +1,33 @@
 #!/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
+. `dirname $0`/mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"
 
-exit 0
+do_setup $MCASTNUM_HEAVY
+do_multicast_test_single_socket $MCASTNUM_HEAVY
+do_cleanup_ns_mcast_join
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
index 67efac73c..459dfb962 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
@@ -1,220 +1,29 @@
 #!/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
+. `dirname $0`/mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on separate sockets"
 
-exit 0
+do_setup $MCASTNUM_HEAVY true
+do_multicast_test_single_socket $MCASTNUM_HEAVY true
+do_cleanup_ns_mcast_join
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope03 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope03
index c44ec2170..2511abbfb 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
-#
+. `dirname $0`/mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+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"
 
-exit 0
+do_setup $MCASTNUM_NORMAL
+do_multicast_test_multiple_sockets
+tst_exit
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
index 8783928f3..8949f5d7c 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
@@ -1,226 +1,31 @@
 #!/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
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# 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
+# 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:
-#	May 2 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# 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}
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# 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
+. `dirname $0`/mcast4-lib.sh
 
 # Prefix of the filter souce adddress
 SOURCE_ADDR_PREFIX="10.10"	# 10.10.x.y
 
+tst_resm TINFO "verify that the kernel is not crashed when joining and leaving the same IPv4 multicast group with a different source filter on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
 
-#-----------------------------------------------------------------------
-#
-# 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
-
-    # 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
-#
-
-tst_resm TPASS "Test is finished successfully."
-
-exit 0
+do_setup $MCASTNUM_NORMAL
+do_multicast_test_multiple_sockets 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..5be7cd79e
--- /dev/null
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
@@ -0,0 +1,143 @@
+#!/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 mcast4-grpope* tests.
+
+export TCID="`basename $0`"
+export TST_TOTAL=1
+
+. test_stress_net.sh
+
+do_cleanup()
+{
+	# Make sure to kill the multicast receiver and sender
+	killall_sighup ns-mcast_join
+	killall_sighup_rhost ns-igmp_querier
+	init_if_lhost_rhost $LINK_NUM
+}
+
+do_setup()
+{
+	local igmp_max_memberships="$1"
+	local increase_max="${2:-}"
+
+	# Initialize the system configuration
+	do_cleanup
+
+	# Call do_cleanup function before exit
+	trap do_cleanup 0
+
+	if [ "$increase_max" ]; then
+		# Increase the maximum number of open file descriptors
+		fd_num=`ulimit -n`
+		if [ $fd_num -lt $igmp_max_memberships ]; then
+			ulimit -n $igmp_max_memberships
+			if [ $? -ne 0 ]; then
+				tst_resm TBROK "$igmp_max_memberships is too many for the file descriptor"
+			fi
+		fi
+	fi
+
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
+
+	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
+
+	lhost_addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
+	rhost_addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+
+	check_connectivity $lhost_ifname $rhost_addr
+
+	sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
+	[ $? -ne 0 ] && tst_brkm TBROK "failed to set the sysctl value regarding multicast"
+
+	sysctl -qw net.ipv4.igmp_max_msf=10
+	sysctl -qw net.ipv4.conf.${lhost_ifname}.force_igmp_version=0
+	sysctl -qw net.ipv4.conf.all.force_igmp_version=0
+}
+
+do_multicast_test_single_socket()
+{
+	local igmp_max_memberships="$1"
+	local is_multi_socket msg ret tmpfile
+
+	[ "${2:-}" = true ] && is_multi_socket="-m"
+
+	# Run a multicast join tool
+	tmpfile=$TMPDIR/ns-mcast_join.$$
+	ns-mcast_join -f 4 -I $lhost_ifname -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX > $tmpfile
+	if [ $? -ne 0 ]; then
+		rm -f $tmpfile
+		tst_brkm TBROK "failed to start multicast joining tool"
+	fi
+	msg=`cat $tmpfile | grep groups`
+	tst_resm TINFO "joined $msg"
+	rm -f $tmpfile
+
+	# Send IGMP General Query from the remote host
+	tst_rhost_run -s -c "ns-igmp_querier -I $rhost_ifname -o -r 1"
+
+	tst_resm TPASS "test is finished successfully"
+}
+
+do_multicast_test_multiple_sockets()
+{
+	local define_source_address filter num params ret source_addr x y
+
+	[ "$1" = true ] && define_source_address="-m"
+
+	# Send IGMP General Query from the remote host
+	tst_rhost_run -s -c "ns-igmp_querier -I $rhost_ifname -i 1000000000 -r 1 -b"
+
+	# Run a multicast join tool
+	num=0
+	while [ $num -lt $MCASTNUM_NORMAL ]; do
+		if [ "$define_source_address" ]; then
+			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
+			params="-F $filter -s $source_addr"
+		fi
+
+		ns-mcast_join -f 4 -I $lhost_ifname -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &
+		[ $? -ne 0 ] && tst_brkm TBROK "failed to start multicast joining tool"
+		num=`expr $num + 1`
+	done
+
+	wait
+
+	tst_resm TPASS "test is finished successfully"
+}
+
+do_cleanup_ns_mcast_join()
+{
+	killall_sighup ns-mcast_join
+	while true; do
+		ps auxw | grep -q [n]s-mcast_join || break
+		sleep 1
+	done
+}
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace()
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (6 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-08 10:53   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

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

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

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index f93f67411..91a62f9f6 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -42,12 +42,19 @@ init_ltp_netspace()
 	tst_wait_ipv6_dad
 }
 
+# Force to reset netns.
+reset_ltp_netspace()
+{
+	[ -n "$TST_USE_NETNS" ] || return
+	ip net del ltp_ns
+	init_ltp_netspace
+}
+
 # Run command on remote host.
 # Options:
 # -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=
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (7 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace() Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-12 12:39   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables Petr Vorel
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

* Fix test for netns based testing.
* 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>
---
 testcases/network/stress/ns-tools/initialize_if    |   3 -
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 287 ++---------------
 testcases/network/stress/route/route4-change-gw    | 308 +++---------------
 testcases/network/stress/route/route4-change-if    | 348 +++------------------
 testcases/network/stress/route/route4-ifdown       | 298 ++++--------------
 testcases/network/stress/route/route4-lib.sh       | 252 +++++++++++++++
 testcases/network/stress/route/route4-redirect     | 232 +++-----------
 testcases/network/stress/route/route4-rmmod        | 329 +++++--------------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 10 files changed, 585 insertions(+), 1497 deletions(-)
 create mode 100644 testcases/network/stress/route/route4-lib.sh

diff --git a/testcases/network/stress/ns-tools/initialize_if b/testcases/network/stress/ns-tools/initialize_if
index d64203e4c..23bf68bc0 100644
--- a/testcases/network/stress/ns-tools/initialize_if
+++ b/testcases/network/stress/ns-tools/initialize_if
@@ -69,9 +69,6 @@ fi
 # Define the interface name
 ifname=`get_ifname $host_type $link_num` || exit 1
 
-# Initialize the specified interface
-command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
-
 if [ $host_type = lhost ]; then
     ( ifconfig $ifname down && \
     ip link set mtu 1500 dev $ifname && \
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..26510bc8b 100644
--- a/testcases/network/stress/route/route4-change-dst
+++ b/testcases/network/stress/route/route4-change-dst
@@ -1,276 +1,51 @@
 #!/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
-
-# 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}
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
+export TST_TOTAL=2
 
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
+. `dirname $0`/route4-lib.sh
 
-# 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_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}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# 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
+	# Initialize the interfaces of the remote host
+	tst_init_iface rhost $LINK_NUM
 
-    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"
+	set_ipv4addr_check rhost $LINK_NUM $IPV4_NETWORK $RHOST_IPV4_HOST
 
-    # Initialize the interface of the local host
-    initialize_if lhost ${LINK_NUM}
+	# IPv4 address of the remote host (gateway)
+	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}"
-
-    # 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
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
 }
 
+do_setup
 
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
+for cmd_name in rt_cmd ip_cmd; do
+	do_test_common "dst" $cmd_name $LINK_NUM 1 $lhost_ifname $rhost_ipv4addr
+done
 
-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
+do_cleanup_common
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-gw b/testcases/network/stress/route/route4-change-gw
index a9a91cca6..00773f676 100644
--- a/testcases/network/stress/route/route4-change-gw
+++ b/testcases/network/stress/route/route4-change-gw
@@ -1,292 +1,64 @@
 #!/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
-
-# 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}
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
+export TST_TOTAL=2
 
-# Netmask of for the tested network
-IPV4_NETMASK_NUM=24
+. `dirname $0`/route4-lib.sh
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+# gateway
+RHOST_IPV4_HOST_TOP=${RHOST_IPV4_HOST_TOP:-10}
 
-# 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_IPV4_HOST_LAST=${RHOST_IPV4_HOST_LAST:-19}
 
-# 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
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
+
+	# Initialize the interfaces of the remote host
+	tst_init_iface 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
+		tst_rhost_run -s -c "ip addr add ${IPV4_NETWORK}.${rhost_part}/$IPV4_NETMASK_NUM broadcast $IPV4_BROADCAST dev $rhost_ifname"
+		rhost_part=$(($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
-
-    # Set the variables regarding the destination host
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
-
-    # 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
+	killall_sighup ns_udpsender
+	do_cleanup_common
 }
 
+do_setup
 
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
+for cmd_name in rt_cmd ip_cmd; do
+	do_test_common "gw" $cmd_name $LINK_NUM 1 $lhost_ifname "${IPV4_NETWORK}.$RHOST_IPV4_HOST_TOP" $RHOST_IPV4_HOST_TOP $RHOST_IPV4_HOST_LAST
+done
 
-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
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-if b/testcases/network/stress/route/route4-change-if
index 33fc3755c..3e0c25915 100644
--- a/testcases/network/stress/route/route4-change-if
+++ b/testcases/network/stress/route/route4-change-if
@@ -1,324 +1,78 @@
 #!/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
-
-# 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
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+export TST_TOTAL=2
 
-# The destination network
-DST_NETWORK="10.10.0"	# destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
+. `dirname $0`/route4-lib.sh
 
-
-#-----------------------------------------------------------------------
-#
-# 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
-
-    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"
+	link_total=$(echo $LHOST_HWADDRS | wc -w)
+	rhost_link_total=$(echo $RHOST_HWADDRS | wc -w)
 
-	# 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
+	if [ $link_total -ne $rhost_link_total ]; then
+		tst_brkm TBROK "the number of element in LHOST_HWADDRS differs from RHOST_HWADDRS"
 	fi
-	rhost_ifname_array="$rhost_ifname_array $rhost_ifname"
-
-	# Initialize the interfaces of the remote host
-	initialize_if rhost ${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
+	if [ $link_total -lt 2 ]; then
+		tst_brkm TCONF "this test case requires more than one test link in LHOST_HWADDRS variable"
 	fi
 
-	link_num=`expr $link_num + 1`
-    done
-}
-
+	lhost_ifname_array=""
+	rhost_ifname_array=""
+	link_num=0
+	while [ $link_num -lt $link_total ]; do
+		lhost_ifname=$(tst_iface lhost $link_num)
+		rhost_ifname=$(tst_iface rhost $link_num)
+		lhost_ifname_array="$lhost_ifname_array $lhost_ifname"
+		rhost_ifname_array="$rhost_ifname_array $rhost_ifname"
 
+		# Initialize the interfaces of the remote host
+		tst_init_iface rhost $link_num
 
+		# Set IPv4 address to the interface of the remote host
+		set_ipv4addr_check rhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${RHOST_IPV4_HOST}
 
-#-----------------------------------------------------------------------
-#
-# 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
+		link_num=$(( $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()
+do_cleanup()
 {
-    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
-
-    # 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
-
-	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
+	killall_sighup ns_udpsender
+
+	# Initialize the interfaces
+	link_num=0
+	while [ $link_num -lt $link_total ]; do
+		init_if_lhost_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
+for cmd_name in rt_cmd ip_cmd; do
+	do_test_common "if" $cmd_name $LINK_NUM $link_total $lhost_ifname $IPV4_NETWORK_PRE
+done
 do_cleanup
-
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-ifdown b/testcases/network/stress/route/route4-ifdown
index e7ce1b4fe..1c81a1f74 100644
--- a/testcases/network/stress/route/route4-ifdown
+++ b/testcases/network/stress/route/route4-ifdown
@@ -1,261 +1,95 @@
 #!/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
-
-# 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
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+export TST_TOTAL=2
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+. `dirname $0`/route4-lib.sh
 
-
-#-----------------------------------------------------------------------
-#
-# 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
-
-    # 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}"
+	do_cleanup_common
 
-    # 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}"
+	set_ipv4addr_check rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
+	rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_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
+	set_ipv4addr_check lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
+	lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_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
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
 
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+	# Set the variables for destination network
+	dst_addr=${DST_NETWORK}.${DST_HOST}
+	dst_network=${DST_NETWORK}.0
 }
 
-
-#-----------------------------------------------------------------------
-#
-# 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_iface cmd_iface_down
+	local cmd_name_route="`get_cmd $cmd_type`"
+	local cnt=0
+
+	if [ "$cmd_type" = 'rt_cmd' ]; then
+		cmd_name_iface='ifconfig'
+		cmd_iface_down="$cmd_name_iface $lhost_ifname down && ifconfig $lhost_ifname up"
+	else
+		cmd_name_iface=$cmd_name_route
+		cmd_iface_down="$cmd_name_iface link set down dev $lhost_ifname && ip link set up dev $lhost_ifname"
 	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 "verify the kernel is not crashed when IPv4 route is added and deleted by '$cmd_name_route' 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
+	while [ $cnt -lt $NS_TIMES ]; do
+		check_connectivity $lhost_ifname $rhost_ipv4addr $cnt
 
-	# 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
+		# Add the route
+		manipulate_route $cmd_name_route 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $rhost_ipv4addr $lhost_ifname
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to add the route to ${dst_network}/$IPV4_NETMASK_NUM"
+			return
+		fi
 
-	cnt=`expr $cnt + 1`
-    done
+		# 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
+		fi
 
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
+		# Down then up the interface
+		run_cmd "$cmd_iface_down"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to down/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
-
-exit $RC
+test_body 'rt_cmd'
+test_body 'ip_cmd'
+do_cleanup_common
+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..e1823b8f1
--- /dev/null
+++ b/testcases/network/stress/route/route4-lib.sh
@@ -0,0 +1,252 @@
+#!/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>
+
+export TCID="`basename $0`"
+
+. test_stress_net.sh
+
+# The first 2 ocnted of the Network portion of the gateway address
+# FIXME: calculate it from IPV4_NETWORK variable as test expects IPV4_NETWORK
+# to be 10.0.0 and prefix 24.
+IPV4_NETWORK_PRE=${IPV4_NETWORK_PRE:-"10.0"}
+
+# The destination network
+# FIXME: generate DST_NETWORK_PREFIX randomly based on IPV4_NETWORK variable as
+# test expects IPV4_NETWORK to be 10.0.0 and prefix 24.
+DST_NETWORK_PREFIX="10.10" # 10.10.n.0/24
+DST_NETWORK="${DST_NETWORK_PREFIX}.0" # 10.10.0.0/24
+DST_HOST=5
+DST_PORT=7
+
+do_cleanup_common()
+{
+    init_if_lhost_rhost $LINK_NUM
+}
+
+prepare_connectivity()
+{
+	local lhost_ifname=$1
+	local link_num=$2
+	local network_part="$3"
+	local host_part="$4"
+	local rhost_addr="$5"
+	local type="lhost"
+
+	tst_init_iface $type $link_num
+	set_ipv4addr_check $type $link_num $network_part $host_part
+	check_connectivity $lhost_ifname $rhost_addr
+}
+
+get_lhost_ifname_loop()
+{
+	local field=$(($1 + 1))
+	echo $lhost_ifname_array | cut -d ' ' -f $field
+}
+
+run_cmd()
+{
+	local cmd="$@"
+	local ret
+
+	sh -c "$cmd"
+	ret=$?
+	[ $ret -ne 0 ] && tst_resm TWARN "'$cmd' failed: $ret"
+	return $ret
+}
+
+manipulate_route()
+{
+	local cmd_name=$1
+	local task=$2
+	local network=$3
+	local prefix=$4
+	local netmask=$5
+	local gateway=$6
+	local lhost_ifname=$7
+	# not required params
+	local gateway2=$8
+	local lhost_ifname2=$9
+
+	local ret t
+
+	[ "$task" = "add" ] || [ "$task" = "del" ] || [ "$task" = "change" ] || \
+		tst_brkm TBROK "wrong task: '$task'"
+
+	if [ "$cmd_name" = "ip" ]; then
+		run_cmd "$cmd_name route $task $network/$prefix via $gateway dev $lhost_ifname"
+		ret=$?
+	else
+		t="$task"
+		# route doesn't have change command
+		[ "$task" = "change" ] && t="add"
+		run_cmd "$cmd_name $t -net $network netmask $netmask gw $gateway dev $lhost_ifname"
+		ret=$?
+
+		if [ "$task" = "change" ]; then
+			run_cmd "$cmd_name del -net $network netmask $netmask gw $gateway2 dev $lhost_ifname2"
+			ret=$?
+		fi
+	fi
+
+	return $ret
+}
+
+# Load the route with UDP traffic.
+run_ns_udpsender()
+{
+	local dst_addr=$1
+	local run_in_background=$2
+	local params="-o"
+
+	if [ "$run_in_background" = true ]; then
+		# daemon is already running
+		ps auxw | grep -q [n]s-udpsender && return 0
+		params="-b"
+	fi
+
+	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -s 1472 $params
+	[ $? -ne 0 ] && tst_brkm TBROK "failed to run a UDP datagram sender"
+}
+
+get_cmd()
+{
+	local cmd_type=$1
+
+	case $cmd_type in
+	rt_cmd) echo 'route' ;;
+	ip_cmd) echo 'ip' ;;
+	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
+	esac
+}
+
+do_test_common()
+{
+	local test_field=$1
+	local cmd_type=$2
+	local link_num=$3
+	local link_total=$4
+	local lhost_ifname=$5
+	local rhost_addr="$6"
+	# not required params
+	local rhost_part_first=$7
+	local rhost_part_last=$8
+
+	local run_in_background=true
+	local cnt=0
+	local dst_addr dst_network dst_network_postfix ipv4_network_loop gateway2 lhost_ifname2 rhost_part task test_field_name
+	local cmd_name="`get_cmd $cmd_type`"
+	local gateway="$rhost_addr"
+
+	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 "verify the kernel is not crashed when the $test_field_name of an IPv4 route is changed frequently by '$cmd_name' command $NS_TIMES times"
+
+	if [ "$test_field" = "if" ]; then
+		link_num=0
+		tst_resm TINFO "preparing connectivity $link_total times"
+		while [ $link_num -lt $link_total ]; do
+			lhost_ifname="$(get_lhost_ifname_loop $link_num)"
+			ipv4_network_loop="${rhost_addr}.${link_num}"
+			prepare_connectivity $lhost_ifname $link_num $ipv4_network_loop $LHOST_IPV4_HOST "$ipv4_network_loop.${LHOST_IPV4_HOST}"
+		done
+		link_num=0
+		lhost_ifname="`get_lhost_ifname_loop $link_num`"
+		gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
+	else
+		tst_resm TINFO "preparing connectivity"
+		if [ "$test_field" = "gw" ]; then
+			rhost_part=$rhost_part_first
+			gateway="${IPV4_NETWORK}.${rhost_part}"
+		fi
+		prepare_connectivity $lhost_ifname $link_num $IPV4_NETWORK $LHOST_IPV4_HOST $gateway
+	fi
+
+	if [ "$test_field" != "dst" ]; then
+		tst_resm TINFO "adding first route"
+		dst_addr=${DST_NETWORK}.${DST_HOST}
+		dst_network=${DST_NETWORK}.0
+
+		manipulate_route $cmd_name add $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+		if [ $? -ne 0 ]; then
+			tst_brkm TBROK "failed to add the gateway to $gateway"
+			return
+		fi
+		run_ns_udpsender $dst_addr yes
+	fi
+
+	tst_resm TINFO "manipulate route $NS_TIMES times"
+	while [ $cnt -lt $NS_TIMES ]; do
+		lhost_ifname2="$lhost_ifname"
+		gateway2="$gateway"
+		if [ "$test_field" = "dst" ]; then
+			run_in_background=
+			task="add"
+			# Define the destination IP address
+			dst_network_postfix="$(($cnt % 255))"
+			dst_addr="${DST_NETWORK_PREFIX}.${dst_network_postfix}.${DST_HOST}"
+			dst_network="${DST_NETWORK_PREFIX}.${dst_network_postfix}.0"
+		elif [ "$test_field" = "if" ]; then
+			link_num=$(($link_num + 1))
+			[ $link_num -ge $link_total ] && link_num=0
+			lhost_ifname="$(get_lhost_ifname_loop $link_num)"
+			gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
+			task="change"
+		elif [ "$test_field" = "gw" ]; then
+			pre_rhost_part=$rhost_part
+			rhost_part=$(($rhost_part + 1))
+			[ $rhost_part -gt $rhost_part_last ] && rhost_part=$rhost_part_first
+			gateway="${IPV4_NETWORK}.${rhost_part}"
+			gateway2="${IPV4_NETWORK}.${pre_rhost_part}"
+			task="change"
+		fi
+
+		manipulate_route $cmd_name $task $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname $gateway2 $lhost_ifname2
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to change the gateway to $gateway"
+			return
+		fi
+
+		run_ns_udpsender $dst_addr $run_in_background
+
+		if [ "$test_field" = "dst" ]; then
+			task="del"
+			manipulate_route $cmd_name $task $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname $gateway2 $lhost_ifname2
+			if [ $? -ne 0 ]; then
+				tst_resm TFAIL "failed to delete the gateway to $gateway"
+				return
+			fi
+		fi
+
+		cnt=$(($cnt + 1))
+	done
+
+	killall_sighup ns_udpsender
+
+	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..718c96b33 100644
--- a/testcases/network/stress/route/route4-redirect
+++ b/testcases/network/stress/route/route4-redirect
@@ -1,212 +1,82 @@
 #!/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
-
-# 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
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+export TST_TOTAL=1
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
-RHOST_IPV4_HOST="2"	# gateway
+. `dirname $0`/route4-lib.sh
 
-# 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_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Kill the redirector utility
-    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	killall_sighup_rhost ns_udpsender
+	do_cleanup_common
 }
 
-
-#-----------------------------------------------------------------------
-#
-# 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
+	do_cleanup
 
-    # 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
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
 
-    # Remove the link-local address of the remote host
-    sleep 3
-    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
+	tst_resm TINFO "remove the link-local address of the remote host"
+	sleep 3
+	tst_rhost_run -s -c "ip addr flush dev $rhost_ifname"
 
-    # 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
+	set_ipv4addr_check lhost $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST
 
-    # 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_resm TINFO "add route to the initial gateway"
+	manipulate_route "route" "add" ${DST_NETWORK}.0 $IPV4_NETMASK_NUM $IPV4_NETMASK ${IPV4_NETWORK}.${RHOST_IPV4_HOST} $lhost_ifname
+	if [ $? -ne 0 ]; then
+		tst_brkm TBROK "failed to add the gateway to $gateway"
+		return
+	fi
 
-    # 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
+	# Make sure the sysctl value is set for accepting the redirect
+	sysctl -qw net.ipv4.conf.${lhost_ifname}.accept_redirects=1
+	sysctl -qw net.ipv4.conf.${lhost_ifname}.secure_redirects=0
 
-    # 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 $rhost_ifname -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
+	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 TFAIL "failed to run udp packet sender"
+			return
+		fi
+		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`
+test_body
 do_cleanup
-
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 36c8c970d..45ab0dd67 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -1,280 +1,115 @@
 #!/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
-
-# 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
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+export TST_TOTAL=2
 
+. `dirname $0`/route4-lib.sh
 
-#-----------------------------------------------------------------------
-#
-# 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}
+	# Make sure to load the network driver
+	if [ -n "${lhost_module:-}" ]; then
+		modprobe $lhost_module
+	fi
+	do_cleanup_common
 }
 
 
-#-----------------------------------------------------------------------
-#
-# 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
-
-    # Make sure to clean up
-    do_cleanup
-
-    # 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
-
-    # 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
+	tst_check_cmds ethtool
+	do_cleanup
+
+	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
+	lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
+	rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	lhost_ifname=$(tst_iface lhost $LINK_NUM)
+	rhost_ifname=$(tst_iface rhost $LINK_NUM)
+
+	# Get the module name of the interface at the local host
+	lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
+
+	# Check 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_brkm TBROK "an active interface $ifname uses the same network driver $module with the test intreface"
+			return
+		fi
+	done
+
+	# Set the variables for destination network
+	dst_addr=${DST_NETWORK}.${DST_HOST}
+	dst_network=${DST_NETWORK}.0
 }
 
-
-#-----------------------------------------------------------------------
-#
-# 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 cnt=0
+	local cmd_name="`get_cmd $cmd_type`"
 
-    TCID=route4-rmmod0${test_type}
-    TST_COUNT=$test_type
+	tst_resm TINFO "verify the kernel is not crashed when IPv4 route is add by '$cmd_name' command and then it is 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
+		check_connectivity $lhost_ifname $rhost_ipv4addr $cnt
 
-    # 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
+		# Add the route
+		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $rhost_ipv4addr $lhost_ifname
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "failed to add the route to ${dst_network}/$IPV4_NETMASK_NUM"
+			return
+		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
+		# 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
+		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 '$lhost_module'"
+			return
+		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
+		# if we use netns we need to reset it as unloading driver breaks it
+		reset_ltp_netspace
 
-	# Make sure to assing the IPv4 address
-	set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1
+		set_ipv4addr_check lhost $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST
 
-	cnt=`expr $cnt + 1`
-    done
+		cnt=$(($cnt + 1))
+	done
 
-    tst_resm TPASS "Test is finished correctly."
-    return 0
+	tst_resm TPASS "test is finished correctly"
 }
 
-
-#-----------------------------------------------------------------------
-#
-# 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
+test_body 'rt_cmd'
+test_body 'ip_cmd'
 do_cleanup
-
-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.12.2


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

* [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (8 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-15 15:00   ` Alexey Kodanev
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
  2017-06-06 12:05 ` [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Alexey Kodanev
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

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

For full list of environment variables which it setup run:
tst_net_vars -h

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/.gitignore     |   1 +
 testcases/lib/Makefile       |   4 +-
 testcases/lib/tst_net_vars.c | 802 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 805 insertions(+), 2 deletions(-)
 create mode 100644 testcases/lib/tst_net_vars.c

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 522889bed..e1274df64 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -4,3 +4,4 @@
 /tst_rod
 /tst_kvcmp
 /tst_device
+/tst_net_vars
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index 1127a59fe..40c64963e 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -26,7 +26,7 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
-			   tst_device
+MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp \
+			   tst_device tst_net_vars
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
new file mode 100644
index 000000000..551bf4707
--- /dev/null
+++ b/testcases/lib/tst_net_vars.c
@@ -0,0 +1,802 @@
+/*
+ * 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"
+
+#define DEFAULT_IPV4_PREFIX 24
+#define DEFAULT_IPV6_PREFIX 64
+
+#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_lhost;
+	char *ipv4_rhost;
+	char *ipv4_lnetwork;
+	char *ipv4_rnetwork;
+	char *lhost_ipv4_host;
+	char *rhost_ipv4_host;
+	char *ipv6_lhost;
+	char *ipv6_rhost;
+	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;
+	unsigned int ipv4_lprefix;
+	unsigned int ipv4_rprefix;
+	unsigned int ipv6_lprefix;
+	unsigned int ipv6_rprefix;
+} ltp_net_variables;
+
+
+static ltp_net_variables vars;
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPv4/PREFIX IPv4/PREFIX\n"
+		"%s IPv6/PREFIX IPv6/PREFIX\n\n"
+		"%s IPv4 IPv4\n"
+		"%s IPv6 IPv6\n"
+		"%s -h\n\n"
+		"IP addresses must be different\n"
+		"Prefixes should be in range <8, 31> (IPv4) or <16, 127> (IPv6) otherwise it's not suitable for tests which need both host part and network part to be set.\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"
+		"Default IPv4 prefix: %d.\n"
+		"Default IPv6 prefix: %d.\n\n"
+		"Exported variables:\n"
+		"IPV4_LHOST: IPv4 address of the local host (first parameter)\n"
+		"IPV4_RHOST: IPv4 address of the remote host (second parameter)\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"
+		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
+		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK (respect user settings)\n"
+		"IPV6_LHOST: IPv6 address of the local host (first parameter)\n"
+		"IPV6_RHOST: IPv6 address of the remote host (second parameter)\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"
+		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
+		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK (respect user settings)\n"
+		"LHOST_IFACES: iface name of the local host\n"
+		"We allow to respect user settings for:\n"
+		"Remote prefixes (IPV4_RPREFIX, IPV6_RPREFIX) as we cannot detect them on remote system.\n"
+		"Local iface (LHOST_IFACES) as user might want to use more ifaces.\n\n"
+		"PARAMS:\n"
+		"-h this help\n",
+		cmd, cmd, cmd, cmd, cmd, DEFAULT_IPV4_PREFIX,
+		DEFAULT_IPV6_PREFIX);
+}
+
+static void get_in_addr(const char *ip_str, struct in_addr *ip)
+{
+	if (inet_pton(AF_INET, ip_str, ip) <= 0)
+		tst_brk(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(TCONF, "bad IPv6 address: '%s'", ip_str);
+}
+
+/*
+ * Function prefix2mask is from ipcalc project, ipcalc.c.
+ */
+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.
+ */
+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);
+}
+
+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;
+}
+
+/*
+ * 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;
+}
+
+/*
+ * 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;
+}
+
+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(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);
+}
+
+/*
+ * 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;
+}
+
+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 int read_prefix_iface(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.lhost_ifaces = strdup(ifname);
+					if (is_ipv6) {
+						vars.ipv6_lprefix = retaddr->ifa_prefixlen;
+						vars.ipv6_rprefix = retaddr->ifa_prefixlen;
+					} else {
+						vars.ipv4_lprefix = retaddr->ifa_prefixlen;
+						vars.ipv4_rprefix = retaddr->ifa_prefixlen;
+					}
+					return 0;
+				}
+			}
+			retrta = RTA_NEXT(retrta, attlen);
+
+		}
+		retmsg = NLMSG_NEXT(retmsg, len);
+	}
+
+	return -1;
+}
+
+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_lhost = strdup(lip_str);
+	vars.ipv4_rhost = strdup(rip_str);
+
+	vars.ipv4_lprefix = lprefix;
+	vars.ipv4_rprefix = 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_lhost = strdup(lip_str);
+	vars.ipv6_rhost = strdup(rip_str);
+
+	vars.ipv6_lprefix = lprefix;
+	vars.ipv6_rprefix = 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_svar(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"%s\"\n", name, val);
+}
+
+static void print_svar_change(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"${%s:-%s}\"\n", name, name, val);
+}
+
+static void print_ivar(const char *name, unsigned int val)
+{
+	if (name)
+		printf("export %s=%d\n", name, val);
+}
+static void print_ivar_change(const char *name, unsigned int val)
+{
+	if (name)
+		printf("export %s=${%s:-%d}\n", name, name, val);
+}
+
+static void print_vars(int is_ipv6)
+{
+	if (is_ipv6) {
+		print_svar("IPV6_LHOST", vars.ipv6_lhost);
+		print_svar("IPV6_RHOST", vars.ipv6_rhost);
+		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);
+		print_ivar("IPV6_LPREFIX", vars.ipv6_lprefix);
+		print_ivar_change("IPV6_RPREFIX", vars.ipv6_rprefix);
+	} else {
+		print_svar("IPV4_LHOST", vars.ipv4_lhost);
+		print_svar("IPV4_RHOST", vars.ipv4_rhost);
+		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);
+		print_ivar("IPV4_LPREFIX", vars.ipv4_lprefix);
+		print_ivar_change("IPV4_RPREFIX", vars.ipv4_rprefix);
+	}
+
+	print_svar_change("LHOST_IFACES", vars.lhost_ifaces);
+}
+
+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 ? 0 : 1);
+	}
+
+	lip_str = argv[1];
+	rip_str = argv[2];
+
+	is_ipv6 = !!strchr(lip_str, ':');
+	if (is_ipv6 != !(strchr(rip_str, ':') == NULL))
+		tst_brk(TBROK, "mixed IPv4 and IPv6 addresses");
+
+	vars.ipv4_lprefix = DEFAULT_IPV4_PREFIX;
+	vars.ipv4_rprefix = DEFAULT_IPV4_PREFIX;
+	vars.ipv6_lprefix = DEFAULT_IPV6_PREFIX;
+	vars.ipv6_rprefix = DEFAULT_IPV6_PREFIX;
+
+	/* read local prefix and iface from rtnetlink data into vars */
+	read_prefix_iface(lip_str, is_ipv6);
+
+	/*
+	 * parse prefix from user input, use it if successful, otherwise use data
+	 * from rtnetlink or default values
+	 */
+	lprefix = get_prefix(lip_str, is_ipv6);
+	rprefix = get_prefix(rip_str, is_ipv6);
+
+	if (lprefix < 0)
+		lprefix = is_ipv6 ? vars.ipv6_lprefix : vars.ipv4_lprefix;
+	else {
+		if (is_ipv6)
+			vars.ipv6_lprefix = lprefix;
+		else
+			vars.ipv4_lprefix = lprefix;
+	}
+
+	if (rprefix < 0)
+		rprefix = is_ipv6 ? vars.ipv6_rprefix : vars.ipv4_rprefix;
+	else {
+		if (is_ipv6)
+			vars.ipv6_rprefix = rprefix;
+		else
+			vars.ipv4_rprefix = rprefix;
+	}
+
+	check_prefix_range(lprefix, is_ipv6, 1);
+	if (rprefix != lprefix)
+		check_prefix_range(rprefix, is_ipv6, 0);
+
+	if (!strcmp(lip_str, rip_str))
+		tst_brk(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.12.2


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

* [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (9 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-06-03 12:00 ` Petr Vorel
  2017-06-15 15:02   ` Alexey Kodanev
  2017-06-06 12:05 ` [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Alexey Kodanev
  11 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-03 12:00 UTC (permalink / raw)
  To: ltp

tst_net_vars simplifies setup as it only needs to have passed 4 IP
addresses (2x IPv4 and 2 IPv6) and alows to define different network
part for local and remote hosts.

Rename variables in rewritten tests to use variables defined by
tst_net_vars. These scripts are run by testscripts/network.sh script
which defined these variables by setting test_net.sh, so it makes a
sense to use them.

Old tests still use IPV4_NETWORK variable instead of IPV4_LNETWORK and
IPV4_RNETWORK and have it defined locally.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh                          | 59 ++++++++++------------
 testcases/network/stress/interface/if4-addr-change |  2 +-
 .../stress/multicast/grp-operation/mcast4-lib.sh   |  6 +--
 .../network/stress/ns-tools/test_stress_net.sh     | 18 ++++---
 testcases/network/stress/route/route4-change-dst   |  4 +-
 testcases/network/stress/route/route4-change-gw    |  4 +-
 testcases/network/stress/route/route4-change-if    |  4 +-
 testcases/network/stress/route/route4-ifdown       |  8 +--
 testcases/network/stress/route/route4-lib.sh       | 20 ++++----
 testcases/network/stress/route/route4-redirect     |  4 +-
 testcases/network/stress/route/route4-rmmod        |  8 +--
 11 files changed, 68 insertions(+), 69 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 91a62f9f6..a470d1c45 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -197,19 +197,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
 }
 
@@ -248,9 +239,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)
 
@@ -495,24 +490,23 @@ 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}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1}"
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1}"
+
+# tst_net_vars exports environment variables related to test links and networks
+# that aren't reachable through the test links.
+# See tst_net_vars -h for a list of exported variables.
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing variables for $IPV4_LHOST $IPV4_RHOST"
+	eval $(tst_net_vars $IPV4_LHOST $IPV4_RHOST)
+	tst_resm TINFO "Parsing variables for $IPV6_LHOST $IPV6_RHOST"
+	eval $(tst_net_vars $IPV6_LHOST $IPV6_RHOST)
+	TST_PARSE_VARIABLES="yes"
+fi
 
 export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
 export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
@@ -539,8 +533,11 @@ export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-40000}"
 
 # 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 54b8fd5fb..5b9a71dc2 100644
--- a/testcases/network/stress/interface/if4-addr-change
+++ b/testcases/network/stress/interface/if4-addr-change
@@ -49,7 +49,7 @@ while [ $cnt -lt $NS_TIMES ]; do
 	[ $num -eq $RHOST_IPV4_HOST ] && continue
 
 	# Change IPv4 address
-	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
+	lhost_ipv4addr="${IPV4_LNETWORK}.${num}"
 
 	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
 		broadcast 255.255.255.255 || \
diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
index 5be7cd79e..21fb4c74d 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
@@ -55,10 +55,10 @@ do_setup()
 	lhost_ifname=$(tst_iface lhost $LINK_NUM)
 	rhost_ifname=$(tst_iface rhost $LINK_NUM)
 
-	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
+	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_LNETWORK $IPV4_RNETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
 
-	lhost_addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-	rhost_addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	lhost_addr="${IPV4_LNETWORK}.${LHOST_IPV4_HOST}"
+	rhost_addr="${IPV4_RNETWORK}.${RHOST_IPV4_HOST}"
 
 	check_connectivity $lhost_ifname $rhost_addr
 
diff --git a/testcases/network/stress/ns-tools/test_stress_net.sh b/testcases/network/stress/ns-tools/test_stress_net.sh
index 3c890fe47..599d9acf1 100644
--- a/testcases/network/stress/ns-tools/test_stress_net.sh
+++ b/testcases/network/stress/ns-tools/test_stress_net.sh
@@ -19,7 +19,7 @@
 
 # Library for all network/stress/ tests.
 
-# using variables IPV4_NETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST and some functions
+# using variables IPV4_LNETWORK IPV4_RNETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST and some functions
 . test_net.sh
 
 tst_check_cmds ifconfig killall
@@ -35,7 +35,7 @@ IPV4_NETMASK="255.255.255.0"
 IPV4_NETMASK_NUM=24
 
 # Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+IPV4_BROADCAST=${IPV4_RNETWORK}.255
 # Prefix of the Multicast Address
 MCAST_IPV4_ADDR_PREFIX="224.10"
 # Multicast Address
@@ -80,18 +80,20 @@ set_ipv4addr_check()
 
 # Set an IPv4 address on local and remote interfaces.
 # LINK_NUM: link number starting from 0. Default value is '0'.
-# NETWORK_PART: network part of local and remote IP address
+# LNETWORK_PART: network part of local IP address
+# RNETWORK_PART: network part of remote IP address
 # LHOST_PART: host part of local IP address
 # RHOST_PART: host part of remote IP address
 set_lhost_rhost_ipv4addr()
 {
 	local link_num="$1"
-	local network_part="$2"
-	local lhost_part="$3"
-	local rhost_part="$4"
+	local lnetwork_part="$2"
+	local rnetwork_part="$3"
+	local lhost_part="$4"
+	local rhost_part="$5"
 
-	set_ipv4addr_check lhost $link_num $network_part $lhost_part
-	set_ipv4addr_check rhost $link_num $network_part $rhost_part
+	set_ipv4addr_check lhost $link_num $lnetwork_part $lhost_part
+	set_ipv4addr_check rhost $link_num $rnetwork_part $rhost_part
 }
 
 # Check connectivity with tst_ping.
diff --git a/testcases/network/stress/route/route4-change-dst b/testcases/network/stress/route/route4-change-dst
index 26510bc8b..89f4a267d 100644
--- a/testcases/network/stress/route/route4-change-dst
+++ b/testcases/network/stress/route/route4-change-dst
@@ -31,10 +31,10 @@ do_setup()
 	# Initialize the interfaces of the remote host
 	tst_init_iface rhost $LINK_NUM
 
-	set_ipv4addr_check rhost $LINK_NUM $IPV4_NETWORK $RHOST_IPV4_HOST
+	set_ipv4addr_check rhost $LINK_NUM $IPV4_RNETWORK $RHOST_IPV4_HOST
 
 	# IPv4 address of the remote host (gateway)
-	rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	rhost_ipv4addr="${IPV4_RNETWORK}.${RHOST_IPV4_HOST}"
 
 	lhost_ifname=$(tst_iface lhost $LINK_NUM)
 	rhost_ifname=$(tst_iface rhost $LINK_NUM)
diff --git a/testcases/network/stress/route/route4-change-gw b/testcases/network/stress/route/route4-change-gw
index 00773f676..a91fade35 100644
--- a/testcases/network/stress/route/route4-change-gw
+++ b/testcases/network/stress/route/route4-change-gw
@@ -42,7 +42,7 @@ do_setup()
 	# 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
-		tst_rhost_run -s -c "ip addr add ${IPV4_NETWORK}.${rhost_part}/$IPV4_NETMASK_NUM broadcast $IPV4_BROADCAST dev $rhost_ifname"
+		tst_rhost_run -s -c "ip addr add ${IPV4_RNETWORK}.${rhost_part}/$IPV4_NETMASK_NUM broadcast $IPV4_BROADCAST dev $rhost_ifname"
 		rhost_part=$(($rhost_part + 1))
 	done
 }
@@ -56,7 +56,7 @@ do_cleanup()
 do_setup
 
 for cmd_name in rt_cmd ip_cmd; do
-	do_test_common "gw" $cmd_name $LINK_NUM 1 $lhost_ifname "${IPV4_NETWORK}.$RHOST_IPV4_HOST_TOP" $RHOST_IPV4_HOST_TOP $RHOST_IPV4_HOST_LAST
+	do_test_common "gw" $cmd_name $LINK_NUM 1 $lhost_ifname "${IPV4_RNETWORK}.$RHOST_IPV4_HOST_TOP" $RHOST_IPV4_HOST_TOP $RHOST_IPV4_HOST_LAST
 done
 
 do_cleanup
diff --git a/testcases/network/stress/route/route4-change-if b/testcases/network/stress/route/route4-change-if
index 3e0c25915..957945d3a 100644
--- a/testcases/network/stress/route/route4-change-if
+++ b/testcases/network/stress/route/route4-change-if
@@ -52,7 +52,7 @@ do_setup()
 		tst_init_iface rhost $link_num
 
 		# Set IPv4 address to the interface of the remote host
-		set_ipv4addr_check rhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${RHOST_IPV4_HOST}
+		set_ipv4addr_check rhost ${link_num} "${IPV4_RNETWORK_PRE}.${link_num}" ${RHOST_IPV4_HOST}
 
 		link_num=$(( $link_num + 1 ))
 	done
@@ -72,7 +72,7 @@ do_cleanup()
 
 do_setup
 for cmd_name in rt_cmd ip_cmd; do
-	do_test_common "if" $cmd_name $LINK_NUM $link_total $lhost_ifname $IPV4_NETWORK_PRE
+	do_test_common "if" $cmd_name $LINK_NUM $link_total $lhost_ifname $IPV4_RNETWORK_PRE
 done
 do_cleanup
 tst_exit
diff --git a/testcases/network/stress/route/route4-ifdown b/testcases/network/stress/route/route4-ifdown
index 1c81a1f74..916944443 100644
--- a/testcases/network/stress/route/route4-ifdown
+++ b/testcases/network/stress/route/route4-ifdown
@@ -27,11 +27,11 @@ do_setup()
 {
 	do_cleanup_common
 
-	set_ipv4addr_check rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
-	rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	set_ipv4addr_check rhost ${LINK_NUM} ${IPV4_RNETWORK} ${RHOST_IPV4_HOST}
+	rhost_ipv4addr="${IPV4_RNETWORK}.${RHOST_IPV4_HOST}"
 
-	set_ipv4addr_check lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-	lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
+	set_ipv4addr_check lhost ${LINK_NUM} ${IPV4_LNETWORK} ${LHOST_IPV4_HOST}
+	lhost_ipv4addr="${IPV4_LNETWORK}.${LHOST_IPV4_HOST}"
 
 	lhost_ifname=$(tst_iface lhost $LINK_NUM)
 	rhost_ifname=$(tst_iface rhost $LINK_NUM)
diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
index e1823b8f1..977cb506c 100644
--- a/testcases/network/stress/route/route4-lib.sh
+++ b/testcases/network/stress/route/route4-lib.sh
@@ -27,13 +27,13 @@ export TCID="`basename $0`"
 . test_stress_net.sh
 
 # The first 2 ocnted of the Network portion of the gateway address
-# FIXME: calculate it from IPV4_NETWORK variable as test expects IPV4_NETWORK
+# FIXME: calculate it from IPV4_RNETWORK variable as test expects IPV4_RNETWORK
 # to be 10.0.0 and prefix 24.
-IPV4_NETWORK_PRE=${IPV4_NETWORK_PRE:-"10.0"}
+IPV4_RNETWORK_PRE=${IPV4_RNETWORK_PRE:-"10.0"}
 
 # The destination network
-# FIXME: generate DST_NETWORK_PREFIX randomly based on IPV4_NETWORK variable as
-# test expects IPV4_NETWORK to be 10.0.0 and prefix 24.
+# FIXME: generate DST_NETWORK_PREFIX randomly based on IPV4_RNETWORK variable as
+# test expects IPV4_LNETWORK and IPV4_RNETWORK to be 10.0.0 and prefix 24.
 DST_NETWORK_PREFIX="10.10" # 10.10.n.0/24
 DST_NETWORK="${DST_NETWORK_PREFIX}.0" # 10.10.0.0/24
 DST_HOST=5
@@ -177,14 +177,14 @@ do_test_common()
 		done
 		link_num=0
 		lhost_ifname="`get_lhost_ifname_loop $link_num`"
-		gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
+		gateway="${IPV4_RNETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
 	else
 		tst_resm TINFO "preparing connectivity"
 		if [ "$test_field" = "gw" ]; then
 			rhost_part=$rhost_part_first
-			gateway="${IPV4_NETWORK}.${rhost_part}"
+			gateway="${IPV4_RNETWORK}.${rhost_part}"
 		fi
-		prepare_connectivity $lhost_ifname $link_num $IPV4_NETWORK $LHOST_IPV4_HOST $gateway
+		prepare_connectivity $lhost_ifname $link_num $IPV4_LNETWORK $LHOST_IPV4_HOST $gateway
 	fi
 
 	if [ "$test_field" != "dst" ]; then
@@ -215,14 +215,14 @@ do_test_common()
 			link_num=$(($link_num + 1))
 			[ $link_num -ge $link_total ] && link_num=0
 			lhost_ifname="$(get_lhost_ifname_loop $link_num)"
-			gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
+			gateway="${IPV4_RNETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
 			task="change"
 		elif [ "$test_field" = "gw" ]; then
 			pre_rhost_part=$rhost_part
 			rhost_part=$(($rhost_part + 1))
 			[ $rhost_part -gt $rhost_part_last ] && rhost_part=$rhost_part_first
-			gateway="${IPV4_NETWORK}.${rhost_part}"
-			gateway2="${IPV4_NETWORK}.${pre_rhost_part}"
+			gateway="${IPV4_RNETWORK}.${rhost_part}"
+			gateway2="${IPV4_RNETWORK}.${pre_rhost_part}"
 			task="change"
 		fi
 
diff --git a/testcases/network/stress/route/route4-redirect b/testcases/network/stress/route/route4-redirect
index 718c96b33..a0d0e3aa2 100644
--- a/testcases/network/stress/route/route4-redirect
+++ b/testcases/network/stress/route/route4-redirect
@@ -43,10 +43,10 @@ do_setup()
 	sleep 3
 	tst_rhost_run -s -c "ip addr flush dev $rhost_ifname"
 
-	set_ipv4addr_check lhost $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST
+	set_ipv4addr_check lhost $LINK_NUM $IPV4_LNETWORK $LHOST_IPV4_HOST
 
 	tst_resm TINFO "add route to the initial gateway"
-	manipulate_route "route" "add" ${DST_NETWORK}.0 $IPV4_NETMASK_NUM $IPV4_NETMASK ${IPV4_NETWORK}.${RHOST_IPV4_HOST} $lhost_ifname
+	manipulate_route "route" "add" ${DST_NETWORK}.0 $IPV4_NETMASK_NUM $IPV4_NETMASK ${IPV4_LNETWORK}.${RHOST_IPV4_HOST} $lhost_ifname
 	if [ $? -ne 0 ]; then
 		tst_brkm TBROK "failed to add the gateway to $gateway"
 		return
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 45ab0dd67..13d91ae85 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -38,9 +38,9 @@ do_setup()
 	tst_check_cmds ethtool
 	do_cleanup
 
-	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
-	lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-	rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
+	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_LNETWORK $IPV4_RNETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
+	lhost_ipv4addr="${IPV4_LNETWORK}.${LHOST_IPV4_HOST}"
+	rhost_ipv4addr="${IPV4_RNETWORK}.${RHOST_IPV4_HOST}"
 	lhost_ifname=$(tst_iface lhost $LINK_NUM)
 	rhost_ifname=$(tst_iface rhost $LINK_NUM)
 
@@ -100,7 +100,7 @@ test_body()
 		# if we use netns we need to reset it as unloading driver breaks it
 		reset_ltp_netspace
 
-		set_ipv4addr_check lhost $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST
+		set_ipv4addr_check lhost $LINK_NUM $IPV4_LNETWORK $LHOST_IPV4_HOST
 
 		cnt=$(($cnt + 1))
 	done
-- 
2.12.2


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

* [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests
  2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (10 preceding siblings ...)
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
@ 2017-06-06 12:05 ` Alexey Kodanev
  2017-06-06 13:23   ` Petr Vorel
  11 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-06 12:05 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> Hi,
>
> as it might be uncomfortable to see patches on mailing list, you can also see
> them on github: https://github.com/pevik/ltp/tree/tst_net_vars.v6
>
> changes v5->v6:
>
> Changes in network setup (testcases/lib/tst_net_vars.c):
> * Simplify parsing network and host part of IP. Now it calculate just network
>   part and set host as the rest of what is left from IP.
> * Try to lookup local iface name and prefix in rtnetlink data if prefix not
>   provided in setup (in form of IP/PREFIX). Don't look up for remote prefix and
>   iface name as we would need to setup connection first, but this requires to
>   know them (remote prefix and iface name) for remote connection (or am I
>   missing something?).
Hi Petr,

tst_rhost_run() with "two hosts" setup is using just RHOST
variable (management link) for rsh/ssh, it can have the same
route as IP_RHOST or better something different that won't be
affected by the tests.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script Petr Vorel
@ 2017-06-06 13:12   ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-06 13:12 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> Script has been unused since:
> commit 5fe27d6a193d12e265509d04f1d7fab980ba5fae

Applied the first five patches from the patch-set. Thank you!


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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage Petr Vorel
@ 2017-06-06 13:15   ` Alexey Kodanev
  2017-06-06 13:45     ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-06 13:15 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> * This library is intended to be used throughout all stress tests reduce
> duplicity and use code test_net.sh where possible instead of legacy
> scripts in testcases/network/stress/ns-tools/.
>
> * check_connectivity() is split into general part (in test_stress_net.sh)
> ment as replacement of check_icmpv4_connectivity script and loop part
> wrapper check_connectivity_loop() (in if-lib.sh).
>
> * if-lib.sh sources test_stress_net.sh.
>
> ...
> +
> +# Library for all network/stress/ tests.
> +
> +# using variables IPV4_NETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST and some functions
> +. test_net.sh
> +
> +tst_check_cmds ifconfig killall

ifconfig is deprecated, it's not a good idea to have it in
the library. Moreover, I think the new tests or updated ones
shouldn't test it too. The same for 'route' command.

> +
> +# NOTE: More information about these network variables can be found
> +# in testcases/network/stress/README
> +
> +# TODO: Test expects prefix to be 24, which can get wrong when called
> +# with different prefix for IPV4_NETWORK.
> +
> +# 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

We shouldn't use IPV4_NETWORK for broadcast or adding
new addresses on the interface, this might affect other
hosts on this network, this is why we have IPV4_NET16_UNUSED
and IPV6_NET32_UNUSED variables. This also simplifies adding
new addresses/routes as we have fixed network with needed IP
address range that doesn't overlap with IP_RHOST/IP_LHOST
addresses.

Thanks,
Alexey

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

* [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests
  2017-06-06 12:05 ` [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Alexey Kodanev
@ 2017-06-06 13:23   ` Petr Vorel
  2017-06-07  9:48     ` Alexey Kodanev
  0 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-06 13:23 UTC (permalink / raw)
  To: ltp

Hi Alexey,

thanks for your input.

> tst_rhost_run() with "two hosts" setup is using just RHOST
> variable (management link) for rsh/ssh, it can have the same
> route as IP_RHOST or better something different that won't be
> affected by the tests.

Ok, for ssh/rsh, if prefix isn't defined in IPV{4,6}_LHOST I'll read it with
tst_rhost_run, using RHOST. That means to have separate binary for rtnetlink code.

I'll move default prefix values (24 and 64) from tst_net_vars.c to test_net.sh, these
values will be used as default for netns and used for rsh/ssh only if prefixes aren't
specified in IPV{4,6}_LHOST and nothing found with rtnetlink.

I also want to find via rtnetlink getting lhost and rhost iface. I wonder whether founded
ifaces (rhost and lhost) should be also added into {L,R}HOST_IFACES even if variables are
already specified by user and don't contain them.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-06 13:15   ` Alexey Kodanev
@ 2017-06-06 13:45     ` Petr Vorel
  2017-06-07 10:03       ` Alexey Kodanev
  0 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-06 13:45 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > +tst_check_cmds ifconfig killall

> ifconfig is deprecated, it's not a good idea to have it in
> the library. Moreover, I think the new tests or updated ones
> shouldn't test it too. The same for 'route' command.
I know, it's deprecated for Linux. Although we're testing Linux kernel, and net-tools for
linux are IMHO abandoned project, there are still people using it (see Ted Ts'o reaction
in Debian ML [1]).
Is it using removing ifconfig and route the only concern about these tests you have?
Wouldn't be worth to rewrite these test into C, using netlink/rtnetlink/libnfnetlink/libnl API?

> > +
> > +# NOTE: More information about these network variables can be found
> > +# in testcases/network/stress/README
> > +
> > +# TODO: Test expects prefix to be 24, which can get wrong when called
> > +# with different prefix for IPV4_NETWORK.
> > +
> > +# 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

> We shouldn't use IPV4_NETWORK for broadcast or adding
> new addresses on the interface, this might affect other
> hosts on this network, this is why we have IPV4_NET16_UNUSED
> and IPV6_NET32_UNUSED variables. This also simplifies adding
> new addresses/routes as we have fixed network with needed IP
> address range that doesn't overlap with IP_RHOST/IP_LHOST
> addresses.
Good point, thanks! Actually, I've experienced problems with local network affected by the
tests. Silly mistake :-(.


Kind regards,
Petr

[1] http://www.mail-archive.com/debian-devel@lists.debian.org/msg344777.html

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

* [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests
  2017-06-06 13:23   ` Petr Vorel
@ 2017-06-07  9:48     ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-07  9:48 UTC (permalink / raw)
  To: ltp

On 06/06/2017 04:23 PM, Petr Vorel wrote:
> Hi Alexey,
>
> thanks for your input.
>
>> tst_rhost_run() with "two hosts" setup is using just RHOST
>> variable (management link) for rsh/ssh, it can have the same
>> route as IP_RHOST or better something different that won't be
>> affected by the tests.
> Ok, for ssh/rsh, if prefix isn't defined in IPV{4,6}_LHOST I'll read it with
> tst_rhost_run, using RHOST. That means to have separate binary for rtnetlink code.
>
> I'll move default prefix values (24 and 64) from tst_net_vars.c to test_net.sh, these
> values will be used as default for netns and used for rsh/ssh only if prefixes aren't
> specified in IPV{4,6}_LHOST and nothing found with rtnetlink.
> I also want to find via rtnetlink getting lhost and rhost iface. I wonder whether founded
> ifaces (rhost and lhost) should be also added into {L,R}HOST_IFACES even if variables are
> already specified by user and don't contain them.

It's better to leave interfaces unchanged if a user has already defined
them.
The rest sounds good to me.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-06 13:45     ` Petr Vorel
@ 2017-06-07 10:03       ` Alexey Kodanev
  2017-06-07 16:27         ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-07 10:03 UTC (permalink / raw)
  To: ltp

On 06/06/2017 04:45 PM, Petr Vorel wrote:
> Hi Alexey,
>
>>> +tst_check_cmds ifconfig killall
>> ifconfig is deprecated, it's not a good idea to have it in
>> the library. Moreover, I think the new tests or updated ones
>> shouldn't test it too. The same for 'route' command.
> I know, it's deprecated for Linux. Although we're testing Linux kernel, and net-tools for
> linux are IMHO abandoned project, there are still people using it (see Ted Ts'o reaction
> in Debian ML [1]).
> Is it using removing ifconfig and route the only concern about these tests you have?

I've not looked at the other patches yet.

> Wouldn't be worth to rewrite these test into C, using netlink/rtnetlink/libnfnetlink/libnl API?

Interesting, may be that would stress more this Linux subsystem as there
will be less latency when adding/removing interfaces, routes, etc.
i.e. without starting a bunch of 'ip' commands in the shell.

Thanks,
Alexey

>
>>> +
>>> +# NOTE: More information about these network variables can be found
>>> +# in testcases/network/stress/README
>>> +
>>> +# TODO: Test expects prefix to be 24, which can get wrong when called
>>> +# with different prefix for IPV4_NETWORK.
>>> +
>>> +# 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
>> We shouldn't use IPV4_NETWORK for broadcast or adding
>> new addresses on the interface, this might affect other
>> hosts on this network, this is why we have IPV4_NET16_UNUSED
>> and IPV6_NET32_UNUSED variables. This also simplifies adding
>> new addresses/routes as we have fixed network with needed IP
>> address range that doesn't overlap with IP_RHOST/IP_LHOST
>> addresses.
> Good point, thanks! Actually, I've experienced problems with local network affected by the
> tests. Silly mistake :-(.
>
>
> Kind regards,
> Petr
>
> [1] http://www.mail-archive.com/debian-devel@lists.debian.org/msg344777.html


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

* [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
@ 2017-06-07 11:04   ` Alexey Kodanev
  2017-06-13 14:35     ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-07 11:04 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> * Fix test for netns based testing.
> * Remove rsh dependency.
> * Create shell library mcast4-lib.sh (mcast4 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 | 222 ++------------------
>  .../stress/multicast/grp-operation/mcast4-grpope02 | 231 ++------------------
>  .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
>  .../stress/multicast/grp-operation/mcast4-grpope04 | 233 ++-------------------
>  .../stress/multicast/grp-operation/mcast4-lib.sh   | 143 +++++++++++++
>  5 files changed, 223 insertions(+), 823 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..b80cd86f5 100644
> --- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
> +++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope01
> @@ -1,211 +1,33 @@
>  #!/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
> +. `dirname $0`/mcast4-lib.sh

. mcast4-lib.sh

>  
> -tst_resm TPASS "Test is finished successfully."
> +tst_resm TINFO "verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"

I think it's enough to print something like this:

tst_resm TINFO "joining $MCASTNUM_HEAVY IPv4 multicast groups on a
single socket"


>  
> -exit 0
> +do_setup $MCASTNUM_HEAVY
> +do_multicast_test_single_socket $MCASTNUM_HEAVY
> +do_cleanup_ns_mcast_join
> +tst_exit
> diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
> index 67efac73c..459dfb962 100644
> --- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
> +++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope02
> @@ -1,220 +1,29 @@
>  #!/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
> +. `dirname $0`/mcast4-lib.sh

. mcast4-lib.sh

>  
> -tst_resm TPASS "Test is finished successfully."
> +tst_resm TINFO "verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on separate sockets"

"verify that the kernel is not crashed when" doesn't have any useful
information :)

>  
> -exit 0
> +do_setup $MCASTNUM_HEAVY true
> +do_multicast_test_single_socket $MCASTNUM_HEAVY true
> +do_cleanup_ns_mcast_join
> +tst_exit
> diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope03 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope03
> index c44ec2170..2511abbfb 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
> -#
> +. `dirname $0`/mcast4-lib.sh

. mcast4-lib.sh

>  
> -tst_resm TPASS "Test is finished successfully."
> +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"

The first part here is not meaningful as well.

>  
> -exit 0
> +do_setup $MCASTNUM_NORMAL
> +do_multicast_test_multiple_sockets
> +tst_exit
> diff --git a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04 b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
> index 8783928f3..8949f5d7c 100644
> --- a/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
> +++ b/testcases/network/stress/multicast/grp-operation/mcast4-grpope04
> @@ -1,226 +1,31 @@
>  #!/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
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
>  #
> -# 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
> +# 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:
> -#	May 2 2006 - Created (Mitsuru Chinen)
> +# Setup: testcases/network/stress/README
>  #
> -#-----------------------------------------------------------------------
> -# 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}
> +# Author: Mitsuru Chinen <mitch@jp.ibm.com>
>  
> -# 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
> +. `dirname $0`/mcast4-lib.sh

. mcast4-lib.sh

>  
>  # Prefix of the filter souce adddress
>  SOURCE_ADDR_PREFIX="10.10"	# 10.10.x.y
>  
> +tst_resm TINFO "verify that the kernel is not crashed when joining and leaving the same IPv4 multicast group with a different source filter on $MCASTNUM_NORMAL sockets in $NS_TIMES times"

The same here.

>  
> -#-----------------------------------------------------------------------
> -#
> -# 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
> -
> -    # 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"

and here

> -
> -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
> -#
> -
> -tst_resm TPASS "Test is finished successfully."
> -
> -exit 0
> +do_setup $MCASTNUM_NORMAL
> +do_multicast_test_multiple_sockets 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..5be7cd79e
> --- /dev/null
> +++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
> @@ -0,0 +1,143 @@
> +#!/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 mcast4-grpope* tests.
> +
> +export TCID="`basename $0`"
> +export TST_TOTAL=1

There is no need for using 'export' here.


> +
> +. test_stress_net.sh
> +
> +do_cleanup()
> +{
> +	# Make sure to kill the multicast receiver and sender
> +	killall_sighup ns-mcast_join
> +	killall_sighup_rhost ns-igmp_querier
> +	init_if_lhost_rhost $LINK_NUM
> +}
> +
> +do_setup()
> +{
> +	local igmp_max_memberships="$1"
> +	local increase_max="${2:-}"
> +
> +	# Initialize the system configuration
> +	do_cleanup
> +
> +	# Call do_cleanup function before exit
> +	trap do_cleanup 0

This should be done with TST_CLEANUP var.


> +
> +	if [ "$increase_max" ]; then
> +		# Increase the maximum number of open file descriptors
> +		fd_num=`ulimit -n`
> +		if [ $fd_num -lt $igmp_max_memberships ]; then
> +			ulimit -n $igmp_max_memberships
> +			if [ $? -ne 0 ]; then
> +				tst_resm TBROK "$igmp_max_memberships is too many for the file descriptor"

TBROK but test continues,  may be TWARN?

> +			fi
> +		fi
> +	fi
> +
> +	lhost_ifname=$(tst_iface lhost $LINK_NUM)
> +	rhost_ifname=$(tst_iface rhost $LINK_NUM)
> +
> +	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST

There is no need for using these variables, also they are deprecated.

$IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST


This function should accept single address and optionally a link number.


> +
> +	lhost_addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
> +	rhost_addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"

IPV4_NETWORK, LHOST_IPV4_* shouldn't be used.

> +
> +	check_connectivity $lhost_ifname $rhost_addr
> +
> +	sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
> +	[ $? -ne 0 ] && tst_brkm TBROK "failed to set the sysctl value regarding multicast"

We have "ROD" library function that TBROK on failure.


> +
> +	sysctl -qw net.ipv4.igmp_max_msf=10
> +	sysctl -qw net.ipv4.conf.${lhost_ifname}.force_igmp_version=0
> +	sysctl -qw net.ipv4.conf.all.force_igmp_version=0

As a general rule, it would be good to change them back to the original
values in cleanup.

> +}
> +
> +do_multicast_test_single_socket()
> +{
> +	local igmp_max_memberships="$1"
> +	local is_multi_socket msg ret tmpfile
> +
> +	[ "${2:-}" = true ] && is_multi_socket="-m"
> +
> +	# Run a multicast join tool
> +	tmpfile=$TMPDIR/ns-mcast_join.$$

hmm, does the test call tst_tmdir()? also there is no need for "$TMPDIR"
prefix.

> +	ns-mcast_join -f 4 -I $lhost_ifname -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX > $tmpfile
> +	if [ $? -ne 0 ]; then
> +		rm -f $tmpfile
> +		tst_brkm TBROK "failed to start multicast joining tool"
> +	fi

just EXPECT_PASS ns-mcast_join -f 4 - ... /> $tmpfile

> +	msg=`cat $tmpfile | grep groups`

why not

tst_resm TINFO "joined $(grep groups $tmpfile)"

instead of `` + cat.

> +	tst_resm TINFO "joined $msg"
> +	rm -f $tmpfile

it will be removed in cleanup.

> +
> +	# Send IGMP General Query from the remote host
> +	tst_rhost_run -s -c "ns-igmp_querier -I $rhost_ifname -o -r 1"

I've recently added EXPECT_RHOST_PASS(), it can be used here.

> +
> +	tst_resm TPASS "test is finished successfully"

so no need for tst_resm with EXPECT_PASS...

> +}
> +
> +do_multicast_test_multiple_sockets()
> +{
> +	local define_source_address filter num params ret source_addr x y
> +
> +	[ "$1" = true ] && define_source_address="-m"
> +
> +	# Send IGMP General Query from the remote host
> +	tst_rhost_run -s -c "ns-igmp_querier -I $rhost_ifname -i 1000000000 -r 1 -b"
> +
> +	# Run a multicast join tool
> +	num=0
> +	while [ $num -lt $MCASTNUM_NORMAL ]; do
> +		if [ "$define_source_address" ]; then
> +			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
> +			params="-F $filter -s $source_addr"
> +		fi
> +
> +		ns-mcast_join -f 4 -I $lhost_ifname -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &
> +		[ $? -ne 0 ] && tst_brkm TBROK "failed to start multicast joining tool"
> +		num=`expr $num + 1`
> +	done
> +
> +	wait
> +
> +	tst_resm TPASS "test is finished successfully"
> +}
> +
> +do_cleanup_ns_mcast_join()
> +{
> +	killall_sighup ns-mcast_join
> +	while true; do
> +		ps auxw | grep -q [n]s-mcast_join || break
pgrep ns-mcast_join || break
> +		sleep 1

I would add a time limit here, and then use -9 signal.
Also s/sleep 1/tst_sleep 10ms/
> +	done
> +}


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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-07 10:03       ` Alexey Kodanev
@ 2017-06-07 16:27         ` Petr Vorel
  2017-06-08  9:44           ` Alexey Kodanev
  0 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-07 16:27 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > Wouldn't be worth to rewrite these test into C, using netlink/rtnetlink/libnfnetlink/libnl API?

> Interesting, may be that would stress more this Linux subsystem as there
> will be less latency when adding/removing interfaces, routes, etc.
> i.e. without starting a bunch of 'ip' commands in the shell.
Would you mind if I finish rewriting it as shell script and ip binary (incorporate your
comments and just removing ifconfig and route). As the most of work is done and it might
take me a while before I rewrite tests into CK


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage
  2017-06-07 16:27         ` Petr Vorel
@ 2017-06-08  9:44           ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-08  9:44 UTC (permalink / raw)
  To: ltp

On 06/07/2017 07:27 PM, Petr Vorel wrote:
> Hi Alexey,
>
>>> Wouldn't be worth to rewrite these test into C, using netlink/rtnetlink/libnfnetlink/libnl API?
>> Interesting, may be that would stress more this Linux subsystem as there
>> will be less latency when adding/removing interfaces, routes, etc.
>> i.e. without starting a bunch of 'ip' commands in the shell.
> Would you mind if I finish rewriting it as shell script and ip binary (incorporate your
> comments and just removing ifconfig and route). As the most of work is done and it might
> take me a while before I rewrite tests into CK

Sure don't mind.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace()
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace() Petr Vorel
@ 2017-06-08 10:53   ` Alexey Kodanev
  2017-06-08 13:09     ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-08 10:53 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> This function is useful when we know we broke netns (e.g. unloading
> network driver).
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 9 ++++++++-

Looks like it's not the right place for this function. Is it going to be
used in tests somehow?

What about adding it to network.sh with special option?

>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index f93f67411..91a62f9f6 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -42,12 +42,19 @@ init_ltp_netspace()
>  	tst_wait_ipv6_dad
>  }
>  
> +# Force to reset netns.
> +reset_ltp_netspace()
> +{
> +	[ -n "$TST_USE_NETNS" ] || return
> +	ip net del ltp_ns

With this patch
  3fb501e net: use LTP ns_create/ns_exec

rm -f /var/run/netns/ltp_ns
pkill ns_create


Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170608/40dd2380/attachment.html>

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

* [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace()
  2017-06-08 10:53   ` Alexey Kodanev
@ 2017-06-08 13:09     ` Petr Vorel
  0 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-06-08 13:09 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Looks like it's not the right place for this function. Is it going to be
> used in tests somehow?

> What about adding it to network.sh with special option?

It's used in testcases/network/stress/route/route4-rmmod (patch [1]) so far, it probably be used
also in testcases/network/stress/route/route6-rmmod.

> > +# Force to reset netns.
> > +reset_ltp_netspace()
> > +{
> > +	[ -n "$TST_USE_NETNS" ] || return
> > +	ip net del ltp_ns

> With this patch
>   3fb501e net: use LTP ns_create/ns_exec

> rm -f /var/run/netns/ltp_ns
> pkill ns_create
It's more readable to use 'ip net del ltp_ns', but ns_create is already used in test_net.sh.
If it's ok for you, I'll keep it in test_net.sh, but use your code.

[1]: http://lists.linux.it/pipermail/ltp/2017-June/004717.html


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
@ 2017-06-12 12:39   ` Alexey Kodanev
  2017-06-27  6:04     ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-12 12:39 UTC (permalink / raw)
  To: ltp

Hi,
On 06/03/2017 03:00 PM, Petr Vorel wrote:
> * Fix test for netns based testing.
> * 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>
> ---
>  testcases/network/stress/ns-tools/initialize_if    |   3 -
>  testcases/network/stress/route/00_Descriptions.txt |  23 +-
>  testcases/network/stress/route/route4-change-dst   | 287 ++---------------
>  testcases/network/stress/route/route4-change-gw    | 308 +++---------------
>  testcases/network/stress/route/route4-change-if    | 348 +++------------------
>  testcases/network/stress/route/route4-ifdown       | 298 ++++--------------
>  testcases/network/stress/route/route4-lib.sh       | 252 +++++++++++++++
>  testcases/network/stress/route/route4-redirect     | 232 +++-----------
>  testcases/network/stress/route/route4-rmmod        | 329 +++++--------------
>  testcases/network/stress/route/route6-change-dst   |   2 +-
>  10 files changed, 585 insertions(+), 1497 deletions(-)
>  create mode 100644 testcases/network/stress/route/route4-lib.sh
>
> diff --git a/testcases/network/stress/ns-tools/initialize_if b/testcases/network/stress/ns-tools/initialize_if
> index d64203e4c..23bf68bc0 100644
> --- a/testcases/network/stress/ns-tools/initialize_if
> +++ b/testcases/network/stress/ns-tools/initialize_if
> @@ -69,9 +69,6 @@ fi
>  # Define the interface name
>  ifname=`get_ifname $host_type $link_num` || exit 1
>  
> -# Initialize the specified interface
> -command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
> -
>  if [ $host_type = lhost ]; then
>      ( ifconfig $ifname down && \
>      ip link set mtu 1500 dev $ifname && \

There are no changes in route IPv6 tests, why do we need this for route
IPv4?


[...]
>  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}
> -}
> -
> -
> -#-----------------------------------------------------------------------
> -#
> -# 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
> +	# Initialize the interfaces of the remote host
> +	tst_init_iface rhost $LINK_NUM

It should really be tst_restore_addr() functions, they invoke
tst_init_iface,
add IP addresses from configuration.

[...]
>  
> -#
> -#-----------------------------------------------------------------------
> +for cmd_name in rt_cmd ip_cmd; do
> +	do_test_common "dst" $cmd_name $LINK_NUM 1 $lhost_ifname $rhost_ipv4addr
> +done

do_test_common dst rt_cmd $LINK_NUM 1 $lhost_ifname $rhost_ipv4addr
do_test_common dst ip_cmd $LINK_NUM 1 $lhost_ifname $rhost_ipv4addr


I think "do_test_common" is too generic name for the library function,
mat be "route_test/route_cleanup"?

One more thing, do the tests use multiple NICs at the same time?
If not,we could simplify them and assume it is default one, i.e. 0.

[...]
>  
> -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
> +do_cleanup_common

There is 'TST_CLEANUP' library variable for this. It'll be called on
tst_exit or TBROK.

[...]
>  
> diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
> new file mode 100644
> index 000000000..e1823b8f1
> --- /dev/null
> +++ b/testcases/network/stress/route/route4-lib.sh
> @@ -0,0 +1,252 @@
> +#!/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>
> +
> +export TCID="`basename $0`"
> +
> +. test_stress_net.sh
> +
> +# The first 2 ocnted of the Network portion of the gateway address
> +# FIXME: calculate it from IPV4_NETWORK variable as test expects IPV4_NETWORK
> +# to be 10.0.0 and prefix 24.
> +IPV4_NETWORK_PRE=${IPV4_NETWORK_PRE:-"10.0"}
> +
> +# The destination network
> +# FIXME: generate DST_NETWORK_PREFIX randomly based on IPV4_NETWORK variable as
> +# test expects IPV4_NETWORK to be 10.0.0 and prefix 24.
> +DST_NETWORK_PREFIX="10.10" # 10.10.n.0/24
> +DST_NETWORK="${DST_NETWORK_PREFIX}.0" # 10.10.0.0/24
> +DST_HOST=5
> +DST_PORT=7
> +
> +do_cleanup_common()
> +{
> +    init_if_lhost_rhost $LINK_NUM

cleanup should restore default configuration on a testinterface,
otherwise the other test would run on an empty one.

> +}
> +
> +prepare_connectivity()
> +{
> +	local lhost_ifname=$1
> +	local link_num=$2
> +	local network_part="$3"
> +	local host_part="$4"
> +	local rhost_addr="$5"
> +	local type="lhost"
> +
> +	tst_init_iface $type $link_num
> +	set_ipv4addr_check $type $link_num $network_part $host_part
> +	check_connectivity $lhost_ifname $rhost_addr
> +}
> +
> +get_lhost_ifname_loop()
> +{
> +	local field=$(($1 + 1))
> +	echo $lhost_ifname_array | cut -d ' ' -f $field
> +}
> +
> +run_cmd()
> +{
> +	local cmd="$@"
> +	local ret
> +
> +	sh -c "$cmd"
> +	ret=$?
> +	[ $ret -ne 0 ] && tst_resm TWARN "'$cmd' failed: $ret"

Can we use EXPECT_PASS instead of run_cmd or ROD if it is inside setup?

> +	return $ret
> +}
> +
> +manipulate_route()
> +{
> +	local cmd_name=$1
> +	local task=$2
> +	local network=$3
> +	local prefix=$4
> +	local netmask=$5
> +	local gateway=$6
> +	local lhost_ifname=$7
> +	# not required params
> +	local gateway2=$8
> +	local lhost_ifname2=$9
> +
> +	local ret t
> +
> +	[ "$task" = "add" ] || [ "$task" = "del" ] || [ "$task" = "change" ] || \
> +		tst_brkm TBROK "wrong task: '$task'"
> +
> +	if [ "$cmd_name" = "ip" ]; then
> +		run_cmd "$cmd_name route $task $network/$prefix via $gateway dev $lhost_ifname"
> +		ret=$?
> +	else
> +		t="$task"
> +		# route doesn't have change command
> +		[ "$task" = "change" ] && t="add"
> +		run_cmd "$cmd_name $t -net $network netmask $netmask gw $gateway dev $lhost_ifname"
> +		ret=$?
> +
> +		if [ "$task" = "change" ]; then
> +			run_cmd "$cmd_name del -net $network netmask $netmask gw $gateway2 dev $lhost_ifname2"
> +			ret=$?
> +		fi
> +	fi
> +

It would be better to use tst_res()/rod/expect_pass/fail here rather
than each time check the status after the command + set test result.

[...]
> +
> +do_test_common()
> +{
> +	local test_field=$1
> +	local cmd_type=$2
> +	local link_num=$3
> +	local link_total=$4
> +	local lhost_ifname=$5
> +	local rhost_addr="$6"
> +	# not required params
> +	local rhost_part_first=$7
> +	local rhost_part_last=$8
> +
> +	local run_in_background=true
> +	local cnt=0
> +	local dst_addr dst_network dst_network_postfix ipv4_network_loop gateway2 lhost_ifname2 rhost_part task test_field_name
> +	local cmd_name="`get_cmd $cmd_type`"
> +	local gateway="$rhost_addr"
> +
> +	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 "verify the kernel is not crashed when the $test_field_name of an IPv4 route is changed frequently by '$cmd_name' command $NS_TIMES times"
> +
> +	if [ "$test_field" = "if" ]; then
> +		link_num=0
> +		tst_resm TINFO "preparing connectivity $link_total times"
> +		while [ $link_num -lt $link_total ]; do
> +			lhost_ifname="$(get_lhost_ifname_loop $link_num)"
> +			ipv4_network_loop="${rhost_addr}.${link_num}"
> +			prepare_connectivity $lhost_ifname $link_num $ipv4_network_loop $LHOST_IPV4_HOST "$ipv4_network_loop.${LHOST_IPV4_HOST}"
> +		done

Hmm, may be I missed something but I didn't notice that the tests
use all the links, only $LINK_NUM, so I guessit is not necessary
tocomplicate setup with setting all the available links.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-06-07 11:04   ` Alexey Kodanev
@ 2017-06-13 14:35     ` Petr Vorel
  2017-06-13 16:35       ` Alexey Kodanev
  0 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-13 14:35 UTC (permalink / raw)
  To: ltp

Hi Alexey,

Thanks for you review and comments! I'll be more radical when I do shell test rewrite :-).
I understand and agree with most of your comments for these two tests rewrite commits,
just some notes and questions below.

> > +
> > +	lhost_ifname=$(tst_iface lhost $LINK_NUM)
> > +	rhost_ifname=$(tst_iface rhost $LINK_NUM)
> > +
> > +	set_lhost_rhost_ipv4addr $LINK_NUM $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST

> There is no need for using these variables, also they are deprecated.

> $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
Variables IPV4_NETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST were used as the cleanup is done
*before* using variables from tst_net_vars. This is my deliberate decision (to easily see
whether fix in test was caused by cleanup or by using tst_net_vars), but if you don't like
it I can squash test cleanup and using tst_net_vars into one commit (i.e. do cleanup in
commit after adding tst_net_vars.c).


> This function should accept single address and optionally a link number.
set_ipv4addr_check in test_stress_net.sh (previous commit) uses these values for ifconfig.
Of course, I change it for ip, but is the best way how to do it?  tst_restore_ipaddr or
tst_init_iface would probably be the best for init iface (as you mentioned before, but tst_add_ipaddr takes IP from tst_ipaddr

set_ipv4addr_check()
{
	local type="${1}"
	local link_num="$2"
	local network_part="$3"
	local host_part="$4"
	local addr broadcast cmd ifname netmask ret

	addr=${network_part}.${host_part}
	netmask=$(echo $network_part | sed "s/[[:digit:]]*/255/g").$(echo $host_part | sed "s/[[:digit:]]*/0/g")
	broadcast=${network_part}.$(echo $host_part | sed "s/[[:digit:]]*/255/g")
	ifname=$(tst_iface $type $link_num)

	# TODO: use tst_init_iface and tst_add_ipaddr (tst_add_ipaddr must be
	# adjusted to take mask as parameter).
	for cmd in "ifconfig $ifname up" \
		"ifconfig $ifname $addr netmask $netmask broadcast $broadcast"; do
		[ $type = "lhost" ] && sh -c "$cmd" || tst_rhost_run -c "$cmd"
		ret=$?
		[ $ret -ne 0 ] && tst_brkm TBROK "failed to set IP '$addr' to '$ifname' at $type ('$cmd': $ret)"
	done
}

> > +
> > +	lhost_addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
> > +	rhost_addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"

> IPV4_NETWORK, LHOST_IPV4_* shouldn't be used.
I got it from your previous comment => use IPV4_NET16_UNUSED + the rest of IPs.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests
  2017-06-13 14:35     ` Petr Vorel
@ 2017-06-13 16:35       ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-13 16:35 UTC (permalink / raw)
  To: ltp

On 06/13/2017 05:35 PM, Petr Vorel wrote:

[...]
> $IPV4_NETWORK $LHOST_IPV4_HOST $RHOST_IPV4_HOST
> Variables IPV4_NETWORK LHOST_IPV4_HOST RHOST_IPV4_HOST were used as the cleanup is done
> *before* using variables from tst_net_vars. This is my deliberate decision (to easily see
> whether fix in test was caused by cleanup or by using tst_net_vars), but if you don't like
> it I can squash test cleanup and using tst_net_vars into one commit (i.e. do cleanup in
> commit after adding tst_net_vars.c).

Understand, but instead of IPV4_NETWORK + *_IPV4_HOST network tests,
which source test_net.sh, are using tst_ipaddr().

>
>
>> This function should accept single address and optionally a link number.
> set_ipv4addr_check in test_stress_net.sh (previous commit) uses these values for ifconfig.
> Of course, I change it for ip, but is the best way how to do it?  tst_restore_ipaddr or
> tst_init_iface would probably be the best for init iface (as you mentioned before, but tst_add_ipaddr takes IP from tst_ipaddr

What about invoking ip command directly? Plus it perfectly fine to pass
IPv6 address without changing the command:

ROD ip a add ${net}${host}/$mask dev $dev

Thanks,
Alexey


>
> set_ipv4addr_check()
> {
> 	local type="${1}"
> 	local link_num="$2"
> 	local network_part="$3"
> 	local host_part="$4"
> 	local addr broadcast cmd ifname netmask ret
>
> 	addr=${network_part}.${host_part}
> 	netmask=$(echo $network_part | sed "s/[[:digit:]]*/255/g").$(echo $host_part | sed "s/[[:digit:]]*/0/g")
> 	broadcast=${network_part}.$(echo $host_part | sed "s/[[:digit:]]*/255/g")
> 	ifname=$(tst_iface $type $link_num)
>
> 	# TODO: use tst_init_iface and tst_add_ipaddr (tst_add_ipaddr must be
> 	# adjusted to take mask as parameter).
> 	for cmd in "ifconfig $ifname up" \
> 		"ifconfig $ifname $addr netmask $netmask broadcast $broadcast"; do
> 		[ $type = "lhost" ] && sh -c "$cmd" || tst_rhost_run -c "$cmd"
> 		ret=$?
> 		[ $ret -ne 0 ] && tst_brkm TBROK "failed to set IP '$addr' to '$ifname' at $type ('$cmd': $ret)"
> 	done
> }
>
>>> +
>>> +	lhost_addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
>>> +	rhost_addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
>> IPV4_NETWORK, LHOST_IPV4_* shouldn't be used.
> I got it from your previous comment => use IPV4_NET16_UNUSED + the rest of IPs.
>
>
> Kind regards,
> Petr


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

* [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-06-15 15:00   ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-15 15:00 UTC (permalink / raw)
  To: ltp

Hi,
On 06/03/2017 03:00 PM, Petr Vorel wrote:
> tst_net_vars take input of local and remote address and setup most of
> test link (IP related) environment variables.
>
> For full list of environment variables which it setup run:
> tst_net_vars -h
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/.gitignore     |   1 +
>  testcases/lib/Makefile       |   4 +-
>  testcases/lib/tst_net_vars.c | 802 +++++++++++++++++++++++++++++++++++++++++++

Looks good, minor comments below.

> +}
> +
> +static int read_prefix_iface(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);

Can we change it to SAFE_SOCKET and use other 'safe' functions in
tst_net_vars?

> +
> +	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);

Here as well.


Also I got a couple of warnings from gcc:

tst_net_vars.c: In function ‘get_ipv6_net32_unused’:
tst_net_vars.c:239: warning: missing braces around initializer
tst_net_vars.c:239: warning: (near initialization for ‘mask.__in6_u’)

better use memset() for portability with older gcc.

tst_net_vars.c: In function ‘read_prefix_iface’:
tst_net_vars.c:592: warning: comparison between signed and unsigned
integer expressions

Please also check the patch with checkpatch utility.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables
  2017-06-03 12:00 ` [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
@ 2017-06-15 15:02   ` Alexey Kodanev
  0 siblings, 0 replies; 32+ messages in thread
From: Alexey Kodanev @ 2017-06-15 15:02 UTC (permalink / raw)
  To: ltp

On 06/03/2017 03:00 PM, Petr Vorel wrote:
> tst_net_vars simplifies setup as it only needs to have passed 4 IP
> addresses (2x IPv4 and 2 IPv6) and alows to define different network
> part for local and remote hosts.
>
> Rename variables in rewritten tests to use variables defined by
> tst_net_vars. These scripts are run by testscripts/network.sh script
> which defined these variables by setting test_net.sh, so it makes a
> sense to use them.
>
> Old tests still use IPV4_NETWORK variable instead of IPV4_LNETWORK and
> IPV4_RNETWORK and have it defined locally.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh                          | 59 ++++++++++------------
>  testcases/network/stress/interface/if4-addr-change |  2 +-
>  .../stress/multicast/grp-operation/mcast4-lib.sh   |  6 +--
>  .../network/stress/ns-tools/test_stress_net.sh     | 18 ++++---
>  testcases/network/stress/route/route4-change-dst   |  4 +-
>  testcases/network/stress/route/route4-change-gw    |  4 +-
>  testcases/network/stress/route/route4-change-if    |  4 +-
>  testcases/network/stress/route/route4-ifdown       |  8 +--
>  testcases/network/stress/route/route4-lib.sh       | 20 ++++----
>  testcases/network/stress/route/route4-redirect     |  4 +-
>  testcases/network/stress/route/route4-rmmod        |  8 +--
>  11 files changed, 68 insertions(+), 69 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index 91a62f9f6..a470d1c45 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -197,19 +197,10 @@ tst_read_opts $*

[...]
> +IPV4_LHOST="${IPV4_LHOST:-10.0.0.2}"
> +IPV4_RHOST="${IPV4_RHOST:-10.0.0.1}"
> +IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2}"
> +IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1}"
> +
> +# tst_net_vars exports environment variables related to test links and networks
> +# that aren't reachable through the test links.
> +# See tst_net_vars -h for a list of exported variables.
> +if [ -z "$TST_PARSE_VARIABLES" ]; then
> +	tst_resm TINFO "Parsing variables for $IPV4_LHOST $IPV4_RHOST"
> +	eval $(tst_net_vars $IPV4_LHOST $IPV4_RHOST)
> +	tst_resm TINFO "Parsing variables for $IPV6_LHOST $IPV6_RHOST"
> +	eval $(tst_net_vars $IPV6_LHOST $IPV6_RHOST)

We should really check whether tst_net_vars failed or not here, and exit
on error.

  eval $(tst_net_vars $IPV6_LHOST $IPV6_RHOST || echo "exit $?")

> +	TST_PARSE_VARIABLES="yes"

export TST_PARSE_VARIABLES="yes"


Thanks,
Alexey


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

* [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests
  2017-06-12 12:39   ` Alexey Kodanev
@ 2017-06-27  6:04     ` Petr Vorel
  2017-07-18 12:14       ` Alexey Kodanev
  0 siblings, 1 reply; 32+ messages in thread
From: Petr Vorel @ 2017-06-27  6:04 UTC (permalink / raw)
  To: ltp

Hi Alexey,

thank you for your review, all will be in v7. Just one comment to initialize_if:

> On 06/03/2017 03:00 PM, Petr Vorel wrote:
...
> > -# Initialize the specified interface
> > -command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
> > -
> >  if [ $host_type = lhost ]; then
> >      ( ifconfig $ifname down && \
> >      ip link set mtu 1500 dev $ifname && \

> There are no changes in route IPv6 tests, why do we need this for route
> IPv4?
testcases/network/stress/ns-tools/initialize_if is a legacy script. Instead of fixing it
should it's usage should be replaced by functions from test_net.sh or test_stress_net.sh
and the file deleted.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests
  2017-07-18 12:14       ` Alexey Kodanev
@ 2017-07-18 12:12         ` Petr Vorel
  0 siblings, 0 replies; 32+ messages in thread
From: Petr Vorel @ 2017-07-18 12:12 UTC (permalink / raw)
  To: ltp

Hi Alexey,
> Hi Petr,

> Right, the usage of 'initialize_if' is replaced in route4 patch, so
> the question was why we need this change in 'initialize_if' here?

Thank you for your comment. But please don't spend your time with reviewing v6. I'm
finishing v7, where I did more radical cleanup (I got inspiration with your interface
tests - if-lib.sh).
ATM I'm fixing issues for SSH based testing (previously I run it only with netns, some
things got broken).


Kind regards,
Petr

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

* [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests
  2017-06-27  6:04     ` Petr Vorel
@ 2017-07-18 12:14       ` Alexey Kodanev
  2017-07-18 12:12         ` Petr Vorel
  0 siblings, 1 reply; 32+ messages in thread
From: Alexey Kodanev @ 2017-07-18 12:14 UTC (permalink / raw)
  To: ltp

On 06/27/2017 09:04 AM, Petr Vorel wrote:
> Hi Alexey,
>
> thank you for your review, all will be in v7. Just one comment to initialize_if:
>
>> On 06/03/2017 03:00 PM, Petr Vorel wrote:
> ...
>>> -# Initialize the specified interface
>>> -command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
>>> -
>>>  if [ $host_type = lhost ]; then
>>>      ( ifconfig $ifname down && \
>>>      ip link set mtu 1500 dev $ifname && \
>> There are no changes in route IPv6 tests, why do we need this for route
>> IPv4?
> testcases/network/stress/ns-tools/initialize_if is a legacy script. Instead of fixing it
> should it's usage should be replaced by functions from test_net.sh or test_stress_net.sh
> and the file deleted.

Hi Petr,

Right, the usage of 'initialize_if' is replaced in route4 patch, so
the question was why we need this change in 'initialize_if' here?

Thanks,
Alexey


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

end of thread, other threads:[~2017-07-18 12:14 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-03 12:00 [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 01/11] gitignore: Prefixing filenames Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 02/11] lib: Fix 'unbound variable' error in shell libraries Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 03/11] network/stress: Fix typo Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 04/11] network/stress: Use correct reporting function Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 05/11] network/stress: Remove bg_tcp_traffic script Petr Vorel
2017-06-06 13:12   ` Alexey Kodanev
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 06/11] network/stress: Add library test_stress_net.sh for general usage Petr Vorel
2017-06-06 13:15   ` Alexey Kodanev
2017-06-06 13:45     ` Petr Vorel
2017-06-07 10:03       ` Alexey Kodanev
2017-06-07 16:27         ` Petr Vorel
2017-06-08  9:44           ` Alexey Kodanev
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 07/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
2017-06-07 11:04   ` Alexey Kodanev
2017-06-13 14:35     ` Petr Vorel
2017-06-13 16:35       ` Alexey Kodanev
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 08/11] lib/test_net.sh: reset_ltp_netspace() Petr Vorel
2017-06-08 10:53   ` Alexey Kodanev
2017-06-08 13:09     ` Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 09/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
2017-06-12 12:39   ` Alexey Kodanev
2017-06-27  6:04     ` Petr Vorel
2017-07-18 12:14       ` Alexey Kodanev
2017-07-18 12:12         ` Petr Vorel
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 10/11] network: Add tools for setup IP related environment variables Petr Vorel
2017-06-15 15:00   ` Alexey Kodanev
2017-06-03 12:00 ` [LTP] [RFC PATCH v6 11/11] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
2017-06-15 15:02   ` Alexey Kodanev
2017-06-06 12:05 ` [LTP] [RFC PATCH v6 00/11] Simplify network setup + fix some network stress tests Alexey Kodanev
2017-06-06 13:23   ` Petr Vorel
2017-06-07  9:48     ` 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.