All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests
@ 2017-07-21  4:03 Petr Vorel
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module Petr Vorel
                   ` (10 more replies)
  0 siblings, 11 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:03 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.v7

Changes v6->v7:
* I more radically cleanup IPV4 multicast and route scripts. Also changed a bit
  interfaces tests. I spent a lot of time with cleanup and testing. Cleaned
  scripts should work under SSH and netns.
* I split tst_net_vars into 3 tools. This was necessary to have reading of
* rtnetlink on rhost.

TODO:
* Add more test links for netns (for route4-change-if).
* Fix also IPv6 scripts.

Alexey Kodanev (1):
  network/dhcp: Fix removing veth kernel module

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

 include/tst_net.h                                  | 140 +++++
 testcases/lib/.gitignore                           |   3 +
 testcases/lib/Makefile                             |   2 +-
 testcases/lib/test_net.sh                          | 149 +++--
 testcases/lib/tst_net_iface_prefix.c               | 173 ++++++
 testcases/lib/tst_net_ip_prefix.c                  | 116 ++++
 testcases/lib/tst_net_vars.c                       | 655 +++++++++++++++++++++
 testcases/network/dhcp/dhcp_lib.sh                 |   9 +-
 testcases/network/stress/interface/if-addr-adddel  |  21 +-
 .../network/stress/interface/if-addr-addlarge      |  22 +-
 testcases/network/stress/interface/if-lib.sh       |  73 ---
 testcases/network/stress/interface/if-mtu-change   |  30 +-
 testcases/network/stress/interface/if-route-adddel |  24 +-
 .../network/stress/interface/if-route-addlarge     |  21 +-
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |  21 +-
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 +------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 +-------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 +------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 +-------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 129 ++++
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 testcases/network/stress/ns-tools/initialize_if    |   3 -
 .../network/stress/ns-tools/test_net_stress.sh     | 172 ++++++
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 283 +--------
 testcases/network/stress/route/route4-change-gw    | 302 +---------
 testcases/network/stress/route/route4-change-if    | 336 ++---------
 testcases/network/stress/route/route4-ifdown       | 283 ++-------
 testcases/network/stress/route/route4-lib.sh       | 206 +++++++
 testcases/network/stress/route/route4-redirect     | 220 ++-----
 testcases/network/stress/route/route4-rmmod        | 305 ++--------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 33 files changed, 2106 insertions(+), 2532 deletions(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh
 create mode 100644 testcases/network/stress/route/route4-lib.sh

-- 
2.13.2


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

* [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
@ 2017-07-21  4:03 ` Petr Vorel
  2017-08-03 11:45   ` Alexey Kodanev
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh Petr Vorel
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:03 UTC (permalink / raw)
  To: ltp

From: Alexey Kodanev <alexey.kodanev@oracle.com>

This patch fixes problems with dhcp based tests run via netns when they
call TCONF:

$ /opt/ltp/testscripts/network.sh -6
dhcpd 1 TCONF: 'dhcpd' not found
...
cat: /sys/class/net/ltp_ns_veth2/address: No such file or directory

This also fixes other tests run after dhcp tests which are broken as
netns setup got broken.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Tested-by: Petr Vorel <pvorel@suse.cz>
---
Alexey, this is your proposed patch from mailing list [1]. I've tested it.

[1]: http://lists.linux.it/pipermail/ltp/2017-June/004850.html
---
 testcases/network/dhcp/dhcp_lib.sh | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/testcases/network/dhcp/dhcp_lib.sh b/testcases/network/dhcp/dhcp_lib.sh
index 85f9b88bf..500123284 100755
--- a/testcases/network/dhcp/dhcp_lib.sh
+++ b/testcases/network/dhcp/dhcp_lib.sh
@@ -40,8 +40,7 @@ init()
 	tst_require_root
 	tst_check_cmds cat $dhcp_name awk ip pgrep pkill dhclient
 
-	veth_loaded=
-	lsmod | grep -q '^veth ' && veth_loaded=1
+	lsmod | grep -q '^veth ' && veth_loaded=yes || veth_loaded=no
 
 	tst_resm TINFO "create veth interfaces"
 	ip li add $iface0 type veth peer name $iface1 || \
@@ -68,6 +67,8 @@ init()
 
 cleanup()
 {
+	[ -z "$veth_loaded" ] && return
+
 	stop_dhcp
 
 	pkill -f "dhclient -$ipv $iface1"
@@ -81,9 +82,7 @@ cleanup()
 
 	[ $veth_added ] && ip li del $iface0
 
-	if [ -z $veth_loaded ]; then
-		lsmod | grep -q '^veth ' && rmmod veth
-	fi
+	[ "$veth_loaded" = "no" ] && lsmod | grep -q '^veth ' && rmmod veth
 
 	tst_rmdir
 }
-- 
2.13.2


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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module Petr Vorel
@ 2017-07-21  4:03 ` Petr Vorel
  2017-07-24 15:54   ` Alexey Kodanev
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:03 UTC (permalink / raw)
  To: ltp

+ use it in interface stress tests

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

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

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I'll port this library to be able to test also IPv6.
---
 testcases/lib/test_net.sh                          |  21 ++-
 testcases/network/stress/interface/if-addr-adddel  |  15 +-
 .../network/stress/interface/if-addr-addlarge      |  16 +-
 testcases/network/stress/interface/if-lib.sh       |  73 ---------
 testcases/network/stress/interface/if-mtu-change   |  23 +--
 testcases/network/stress/interface/if-route-adddel |  17 +-
 .../network/stress/interface/if-route-addlarge     |  15 +-
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |   4 +-
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_net_stress.sh     | 171 +++++++++++++++++++++
 11 files changed, 229 insertions(+), 137 deletions(-)
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh

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


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

* [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module Petr Vorel
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh Petr Vorel
@ 2017-07-21  4:03 ` Petr Vorel
  2017-07-24 15:57   ` Alexey Kodanev
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 04/11] network/stress: Reduce the default number of cycles for various tests Petr Vorel
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:03 UTC (permalink / raw)
  To: ltp

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

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


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

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

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

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

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


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

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

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

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


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

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

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

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

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


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

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

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

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

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index 0cafe1514..cecb0bab2 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -42,7 +42,7 @@ init_ltp_netspace()
 	export TST_INIT_NETNS="no"
 
 	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
-	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
+	export LTP_NETNS="ns_exec $pid net,mnt"
 
 	tst_restore_ipaddr
 	tst_restore_ipaddr rhost
@@ -50,6 +50,18 @@ init_ltp_netspace()
 	tst_wait_ipv6_dad
 }
 
+# Force to reset netns.
+reset_ltp_netspace()
+{
+	[ -n "$TST_USE_NETNS" ] || return
+
+	tst_resm TINFO "reset netns"
+	ip link delete ltp_ns_veth2 2> /dev/null
+	rm -f /var/run/netns/ltp_ns
+	pkill ns_create
+	init_ltp_netspace
+}
+
 # Run command on remote host.
 # Options:
 # -b run in background
-- 
2.13.2


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

* [LTP] [RFC PATCH v7 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (6 preceding siblings ...)
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
@ 2017-07-21  4:04 ` Petr Vorel
  2017-07-26 14:58   ` Alexey Kodanev
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:04 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/network/stress/ns-tools/initialize_if    |   3 -
 .../network/stress/ns-tools/test_net_stress.sh     |   9 +-
 testcases/network/stress/route/00_Descriptions.txt |  23 +-
 testcases/network/stress/route/route4-change-dst   | 283 ++---------------
 testcases/network/stress/route/route4-change-gw    | 302 ++----------------
 testcases/network/stress/route/route4-change-if    | 336 +++------------------
 testcases/network/stress/route/route4-ifdown       | 283 ++++-------------
 testcases/network/stress/route/route4-lib.sh       | 206 +++++++++++++
 testcases/network/stress/route/route4-redirect     | 220 +++-----------
 testcases/network/stress/route/route4-rmmod        | 314 +++++--------------
 testcases/network/stress/route/route6-change-dst   |   2 +-
 11 files changed, 480 insertions(+), 1501 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/ns-tools/test_net_stress.sh b/testcases/network/stress/ns-tools/test_net_stress.sh
index 5ab3304db..d112286bd 100644
--- a/testcases/network/stress/ns-tools/test_net_stress.sh
+++ b/testcases/network/stress/ns-tools/test_net_stress.sh
@@ -31,7 +31,6 @@ export TCID="${TCID:-$(basename $0)}"
 # Netmask of for the tested network
 IPV4_NETMASK="255.255.255.0"
 IPV4_NETMASK_NUM=24
-IPV4_BROADCAST=${IPV4_NET16_UNUSED}.0.255
 
 # Prefix of the Multicast Address
 MCAST_IPV4_ADDR_PREFIX="224.10"
@@ -64,16 +63,16 @@ netstress_cleanup()
 }
 
 # Set an IPv4 address on local/remote interface.
-# tst_add_ipaddr_stress [TYPE] [LINK] [IP]
+# tst_add_ipaddr_stress [TYPE] [IP] [LINK]
 # TYPE: { lhost | rhost }; Default value is 'lhost'.
-# LINK: link number starting from 0. Default value is '0'.
 # IP: IP address to be set; Default value is $LHOST_IPV4_UNUSED (for lhost)
 # or $RHOST_IPV4_UNUSED (for rhost).
+# LINK: link number starting from 0. Default value is '0'.
 tst_add_ipaddr_stress()
 {
 	local type="${1:-lhost}"
-	local link_num="${2:-0}"
-	local ip="${3:-}"
+	local ip="${2:-}"
+	local link_num="${3:-0}"
 	local mask=$IPV4_NETMASK_NUM
 	local iface=$(tst_iface $type $link_num)
 
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..89a925715 100644
--- a/testcases/network/stress/route/route4-change-dst
+++ b/testcases/network/stress/route/route4-change-dst
@@ -1,276 +1,43 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-dst
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the destination of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the destination of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 16 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-dst
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
 
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+TST_CLEANUP="netstress_cleanup"
 
-# 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}
+	route_setup
+	tst_add_ipaddr_stress rhost $RHOST_IPV4_UNUSED
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-dst0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the destination of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    # Initialize the interface of the local host
-    initialize_if lhost ${LINK_NUM}
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-    lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-
-    # Check the connectivity to the gateway
-    check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	return 1
-    fi
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Define the destination IP address
-	dst_network_postfix=`expr $cnt % 255`
-	dst_addr=${DST_NETWORK_PREFIX}.${dst_network_postfix}.${DST_HOST}
-	dst_network=${DST_NETWORK_PREFIX}.${dst_network_postfix}.0
-
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
-
-	# Load the route with UDP datagram
-	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Delete the route
-	case $test_type in
-	    1)
-	    route del -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route del ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Cannot delte the route to ${ADDDEL_ROUTE}"
-	    return 1
-	fi
-
-	cnt=`expr $cnt + 1`
-    done
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
 
-exit $RC
+for cmd_name in rt_cmd ip_cmd; do
+	route_test_change "dst" $cmd_name
+done
+
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-gw b/testcases/network/stress/route/route4-change-gw
index a9a91cca6..9801d0906 100644
--- a/testcases/network/stress/route/route4-change-gw
+++ b/testcases/network/stress/route/route4-change-gw
@@ -1,292 +1,52 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-gw
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the gateway of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the gateway of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 16 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-gw
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
 
-# Netmask of for the tested network
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+TST_CLEANUP="netstress_cleanup"
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
-RHOST_IPV4_HOST_TOP="10"	# gateway
-RHOST_IPV4_HOST_LAST=19
+RHOST_IPV4_HOST_TOP=${RHOST_IPV4_HOST_TOP:-10} # gateway
+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
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    killall -SIGHUP ns-udpsender >/dev/null 2>&1
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-gw0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the gateway of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    # Initialize the interface of the local host
-    initialize_if lhost ${LINK_NUM}
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-
-    # Check the connectivity to the gateway
-    rhost_part=$RHOST_IPV4_HOST_TOP
-    check_icmpv4_connectivity $lhost_ifname ${IPV4_NETWORK}.${rhost_part}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	return 1
-    fi
+	local rhost_part=$RHOST_IPV4_HOST_TOP
 
-    # Set the variables regarding the destination host
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+	route_setup
 
-    # Set the first route
-    case $test_type in
-	1)
-	route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	;;
-	2)
-	ip route add ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	;;
-    esac
-
-    # Load the route with UDP traffic
-    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-    if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Failed to run a UDP datagram sender"
-	return 1
-    fi
-
-    # Loop for changing the route
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	pre_rhost_part=$rhost_part
-	rhost_part=`expr $rhost_part + 1`
-	if [ $rhost_part -gt $RHOST_IPV4_HOST_LAST ]; then
-	    rhost_part=$RHOST_IPV4_HOST_TOP
-	fi
-
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	    route del -net $dst_network netmask 255.255.255.0 gw ${IPV4_NETWORK}.${pre_rhost_part} dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route change ${dst_network}/24 via ${IPV4_NETWORK}.${rhost_part} dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to change the gateway to ${IPV4_NETWORK}.${rhost_part}"
-	    return 1
-	fi
-
-	# Rerun if udp datagram sender is dead
-	ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null
-	if [ $? -ne 0 ]; then
-	    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-	    if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Failed to run a UDP datagram sender"
-		return 1
-	    fi
-	fi
-
-	cnt=`expr $cnt + 1`
-    done
-
-    # Kill the udp datagram sender
-    killall -SIGHUP ns-udpsender >/dev/null 2>&1
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
+	while [ $rhost_part -le $RHOST_IPV4_HOST_LAST ]; do
+		tst_add_ipaddr_stress rhost ${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}
+		rhost_part=$(($rhost_part + 1))
+	done
 }
 
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
 
-exit $RC
+for cmd_name in rt_cmd ip_cmd; do
+	route_test_change "gw" $cmd_name
+done
+
+tst_exit
diff --git a/testcases/network/stress/route/route4-change-if b/testcases/network/stress/route/route4-change-if
index 33fc3755c..0b2c8ac2d 100644
--- a/testcases/network/stress/route/route4-change-if
+++ b/testcases/network/stress/route/route4-change-if
@@ -1,324 +1,72 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-change-if
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the interface of an IPv4 route is
-#   changed frequently
-#    test01 - by route command
-#    test02 - by ip command
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the interface of an IPv4 route is
+# changed frequently.
 #
-# History:
-#	Mar 17 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-change-if
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The first 2 ocnted of the Network portion of the gateway address
-IPV4_NETWORK_PRE=${IPV4_NETWORK_PRE:-"10.0"}
 
-# Netmask of for the gateway
-IPV4_NETMASK_NUM=24
+. route4-lib.sh
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
+TST_CLEANUP="do_cleanup"
 
-# The destination network
-DST_NETWORK="10.10.0"	# destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
-
-
-#-----------------------------------------------------------------------
-#
-# 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
+	local link_num=0
+	local lhost_ip rhost_ip
 
-    # 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
+	route_setup
 
-    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 -lt 2 ] && \
+		tst_brkm TCONF "this test case requires more than one test link in LHOST_HWADDRS variable"
 
-	# Get the Interface names of the remote host
-	rhost_ifname=`get_ifname rhost ${link_num}`
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to get the interface name at the remote host"
-	    exit $TST_TOTAL
-	fi
-	rhost_ifname_array="$rhost_ifname_array $rhost_ifname"
+	while [ $link_num -lt $LINK_TOTAL ]; do
+		lhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
+		rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
 
-	# Initialize the interfaces of the remote host
-	initialize_if rhost ${link_num}
+		tst_add_ipaddr_stress lhost $lhost_ip $link_num
+		tst_add_ipaddr_stress rhost $rhost_ip $link_num
 
-	# Set IPv4 address to the interface of the remote host
-	set_ipv4addr rhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${RHOST_IPV4_HOST}
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to assign IP address to the interface $rhost_ifname at the remote host"
-	    exit $TST_TOTAL
-	fi
+		check_connectivity $(tst_iface lhost $link_num) $rhost_ip
 
-	link_num=`expr $link_num + 1`
-    done
+		link_num=$(($link_num + 1))
+	done
 }
 
-
-
-
-#-----------------------------------------------------------------------
-#
-# 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
-}
+	local link_num=0
 
+	route_cleanup
 
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#       1 - route command case
-#       2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-change-if0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	test_command="route"
-	;;
-	2)
-	test_command="ip"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    tst_resm TINFO "Verify the kernel is not crashed when the interface of an IPv4 route is changed frequently by $test_command command in $NS_TIMES times"
-
-    link_num=0
-    while [ $link_num -lt $link_total ]; do
-	# Initialize the interface of the local host
-	initialize_if lhost ${link_num}
-
-	# Assign IPv4 address to the interface of the local host
-	set_ipv4addr lhost ${link_num} "${IPV4_NETWORK_PRE}.${link_num}" ${LHOST_IPV4_HOST}
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	    return 1
-	fi
-
-	# Check the connectivity to the gateway
-	field=`expr $link_num + 1`
-	lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field`
-	check_icmpv4_connectivity $lhost_ifname "${IPV4_NETWORK_PRE}.${link_num}.${LHOST_IPV4_HOST}"
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $link_num is somthing wrong."
-	    return 1
-	fi
-	link_num=`expr $link_num + 1`
-    done
-
-    # Set the variables regarding the destination host
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
-
-    # Set the first route
-    link_num=0
-    field=`expr $link_num + 1`
-    lhost_ifname=`echo $lhost_ifname_array | cut -d ' ' -f $field`
-    gateway="${IPV4_NETWORK_PRE}.${link_num}.${RHOST_IPV4_HOST}"
-    case $test_type in
-	1)
-	route add -net $dst_network netmask 255.255.255.0 gw $gateway dev $lhost_ifname
-	;;
-	2)
-	ip route add ${dst_network}/24 via $gateway dev $lhost_ifname
-	;;
-    esac
-
-    # Load the route with UDP traffic
-    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -b -s 1472
-    if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Failed to run a UDP datagram sender"
-	return 1
-    fi
-
-    # 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
+	while [ $link_num -lt $LINK_TOTAL ]; do
+		restore_ipaddr lhost $link_num
+		restore_ipaddr rhost $link_num
+		link_num=$(($link_num + 1))
+	done
 }
 
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
 do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
+for cmd_name in rt_cmd ip_cmd; do
+	route_test_change "if" $cmd_name
+done
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-ifdown b/testcases/network/stress/route/route4-ifdown
index e7ce1b4fe..60d19babb 100644
--- a/testcases/network/stress/route/route4-ifdown
+++ b/testcases/network/stress/route/route4-ifdown
@@ -1,261 +1,80 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route4-ifdown
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Description:
-#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
-#   by the interface down
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-ifdown
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv4 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
-
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
-
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+. route4-lib.sh
 
+TST_CLEANUP="netstress_cleanup"
 
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-# SET VALUES:
-#   rhost_ipv4addr	- IPv4 Address of the remote host
-#   lhost_ifname	- Interface name of the local host
-#   rhost_ifname	- Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Make sure to clean up
-    do_cleanup
-
-    # 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}"
+	route_setup
 
-    # Get the Interface names
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
+	tst_add_ipaddr_stress
+	tst_add_ipaddr_stress rhost
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    test_type=$1
-
-    TCID=route4-ifdown0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by the interface down with ifconfing command in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by the interface down with ip command in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
+	local cmd_type=$1
+	local cmd_name_iface cmd_iface_down
+	local cmd_name_route="$(get_cmd $cmd_type)"
+	local lhost_ifname="$(tst_iface)"
+	local dst_addr="${DST_NETWORK}.${DST_HOST}"
+	local dst_network="${DST_NETWORK}.0"
+	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 "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
+		make_background_tcp_traffic $LHOST_IPV4_UNUSED
 
-	# 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
+		manipulate_route $cmd_name_route 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $lhost_ifname
 
-	cnt=`expr $cnt + 1`
-    done
+		check_connectivity_interval $cnt false $lhost_ifname $RHOST_IPV4_UNUSED
 
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
+		# Down then up the interface
+		sh -c "$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
+test_body 'rt_cmd'
+test_body 'ip_cmd'
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
new file mode 100644
index 000000000..1f0047f68
--- /dev/null
+++ b/testcases/network/stress/route/route4-lib.sh
@@ -0,0 +1,206 @@
+#!/bin/sh
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Setup script for route4-* tests.
+#
+# More information about network parameters can be found
+# in the following document: testcases/network/stress/README
+#
+# Author: Petr Vorel <pvorel@suse.cz>
+
+. test_net_stress.sh
+
+tst_check_cmds ip pgrep route
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
+
+# The destination network
+# NOTE: DST_NETWORK expects NETMASK IPV4_NETMASK_NUM=24
+DST_NETWORK="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}"
+DST_HOST=5
+DST_PORT=7
+
+route_cleanup()
+{
+	netstress_cleanup
+	restore_ipaddr
+	restore_ipaddr rhost
+}
+
+route_ns_udpsender_cleanup()
+{
+	stop_ns_udpsender
+	restore_ipaddr
+	restore_ipaddr rhost
+}
+
+route_setup()
+{
+	netstress_setup
+	tst_check_cmds route
+	route_cleanup
+}
+
+manipulate_route()
+{
+	local cmd_name=$1
+	local task=$2
+	local network=$3
+	local prefix=$4
+	local netmask=$5
+	local gateway=$6
+	local ifname=$7
+
+	[ "$task" = "add" ] || [ "$task" = "del" ] || \
+		[ "$cmd_name" = "ip" -a "$task" = "append" ] || tst_brkm TBROK "wrong task: '$task'"
+
+	[ "$cmd_name" = "ip" -a "$task" = "add" ] && task="append"
+	if [ "$cmd_name" = "ip" ]; then
+		ROD "$cmd_name route $task $network/$prefix via $gateway dev $ifname"
+	else
+		ROD "$cmd_name $task -net $network netmask $netmask gw $gateway dev $ifname"
+	fi
+}
+
+# Load the route with UDP traffic.
+run_ns_udpsender()
+{
+	local dst_addr=$1
+	local run_in_background=$2
+	local udp_size="${3:-1472}"
+	local params="-o"
+
+	if [ "$run_in_background" = true ]; then
+		# daemon is already running
+		pgrep -x ns-udpsender > /dev/null && return 0
+		params="-b"
+	fi
+
+	ROD ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -s $udp_size $params
+}
+
+stop_ns_udpsender()
+{
+	local type="${1:-lhost}"
+	kill_daemon ns-udpsender $type
+}
+
+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
+}
+
+route_test_change()
+{
+	local test_field=$1
+	local cmd_type=$2
+
+	local rhost_ip="$RHOST_IPV4_UNUSED"
+	local lhost_ifname=$(tst_iface)
+	local rhost_part_first=$RHOST_IPV4_HOST_TOP
+	local rhost_part_last=$RHOST_IPV4_HOST_LAST
+	local cnt=0
+	local link_num=0
+	local first_route_net=${DST_NETWORK}.0
+	local cmd_name="$(get_cmd $cmd_type)"
+	local gateway="$rhost_ip"
+	local dst_addr dst_network dst_network_postfix gateway2 lhost_ifname2 rhost_part test_field_name
+
+	case $test_field in
+	dst) test_field_name='destination' ;;
+	gw) test_field_name='gateway' ;;
+	if) test_field_name='interface' ;;
+	*) tst_brkm TBROK "Unknown test parameter '$test_field'"
+	esac
+
+	tst_resm TINFO "the $test_field_name of an IPv4 route is changed by '$cmd_name' command $NS_TIMES times"
+
+	if [ "$test_field" = "if" ]; then
+		while [ $link_num -lt $LINK_TOTAL ]; do
+			rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
+			check_connectivity $(tst_iface lhost $link_num) $rhost_ip
+			link_num=$(($link_num + 1))
+		done
+		link_num=0
+		lhost_ifname="$(tst_iface lhost $link_num)"
+		gateway="${IPV4_NET16_UNUSED}.${link_num}.${RHOST_IPV4_HOST}"
+	else
+		if [ "$test_field" = "gw" ]; then
+			rhost_ip="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.$RHOST_IPV4_HOST_TOP"
+			rhost_part=$rhost_part_first
+			gateway="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}"
+		fi
+		tst_add_ipaddr_stress
+		check_connectivity $(tst_iface) $rhost_ip
+	fi
+
+	if [ "$test_field" != "dst" ]; then
+		dst_addr=${DST_NETWORK}.${DST_HOST}
+		dst_network=$first_route_net
+
+		tst_resm TINFO "adding first route"
+		ROD manipulate_route $cmd_name 'add' $first_route_net $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+	fi
+
+	while [ $cnt -lt $NS_TIMES ]; do
+		lhost_ifname2="$lhost_ifname"
+		gateway2="$gateway"
+
+		make_background_tcp_traffic $LHOST_IPV4_UNUSED
+
+		if [ "$test_field" = "dst" ]; then
+			dst_network_postfix="$(($cnt % 255))"
+			dst_addr="${IPV4_NET16_UNUSED}.${dst_network_postfix}.${DST_HOST}"
+			dst_network="${IPV4_NET16_UNUSED}.${dst_network_postfix}.0"
+		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_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}"
+			gateway2="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${pre_rhost_part}"
+		elif [ "$test_field" = "if" ]; then
+			link_num=$(($link_num + 1))
+			[ $link_num -ge $LINK_TOTAL ] && link_num=0
+			lhost_ifname="$(tst_iface lhost $link_num)"
+			gateway="${IPV4_NET16_UNUSED}.${link_num}.${RHOST_IPV4_HOST}"
+			rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
+		fi
+
+		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+		manipulate_route $cmd_name 'del' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
+
+		check_connectivity_interval $cnt false $lhost_ifname $rhost_ip || return
+
+		cnt=$(($cnt + 1))
+	done
+
+	if [ "$test_field" != "dst" ]; then
+		ROD manipulate_route $cmd_name del $first_route_net $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
+	fi
+
+	if [ "$test_field" != "if" ]; then
+		restore_ipaddr
+	fi
+
+	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..714e0af25 100644
--- a/testcases/network/stress/route/route4-redirect
+++ b/testcases/network/stress/route/route4-redirect
@@ -1,212 +1,72 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# File:
-#   route4-redirect
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Description:
-#   Verify the kernel is not crashed when the IPv4 route is modified by
-#   ICMP Redirects frequently
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# Verify the kernel is not crashed when the IPv4 route is modified by
+# ICMP Redirects frequently.
 #
-# History:
-#	Apr 07 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# The test case ID, the test case count and the total number of test case
-TCID=route4-redirect01
 TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Test description
-tst_resm TINFO "Verify the kernel is not crashed when the IPv4 route is modified by  ICMP Redirects frequently"
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where route is changed
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK_NUM=24
 
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
+. route4-lib.sh
 
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
-RHOST_IPV4_HOST="2"	# gateway
+TST_CLEANUP="do_cleanup"
 
-# The destination network
-DST_NETWORK="10.10.0"   # destination network would be 10.10.0.0/24
-DST_HOST="5"
-DST_PORT="7"
+SYSFS_ACCEPT_REDIRECTS=
+SYSFS_SECURE_REDIRECTS=
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Kill the redirector utility
-    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	route_ns_udpsender_cleanup
+	kill_daemon ns-icmp_redirector remote
+	[ -n "$SYSFS_ACCEPT_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).accept_redirects=$SYSFS_ACCEPT_REDIRECTS
+	[ -n "$SYSFS_SECURE_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).secure_redirects=$SYSFS_SECURE_REDIRECTS
 }
 
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Set the initial route and start icmp redirect on the remote host
-#
-# SET VALUES:
-#   rhost_ipv4addr      - IPv4 Address of the remote host
-#   lhost_ifname        - Interface name of the local host
-#   rhost_ifname        - Interface name of the remote host
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Make sure to clean up
-    do_cleanup
-
-    # Get the Interface name of local host
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the Interface name of remote host
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
+	route_setup
 
-    # Remove the link-local address of the remote host
-    sleep 3
-    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
+	SYSFS_ACCEPT_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).accept_redirects)
+	SYSFS_SECURE_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).secure_redirects)
 
-    # 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
+	tst_add_ipaddr_stress
 
-    # 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"
+	ROD manipulate_route "route" "add" ${DST_NETWORK}.0 $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $(tst_iface)
 
-    # Make sure the sysctl value is set for accepting the redirect
-    sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null
-
-    # Run the redirector utility at the remote host
-    ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
-    if [ $ret -ne 0 ]; then
-	tst_resm TBROK "Failed to run icmp redirector at the remote host"
-	exit $TST_TOTAL
-    fi
+	# Run the redirector utility at the remote host
+	tst_rhost_run -s -c "ns-icmp_redirector -I $(tst_iface rhost) -b"
 }
 
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   None
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    # Loop for changing the route
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Failed to run udp packet sender"
-	    return 1
-	fi
-	cnt=`expr $cnt + 1`
-    done
+	local cnt=0
+	while [ $cnt -lt $NS_TIMES ]; do
+		run_ns_udpsender ${DST_NETWORK}.${DST_HOST} no 8
+		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 || RC=`expr $RC + 1`
-do_cleanup
+test_body
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 36c8c970d..70a6e3745 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -1,280 +1,104 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route4-rmmod
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 #
-# Description:
-#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
-#   by the removing network driver
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
 #
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
+# Setup: testcases/network/stress/README
 #
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
-# Total number of the test case
 TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-rmmod
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv4 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
-
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
-
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
 
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
+. route4-lib.sh
 
+TST_CLEANUP="do_cleanup"
 
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
 do_cleanup()
 {
-    # Make sure to load the network driver
-    if [ x${lhost_module} != x ]; then
-	modprobe $lhost_module
-    fi
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
+	if [ -n "${lhost_module}" ]; then
+		modprobe $lhost_module
+		tst_sleep 100ms
+	fi
+	netstress_cleanup
+	restore_ipaddr
 }
 
 
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-#-----------------------------------------------------------------------
 do_setup()
 {
-    # Check the local host has ethtool utility
-    which ethtool >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "This test case requires ethtool utility"
-	exit $TST_TOTAL
-    fi
-
-    # 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
+	route_setup
+	tst_check_cmds ethtool
+
+	tst_add_ipaddr_stress
+
+	# Get the module name of the interface at the local host
+	lhost_module=$(ethtool -i $(tst_iface) | 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 [ "$(tst_iface)" = "$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 driver '$module' with the test intreface"
+			return
+		fi
+	done
 }
 
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
 test_body()
 {
-    test_type=$1
+	local cmd_type=$1
+	local cmd_name="$(get_cmd $cmd_type)"
+	local dst_addr=${DST_NETWORK}.${DST_HOST}
+	local dst_network=${DST_NETWORK}.0
+	local cnt=0
 
-    TCID=route4-rmmod0${test_type}
-    TST_COUNT=$test_type
+	tst_resm TINFO "IPv4 route is added by '$cmd_name' command and then deleted by removing network driver $NS_TIMES times"
 
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
+	while [ $cnt -lt $NS_TIMES ]; do
+		make_background_tcp_traffic $LHOST_IPV4_UNUSED
 
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
-	fi
+		check_connectivity_interval $cnt false $(tst_iface) $RHOST_IPV4_UNUSED || return
 
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
+		# Add the route
+		ROD manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $(tst_iface)
 
-	# 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
+		tst_sleep 100ms
 
-	# 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 kernel module 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
+		tst_add_ipaddr_stress
 
-	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
-do_cleanup
+test_body 'rt_cmd'
+test_body 'ip_cmd'
 
-exit $RC
+tst_exit
diff --git a/testcases/network/stress/route/route6-change-dst b/testcases/network/stress/route/route6-change-dst
index 33e89e985..649f0cc00 100644
--- a/testcases/network/stress/route/route6-change-dst
+++ b/testcases/network/stress/route/route6-change-dst
@@ -242,7 +242,7 @@ test_body()
 	    ;;
 	esac
 	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Cannot delte the route to ${ADDDEL_ROUTE}"
+	    tst_resm TFAIL "Cannot delete the route to ${ADDDEL_ROUTE}"
 	    return 1
 	fi
 
-- 
2.13.2


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

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

* Remove dependency to ifconfig
* Use TCONF when test would break other interface
* Don't raise TCONF only if the other device is in 'down' mode

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

diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
index 70a6e3745..a089d6712 100644
--- a/testcases/network/stress/route/route4-rmmod
+++ b/testcases/network/stress/route/route4-rmmod
@@ -35,28 +35,29 @@ do_cleanup()
 	restore_ipaddr
 }
 
-
 do_setup()
 {
 	route_setup
+
+	# NOTE: we have to use ethtool as
+	# /sys/class/net/<iface>/device/driver/module doesn't exist
+	# for virtual drivers (e.g. veth)
 	tst_check_cmds ethtool
 
 	tst_add_ipaddr_stress
 
 	# Get the module name of the interface at the local host
 	lhost_module=$(ethtool -i $(tst_iface) | grep driver | sed "s/driver:[[:blank:]]*//")
+	[ -z "$lhost_module" ] && tst_resm TBROK "module for interface '$(tst_iface)' not found"
 
 	# Check the other active interface uses the same driver
-	for ifname in $(ifconfig | grep ^eth | awk '{ print $1}'); do
-		if [ "$(tst_iface)" = "$ifname" ]; then
-			continue
-		fi
+	for ifname in $(basename -a /sys/class/net/*); do
+		[ "$(tst_iface)" = "$ifname" ] && continue
 
 		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 driver '$module' with the test intreface"
-			return
-		fi
+
+		[ "$lhost_module" = "$module" -a "$(cat /sys/class/net/$ifname/operstate)" != "down" ] && \
+			tst_brkm TCONF "an active interface '$ifname' uses the same network driver '$module' with the test interface '$(tst_iface)'"
 	done
 }
 
-- 
2.13.2


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

* [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (8 preceding siblings ...)
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
@ 2017-07-21  4:04 ` Petr Vorel
  2017-07-26 15:17   ` Alexey Kodanev
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:04 UTC (permalink / raw)
  To: ltp

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

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

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

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

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

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

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

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

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


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

* [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
                   ` (9 preceding siblings ...)
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-07-21  4:04 ` Petr Vorel
  2017-07-26 15:32   ` Alexey Kodanev
  10 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-21  4:04 UTC (permalink / raw)
  To: ltp

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

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

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh                          | 94 +++++++++++++++-------
 testcases/network/stress/interface/if4-addr-change | 17 ++--
 2 files changed, 75 insertions(+), 36 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index cecb0bab2..95510f7cf 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -230,19 +230,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
 }
 
@@ -281,9 +272,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)
 
@@ -529,25 +524,58 @@ export PASSWD="${PASSWD:-}"
 export LTP_RSH="${LTP_RSH:-rsh -n}"
 
 # Test Links
-# Set first three octets of the network address, default is '10.0.0'
-export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
-# Set local host last octet, default is '2'
-export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
-# Set the reverse of IPV4_NETWORK
-export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
-# Set first three octets of the network address, default is 'fd00:1:1:1'
-export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
-# Set local host last octet, default is '2'
-export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
-
-# Networks that aren't reachable through the test links
-export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
-export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
+# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
+# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
+IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
+
+# tst_net_ip_prefix
+# Strip prefix from IP address and save both If no prefix found sets
+# default prefix.
+#
+# tst_net_iface_prefix reads prefix and interface from rtnetlink.
+# If nothing found sets default prefix value.
+#
+# tst_net_vars exports environment variables related to test links and
+# networks that aren't reachable through the test links.
+# Not run for netns (init_ltp_netspace is not called, no links setup yet).
+#
+# For full list of exported environment variables see:
+# tst_net_ip_prefix -h
+# tst_net_iface_prefix -h
+# tst_net_vars -h
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing IP and prefixes"
+	set -x
+	eval "$(tst_net_ip_prefix $IPV4_LHOST)" || exit $?
+	eval "$(tst_net_ip_prefix -r $IPV4_RHOST)" || exit $?
+	eval "$(tst_net_ip_prefix $IPV6_LHOST)" || exit $?
+	eval "$(tst_net_ip_prefix -r $IPV6_RHOST)" || exit $?
+	set +x
+
+	if [ "$TST_USE_NETNS" != "yes" ]; then
+		tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
+		set -x
+		eval "$(tst_net_iface_prefix $IPV4_LHOST)" || exit $?
+		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST)" || exit $?
+		eval "$(tst_net_iface_prefix $IPV6_LHOST)" || exit $?
+		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST)" || exit $?
+		set +x
+	fi
 
+	tst_resm TINFO "Parsing all remaining variables"
+	set -x
+	eval "$(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX)" || exit $?
+	eval "$(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX)" || exit $?
+	set +x
+
+	export TST_PARSE_VARIABLES="yes"
+fi
+
+# The rest of variables for networks that aren't reachable through the test links.
+# IPV4_NET16_UNUSED and IPV6_NET32_UNUSED are set by tst_net_vars.
 export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
 export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
 export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
@@ -564,6 +592,7 @@ export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_
 export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
 export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
 
+# Directories for http and ftp stress tests
 export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
 export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
 export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
@@ -589,8 +618,11 @@ export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
 # Warning: make sure to set valid interface names and IP addresses below.
 # Set names for test interfaces, e.g. "eth0 eth1"
+# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
+# want to use more ifaces.
 export LHOST_IFACES="${LHOST_IFACES:-eth0}"
 export RHOST_IFACES="${RHOST_IFACES:-eth0}"
+
 # Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02"
 export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}"
 export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}"
diff --git a/testcases/network/stress/interface/if4-addr-change b/testcases/network/stress/interface/if4-addr-change
index 567f86643..a7469c252 100644
--- a/testcases/network/stress/interface/if4-addr-change
+++ b/testcases/network/stress/interface/if4-addr-change
@@ -48,12 +48,19 @@ while [ $cnt -lt $NS_TIMES ]; do
 
 	[ $num -eq $RHOST_IPV4_HOST ] && continue
 
-	# Change IPv4 address
-	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
+	# check prefix and fix values for prefix != 24
+	add_to_net=
+	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
+		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
+	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
+		add_to_net=".0.1"
+	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
+		add_to_net=".1"
+	fi
 
-	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
-		broadcast 255.255.255.255 || \
-		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
+	# Change IPv4 address
+	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
+		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
 
 	cnt=$(($cnt + 1))
 
-- 
2.13.2


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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh Petr Vorel
@ 2017-07-24 15:54   ` Alexey Kodanev
  2017-07-25  9:57     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-24 15:54 UTC (permalink / raw)
  To: ltp

Hi,
On 07/21/2017 07:03 AM, Petr Vorel wrote:
> + use it in interface stress tests
>
> test_net_stress.sh:
> * test_net_stress.sh library is intended to be used throughout all
>   stress tests reduce duplicity and use code from test_net.sh where
>   possible instead of legacy scripts in testcases/network/stress/ns-tools/.
> * TCID set automatically from basename.
> * Add "unused network" related variables. So far used only IPv4 ones.
> * Functions from if-lib.sh moved and (and some renamed) to
>   test_net_stress.sh as they are going to be reused in other tests (not
>   just interface stress tests).
>
> Interfaces tests:
> * Interfaces tests use test_net_stress.sh.
> * Remove restore_ipaddr from cleanup functions as these functions would
>   break netns testing with RTNETLINK errors. Use them just in setup during
>   if-mtu-change where are really needed.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> I'll port this library to be able to test also IPv6.
> ---
>  testcases/lib/test_net.sh                          |  21 ++-
>  testcases/network/stress/interface/if-addr-adddel  |  15 +-
>  .../network/stress/interface/if-addr-addlarge      |  16 +-
>  testcases/network/stress/interface/if-lib.sh       |  73 ---------
>  testcases/network/stress/interface/if-mtu-change   |  23 +--
>  testcases/network/stress/interface/if-route-adddel |  17 +-
>  .../network/stress/interface/if-route-addlarge     |  15 +-
>  testcases/network/stress/interface/if-updown       |   9 +-
>  testcases/network/stress/interface/if4-addr-change |   4 +-
>  testcases/network/stress/ns-tools/Makefile         |   2 +-
>  .../network/stress/ns-tools/test_net_stress.sh     | 171 +++++++++++++++++++++
>  11 files changed, 229 insertions(+), 137 deletions(-)
>  delete mode 100644 testcases/network/stress/interface/if-lib.sh
>  create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index 10cf6da3a..178df3527 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -428,6 +428,7 @@ tst_ping()
>  	local src_iface="${1:-$(tst_iface)}"
>  	local dst_addr="${2:-$(tst_ipaddr rhost)}"; shift $(( $# >= 2 ? 2 : 0 ))
>  	local msg_sizes="$*"
> +	local msg="tst_ping IPv${TST_IPV6:-4} iface $src_iface, msg_size"
>  	local ret=0
>  
>  	# ping cmd use 56 as default message size
> @@ -436,9 +437,9 @@ tst_ping()
>  			-s $size -i 0 > /dev/null 2>&1
>  		ret=$?
>  		if [ $ret -eq 0 ]; then
> -			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size pass"
> +			tst_resm TINFO "$msg $size: pass"
>  		else
> -			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size fail"
> +			tst_resm TINFO "$msg $size: fail"
>  			break
>  		fi
>  	done
> @@ -535,6 +536,22 @@ export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
>  export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
>  export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
>  
> +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
> +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
> +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
> +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
> +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
> +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
> +
> +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
> +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
> +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
> +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
> +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
> +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
> +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
> +

Hmm, what is the purpose of adding these variables to the library?
Why someone would need to redefine any of them?

>  export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
>  export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
>  export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"

...

> +
> +# check_connectivity_interval CNT [RESTORE] [SRC_IFACE] [DST_ADDR]
> +# CNT: loop step.
> +# RESTORE: whether restore ip addr.
> +# SRC_IFACE: source interface name.
> +# DST_ADDR: destination IPv4 or IPv6 address.
> +check_connectivity_interval()
> +{
> +	local cnt="$1"
> +	local restore="${2:-false}"
> +	local src_iface="${3:-$(tst_iface)}"
> +	local dst_addr="${4:-$(tst_ipaddr rhost)}"
> +
> +	[ $CHECK_INTERVAL -eq 0 ] && return
> +
> +	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && return
> +
> +	[ "$restore" != "false" ] && restore_ipaddr
> +
> +	check_connectivity $src_iface $dst_addr $cnt
> +	return $?
> +}

No need for 'return $?', the last command determines exit status for a
function.

> +
> +# Run netstress process on both lhost and rhost.
> +# make_background_tcp_traffic [IP]
> +# IP: server IP. Default value is $(tst_ipaddr)
> +make_background_tcp_traffic()
> +{
> +	local port=$(tst_get_unused_port ipv${ipver} stream)
> +	local ip="${1:-$(tst_ipaddr)}"
> +
> +	ROD netstress -R 3 -g $port > /dev/null 2>&1 &
> +	tst_rhost_run -s -b -c "netstress -l -H $ip -g $port"

There is no point in adding 'ROD' and '-s' option for tst_rhost_run() if
it's started in background.

Thanks,
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170724/b6966ad0/attachment.html>

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

* [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
@ 2017-07-24 15:57   ` Alexey Kodanev
  2017-07-25 10:12     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-24 15:57 UTC (permalink / raw)
  To: ltp

On 07/21/2017 07:03 AM, Petr Vorel wrote:
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/network/stress/interface/if-addr-adddel    | 6 +-----
>  testcases/network/stress/interface/if-addr-addlarge  | 6 +-----
>  testcases/network/stress/interface/if-mtu-change     | 7 ++-----
>  testcases/network/stress/interface/if-route-adddel   | 7 ++-----
>  testcases/network/stress/interface/if-route-addlarge | 6 +-----
>  testcases/network/stress/ns-tools/test_net_stress.sh | 2 ++
>  6 files changed, 9 insertions(+), 25 deletions(-)
>
> diff --git a/testcases/network/stress/interface/if-addr-adddel b/testcases/network/stress/interface/if-addr-adddel
> index 42c2d5afa..3b1ab50bb 100644
> --- a/testcases/network/stress/interface/if-addr-adddel
> +++ b/testcases/network/stress/interface/if-addr-adddel
> @@ -53,10 +53,9 @@ test_body()
>  		return
>  	fi
>  
> -	make_background_tcp_traffic
> -
>  	local cnt=1
>  	while [ $cnt -le $NS_TIMES ]; do
> +		make_background_tcp_traffic
>  
>  		case $cmd_type in
>  		if_cmd)
> @@ -85,9 +84,6 @@ test_body()
>  
>  		cnt=$(($cnt + 1))
>  
> -		# Check the background TCP traffic
> -		pgrep -x netstress > /dev/null || make_background_tcp_traffic


Does 'make_background_tcp_traffic()' function check that background
traffic is not running already?


Thanks,
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170724/84692954/attachment.html>

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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-24 15:54   ` Alexey Kodanev
@ 2017-07-25  9:57     ` Petr Vorel
  2017-07-25 10:48       ` Alexey Kodanev
  0 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-25  9:57 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
> > +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
> > +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
> > +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
> > +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> > +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
> > +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
> > +
> > +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
> > +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
> > +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
> > +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
> > +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
> > +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
> > +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"

> Hmm, what is the purpose of adding these variables to the library?
> Why someone would need to redefine any of them?
I thought someone might appreciate ability to full control of IP
addresses, but you're right it's probably useless.
If you don't mind, I'll keep {L,R}HOST_IPV{4,6}_UNUSED variables as they are used in many scripts
(DRY approach) and delete the rest of variables.


> > +check_connectivity_interval()
> > +{
> > +	local cnt="$1"
> > +	local restore="${2:-false}"
> > +	local src_iface="${3:-$(tst_iface)}"
> > +	local dst_addr="${4:-$(tst_ipaddr rhost)}"
> > +
> > +	[ $CHECK_INTERVAL -eq 0 ] && return
> > +
> > +	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && return
> > +
> > +	[ "$restore" != "false" ] && restore_ipaddr
> > +
> > +	check_connectivity $src_iface $dst_addr $cnt
> > +	return $?
> > +}

> No need for 'return $?', the last command determines exit status for a
> function.
Right, thanks.

> > +make_background_tcp_traffic()
> > +{
> > +	local port=$(tst_get_unused_port ipv${ipver} stream)
> > +	local ip="${1:-$(tst_ipaddr)}"
> > +
> > +	ROD netstress -R 3 -g $port > /dev/null 2>&1 &
> > +	tst_rhost_run -s -b -c "netstress -l -H $ip -g $port"

> There is no point in adding 'ROD' and '-s' option for tst_rhost_run() if
> it's started in background.
Right, thanks.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage
  2017-07-24 15:57   ` Alexey Kodanev
@ 2017-07-25 10:12     ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-25 10:12 UTC (permalink / raw)
  To: ltp

Hi Alexey,

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

> >  		case $cmd_type in
> >  		if_cmd)
> > @@ -85,9 +84,6 @@ test_body()

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

> > -		# Check the background TCP traffic
> > -		pgrep -x netstress > /dev/null || make_background_tcp_traffic


> Does 'make_background_tcp_traffic()' function check that background
> traffic is not running already?

Sure, I just moved your pgrep check into function (it's in the same commit):
make_background_tcp_traffic()
{
	pgrep -x netstress > /dev/null && return

	local port=$(tst_get_unused_port ipv${ipver} stream)
	local ip="${1:-$(tst_ipaddr)}"

	netstress -R 3 -g $port > /dev/null 2>&1 &
	tst_rhost_run -s -c "netstress -l -H $ip -g $port"
}


Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-25  9:57     ` Petr Vorel
@ 2017-07-25 10:48       ` Alexey Kodanev
  2017-07-25 14:52         ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-25 10:48 UTC (permalink / raw)
  To: ltp

On 07/25/2017 12:57 PM, Petr Vorel wrote:
> Hi Alexey,
>
>>> +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
>>> +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
>>> +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
>>> +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
>>> +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
>>> +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
>>> +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
>>> +
>>> +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
>>> +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
>>> +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
>>> +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
>>> +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
>>> +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
>>> +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
>> Hmm, what is the purpose of adding these variables to the library?
>> Why someone would need to redefine any of them?
> I thought someone might appreciate ability to full control of IP
> addresses, but you're right it's probably useless.
> If you don't mind, I'll keep {L,R}HOST_IPV{4,6}_UNUSED variables as they are used in many scripts
> (DRY approach) and delete the rest of variables.


What about adding a new function similar to tst_ipaddr()?

tst_ipaddr_un(), tst_ipaddr_new(), etc.? Probably we would need to add
some optional counter parameter along with lhost/rhost...

Best regards,
Alexey


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

* [LTP] [RFC PATCH v7 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
@ 2017-07-25 12:50   ` Alexey Kodanev
  2017-07-25 14:28     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-25 12:50 UTC (permalink / raw)
  To: ltp

Hi,
On 07/21/2017 07:04 AM, Petr Vorel wrote:
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index 76e6b0a41..0cafe1514 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -55,7 +55,6 @@ init_ltp_netspace()
>  # -b run in background
>  # -s safe option, if something goes wrong, will exit with TBROK
>  # -c specify command to run
> -
>  tst_rhost_run()
>  {
>  	local pre_cmd=
> @@ -91,15 +90,16 @@ tst_rhost_run()
>  
>  	local output=
>  	local ret=0
> +	local newpath="$LTPROOT/testcases/bin"

Why setting the PATH, LTPROOT can't be done before test run on remote
host? what if LTPROOT differs b/w machines?

>  	if [ -n "${TST_USE_SSH:-}" ]; then
> -		output=`ssh -n -q $user@$RHOST "sh -c \
> -			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
> +		output=`ssh -n -q $user@$RHOST "PATH=$newpath:\$PATH \
> +			sh -c '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`

$PATH still expands on local machine with backticks

echo `echo "\$PATH"` vs echo `echo "\\$PATH"`

or better use POSIX $(...)

echo $(echo "\$PATH")

Thanks,
Alexey

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

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

* [LTP] [RFC PATCH v7 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH
  2017-07-25 12:50   ` Alexey Kodanev
@ 2017-07-25 14:28     ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-25 14:28 UTC (permalink / raw)
  To: ltp

Hi Alexey,
> > +	local newpath="$LTPROOT/testcases/bin"

> Why setting the PATH, LTPROOT can't be done before test run on remote
> host? what if LTPROOT differs b/w machines?

You're right, that setting correct PATH is required by doc [1], so I'll drop this patch
from v8.

But PATH is set in several local scripts, the same is for LTPROOT (see `git grep
LTPROOT=' and `git grep PATH=.*LTPROOT.*testcases/bin'), including our
testscripts/network.sh, so for localhost is not really required. I'd like to have it for
remote host as well.

But of course the whole problem is how to detect correct LTPROOT for remote. I used the
same as I had an idea, that ltp should be installed into same path for lhost and rhost,
but I'm wrong.

BTW this is IMHO better way how to set LTPROOT:
# /opt/ltp/testscripts/network.sh
export LTPROOT="${LTPROOT:-$(cd $(dirname $0)/../testcases/bin; pwd)}"

# /opt/ltp/testcases/bin/test_net.sh
export LTPROOT="${LTPROOT:-$(cd $(dirname $0); pwd)}"


> >  	if [ -n "${TST_USE_SSH:-}" ]; then
> > -		output=`ssh -n -q $user@$RHOST "sh -c \
> > -			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
> > +		output=`ssh -n -q $user@$RHOST "PATH=$newpath:\$PATH \
> > +			sh -c '$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`

> $PATH still expands on local machine with backticks

> echo `echo "\$PATH"` vs echo `echo "\\$PATH"`

> or better use POSIX $(...)

> echo $(echo "\$PATH")
Oh, you're right.


Kind regards,
Petr

[1]: https://github.com/linux-test-project/ltp/tree/master/testcases/network#ltp-setup

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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-25 10:48       ` Alexey Kodanev
@ 2017-07-25 14:52         ` Petr Vorel
  2017-07-25 16:01           ` Alexey Kodanev
  0 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-25 14:52 UTC (permalink / raw)
  To: ltp

> On 07/25/2017 12:57 PM, Petr Vorel wrote:
> > Hi Alexey,

> >>> +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
> >>> +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
> >>> +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
> >>> +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
> >>> +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> >>> +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
> >>> +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
> >>> +
> >>> +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
> >>> +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
> >>> +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
> >>> +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
> >>> +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
> >>> +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
> >>> +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
> >> Hmm, what is the purpose of adding these variables to the library?
> >> Why someone would need to redefine any of them?
> > I thought someone might appreciate ability to full control of IP
> > addresses, but you're right it's probably useless.
> > If you don't mind, I'll keep {L,R}HOST_IPV{4,6}_UNUSED variables as they are used in many scripts
> > (DRY approach) and delete the rest of variables.


> What about adding a new function similar to tst_ipaddr()?

> tst_ipaddr_un(), tst_ipaddr_new(), etc.? Probably we would need to add
> some optional counter parameter along with lhost/rhost...

How about this?

tst_ipaddr_un()
{
	local type="${1:-lhost}"
	local counter="${2:-1}"
	local host net max_counter max_net max_host tmp

	[ "$TST_IPV6" ] && max_net=65536 || max_net=256
	max_host=$((max_net - 2))
	max_counter=$((max_host * max_net / 2))

	if [ $counter -gt $max_counter ]; then
		tst_resm TCONF "'$counter' higher than max counter limit '$max_counter'"
	fi

	tmp=$((counter * 2))
	[ "$type" = "rhost" ] && tmp=$((tmp - 1))

	host=$((tmp % max_host))
	net=$((tmp / max_host))
	[ $host -eq 0 ] && { host=$max_host; net=$((net - 1)); }

	if [ "$TST_IPV6" ]; then
		echo "${IPV6_NET32_UNUSED}::$(printf %x:%x ${net} ${host})"
	else
		echo "${IPV4_NET16_UNUSED}.${net}.${host}"
	fi
}

Given the fact that most of the tests needs just one IP address (the
exception are route4-change-{if,gw}, if-{addr,route}-{adddel,addlarge}) it's probably too
overhead and error prone. I mean working with last octet/hextet might be enough.

And if we want to work with more than last octet, we might appreciate to be able to
specify (optionally) third octet as well ($net variable).
Scripts which could benefit from it are at least:
if-{addr,route}-addlarge, route4-change-if.


Kind regards,
Petr

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

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

On 07/21/2017 07:04 AM, Petr Vorel wrote:
> * Fix test for SSH and netns based testing.
> * Remove hardcoded rsh dependency.
> * Create shell library mcast4-lib.sh (multicast IPv4 specific)
>   to reduce duplicity in tests. Library uses test_stress_net.sh
>   (and therefore test_net.sh).
> * Cleanup code + fixed typos.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  .../stress/multicast/grp-operation/mcast4-grpope01 | 221 ++-----------------
>  .../stress/multicast/grp-operation/mcast4-grpope02 | 230 ++------------------
>  .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
>  .../stress/multicast/grp-operation/mcast4-grpope04 | 236 ++-------------------
>  .../stress/multicast/grp-operation/mcast4-lib.sh   | 129 +++++++++++
>  5 files changed, 207 insertions(+), 826 deletions(-)
>  create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
>
...
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Author: Petr Vorel <pvorel@suse.cz>
> +#
> +# Setup script for mcast4-grpope* tests.
> +
> +TST_TOTAL=1
> +TST_CLEANUP="mcast_cleanup"
> +
> +. test_net_stress.sh
> +
> +mcast_setup()
> +{
> +	local igmp_max_memberships="$1"
> +	local increase_max="${2:-}"
> +	local iface=$(tst_iface)
> +
> +	netstress_setup
> +	tst_tmpdir
> +
> +	SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships)
> +	SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf)
> +	SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.${iface}.force_igmp_version)
> +	SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version)
> +
> +	if [ "$increase_max" ]; then
> +		# Increase the maximum number of open file descriptors
> +		[ `ulimit -n` -lt $igmp_max_memberships ] && ROD ulimit -n $igmp_max_memberships
> +	fi
> +
> +	tst_add_ipaddr_stress
> +	tst_add_ipaddr_stress rhost

This is very strange, the test adds a new pair of addresses and then
runs ping in setup. After that they not used...

By the way, we already have IP addresses defined by IPV4_HOST variables,
better use them if needed.


> +	check_connectivity $iface $RHOST_IPV4_UNUSED

No need for this test.

> +
> +	ROD sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
> +	ROD sysctl -qw net.ipv4.igmp_max_msf=10
> +	ROD sysctl -qw net.ipv4.conf.${iface}.force_igmp_version=0
> +	ROD sysctl -qw net.ipv4.conf.all.force_igmp_version=0
> +}
> +
> +mcast_cleanup()
> +{
> +	local iface=$(tst_iface)
> +
> +	[ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -qw net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS
> +	[ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -qw net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF
> +	[ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.${iface}.force_igmp_version=$SYSFS_FORCE_IGMP_VERSION
> +	[ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION
> +
> +	pkill -SIGHUP -x ns-mcast_join
> +	tst_sleep 10ms
> +	pkill -9 -x ns-mcast_join
> +
> +	tst_rhost_run -c "pkill -SIGHUP -x ns-igmp_querier"
> +
> +	restore_ipaddr
> +	restore_ipaddr rhost
> +}
> +
> +do_multicast_test_multiple_join()
> +{
> +	local igmp_max_memberships="$1"
> +	local iface=$(tst_iface)
> +	local riface=$(tst_iface rhost)

I would rather use those functions inline.

> +	local param_multi_socket ret tmpfile
> +
> +	[ "${2:-}" = true ] && param_multi_socket="-m"
> +
> +	# Run a multicast join tool
> +	tmpfile=ns-mcast_join.$$
> +
> +	EXPECT_PASS ns-mcast_join $param_multi_socket -f 4 -I $iface -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX > $tmpfile

EXPECT_PASS ... \> $tmpfile

> +
> +	tst_resm TINFO "joined $(grep groups $tmpfile)"
> +
> +	# Send IGMP General Query from the remote host
> +	EXPECT_RHOST_PASS ns-igmp_querier -I $riface -o -r 1

We need to use the address defined with the prefix
$MCAST_IPV4_ADDR_PREFIX above otherwise we won't get a reply, i.e. "-m
$MCAST_IPV4_ADDR"

> +}
> +
> +do_multicast_test_join_leave()
> +{
> +	local iface=$(tst_iface)
> +	local riface=$(tst_iface rhost)
> +	local define_source_address filter num ret source_addr x y
> +
> +	[ "$1" = true ] && define_source_address=true
> +
> +	# Send IGMP General Query from the remote host
> +	tst_rhost_run -s -c "ns-igmp_querier -I $riface -i 1000000000 -r 1 -b"
> +
> +	# Run a multicast join tool
> +	num=0
> +	while [ $num -lt $MCASTNUM_NORMAL ]; do
> +		if [ "$define_source_address" ]; then
> +			x=$(($num / 254))
> +			y=$(($num % 254 + 1))
> +			if [ $x -gt 254 ]; then
> +				tst_resm TINFO "the number of the connection is less than $num"
> +				break
> +			fi
> +			source_addr="${IPV4_NET16_UNUSED}.${x}.${y}"
> +
> +			[ $(($num % 5)) -ne 2 ] && filter="include" || filter="exclude"
> +			params="-F $filter -s $source_addr"
> +		fi
> +
> +		ROD ns-mcast_join -f 4 -I $iface -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &


just ns-mcast_join ... &

> +		num=$(($num + 1))
> +	done
> +
> +	wait
> +
> +	tst_resm TPASS "test is finished successfully"
> +}


Thanks,
Alexey

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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-25 14:52         ` Petr Vorel
@ 2017-07-25 16:01           ` Alexey Kodanev
  2017-07-25 16:37             ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-25 16:01 UTC (permalink / raw)
  To: ltp

On 07/25/2017 05:52 PM, Petr Vorel wrote:
>> On 07/25/2017 12:57 PM, Petr Vorel wrote:
>>> Hi Alexey,
>>>>> +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
>>>>> +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
>>>>> +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
>>>>> +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
>>>>> +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
>>>>> +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
>>>>> +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
>>>>> +
>>>>> +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
>>>>> +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
>>>>> +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
>>>>> +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
>>>>> +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
>>>>> +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
>>>>> +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
>>>> Hmm, what is the purpose of adding these variables to the library?
>>>> Why someone would need to redefine any of them?
>>> I thought someone might appreciate ability to full control of IP
>>> addresses, but you're right it's probably useless.
>>> If you don't mind, I'll keep {L,R}HOST_IPV{4,6}_UNUSED variables as they are used in many scripts
>>> (DRY approach) and delete the rest of variables.
>
>> What about adding a new function similar to tst_ipaddr()?
>> tst_ipaddr_un(), tst_ipaddr_new(), etc.? Probably we would need to add
>> some optional counter parameter along with lhost/rhost...
> How about this?
>
> tst_ipaddr_un()
> {
> 	local type="${1:-lhost}"
> 	local counter="${2:-1}"
> 	local host net max_counter max_net max_host tmp
>
> 	[ "$TST_IPV6" ] && max_net=65536 || max_net=256
> 	max_host=$((max_net - 2))
> 	max_counter=$((max_host * max_net / 2))
>
> 	if [ $counter -gt $max_counter ]; then
> 		tst_resm TCONF "'$counter' higher than max counter limit '$max_counter'"
> 	fi

I guess we can safely omit this check.

>
> 	tmp=$((counter * 2))
> 	[ "$type" = "rhost" ] && tmp=$((tmp - 1))
>
> 	host=$((tmp % max_host))
> 	net=$((tmp / max_host))
> 	[ $host -eq 0 ] && { host=$max_host; net=$((net - 1)); }
>
> 	if [ "$TST_IPV6" ]; then
> 		echo "${IPV6_NET32_UNUSED}::$(printf %x:%x ${net} ${host})"
> 	else
> 		echo "${IPV4_NET16_UNUSED}.${net}.${host}"
> 	fi
> }

Looks good to me.

>
> Given the fact that most of the tests needs just one IP address (the
> exception are route4-change-{if,gw}, if-{addr,route}-{adddel,addlarge}) it's probably too
> overhead and error prone. I mean working with last octet/hextet might be enough.
>
> And if we want to work with more than last octet, we might appreciate to be able to
> specify (optionally) third octet as well ($net variable).
> Scripts which could benefit from it are at least:
> if-{addr,route}-addlarge, route4-change-if.
>
>
> Kind regards,
> Petr


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

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

Hi Alexey,

thank you for your review.

> > +	if [ "$increase_max" ]; then
> > +		# Increase the maximum number of open file descriptors
> > +		[ `ulimit -n` -lt $igmp_max_memberships ] && ROD ulimit -n $igmp_max_memberships
> > +	fi
> > +
> > +	tst_add_ipaddr_stress
> > +	tst_add_ipaddr_stress rhost

 This is very strange, the test adds a new pair of addresses and then
> runs ping in setup. After that they not used...

> By the way, we already have IP addresses defined by IPV4_HOST variables,
> better use them if needed.
I thought that it'd be more secure to use "unused network" also for multicast. OK, I'll
use regular IP addresses.
BTW would you use "unused network"? with tests in testcases/network/stress/ than route and
interface?

> > +	check_connectivity $iface $RHOST_IPV4_UNUSED

> No need for this test.
OK (copied from your interface tests).


...
> > +mcast_cleanup()
> > +{
> > +	local iface=$(tst_iface)
...

> > +do_multicast_test_multiple_join()
> > +{
> > +	local igmp_max_memberships="$1"
> > +	local iface=$(tst_iface)
> > +	local riface=$(tst_iface rhost)

> I would rather use those functions inline.
OK.

> > +	local param_multi_socket ret tmpfile
> > +
> > +	[ "${2:-}" = true ] && param_multi_socket="-m"
> > +
> > +	# Run a multicast join tool
> > +	tmpfile=ns-mcast_join.$$
> > +
> > +	EXPECT_PASS ns-mcast_join $param_multi_socket -f 4 -I $iface -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX > $tmpfile

> EXPECT_PASS ... \> $tmpfile
Eh, silly mistake.

> > +
> > +	tst_resm TINFO "joined $(grep groups $tmpfile)"
> > +
> > +	# Send IGMP General Query from the remote host
> > +	EXPECT_RHOST_PASS ns-igmp_querier -I $riface -o -r 1

> We need to use the address defined with the prefix
> $MCAST_IPV4_ADDR_PREFIX above otherwise we won't get a reply, i.e. "-m
> $MCAST_IPV4_ADDR"
Right, thanks. It was broken in original code. Trying to read ns-mcast_join.c and
ns-igmp_querier.c, but still not sure I fully understand tham. Hope the other flags are
correct (e.g. not missing MCAST_IPV4_ADDR_PREFIX resp. MCAST_IPV4_ADDR).

> > +}
> > +
> > +do_multicast_test_join_leave()
> > +{
> > +	local iface=$(tst_iface)
> > +	local riface=$(tst_iface rhost)
> > +	local define_source_address filter num ret source_addr x y
> > +
> > +	[ "$1" = true ] && define_source_address=true
> > +
> > +	# Send IGMP General Query from the remote host
> > +	tst_rhost_run -s -c "ns-igmp_querier -I $riface -i 1000000000 -r 1 -b"
> > +
> > +	# Run a multicast join tool
> > +	num=0
> > +	while [ $num -lt $MCASTNUM_NORMAL ]; do
> > +		if [ "$define_source_address" ]; then
> > +			x=$(($num / 254))
> > +			y=$(($num % 254 + 1))
> > +			if [ $x -gt 254 ]; then
> > +				tst_resm TINFO "the number of the connection is less than $num"
> > +				break
> > +			fi
> > +			source_addr="${IPV4_NET16_UNUSED}.${x}.${y}"
> > +
> > +			[ $(($num % 5)) -ne 2 ] && filter="include" || filter="exclude"
> > +			params="-F $filter -s $source_addr"
> > +		fi
> > +
> > +		ROD ns-mcast_join -f 4 -I $iface -l $NS_TIMES -a $MCAST_IPV4_ADDR $params &


> just ns-mcast_join ... &
OK



Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh
  2017-07-25 16:01           ` Alexey Kodanev
@ 2017-07-25 16:37             ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-25 16:37 UTC (permalink / raw)
  To: ltp

> On 07/25/2017 05:52 PM, Petr Vorel wrote:
> >> On 07/25/2017 12:57 PM, Petr Vorel wrote:
> >>> Hi Alexey,
> >>>>> +export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
> >>>>> +export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
> >>>>> +export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
> >>>>> +export LHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_LHOST_IPV4_HOST_UNUSED}"
> >>>>> +export RHOST_IPV4_HOST_UNUSED="${OCTET_3_IPV4_UNUSED}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> >>>>> +export LHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$LHOST_IPV4_HOST_UNUSED"
> >>>>> +export RHOST_IPV4_UNUSED="${IPV4_NET16_UNUSED}.$RHOST_IPV4_HOST_UNUSED"
> >>>>> +
> >>>>> +export OCTET_3_IPV6_UNUSED="${OCTET_3_IPV6_UNUSED:-:0}"
> >>>>> +export OCTET_4_LHOST_IPV6_HOST_UNUSED=${OCTET_4_LHOST_IPV6_HOST_UNUSED:-2}
> >>>>> +export OCTET_4_RHOST_IPV6_HOST_UNUSED=${OCTET_4_RHOST_IPV6_HOST_UNUSED:-1}
> >>>>> +export LHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_LHOST_IPV6_HOST_UNUSED}"
> >>>>> +export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_UNUSED}"
> >>>>> +export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
> >>>>> +export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
> >>>> Hmm, what is the purpose of adding these variables to the library?
> >>>> Why someone would need to redefine any of them?
> >>> I thought someone might appreciate ability to full control of IP
> >>> addresses, but you're right it's probably useless.
> >>> If you don't mind, I'll keep {L,R}HOST_IPV{4,6}_UNUSED variables as they are used in many scripts
> >>> (DRY approach) and delete the rest of variables.

> >> What about adding a new function similar to tst_ipaddr()?
> >> tst_ipaddr_un(), tst_ipaddr_new(), etc.? Probably we would need to add
> >> some optional counter parameter along with lhost/rhost...
> > How about this?

> > tst_ipaddr_un()
> > {
> > 	local type="${1:-lhost}"
> > 	local counter="${2:-1}"
> > 	local host net max_counter max_net max_host tmp

> > 	[ "$TST_IPV6" ] && max_net=65536 || max_net=256
> > 	max_host=$((max_net - 2))
> > 	max_counter=$((max_host * max_net / 2))

> > 	if [ $counter -gt $max_counter ]; then
> > 		tst_resm TCONF "'$counter' higher than max counter limit '$max_counter'"
> > 	fi

> I guess we can safely omit this check.
OK.


> > 	tmp=$((counter * 2))
> > 	[ "$type" = "rhost" ] && tmp=$((tmp - 1))

> > 	host=$((tmp % max_host))
> > 	net=$((tmp / max_host))
> > 	[ $host -eq 0 ] && { host=$max_host; net=$((net - 1)); }

> > 	if [ "$TST_IPV6" ]; then
> > 		echo "${IPV6_NET32_UNUSED}::$(printf %x:%x ${net} ${host})"
> > 	else
> > 		echo "${IPV4_NET16_UNUSED}.${net}.${host}"
> > 	fi
> > }

> Looks good to me.
Thanks. It will be all in v8. I'd like to send it ASAP as I'm on holiday since next week
for two weeks.

> > And if we want to work with more than last octet, we might appreciate to be able to
> > specify (optionally) third octet as well ($net variable).
> > Scripts which could benefit from it are at least:
> > if-{addr,route}-addlarge, route4-change-if.
Do we want to get rid of direct usage of IPV4_NET16_UNUSED and IPV6_NET32_UNUSED (at least
in most of the scripts) and use tst_ipaddr_un()? I'm not sure if this is useful, but, as I
wrote before, tests in if-{addr,route}-addlarge, route4-change-if require change in third
octet.

So how about this (I also added security check, even it's close to impossible that will be
needed):

# Get IP address of unused network
# tst_ipaddr_un [TYPE] [COUNTER] [OCTET_3]
# TYPE: { lhost | rhost }; Default value is 'lhost'.
# COUNTER: Integer value; Default is 1.
# OCTET_3: Specify third octet; Default is calculated from counter.
tst_ipaddr_un()
{
	local type="${1:-lhost}"
	local counter="${2:-1}"
	local octet_3="${3:-}"
	local host net max_net max_host tmp

	[ "$TST_IPV6" ] && max_net=65536 || max_net=256
	max_host=$((max_net - 2))

	tmp=$((counter * 2))
	[ "$type" = "rhost" ] && tmp=$((tmp - 1))

	host=$((tmp % max_host))
	net=$((tmp / max_host))
	[ $host -eq 0 ] && { host=$max_host; net=$((net - 1)); }

	[ -n "$octet_3" ] && net=$octet_3

	[ $host -gt $max_host ] && host=$max_host
	[ $net -gt $max_net ] && net=$max_net

	if [ "$TST_IPV6" ]; then
		echo "${IPV6_NET32_UNUSED}::$(printf %x:%x ${net} ${host})"
	else
		echo "${IPV4_NET16_UNUSED}.${net}.${host}"
	fi
}


Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
@ 2017-07-26 14:44   ` Alexey Kodanev
  2017-07-26 14:55     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-26 14:44 UTC (permalink / raw)
  To: ltp

Hi,
On 21.07.2017 7:04, Petr Vorel wrote:
> This function is useful when we know we broke netns (e.g. by unloading
> network driver).
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index 0cafe1514..cecb0bab2 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -42,7 +42,7 @@ init_ltp_netspace()
>  	export TST_INIT_NETNS="no"
>  
>  	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
> -	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
> +	export LTP_NETNS="ns_exec $pid net,mnt"

It is better to reset LTP_NETNS variable before calling
init_ltp_netspace in reset_ltp_netspace().

Thanks,
Alexey

>  
>  	tst_restore_ipaddr
>  	tst_restore_ipaddr rhost
> @@ -50,6 +50,18 @@ init_ltp_netspace()
>  	tst_wait_ipv6_dad
>  }
>  
> +# Force to reset netns.
> +reset_ltp_netspace()
> +{
> +	[ -n "$TST_USE_NETNS" ] || return
> +
> +	tst_resm TINFO "reset netns"
> +	ip link delete ltp_ns_veth2 2> /dev/null
> +	rm -f /var/run/netns/ltp_ns
> +	pkill ns_create
> +	init_ltp_netspace
> +}
> +
>  # Run command on remote host.
>  # Options:
>  # -b run in background


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170726/7e04e5c7/attachment.html>

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

* [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-07-26 14:44   ` Alexey Kodanev
@ 2017-07-26 14:55     ` Petr Vorel
  2017-07-26 15:00       ` Alexey Kodanev
  0 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-26 14:55 UTC (permalink / raw)
  To: ltp

Hi Alexey,

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

> It is better to reset LTP_NETNS variable before calling
> init_ltp_netspace in reset_ltp_netspace().
OK, I'll do it :-). I wonder what is a real usage for LTP_NETNS configured by user...

Thanks for your review!

Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
@ 2017-07-26 14:58   ` Alexey Kodanev
  2017-07-26 23:29     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-26 14:58 UTC (permalink / raw)
  To: ltp

On 21.07.2017 7:04, Petr Vorel wrote:
> * Fix test for netns based testing (route4-change-if requires to have
>   manually set another pair of interfaces).
> * Remove rsh dependency.
> * Create shell library route4-lib.sh (route IPv4 specific) to reduce
>   duplicity in tests. Library uses test_stress_net.sh (and therefore test_net.sh).
> * Stop using TST_COUNT, simplify TCID
> * Cleanup code, fix typos, update doc.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/network/stress/ns-tools/initialize_if    |   3 -
>  .../network/stress/ns-tools/test_net_stress.sh     |   9 +-
>  testcases/network/stress/route/00_Descriptions.txt |  23 +-
>  testcases/network/stress/route/route4-change-dst   | 283 ++---------------
>  testcases/network/stress/route/route4-change-gw    | 302 ++----------------
>  testcases/network/stress/route/route4-change-if    | 336 +++------------------
>  testcases/network/stress/route/route4-ifdown       | 283 ++++-------------
>  testcases/network/stress/route/route4-lib.sh       | 206 +++++++++++++
>  testcases/network/stress/route/route4-redirect     | 220 +++-----------
>  testcases/network/stress/route/route4-rmmod        | 314 +++++--------------
>  testcases/network/stress/route/route6-change-dst   |   2 +-
>  11 files changed, 480 insertions(+), 1501 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"
> -

Again, why?

>  if [ $host_type = lhost ]; then
>      ( ifconfig $ifname down && \
>      ip link set mtu 1500 dev $ifname && \
> diff --git a/testcases/network/stress/ns-tools/test_net_stress.sh b/testcases/network/stress/ns-tools/test_net_stress.sh
> index 5ab3304db..d112286bd 100644
> --- a/testcases/network/stress/ns-tools/test_net_stress.sh
> +++ b/testcases/network/stress/ns-tools/test_net_stress.sh
> @@ -31,7 +31,6 @@ export TCID="${TCID:-$(basename $0)}"
>  # Netmask of for the tested network
>  IPV4_NETMASK="255.255.255.0"
>  IPV4_NETMASK_NUM=24
> -IPV4_BROADCAST=${IPV4_NET16_UNUSED}.0.255
>  
>  # Prefix of the Multicast Address
>  MCAST_IPV4_ADDR_PREFIX="224.10"
> @@ -64,16 +63,16 @@ netstress_cleanup()
>  }
>  
...
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to down/up the interface"
> -	    return 1
> -	fi
> +		manipulate_route $cmd_name_route 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $lhost_ifname
>  
> -	cnt=`expr $cnt + 1`
> -    done
> +		check_connectivity_interval $cnt false $lhost_ifname $RHOST_IPV4_UNUSED
>  
> -    tst_resm TPASS "Test is finished correctly."
> -    return 0
> -}
> +		# Down then up the interface
> +		sh -c "$cmd_iface_down"

Can be just $cmd_iface_down, or better ROD/EXPECT_PASS.

> +		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
> +test_body 'rt_cmd'
> +test_body 'ip_cmd'
>  
> -exit $RC
> +tst_exit
> diff --git a/testcases/network/stress/route/route4-lib.sh b/testcases/network/stress/route/route4-lib.sh
> new file mode 100644
> index 000000000..1f0047f68
> --- /dev/null
> +++ b/testcases/network/stress/route/route4-lib.sh
> @@ -0,0 +1,206 @@
> +#!/bin/sh
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> +#
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation; either version 2 of
> +# the License, or (at your option) any later version.
> +#
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Setup script for route4-* tests.
> +#
> +# More information about network parameters can be found
> +# in the following document: testcases/network/stress/README
> +#
> +# Author: Petr Vorel <pvorel@suse.cz>
> +
> +. test_net_stress.sh
> +
> +tst_check_cmds ip pgrep route
> +
> +CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
> +
> +# The destination network
> +# NOTE: DST_NETWORK expects NETMASK IPV4_NETMASK_NUM=24
> +DST_NETWORK="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}"
> +DST_HOST=5
> +DST_PORT=7
> +
> +route_cleanup()
> +{
> +	netstress_cleanup
> +	restore_ipaddr
> +	restore_ipaddr rhost
> +}
> +
> +route_ns_udpsender_cleanup()
> +{
> +	stop_ns_udpsender
> +	restore_ipaddr
> +	restore_ipaddr rhost
> +}
> +
> +route_setup()
> +{
> +	netstress_setup
> +	tst_check_cmds route
> +	route_cleanup
> +}
> +
> +manipulate_route()
> +{
> +	local cmd_name=$1
> +	local task=$2
> +	local network=$3
> +	local prefix=$4
> +	local netmask=$5
> +	local gateway=$6
> +	local ifname=$7
> +
> +	[ "$task" = "add" ] || [ "$task" = "del" ] || \
> +		[ "$cmd_name" = "ip" -a "$task" = "append" ] || tst_brkm TBROK "wrong task: '$task'"
> +
> +	[ "$cmd_name" = "ip" -a "$task" = "add" ] && task="append"
> +	if [ "$cmd_name" = "ip" ]; then
> +		ROD "$cmd_name route $task $network/$prefix via $gateway dev $ifname"
> +	else
> +		ROD "$cmd_name $task -net $network netmask $netmask gw $gateway dev $ifname"
> +	fi
> +}
> +
> +# Load the route with UDP traffic.
> +run_ns_udpsender()
> +{
> +	local dst_addr=$1
> +	local run_in_background=$2
> +	local udp_size="${3:-1472}"
> +	local params="-o"
> +
> +	if [ "$run_in_background" = true ]; then
> +		# daemon is already running
> +		pgrep -x ns-udpsender > /dev/null && return 0
> +		params="-b"
> +	fi
> +
> +	ROD ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -s $udp_size $params
> +}
> +
> +stop_ns_udpsender()
> +{
> +	local type="${1:-lhost}"
> +	kill_daemon ns-udpsender $type
> +}
> +
> +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
> +}
> +
> +route_test_change()
> +{
> +	local test_field=$1
> +	local cmd_type=$2
> +
> +	local rhost_ip="$RHOST_IPV4_UNUSED"
> +	local lhost_ifname=$(tst_iface)
> +	local rhost_part_first=$RHOST_IPV4_HOST_TOP
> +	local rhost_part_last=$RHOST_IPV4_HOST_LAST
> +	local cnt=0
> +	local link_num=0
> +	local first_route_net=${DST_NETWORK}.0
> +	local cmd_name="$(get_cmd $cmd_type)"
> +	local gateway="$rhost_ip"
> +	local dst_addr dst_network dst_network_postfix gateway2 lhost_ifname2 rhost_part test_field_name
> +
> +	case $test_field in
> +	dst) test_field_name='destination' ;;
> +	gw) test_field_name='gateway' ;;
> +	if) test_field_name='interface' ;;
> +	*) tst_brkm TBROK "Unknown test parameter '$test_field'"
> +	esac
> +
> +	tst_resm TINFO "the $test_field_name of an IPv4 route is changed by '$cmd_name' command $NS_TIMES times"
> +
> +	if [ "$test_field" = "if" ]; then
> +		while [ $link_num -lt $LINK_TOTAL ]; do
> +			rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> +			check_connectivity $(tst_iface lhost $link_num) $rhost_ip
> +			link_num=$(($link_num + 1))
> +		done
> +		link_num=0
> +		lhost_ifname="$(tst_iface lhost $link_num)"
> +		gateway="${IPV4_NET16_UNUSED}.${link_num}.${RHOST_IPV4_HOST}"
> +	else
> +		if [ "$test_field" = "gw" ]; then
> +			rhost_ip="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.$RHOST_IPV4_HOST_TOP"
> +			rhost_part=$rhost_part_first
> +			gateway="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}"
> +		fi
> +		tst_add_ipaddr_stress
> +		check_connectivity $(tst_iface) $rhost_ip
> +	fi
> +
> +	if [ "$test_field" != "dst" ]; then
> +		dst_addr=${DST_NETWORK}.${DST_HOST}
> +		dst_network=$first_route_net
> +
> +		tst_resm TINFO "adding first route"
> +		ROD manipulate_route $cmd_name 'add' $first_route_net $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname

Without 'ROD', in the new library it won't work with script functions,
besides you have ROD on every command in that function already.

> +	fi
> +
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		lhost_ifname2="$lhost_ifname"
> +		gateway2="$gateway"
> +
> +		make_background_tcp_traffic $LHOST_IPV4_UNUSED
> +
> +		if [ "$test_field" = "dst" ]; then
> +			dst_network_postfix="$(($cnt % 255))"
> +			dst_addr="${IPV4_NET16_UNUSED}.${dst_network_postfix}.${DST_HOST}"
> +			dst_network="${IPV4_NET16_UNUSED}.${dst_network_postfix}.0"
> +		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_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}"
> +			gateway2="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${pre_rhost_part}"
> +		elif [ "$test_field" = "if" ]; then
> +			link_num=$(($link_num + 1))
> +			[ $link_num -ge $LINK_TOTAL ] && link_num=0
> +			lhost_ifname="$(tst_iface lhost $link_num)"
> +			gateway="${IPV4_NET16_UNUSED}.${link_num}.${RHOST_IPV4_HOST}"
> +			rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> +		fi
> +
> +		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname

Looking at the original test-case, after new route added, the
test triesto send a single UDP datagram in order to load it.
But now all the tests have a background traffic on that
interface and route not used, correct?

> +		manipulate_route $cmd_name 'del' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
> +
> +		check_connectivity_interval $cnt false $lhost_ifname $rhost_ip || return
> +
> +		cnt=$(($cnt + 1))
> +	done
> +
> +	if [ "$test_field" != "dst" ]; then
> +		ROD manipulate_route $cmd_name del $first_route_net $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname
> +	fi
> +
> +	if [ "$test_field" != "if" ]; then
> +		restore_ipaddr
> +	fi
> +
> +	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..714e0af25 100644
> --- a/testcases/network/stress/route/route4-redirect
> +++ b/testcases/network/stress/route/route4-redirect
> @@ -1,212 +1,72 @@
>  #!/bin/sh
> -
> -################################################################################
> -##                                                                            ##
> -## Copyright (c) International Business Machines  Corp., 2006                 ##
> -##                                                                            ##
> -## This program is free software;  you can redistribute it and#or modify      ##
> -## it under the terms of the GNU General Public License as published by       ##
> -## the Free Software Foundation; either version 2 of the License, or          ##
> -## (at your option) any later version.                                        ##
> -##                                                                            ##
> -## This program is distributed in the hope that it will be useful, but        ##
> -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
> -## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
> -## for more details.                                                          ##
> -##                                                                            ##
> -## You should have received a copy of the GNU General Public License          ##
> -## along with this program;  if not, write to the Free Software               ##
> -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
> -##                                                                            ##
> -##                                                                            ##
> -################################################################################
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
>  #
> -# File:
> -#   route4-redirect
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation; either version 2 of
> +# the License, or (at your option) any later version.
>  #
> -# Description:
> -#   Verify the kernel is not crashed when the IPv4 route is modified by
> -#   ICMP Redirects frequently
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
>  #
> -# Setup:
> -#   See ltp-yyyymmdd/testcases/network/stress/README
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
>  #
> -# Author:
> -#   Mitsuru Chinen <mitch@jp.ibm.com>
> +# Verify the kernel is not crashed when the IPv4 route is modified by
> +# ICMP Redirects frequently.
>  #
> -# History:
> -#	Apr 07 2006 - Created (Mitsuru Chinen)
> +# Setup: testcases/network/stress/README
>  #
> -#-----------------------------------------------------------------------
> -# Uncomment line below for debug output.
> -#trace_logic=${trace_logic:-"set -x"}
> -$trace_logic
> +# Author: Mitsuru Chinen <mitch@jp.ibm.com>
>  
> -# The test case ID, the test case count and the total number of test case
> -TCID=route4-redirect01
>  TST_TOTAL=1
> -TST_COUNT=1
> -export TCID
> -export TST_COUNT
> -export TST_TOTAL
> -
> -# Test description
> -tst_resm TINFO "Verify the kernel is not crashed when the IPv4 route is modified by  ICMP Redirects frequently"
> -
> -# Make sure the value of LTPROOT
> -LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
> -export LTPROOT
> -
> -# Check the environmanet variable
> -. check_envval || exit $TST_TOTAL
> -
> -# The number of times where route is changed
> -NS_TIMES=${NS_TIMES:-10000}
> -
> -# The number of the test link where tests run
> -LINK_NUM=${LINK_NUM:-0}
> -
> -# Network portion of the IPv4 address
> -IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
> -
> -# Netmask of for the tested network
> -IPV4_NETMASK_NUM=24
>  
> -# Broadcast address of the tested network
> -IPV4_BROADCAST=${IPV4_NETWORK}.255
> +. route4-lib.sh
>  
> -# Host portion of the IPv4 address
> -LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
> -RHOST_IPV4_HOST="2"	# gateway
> +TST_CLEANUP="do_cleanup"
>  
> -# The destination network
> -DST_NETWORK="10.10.0"   # destination network would be 10.10.0.0/24
> -DST_HOST="5"
> -DST_PORT="7"
> +SYSFS_ACCEPT_REDIRECTS=
> +SYSFS_SECURE_REDIRECTS=
>  
> -
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_cleanup
> -#
> -# DESCRIPTION:
> -#   Recover the tested interfaces
> -#
> -#-----------------------------------------------------------------------
>  do_cleanup()
>  {
> -    # Kill the redirector utility
> -    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
> -
> -    # Initialize the interfaces
> -    initialize_if lhost ${LINK_NUM}
> -    initialize_if rhost ${LINK_NUM}
> +	route_ns_udpsender_cleanup
> +	kill_daemon ns-icmp_redirector remote
> +	[ -n "$SYSFS_ACCEPT_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).accept_redirects=$SYSFS_ACCEPT_REDIRECTS
> +	[ -n "$SYSFS_SECURE_REDIRECTS" ] && sysctl -qw net.ipv4.conf.$(tst_iface).secure_redirects=$SYSFS_SECURE_REDIRECTS
>  }
>  
> -
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_setup
> -#
> -# DESCRIPTION:
> -#   Set the initial route and start icmp redirect on the remote host
> -#
> -# SET VALUES:
> -#   rhost_ipv4addr      - IPv4 Address of the remote host
> -#   lhost_ifname        - Interface name of the local host
> -#   rhost_ifname        - Interface name of the remote host
> -#
> -#-----------------------------------------------------------------------
>  do_setup()
>  {
> -    # Make sure to clean up
> -    do_cleanup
> -
> -    # Get the Interface name of local host
> -    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "Failed to get the interface name at the local host"
> -	exit $TST_TOTAL
> -    fi
> -
> -    # Get the Interface name of remote host
> -    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "Failed to get the interface name at the remote host"
> -	exit $TST_TOTAL
> -    fi
> +	route_setup
>  
> -    # Remove the link-local address of the remote host
> -    sleep 3
> -    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
> +	SYSFS_ACCEPT_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).accept_redirects)
> +	SYSFS_SECURE_REDIRECTS=$(sysctl -b net.ipv4.conf.$(tst_iface).secure_redirects)
>  
> -    # 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
> +	tst_add_ipaddr_stress
>  
> -    # 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"
> +	ROD manipulate_route "route" "add" ${DST_NETWORK}.0 $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $(tst_iface)
>  
> -    # Make sure the sysctl value is set for accepting the redirect
> -    sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
> -    sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null
> -
> -    # Run the redirector utility at the remote host
> -    ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
> -    if [ $ret -ne 0 ]; then
> -	tst_resm TBROK "Failed to run icmp redirector at the remote host"
> -	exit $TST_TOTAL
> -    fi
> +	# Run the redirector utility at the remote host
> +	tst_rhost_run -s -c "ns-icmp_redirector -I $(tst_iface rhost) -b"
>  }
>  
> -
> -
> -#-----------------------------------------------------------------------
> -#
> -# FUNCTION:
> -#   test_body
> -#
> -# DESCRIPTION:
> -#   main code of the test
> -#
> -# Arguments:
> -#   None
> -#
> -#-----------------------------------------------------------------------
>  test_body()
>  {
> -    # Loop for changing the route
> -    cnt=0
> -    while [ $cnt -lt $NS_TIMES ]; do
> -	ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TBROK "Failed to run udp packet sender"
> -	    return 1
> -	fi
> -	cnt=`expr $cnt + 1`
> -    done
> +	local cnt=0
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		run_ns_udpsender ${DST_NETWORK}.${DST_HOST} no 8
> +		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 || RC=`expr $RC + 1`
> -do_cleanup
> +test_body
>  
> -exit $RC
> +tst_exit
> diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
> index 36c8c970d..70a6e3745 100644
> --- a/testcases/network/stress/route/route4-rmmod
> +++ b/testcases/network/stress/route/route4-rmmod
> @@ -1,280 +1,104 @@
>  #!/bin/sh
> -
> -################################################################################
> -##                                                                            ##
> -## Copyright (c) International Business Machines  Corp., 2006                 ##
> -##                                                                            ##
> -## This program is free software;  you can redistribute it and#or modify      ##
> -## it under the terms of the GNU General Public License as published by       ##
> -## the Free Software Foundation; either version 2 of the License, or          ##
> -## (at your option) any later version.                                        ##
> -##                                                                            ##
> -## This program is distributed in the hope that it will be useful, but        ##
> -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
> -## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
> -## for more details.                                                          ##
> -##                                                                            ##
> -## You should have received a copy of the GNU General Public License          ##
> -## along with this program;  if not, write to the Free Software               ##
> -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
> -##                                                                            ##
> -##                                                                            ##
> -################################################################################
> -#
> -# File:
> -#   route4-rmmod
> +# Copyright (c) International Business Machines  Corp., 2006
> +# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
>  #
> -# Description:
> -#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
> -#   by the removing network driver
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License as
> +# published by the Free Software Foundation; either version 2 of
> +# the License, or (at your option) any later version.
>  #
> -# Setup:
> -#   See ltp-yyyymmdd/testcases/network/stress/README
> +# This program is distributed in the hope that it would be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
>  #
> -# Author:
> -#   Mitsuru Chinen <mitch@jp.ibm.com>
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
>  #
> -# History:
> -#	Apr 8 2006 - Created (Mitsuru Chinen)
> +# Setup: testcases/network/stress/README
>  #
> -#-----------------------------------------------------------------------
> -# Uncomment line below for debug output.
> -#trace_logic=${trace_logic:-"set -x"}
> -$trace_logic
> -
> -# Make sure the value of LTPROOT
> -LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
> -export LTPROOT
> +# Author: Mitsuru Chinen <mitch@jp.ibm.com>
>  
> -# Total number of the test case
>  TST_TOTAL=2
> -export TST_TOTAL
> -
> -# Default of the test case ID and the test case count
> -TCID=route4-rmmod
> -TST_COUNT=0
> -export TCID
> -export TST_COUNT
> -
> -# Check the environmanet variable
> -. check_envval || exit $TST_TOTAL
> -
> -# The number of times where IPv4 route is add/delete
> -NS_TIMES=${NS_TIMES:-10000}
> -
> -# The number of the test link where tests run
> -LINK_NUM=${LINK_NUM:-0}
> -
> -# Network portion of the IPv4 address
> -IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
> -
> -# Netmask of for the tested network
> -IPV4_NETMASK="255.255.255.0"
> -IPV4_NETMASK_NUM=24
> -
> -# Broadcast address of the tested network
> -IPV4_BROADCAST=${IPV4_NETWORK}.255
> -
> -# Host portion of the IPv4 address
> -LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
> -RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
>  
> -# The destination network
> -DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
> -DST_HOST="5"
> -DST_PORT="7"
> +. route4-lib.sh
>  
> +TST_CLEANUP="do_cleanup"
>  
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_cleanup
> -#
> -# DESCRIPTION:
> -#   Recover the tested interfaces
> -#
> -#-----------------------------------------------------------------------
>  do_cleanup()
>  {
> -    # Make sure to load the network driver
> -    if [ x${lhost_module} != x ]; then
> -	modprobe $lhost_module
> -    fi
> -
> -    # Initialize the interfaces
> -    initialize_if lhost ${LINK_NUM}
> -    initialize_if rhost ${LINK_NUM}
> +	if [ -n "${lhost_module}" ]; then
> +		modprobe $lhost_module
> +		tst_sleep 100ms
> +	fi
> +	netstress_cleanup
> +	restore_ipaddr
>  }
>  
>  
> -#-----------------------------------------------------------------------
> -#
> -# NAME:
> -#   do_setup
> -#
> -# DESCRIPTION:
> -#   Make a IPv4 connectivity
> -#
> -#-----------------------------------------------------------------------
>  do_setup()
>  {
> -    # Check the local host has ethtool utility
> -    which ethtool >/dev/null
> -    if [ $? -ne 0 ]; then
> -	tst_resm TBROK "This test case requires ethtool utility"
> -	exit $TST_TOTAL
> -    fi
> -
> -    # 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
> +	route_setup
> +	tst_check_cmds ethtool
> +
> +	tst_add_ipaddr_stress

tst_add_ipaddr_stress() should be after all the checks. Also I doubt
that we need to add a new address in every test. Could you check again
if we really need it?

> +
> +	# Get the module name of the interface at the local host
> +	lhost_module=$(ethtool -i $(tst_iface) | 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 [ "$(tst_iface)" = "$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 driver '$module' with the test intreface"
> +			return
> +		fi
> +	done
>  }
>  
> -
> -#-----------------------------------------------------------------------
> -#
> -# FUNCTION:
> -#   test_body
> -#
> -# DESCRIPTION:
> -#   main code of the test
> -#
> -# Arguments:
> -#   $1: define the test type
> -#	1 - route command case
> -#	2 - ip command case
> -#
> -#-----------------------------------------------------------------------
>  test_body()
>  {
> -    test_type=$1
> +	local cmd_type=$1
> +	local cmd_name="$(get_cmd $cmd_type)"
> +	local dst_addr=${DST_NETWORK}.${DST_HOST}
> +	local dst_network=${DST_NETWORK}.0
> +	local cnt=0
>  
> -    TCID=route4-rmmod0${test_type}
> -    TST_COUNT=$test_type
> +	tst_resm TINFO "IPv4 route is added by '$cmd_name' command and then deleted by removing network driver $NS_TIMES times"
>  
> -    case $test_type in
> -	1)
> -	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
> -	;;
> -	2)
> -	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
> -	;;
> -	*)
> -	tst_resm TBROK "unspecified case"
> -	return 1
> -	;;
> -    esac
> +	while [ $cnt -lt $NS_TIMES ]; do
> +		make_background_tcp_traffic $LHOST_IPV4_UNUSED
>  
> -    # Start the loop
> -    cnt=0
> -    while [ $cnt -lt $NS_TIMES ]; do
> -	# Check the connectivity to the gateway
> -	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
> -	    return 1
> -	fi
> +		check_connectivity_interval $cnt false $(tst_iface) $RHOST_IPV4_UNUSED || return
>  
> -	# Add the route
> -	case $test_type in
> -	    1)
> -	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	    2)
> -	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
> -	    ;;
> -	esac
> -	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
> -	    return 1
> -	fi
> +		# Add the route
> +		ROD manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $RHOST_IPV4_UNUSED $(tst_iface)
>  
> -	# 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

ROD modprobe -r $module
ROD modprobe $module

> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "failed to unload/reload the network driver '$lhost_module'"
> +			return
> +		fi
> +		tst_sleep 100ms

Are you sure we need sleep here?

>  
> -	# 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 kernel module 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
> +		tst_add_ipaddr_stress
>  
> -	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
> -do_cleanup
> +test_body 'rt_cmd'
> +test_body 'ip_cmd'
>  
> -exit $RC
> +tst_exit
> diff --git a/testcases/network/stress/route/route6-change-dst b/testcases/network/stress/route/route6-change-dst
> index 33e89e985..649f0cc00 100644
> --- a/testcases/network/stress/route/route6-change-dst
> +++ b/testcases/network/stress/route/route6-change-dst
> @@ -242,7 +242,7 @@ test_body()
>  	    ;;
>  	esac
>  	if [ $? -ne 0 ]; then
> -	    tst_resm TFAIL "Cannot delte the route to ${ADDDEL_ROUTE}"
> +	    tst_resm TFAIL "Cannot delete the route to ${ADDDEL_ROUTE}"
>  	    return 1
>  	fi
>  

Thanks,
Alexey

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

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

* [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace()
  2017-07-26 14:55     ` Petr Vorel
@ 2017-07-26 15:00       ` Alexey Kodanev
  0 siblings, 0 replies; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-26 15:00 UTC (permalink / raw)
  To: ltp

On 26.07.2017 17:55, Petr Vorel wrote:
> Hi Alexey,
>
>>>  	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>>> -	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
>>> +	export LTP_NETNS="ns_exec $pid net,mnt"
>> It is better to reset LTP_NETNS variable before calling
>> init_ltp_netspace in reset_ltp_netspace().
> OK, I'll do it :-). I wonder what is a real usage for LTP_NETNS configured by user...

e.g. to use 'ip' command instead.

Thanks,
Alexey

>
> Thanks for your review!
>
> Kind regards,
> Petr



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

* [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables Petr Vorel
@ 2017-07-26 15:17   ` Alexey Kodanev
  2017-07-27  8:35     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-26 15:17 UTC (permalink / raw)
  To: ltp

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

Have you checked my comments for the previous version?

> NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
> Network variables are defined for both local and remote:
> IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK
> IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK
>
> NEW VARIABLES:
> IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX,
> IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,
>
> For full list of environment variables which tools setup run:
> tst_net_ip_prefix -h
> tst_net_iface_prefix -h
> tst_net_vars -h
>
> Thanks a lot to Alexey Kodanev who reviewed many versions of this patch
> and give feedback and pointed out errors, as well as to Cyril Hrubis who
> reviewed orignal version of tst_net_vars.c.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  include/tst_net.h                    | 140 ++++++++
>  testcases/lib/.gitignore             |   3 +
>  testcases/lib/Makefile               |   2 +-
>  testcases/lib/tst_net_iface_prefix.c | 173 +++++++++
>  testcases/lib/tst_net_ip_prefix.c    | 116 +++++++
>  testcases/lib/tst_net_vars.c         | 655 +++++++++++++++++++++++++++++++++++
>  6 files changed, 1088 insertions(+), 1 deletion(-)
>  create mode 100644 include/tst_net.h
>  create mode 100644 testcases/lib/tst_net_iface_prefix.c
>  create mode 100644 testcases/lib/tst_net_ip_prefix.c
>  create mode 100644 testcases/lib/tst_net_vars.c
>
> diff --git a/include/tst_net.h b/include/tst_net.h
> new file mode 100644
> index 000000000..07ca79825
> --- /dev/null
> +++ b/include/tst_net.h
> @@ -0,0 +1,140 @@
> +/*
> + * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <arpa/inet.h>
> +#include <errno.h>
> +
> +#define MAX_IPV4_PREFIX 32
> +#define MAX_IPV6_PREFIX 128
> +
> +#define tst_res_comment(...) { \
> +	fprintf(stderr, "# "); \
> +	tst_res(__VA_ARGS__); } \
> +
> +
> +#define tst_brk_comment(...) { \
> +	fprintf(stderr, "# "); \
> +	tst_brk(__VA_ARGS__); } \
> +
> +static inline void print_svar(const char *name, const char *val)
> +{
> +	if (name && val)
> +		printf("export %s=\"%s\"\n", name, val);
> +}
> +
> +static inline void print_svar_change(const char *name, const char *val)
> +{
> +	if (name && val)
> +		printf("export %s=\"${%s:-%s}\"\n", name, name, val);
> +}
> +
> +/*
> + * Function bit_count is from ipcalc project, ipcalc.c.
> + */
> +static int bit_count(uint32_t i)
> +{
> +	int c = 0;
> +	unsigned int seen_one = 0;
> +
> +	while (i > 0) {
> +		if (i & 1) {
> +			seen_one = 1;
> +			c++;
> +		} else {
> +			if (seen_one)
> +				return -1;
> +		}
> +		i >>= 1;
> +	}
> +
> +	return c;
> +}
> +
> +/*
> + * Function mask2prefix is from ipcalc project, ipcalc.c.
> + */
> +static int mask2prefix(struct in_addr mask)
> +{
> +	return bit_count(ntohl(mask.s_addr));
> +}
> +
> +/*
> + * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
> + */
> +static int ipv4_mask_to_int(const char *prefix)
> +{
> +	int ret;
> +	struct in_addr in;
> +
> +	ret = inet_pton(AF_INET, prefix, &in);
> +	if (ret == 0)
> +		return -1;
> +
> +	return mask2prefix(in);
> +}
> +
> +/*
> + * Function safe_atoi is from ipcalc project, ipcalc.c.
> + */
> +static int safe_atoi(const char *s, int *ret_i)
> +{
> +	char *x = NULL;
> +	long l;
> +
> +	errno = 0;
> +	l = strtol(s, &x, 0);
> +
> +	if (!x || x == s || *x || errno)
> +		return errno > 0 ? -errno : -EINVAL;
> +
> +	if ((long)(int)l != l)
> +		return -ERANGE;
> +
> +	*ret_i = (int)l;
> +
> +	return 0;
> +}
> +
> +/*
> + * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
> + */
> +static int get_prefix(const char *ip_str, int is_ipv6)
> +{
> +	char *prefix_str = NULL;
> +	int prefix = -1, r;
> +
> +	prefix_str = strchr(ip_str, '/');
> +	if (!prefix_str)
> +		return -1;
> +
> +	*(prefix_str++) = '\0';
> +
> +	if (!is_ipv6 && strchr(prefix_str, '.'))
> +		prefix = ipv4_mask_to_int(prefix_str);
> +	else {
> +		r = safe_atoi(prefix_str, &prefix);
> +		if (r != 0)
> +			tst_brk(TBROK, "conversion error");
> +	}
> +
> +	if (prefix < 0 || ((is_ipv6 && prefix > MAX_IPV6_PREFIX) ||
> +		(!is_ipv6 && prefix > MAX_IPV4_PREFIX)))
> +		tst_brk(TBROK, "bad %s prefix: %s", is_ipv6 ? "IPv6" : "IPv4",
> +			prefix_str);
> +
> +	return prefix;
> +}
> diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
> index 522889bed..f36ed99fa 100644
> --- a/testcases/lib/.gitignore
> +++ b/testcases/lib/.gitignore
> @@ -4,3 +4,6 @@
>  /tst_rod
>  /tst_kvcmp
>  /tst_device
> +/tst_net_iface_prefix
> +/tst_net_ip_prefix
> +/tst_net_vars
> diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
> index 1127a59fe..398150ae0 100644
> --- a/testcases/lib/Makefile
> +++ b/testcases/lib/Makefile
> @@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk
>  INSTALL_TARGETS		:= *.sh
>  
>  MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
> -			   tst_device
> +			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars
>  
>  include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/lib/tst_net_iface_prefix.c b/testcases/lib/tst_net_iface_prefix.c
> new file mode 100644
> index 000000000..7a90b1d9e
> --- /dev/null
> +++ b/testcases/lib/tst_net_iface_prefix.c
> @@ -0,0 +1,173 @@
> +/*
> + * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/rtnetlink.h>
> +#include <net/if.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +#include "tst_net.h"
> +
> +typedef struct data {
> +	char *ifname;
> +	int prefix;
> +} data;
> +
> +static data vars;
> +
> +static void usage(const char *cmd)
> +{
> +	fprintf(stderr, "USAGE:\n"
> +		"%s IPV4_LHOST/IPV4_LPREFIX\n"
> +		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"
> +		"%s IPV6_LHOST/IPV6_LPREFIX\n"
> +		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
> +		"%s IPV4_LHOST\n"
> +		"%s -r IPV4_RHOST\n\n"
> +		"%s IPV6_LHOST\n"
> +		"%s -r IPV6_RHOST\n\n"
> +		"%s -h\n\n"
> +		"Set prefix and interface name for given IP.\n"
> +		"Tries to find prefix and interface from kernel exported info (rtnetlink).\n\n"
> +		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"
> +		"EXPORTED VARIABLES:\n"
> +		"Export one of following variables:\n"
> +		"Export one of following variables:\n"
> +		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
> +		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK\n"
> +		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
> +		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK\n"
> +		"Export one of following variables (if found):\n"
> +		"LHOST_IFACES: iface name of the local host (*)\n"
> +		"RHOST_IFACES: iface name of the remote host (*)\n\n"
> +		"(*): respect user settings\n"
> +		"Iface (LHOST_IFACES, RHOST_IFACES) as user might want to use more ifaces.\n\n"
> +		"PARAMS:\n"
> +		"-h this help\n"
> +		"-r export remote environment variables\n",
> +		cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd);
> +}
> +
> +static int read_iface_prefix(const char *ip_str, int is_ipv6)
> +{
> +	uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;
> +
> +	char buf[16384];
> +	int len;
> +
> +	struct {
> +		struct nlmsghdr nlhdr;
> +		struct ifaddrmsg addrmsg;
> +	} msg;
> +
> +	struct nlmsghdr *retmsg;
> +
> +	int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
> +
> +	memset(&msg, 0, sizeof(msg));
> +	msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
> +	msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
> +	msg.nlhdr.nlmsg_type = RTM_GETADDR;
> +	msg.addrmsg.ifa_family = family;
> +
> +	send(sock, &msg, msg.nlhdr.nlmsg_len, 0);
> +	len = recv(sock, buf, sizeof(buf), 0);
> +	retmsg = (struct nlmsghdr *)buf;
> +
> +	while NLMSG_OK(retmsg, len) {
> +		char ifname[IFNAMSIZ];
> +		struct ifaddrmsg *retaddr;
> +		struct rtattr *retrta;
> +		char pradd[128];
> +		int attlen;
> +
> +		retaddr = (struct ifaddrmsg *)NLMSG_DATA(retmsg);
> +		retrta = (struct rtattr *)IFA_RTA(retaddr);
> +		attlen = IFA_PAYLOAD(retmsg);
> +
> +		while RTA_OK(retrta, attlen) {
> +			if (retrta->rta_type == IFA_ADDRESS) {
> +				inet_ntop(family, RTA_DATA(retrta), pradd,
> +					  sizeof(pradd));
> +
> +				if_indextoname(retaddr->ifa_index, ifname);
> +
> +				if (!strcmp(pradd, ip_str)) {
> +					vars.prefix = retaddr->ifa_prefixlen;
> +					vars.ifname = strdup(ifname);
> +					return 0;
> +				}
> +			}
> +			retrta = RTA_NEXT(retrta, attlen);
> +
> +		}
> +		retmsg = NLMSG_NEXT(retmsg, len);
> +	}
> +
> +	return -1;
> +}
> +
> +static void print_ivar(const char *name, unsigned int val)
> +{
> +	if (name)
> +		printf("export %s=%d\n", name, val);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	char *ip_str = NULL, *prefix_str = NULL;
> +	int is_ipv6, is_rhost = 0;
> +
> +	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
> +		!strcmp(argv[1], "--help"));
> +	if (argc < 2 || is_usage) {
> +		usage(argv[0]);
> +		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
> +	}
> +	if (!strcmp(argv[1], "-r"))
> +		is_rhost = 1;
> +
> +	ip_str = argv[is_rhost ? 2 : 1];
> +	is_ipv6 = !!strchr(ip_str, ':');
> +
> +	prefix_str = strchr(ip_str, '/');
> +	if (prefix_str) {
> +		vars.prefix = get_prefix(ip_str, is_ipv6);
> +		tst_res_comment(TINFO,
> +			"IP address '%s' contains prefix %d, using it and don't search for iface.\n",
> +			ip_str, vars.prefix);
> +	} else if (read_iface_prefix(ip_str, is_ipv6)) {
> +		tst_res_comment(TINFO,
> +			"prefix and interface not found for '%s'.\n", ip_str);
> +		exit(EXIT_SUCCESS);
> +	}
> +
> +	if (is_ipv6) {
> +		print_svar_change("LHOST_IFACES", vars.ifname);
> +		print_ivar(is_rhost ? "IPV6_RPREFIX" : "IPV6_LPREFIX",
> +			vars.prefix);
> +	} else {
> +		print_svar_change("RHOST_IFACES", vars.ifname);
> +		print_ivar(is_rhost ? "IPV4_RPREFIX" : "IPV4_LPREFIX",
> +			vars.prefix);
> +	}
> +
> +	exit(EXIT_SUCCESS);
> +}
> diff --git a/testcases/lib/tst_net_ip_prefix.c b/testcases/lib/tst_net_ip_prefix.c
> new file mode 100644
> index 000000000..19a3929bb
> --- /dev/null
> +++ b/testcases/lib/tst_net_ip_prefix.c
> @@ -0,0 +1,116 @@
> +/*
> + * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/rtnetlink.h>
> +#include <net/if.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +#include "tst_net.h"
> +
> +#define DEFAULT_IPV4_PREFIX 24
> +#define DEFAULT_IPV6_PREFIX 64
> +
> +typedef struct data {
> +	int prefix;
> +} data;
> +
> +static data vars;
> +
> +static void usage(const char *cmd)
> +{
> +	fprintf(stderr, "USAGE:\n"
> +		"%s IPV4_LHOST/IPV4_LPREFIX\n"
> +		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"
> +		"%s IPV6_LHOST/IPV6_LPREFIX\n"
> +		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
> +		"%s IPV4_LHOST\n"
> +		"%s -r IPV4_RHOST\n\n"
> +		"%s IPV6_LHOST\n"
> +		"%s -r IPV6_RHOST\n\n"
> +		"%s -h\n\n"
> +		"Set IP without prefix and prefix for given IP.\n"
> +		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"
> +		"EXPORTED VARIABLES:\n"
> +		"Export one of following variables:\n"
> +		"IPV4_LHOST: IPv4 address of the local host (without /prefix)\n"
> +		"IPV4_RHOST: IPv4 address of the remote host (without /prefix)\n"
> +		"IPV6_LHOST: IPv6 address of the local host (without /prefix)\n"
> +		"IPV6_RHOST: IPv6 address of the remote host (without /prefix)\n"
> +		"Export one of following variables:\n"
> +		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
> +		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK\n"
> +		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
> +		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK\n"
> +		"Export one of following variables (if found):\n"
> +		"Default IPv4 prefix: %d.\n"
> +		"Default IPv6 prefix: %d.\n\n"
> +		"PARAMS:\n"
> +		"-h this help\n"
> +		"-r export remote environment variables\n",
> +		cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd,
> +		DEFAULT_IPV4_PREFIX, DEFAULT_IPV6_PREFIX);
> +}
> +
> +static void print_ivar(const char *name, unsigned int val)
> +{
> +	if (name)
> +		printf("export %s=%d\n", name, val);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	char *ip_str = NULL, *prefix_str = NULL;
> +	int is_ipv6, is_rhost = 0;
> +
> +	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
> +		!strcmp(argv[1], "--help"));
> +	if (argc < 2 || is_usage) {
> +		usage(argv[0]);
> +		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
> +	}
> +	if (!strcmp(argv[1], "-r"))
> +		is_rhost = 1;
> +
> +	ip_str = argv[is_rhost ? 2 : 1];
> +	is_ipv6 = !!strchr(ip_str, ':');
> +
> +	prefix_str = strchr(ip_str, '/');
> +	if (prefix_str)
> +		vars.prefix = get_prefix(ip_str, is_ipv6);
> +	else {
> +		vars.prefix = is_ipv6 ? DEFAULT_IPV6_PREFIX : DEFAULT_IPV4_PREFIX;
> +		tst_res_comment(TBROK,
> +				"prefix and interface not found for '%s'. Using default value %d.\n",
> +				ip_str, vars.prefix);

The message is misleading, after tst_net_ip_prefix the script
callstst_net_iface_prefix.So better remove it, looks like
it will be printed every time if you relies on auto configuration.


> +	}
> +
> +	if (is_ipv6) {
> +		print_ivar(is_rhost ? "IPV6_RPREFIX" : "IPV6_LPREFIX",
> +			vars.prefix);
> +		print_svar(is_rhost ? "IPV6_RHOST" : "IPV6_LHOST", ip_str);
> +	} else {
> +		print_ivar(is_rhost ? "IPV4_RPREFIX" : "IPV4_LPREFIX",
> +			vars.prefix);
> +		print_svar(is_rhost ? "IPV4_RHOST" : "IPV4_LHOST", ip_str);
> +	}
> +
> +	exit(EXIT_SUCCESS);
> +}
> diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
> new file mode 100644
> index 000000000..a4b58951c
> --- /dev/null
> +++ b/testcases/lib/tst_net_vars.c
> @@ -0,0 +1,655 @@
> +/*
> + * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
> + * Copyright (c) 1997-2015 Red Hat, Inc. All rights reserved.
> + * Copyright (c) 2011-2013 Rich Felker, et al.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <arpa/inet.h>
> +#include <arpa/nameser.h>
> +#include <assert.h>
> +#include <errno.h>
> +#include <linux/rtnetlink.h>
> +#include <net/if.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <time.h>
> +#include <stdarg.h>
> +
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +#include "tst_net.h"
> +
> +#define BASE_IPV4_PREFIX 8
> +#define BASE_IPV6_PREFIX 16
> +
> +#define MAX_IPV4_PREFIX 32
> +#define MAX_IPV6_PREFIX 128
> +
> +#define DEFAULT_IPV4_UNUSED_PART1 10
> +#define DEFAULT_IPV6_UNUSED_PART1 0xfd
> +
> +#define DEFAULT_IPV4_UNUSED_PART2 23
> +#define DEFAULT_IPV6_UNUSED_PART2 0x23
> +
> +typedef struct ltp_net_variables {
> +	char *ipv4_lhost;
> +	char *ipv4_rhost;
> +	char *ipv4_lbroadcast;
> +	char *ipv4_rbroadcast;
> +	char *ipv4_lnetmask;
> +	char *ipv4_rnetmask;
> +	char *ipv4_lnetwork;
> +	char *ipv4_rnetwork;
> +	char *lhost_ipv4_host;
> +	char *rhost_ipv4_host;
> +	char *ipv6_lhost;
> +	char *ipv6_rhost;
> +	char *ipv6_lnetmask;
> +	char *ipv6_rnetmask;
> +	char *ipv6_lnetwork;
> +	char *ipv6_rnetwork;
> +	char *lhost_ipv6_host;
> +	char *rhost_ipv6_host;
> +	char *ipv4_net16_unused;
> +	char *ipv6_net32_unused;
> +	char *lhost_ifaces;
> +} ltp_net_variables;
> +
> +
> +static ltp_net_variables vars;
> +
> +static void usage(const char *cmd)
> +{
> +	fprintf(stderr, "USAGE:\n"
> +		"%s IPV4_LHOST/IPV4_LPREFIX IPV4_RHOST/IPV4_RPREFIX\n"
> +		"%s IPV6_LHOST/IPV6_LPREFIX IPV6_RHOST/IPV6_RPREFIX\n\n"
> +		"%s IPV4_LHOST IPV4_RHOST\n"
> +		"%s IPV6_LHOST IPV6_RHOST\n"
> +		"%s -h\n\n"
> +		"IP addresses must be different\n"
> +		"Exported variables:\n"
> +		"IPV4_LHOST: IPv4 address of the local host (1st parameter)\n"
> +		"IPV4_RHOST: IPv4 address of the remote host (2nd parameter)\n"
> +		"IPV4_LBROADCAST: IPv4 broadcast of the local host\n"
> +		"IPV4_RBROADCAST: IPv4 broadcast of the remote host\n"
> +		"IPV4_LNETMASK: IPv4 netmask of the local host\n"
> +		"IPV4_RNETMASK: IPv4 netmask of the remote host\n"
> +		"IPV4_LNETWORK: IPv4 network part of IPV4_LHOST\n"
> +		"IPV4_RNETWORK: IPv4 network part of IPV4_RHOST\n"
> +		"LHOST_IPV4_HOST IPv4 host part of IPV4_LHOST\n"
> +		"RHOST_IPV4_HOST IPv4 host part of IPV4_RHOST\n"
> +		"IPV4_NET16_UNUSED: IPv4 16 bit unused subnet\n"
> +		"IPV6_LHOST: IPv6 address of the local host (1st parameter)\n"
> +		"IPV6_RHOST: IPv6 address of the remote host (2nd parameter)\n"
> +		"IPV6_LNETMASK: IPv6 netmask of the local host\n"
> +		"IPV6_RNETMASK: IPv6 netmask of the remote host (*)\n"
> +		"IPV6_LNETWORK: IPv6 network part of IPV6_LHOST\n"
> +		"IPV6_RNETWORK: IPv6 network part of IPV6_LHOST\n"
> +		"LHOST_IPV6_HOST: IPv6 unique part of IPV6_LHOST\n"
> +		"RHOST_IPV6_HOST: IPv6 unique part of IPV6_RHOST\n"
> +		"IPV6_NET32_UNUSED: IPv6 32 bit unused subnet\n"
> +		"(*): respect user settings:\n"
> +		"NOTE: Prefixes, ifaces and lhosts are expected to be set by tst_net_iface_prefix.\n"
> +		"OPTIONS:\n"
> +		"-h this help\n",
> +		cmd, cmd, cmd, cmd, cmd);
> +}
> +
> +static void get_in_addr(const char *ip_str, struct in_addr *ip)
> +{
> +	if (inet_pton(AF_INET, ip_str, ip) <= 0)
> +		tst_brk_comment(TCONF, "bad IPv4 address: '%s'", ip_str);
> +}
> +
> +static void get_in6_addr(const char *ip_str, struct in6_addr *ip6)
> +{
> +	if (inet_pton(AF_INET6, ip_str, ip6) <= 0)
> +		tst_brk_comment(TCONF, "bad IPv6 address: '%s'", ip_str);
> +}
> +
> +/*
> + * Function prefix2mask is from ipcalc project, ipcalc.c.
> + */
> +static struct in_addr prefix2mask(unsigned int prefix)
> +{
> +	struct in_addr mask = {0};
> +
> +	if (prefix)
> +		mask.s_addr = htonl(~((1 << (32 - prefix)) - 1));
> +	else
> +		mask.s_addr = htonl(0);
> +
> +	return mask;
> +}
> +
> +/*
> + * Function calc_network is based on ipcalc project,
> + * calc_network/ipcalc.c.
> + */
> +static struct in_addr calc_network(const struct in_addr *ip, struct in_addr *mask)
> +{
> +	struct in_addr network = {0};
> +
> +	network.s_addr = ip->s_addr & mask->s_addr;
> +	return network;
> +}
> +
> +static int is_in_subnet_ipv4(const struct in_addr *network,
> +	const struct in_addr *mask, const struct in_addr *ip)
> +{
> +	return (ip->s_addr & mask->s_addr) ==
> +		(network->s_addr & mask->s_addr);
> +}
> +
> +static int is_in_subnet_ipv6(const struct in6_addr *network,
> +	const struct in6_addr *mask, const struct in6_addr *ip6)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < sizeof(struct in6_addr) / sizeof(int); i++) {
> +		if (((((int *) ip6)[i] & ((int *) mask)[i])) !=
> +			(((int *) network)[i] & ((int *) mask)[i]))
> +			return 0;
> +	}
> +	return 1;
> +}
> +
> +/*
> + * Function get_ipv4_netmask uses code from calc_network, which is from
> + * ipcalc project, ipcalc.c.
> + */
> +static char *get_ipv4_netmask(unsigned int prefix)
> +{
> +	char buf[INET_ADDRSTRLEN + 1];
> +	struct in_addr mask = prefix2mask(prefix);
> +
> +	if (prefix > MAX_IPV4_PREFIX)
> +		return NULL;
> +
> +	if (!inet_ntop(AF_INET, &mask, buf, sizeof(buf)))
> +		tst_brk_comment(TCONF, "error calculating IPv4 address");
> +
> +	return strdup(buf);
> +}
> +
> +/*
> + * Function get_ipv4_netmask uses code from ipv6_prefix_to_mask and
> + * ipv6_mask_to_str, which are from ipcalc project, ipcalc.c.
> + */
> +static char *get_ipv6_netmask(unsigned int prefix)
> +{
> +	struct in6_addr in6;
> +	char buf[128];
> +	int i, j;
> +
> +	if (prefix > MAX_IPV6_PREFIX)
> +		return NULL;
> +
> +	memset(&in6, 0x0, sizeof(in6));
> +	for (i = prefix, j = 0; i > 0; i -= 8, j++) {
> +		if (i >= 8)
> +			in6.s6_addr[j] = 0xff;
> +		else
> +			in6.s6_addr[j] = (unsigned long)(0xffU << (8 - i));
> +	}
> +
> +	if (!inet_ntop(AF_INET6, &in6, buf, sizeof(buf)))
> +		tst_brk_comment(TCONF, "error calculating IPv6 address");
> +
> +	return strdup(buf);
> +}
> +
> +/*
> + * Function get_ipv4_broadcast uses code from calc_broadcast, which is from
> + * ipcalc project, ipcalc.c.
> + */
> +static char *get_ipv4_broadcast(struct in_addr ip, unsigned int prefix)
> +{
> +	struct in_addr mask = prefix2mask(prefix);
> +	struct in_addr broadcast;
> +	char buf[INET_ADDRSTRLEN + 1];
> +
> +	memset(&broadcast, 0, sizeof(broadcast));
> +	broadcast.s_addr = (ip.s_addr & mask.s_addr) | ~mask.s_addr;
> +
> +	if (!inet_ntop(AF_INET, &broadcast, buf, sizeof(buf)))
> +		tst_brk_comment(TCONF, "error calculating IPv4 address");
> +
> +	return strdup(buf);
> +}
> +
> +/*
> + * For unused network we use
> + * DEFAULT_IPV4_UNUSED_PART1:DEFAULT_IPV4_UNUSED_PART2 or
> + * {DEFAULT_IPV4_UNUSED_PART1}.XY, when there is a collision with IP.
> + */
> +static char *get_ipv4_net16_unused(const struct in_addr *ip,
> +	unsigned int prefix)
> +{
> +	struct in_addr mask, network;
> +	char buf[128], net_unused[128];
> +
> +	mask = prefix2mask(prefix);
> +	network = calc_network(ip, &mask);
> +
> +	sprintf(net_unused, "%d.%d", DEFAULT_IPV4_UNUSED_PART1,
> +			DEFAULT_IPV4_UNUSED_PART2);
> +	sprintf(buf, "%s.0.0", net_unused);
> +
> +	get_in_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv4(ip, &mask, &network))
> +		return strdup(net_unused);
> +
> +	srand(time(NULL));
> +
> +	/* try to randomize second group */
> +	sprintf(net_unused, "%d.%d", DEFAULT_IPV4_UNUSED_PART1,
> +		(rand() % 128) + (((ip->s_addr >> 8) & 0xff) < 128 ? 128 : 0));
> +	sprintf(buf, "%s.0.0", net_unused);
> +
> +	get_in_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv4(ip, &mask, &network))
> +		return strdup(net_unused);
> +
> +	/* try to randomize first group */
> +	sprintf(net_unused, "%d.%d", (rand() % 128) + (((ip->s_addr) & 0xff)
> +			< 128 ? 128 : 0), DEFAULT_IPV4_UNUSED_PART2);
> +	sprintf(buf, "%s.0.0", net_unused);
> +
> +	get_in_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv4(ip, &mask, &network))
> +		return strdup(net_unused);
> +
> +	return NULL;
> +}
> +
> +/*
> + * Function get_ipv6_net32_unused is inspired by ipcalc project,
> + * get_ipv6_info/ipcalc.c.
> + *
> + * For unused network we use DEFAULT_IPV6_UNUSED_PART1:DEFAULT_IPV6_UNUSED_PART2
> + * if no collision with existing IP range.
> + * Otherwise we try to use
> + * {DEFAULT_IPV6_UNUSED_PART1}XY:DEFAULT_IPV6_UNUSED_PART2 or
> + * XY:DEFAULT_IPV6_UNUSED_PART2.
> + */
> +static char *get_ipv6_net32_unused(const struct in6_addr *ip6,
> +	unsigned int prefix)
> +{
> +	int i, j;
> +	struct in6_addr mask = {0}, network;
> +	char buf[128], net_unused[128];
> +
> +	if (prefix > 128)
> +		return NULL;
> +
> +
> +	for (i = prefix, j = 0; i > 0; i -= 8, j++) {
> +		if (i >= 8)
> +			mask.s6_addr[j] = 0xff;
> +		else
> +			mask.s6_addr[j] = (unsigned long)(0xffU << (8 - i));
> +	}
> +
> +	sprintf(net_unused, "%x:%x", 256 * DEFAULT_IPV6_UNUSED_PART1,
> +			DEFAULT_IPV6_UNUSED_PART2);
> +	sprintf(buf, "%s::", net_unused);
> +
> +	get_in6_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv6(ip6, &mask, &network))
> +		return strdup(net_unused);
> +
> +	srand(time(NULL));
> +
> +	/* try to randomize second group */
> +	sprintf(net_unused, "%x:%x", 256 * DEFAULT_IPV6_UNUSED_PART1 +
> +			(rand() % 128) + (ip6->s6_addr[1] < 128 ? 128 : 0),
> +			DEFAULT_IPV6_UNUSED_PART2);
> +	sprintf(buf, "%s::", net_unused);
> +
> +	get_in6_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv6(ip6, &mask, &network))
> +		return strdup(net_unused);
> +
> +	/* try to randomize first group */
> +	sprintf(net_unused, "%x:%x",
> +			256 * (rand() % 128) + (256 * ip6->s6_addr[0] < 128 ?
> +			128 : 0), DEFAULT_IPV6_UNUSED_PART2);
> +	sprintf(buf, "%s::", net_unused);
> +
> +	get_in6_addr(buf, &network);
> +
> +	if (!is_in_subnet_ipv6(ip6, &mask, &network))
> +		return strdup(net_unused);
> +
> +	return NULL;
> +}
> +
> +/*
> + * Function get_ipv6_network is based on musl libc project,
> + * inet_ntop/inet_ntop.c.
> + */
> +static char *get_ipv6_network(const unsigned char *a0, unsigned int prefix)
> +{
> +	const unsigned char *a = a0;
> +	unsigned int i, j, max, best, border = 0;
> +	char buf[100];
> +	char ret[100];
> +	char tmp[100];
> +	char *p_ret = ret;
> +	char *p_tmp = tmp;
> +	size_t offset;
> +
> +	if (prefix > MAX_IPV6_PREFIX)
> +		return NULL;
> +
> +	if (prefix == MAX_IPV6_PREFIX)
> +		return strdup("\0");
> +
> +	snprintf(buf, sizeof(buf),
> +		"%x:%x:%x:%x:%x:%x:%x:%x",
> +		256 * a[0] + a[1], 256 * a[2] + a[3],
> +		256 * a[4] + a[5], 256 * a[6] + a[7],
> +		256 * a[8] + a[9], 256 * a[10] + a[11],
> +		256 * a[12] + a[13], 256 * a[14] + a[15]);
> +
> +	for (i = 0; i < 8; i++) {
> +		if (i < prefix >> 4) {
> +			border += sprintf(p_tmp, "%x", 256 * a[2 * i] +
> +				a[2 * i + 1]);
> +			if (i > 0)
> +				border++;
> +		}
> +
> +		if (i >= prefix >> 4)
> +			break;
> +
> +		/* ':' only if no leading in host or ending in net */
> +		if (i > 0)
> +			*p_ret++ = ':';
> +
> +		offset = sprintf(p_ret, "%x", 256 * a[2 * i] + a[2 * i + 1]);
> +		p_ret += offset;
> +	}
> +
> +	*p_ret = '\0';
> +
> +	/* Find longest /(^0|:)[:0]{2,}/ */
> +	for (i = best = 0, max = 2; buf[i]; i++) {
> +		if (i && buf[i] != ':')
> +			continue;
> +		j = strspn(buf + i, ":0");
> +
> +		if (j > max)
> +			best = i, max = j;
> +	}
> +
> +	size_t length = strlen(ret);
> +	size_t best_end = best + max - 1;
> +
> +	if (max > 2 && best < border) {
> +		p_ret = ret;
> +		/* Replace longest /(^0|:)[:0]{2,}/ with "::" */
> +		if (best == 0 && best_end >= border) {
> +			/* zeros in whole net part or continue to host */
> +			ret[0] = ':';
> +			ret[1] = '\0';
> +		} else if (best == 0 && best_end < border) {
> +			/* zeros on beginning, not whole part */
> +			ret[0] = ':';
> +			memmove(p_ret + 1, p_ret + best_end, border - best_end
> +				+ 1);
> +		} else if (best > 0 && best_end >= border) {
> +			/* zeros not from beginning to border or continue to host */
> +			ret[best] = ':';
> +			ret[best + 1] = '\0';
> +		} else {
> +			/* zeros somewhere in the middle */
> +			ret[best] = ':';
> +			memmove(p_ret + best + 1, p_ret + best_end,
> +					border - best + 1);
> +		}
> +	}
> +
> +	if (length < INET6_ADDRSTRLEN)
> +		return strdup(ret);
> +
> +	return NULL;
> +}
> +
> +/*
> + * Strip host part from ip address.
> + */
> +static char *get_host_from_ip(const char *ip, const char *net)
> +{
> +	if (ip == NULL || net == NULL)
> +		return NULL;
> +
> +	char *result = strstr(ip, net);
> +
> +	if (!result || result != ip)
> +		return NULL;
> +
> +	char *buf = strdup(ip);
> +	unsigned int index = strlen(net);
> +
> +	/* prefix < 8 (IPv4) or 128 (IPv6) */
> +	if (index == strlen(ip))
> +		return strdup("\0");
> +
> +	/* prefix > 0 && prefix < 32 (IPv4) or 128 (IPv6) */
> +	if (index > 0 && index < strlen(ip)) {
> +		int len = strlen(ip) - index - 1;
> +		assert(ip[index] == ':' || ip[index] == '.');
> +		memmove(buf, buf + index + 1, len);
> +		buf[len] = '\0';
> +	}
> +
> +	return buf;
> +}
> +
> +static void check_prefix_range(unsigned int prefix, int is_ipv6, int is_lhost)
> +{
> +	unsigned int base_prefix = is_ipv6 ? BASE_IPV6_PREFIX :
> +		BASE_IPV4_PREFIX;
> +	unsigned int max_prefix = is_ipv6 ? MAX_IPV6_PREFIX : MAX_IPV4_PREFIX;
> +
> +	if (prefix < base_prefix || (is_ipv6 && prefix == 128) ||
> +		(!is_ipv6 && prefix == 32))
> +		tst_res_comment(TWARN,
> +			"prefix %d for %s will be unsuitable for some stress tests which needs %s variable."
> +			" To avoid this use prefix >= %d and prefix < %d.",
> +			prefix, is_ipv6 ?  "IPv6" : "IPv4",
> +			is_ipv6 ? (is_lhost ? "IPV6_LNETWORK" : "IPV6_RNETWORK")
> +				: (is_lhost ? "IPV4_LNETWORK" : "IPV4_RNETWORK"),
> +			base_prefix, max_prefix);
> +}
> +
> +static char *get_ipv4_network(int ip, unsigned int prefix)
> +{
> +	char buf[INET_ADDRSTRLEN + 1];
> +	char *p_buf = buf;
> +	unsigned char byte;
> +	unsigned int i;
> +
> +	if (prefix > MAX_IPV4_PREFIX)
> +		return NULL;
> +
> +	if (prefix == MAX_IPV4_PREFIX)
> +		return strdup("\0");
> +
> +	prefix &= 0x18;
> +
> +	for (i = 0; i < MAX_IPV4_PREFIX && (prefix == 0 || i < prefix); i += 8) {
> +		if (i == 0) {
> +			byte = ip & 0xff;
> +			sprintf(p_buf, "%d", byte);
> +		} else {
> +			byte = (ip >> i) & 0xff;
> +			sprintf(p_buf, ".%d", byte);
> +		}
> +		p_buf += strlen(p_buf);
> +	}
> +
> +	return strdup(buf);
> +}
> +
> +/*
> + * Round down prefix.
> + */
> +static int round_down_prefix(unsigned int prefix, int is_ipv6)
> +{
> +	unsigned int base_prefix = is_ipv6 ? BASE_IPV6_PREFIX :
> +		BASE_IPV4_PREFIX;
> +
> +	return prefix / base_prefix * base_prefix;
> +}
> +
> +static void get_ipv4_info(const char *lip_str, const char *rip_str, int lprefix,
> +	int rprefix)
> +{
> +	struct in_addr lip, rip;
> +	int lprefix_round, rprefix_round;
> +
> +	lprefix_round = round_down_prefix(lprefix, 0);
> +	rprefix_round = round_down_prefix(rprefix, 0);
> +
> +	get_in_addr(lip_str, &lip);
> +	get_in_addr(rip_str, &rip);
> +
> +	vars.ipv4_lhost = strdup(lip_str);
> +	vars.ipv4_rhost = strdup(rip_str);
> +
> +	vars.ipv4_lbroadcast = get_ipv4_broadcast(lip, lprefix);
> +	vars.ipv4_rbroadcast = get_ipv4_broadcast(rip, rprefix);
> +
> +	vars.ipv4_lnetmask = get_ipv4_netmask(lprefix);
> +	vars.ipv4_rnetmask = get_ipv4_netmask(rprefix);
> +
> +	vars.ipv4_lnetwork = get_ipv4_network(lip.s_addr, lprefix_round);
> +	vars.ipv4_rnetwork = get_ipv4_network(rip.s_addr, rprefix_round);
> +
> +	vars.lhost_ipv4_host = get_host_from_ip(lip_str, vars.ipv4_lnetwork);
> +	vars.rhost_ipv4_host = get_host_from_ip(rip_str, vars.ipv4_rnetwork);
> +
> +	vars.ipv4_net16_unused = get_ipv4_net16_unused(&lip, lprefix_round);
> +}
> +
> +static void get_ipv6_info(const char *lip_str, const char *rip_str,
> +	int lprefix, int rprefix)
> +{
> +	struct in6_addr lip, rip;
> +	int lprefix_round, rprefix_round;
> +
> +	lprefix_round = round_down_prefix(lprefix, 1);
> +	rprefix_round = round_down_prefix(rprefix, 1);
> +
> +	get_in6_addr(lip_str, &lip);
> +	get_in6_addr(rip_str, &rip);
> +
> +	vars.ipv6_lhost = strdup(lip_str);
> +	vars.ipv6_rhost = strdup(rip_str);
> +
> +	vars.ipv6_lnetmask = get_ipv6_netmask(lprefix);
> +	vars.ipv6_rnetmask = get_ipv6_netmask(rprefix);
> +
> +	vars.ipv6_lnetwork = get_ipv6_network(lip.s6_addr, lprefix_round);
> +	vars.ipv6_rnetwork = get_ipv6_network(rip.s6_addr, rprefix_round);
> +
> +	vars.lhost_ipv6_host = get_host_from_ip(lip_str, vars.ipv6_lnetwork);
> +	vars.rhost_ipv6_host = get_host_from_ip(rip_str, vars.ipv6_rnetwork);
> +
> +	vars.ipv6_net32_unused = get_ipv6_net32_unused(&lip, lprefix_round);
> +}
> +
> +static void print_vars(int is_ipv6)
> +{
> +	if (is_ipv6) {
> +		print_svar("IPV6_LHOST", vars.ipv6_lhost);
> +		print_svar("IPV6_RHOST", vars.ipv6_rhost);

It is already done by tst_net_ip_prefix

> +		print_svar("IPV6_LNETMASK", vars.ipv6_lnetmask);
> +		print_svar_change("IPV6_RNETMASK", vars.ipv6_rnetmask);
> +		print_svar("IPV6_LNETWORK", vars.ipv6_lnetwork);
> +		print_svar("IPV6_RNETWORK", vars.ipv6_rnetwork);
> +		print_svar("LHOST_IPV6_HOST", vars.lhost_ipv6_host);
> +		print_svar("RHOST_IPV6_HOST", vars.rhost_ipv6_host);
> +		print_svar("IPV6_NET32_UNUSED", vars.ipv6_net32_unused);
> +	} else {
> +		print_svar("IPV4_LHOST", vars.ipv4_lhost);
> +		print_svar("IPV4_RHOST", vars.ipv4_rhost);

Here the same.

> +		print_svar("IPV4_LBROADCAST", vars.ipv4_lbroadcast);
> +		print_svar_change("IPV4_RBROADCAST", vars.ipv4_rbroadcast);
> +		print_svar("IPV4_LNETMASK", vars.ipv4_lnetmask);
> +		print_svar_change("IPV4_RNETMASK", vars.ipv4_rnetmask);
> +		print_svar("IPV4_LNETWORK", vars.ipv4_lnetwork);
> +		print_svar("IPV4_RNETWORK", vars.ipv4_rnetwork);
> +		print_svar("LHOST_IPV4_HOST", vars.lhost_ipv4_host);
> +		print_svar("RHOST_IPV4_HOST", vars.rhost_ipv4_host);
> +		print_svar("IPV4_NET16_UNUSED", vars.ipv4_net16_unused);
> +	}
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	char *lip_str = NULL, *rip_str = NULL;
> +	int is_ipv6, lprefix, rprefix;
> +
> +	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
> +		!strcmp(argv[1], "--help"));
> +	if (argc < 3 || is_usage) {
> +		usage(argv[0]);
> +		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
> +	}
> +
> +	lip_str = argv[1];
> +	rip_str = argv[2];
> +
> +	is_ipv6 = !!strchr(lip_str, ':');
> +	if (is_ipv6 != !(strchr(rip_str, ':') == NULL))
> +		tst_brk_comment(TBROK, "mixed IPv4 and IPv6 addresses");
> +
> +	lprefix = get_prefix(lip_str, is_ipv6);
> +	rprefix = get_prefix(rip_str, is_ipv6);
> +
> +	if (lprefix < 0)
> +		tst_brk_comment(TBROK, "wrong lprefix");
> +
> +	if (rprefix < 0)
> +		tst_brk_comment(TBROK, "wrong rprefix");
> +
> +	check_prefix_range(lprefix, is_ipv6, 1);
> +	check_prefix_range(rprefix, is_ipv6, 0);
> +
> +	if (!strcmp(lip_str, rip_str))
> +		tst_brk_comment(TBROK, "IP addresses cannot be the same");
> +
> +	if (is_ipv6)
> +		get_ipv6_info(lip_str, rip_str, lprefix, rprefix);
> +	else
> +		get_ipv4_info(lip_str, rip_str, lprefix, rprefix);
> +
> +	print_vars(is_ipv6);
> +
> +	exit(EXIT_SUCCESS);
> +}

Thanks,
Alexey

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

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

* [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-07-21  4:04 ` [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
@ 2017-07-26 15:32   ` Alexey Kodanev
  2017-07-27  9:03     ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-26 15:32 UTC (permalink / raw)
  To: ltp

On 21.07.2017 7:04, Petr Vorel wrote:
> Tools (tst_net_ip_prefix, tst_net_iface_prefix, tst_net_vars)
> simplify setup as it only needs to have passed 4 IP addresses
> (IPv4 lhost + rhost and IPv6 lhost + rhost).
>
> It's possible to define different network part for local
> and remote hosts.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/test_net.sh                          | 94 +++++++++++++++-------
>  testcases/network/stress/interface/if4-addr-change | 17 ++--
>  2 files changed, 75 insertions(+), 36 deletions(-)
>
> diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
> index cecb0bab2..95510f7cf 100644
> --- a/testcases/lib/test_net.sh
> +++ b/testcases/lib/test_net.sh
> @@ -230,19 +230,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
>  }
>  
> @@ -281,9 +272,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)
>  
> @@ -529,25 +524,58 @@ export PASSWD="${PASSWD:-}"
>  export LTP_RSH="${LTP_RSH:-rsh -n}"
>  
>  # Test Links
> -# Set first three octets of the network address, default is '10.0.0'
> -export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
> -# Set local host last octet, default is '2'
> -export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
> -# Set remote host last octet, default is '1'
> -export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
> -# Set the reverse of IPV4_NETWORK
> -export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
> -# Set first three octets of the network address, default is 'fd00:1:1:1'
> -export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
> -# Set local host last octet, default is '2'
> -export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
> -# Set remote host last octet, default is '1'
> -export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
> -
> -# Networks that aren't reachable through the test links
> -export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
> -export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
> +# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
> +# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
> +IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
> +IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
> +IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
> +IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
> +
> +# tst_net_ip_prefix
> +# Strip prefix from IP address and save both If no prefix found sets
> +# default prefix.
> +#
> +# tst_net_iface_prefix reads prefix and interface from rtnetlink.
> +# If nothing found sets default prefix value.
> +#
> +# tst_net_vars exports environment variables related to test links and
> +# networks that aren't reachable through the test links.
> +# Not run for netns (init_ltp_netspace is not called, no links setup yet).
> +#
> +# For full list of exported environment variables see:
> +# tst_net_ip_prefix -h
> +# tst_net_iface_prefix -h
> +# tst_net_vars -h
> +if [ -z "$TST_PARSE_VARIABLES" ]; then
> +	tst_resm TINFO "Parsing IP and prefixes"
> +	set -x

It might be useful just for debugging, please remove it.

> +	eval "$(tst_net_ip_prefix $IPV4_LHOST)" || exit $?

Not quite right, if you want to deal with the status of
tst_net_ip_prefix, you have to set 'exit' on error inside $(...)

eval "$(tst_net_ip_prefix $IPV4_LHOST || echo 'exit $?')"


> +	eval "$(tst_net_ip_prefix -r $IPV4_RHOST)" || exit $?
> +	eval "$(tst_net_ip_prefix $IPV6_LHOST)" || exit $?
> +	eval "$(tst_net_ip_prefix -r $IPV6_RHOST)" || exit $?
> +	set +x
> +
> +	if [ "$TST_USE_NETNS" != "yes" ]; then
> +		tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
> +		set -x
> +		eval "$(tst_net_iface_prefix $IPV4_LHOST)" || exit $?
> +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST)" || exit $?
> +		eval "$(tst_net_iface_prefix $IPV6_LHOST)" || exit $?
> +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST)" || exit $?
> +		set +x
> +	fi
>  

Why netns is not working in the above case or it's an optimization?

> +	tst_resm TINFO "Parsing all remaining variables"
> +	set -x
> +	eval "$(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX)" || exit $?
> +	eval "$(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX)" || exit $?
> +	set +x
> +
> +	export TST_PARSE_VARIABLES="yes"
> +fi
> +
> +# The rest of variables for networks that aren't reachable through the test links.
> +# IPV4_NET16_UNUSED and IPV6_NET32_UNUSED are set by tst_net_vars.
>  export OCTET_3_IPV4_UNUSED=${OCTET_3_IPV4_UNUSED:-23} # x.x.N.x
>  export OCTET_4_LHOST_IPV4_HOST_UNUSED=${OCTET_4_LHOST_IPV4_HOST_UNUSED:-2} # x.x.x.N
>  export OCTET_4_RHOST_IPV4_HOST_UNUSED=${OCTET_4_RHOST_IPV4_HOST_UNUSED:-1} # x.x.x.N
> @@ -564,6 +592,7 @@ export RHOST_IPV6_HOST_UNUSED="${OCTET_3_IPV6_UNUSED}:${OCTET_4_RHOST_IPV6_HOST_
>  export LHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$LHOST_IPV6_HOST_UNUSED"
>  export RHOST_IPV6_UNUSED="${IPV6_NET32_UNUSED}:$RHOST_IPV6_HOST_UNUSED"
>  
> +# Directories for http and ftp stress tests
>  export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
>  export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
>  export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
> @@ -589,8 +618,11 @@ export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
>  
>  # Warning: make sure to set valid interface names and IP addresses below.
>  # Set names for test interfaces, e.g. "eth0 eth1"
> +# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
> +# want to use more ifaces.
>  export LHOST_IFACES="${LHOST_IFACES:-eth0}"
>  export RHOST_IFACES="${RHOST_IFACES:-eth0}"
> +
>  # Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02"
>  export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}"
>  export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}"
> diff --git a/testcases/network/stress/interface/if4-addr-change b/testcases/network/stress/interface/if4-addr-change
> index 567f86643..a7469c252 100644
> --- a/testcases/network/stress/interface/if4-addr-change
> +++ b/testcases/network/stress/interface/if4-addr-change
> @@ -48,12 +48,19 @@ while [ $cnt -lt $NS_TIMES ]; do
>  
>  	[ $num -eq $RHOST_IPV4_HOST ] && continue
>  
> -	# Change IPv4 address
> -	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
> +	# check prefix and fix values for prefix != 24
> +	add_to_net=
> +	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
> +		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
> +	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
> +		add_to_net=".0.1"
> +	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
> +		add_to_net=".1"
> +	fi
>  
> -	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
> -		broadcast 255.255.255.255 || \
> -		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
> +	# Change IPv4 address
> +	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
> +		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
>  

Could you make a separate patch for this? It looks completely
unrelated to the rest in this patch.


Thanks,
Alexey

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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170726/2279d07f/attachment.html>

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

* [LTP] [RFC PATCH v7 08/11] network/stress: Fix and cleanup route IPv4 tests
  2017-07-26 14:58   ` Alexey Kodanev
@ 2017-07-26 23:29     ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-26 23:29 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > diff --git a/testcases/network/stress/ns-tools/initialize_if b/testcases/network/stress/ns-tools/initialize_if
...
> > -# Initialize the specified interface
> > -command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
> > -

> Again, why?
OK, I'll drop this part.
Why: I admit that this cleanup is unnecessary as initialize_if is deprecated I just didn't
consider cleaning initialize_if harmful (the script is still used).


> > +		# Down then up the interface
> > +		sh -c "$cmd_iface_down"

> Can be just $cmd_iface_down, or better ROD/EXPECT_PASS.
I'll have to split command into two, as only 'sh -c' can handle '&&' (and ROD_BASE doesn't
use 'sh -c')

> > +
> > +		tst_resm TINFO "adding first route"
> > +		ROD manipulate_route $cmd_name 'add' $first_route_net $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname

> Without 'ROD', in the new library it won't work with script functions,
> besides you have ROD on every command in that function already.
OK. I'm not sure, if it's best to have ROD inside manipulate_route, but I'll keep it for
simplicity.


> > +	while [ $cnt -lt $NS_TIMES ]; do
> > +		lhost_ifname2="$lhost_ifname"
> > +		gateway2="$gateway"
> > +
> > +		make_background_tcp_traffic $LHOST_IPV4_UNUSED
> > +
> > +		if [ "$test_field" = "dst" ]; then
> > +			dst_network_postfix="$(($cnt % 255))"
> > +			dst_addr="${IPV4_NET16_UNUSED}.${dst_network_postfix}.${DST_HOST}"
> > +			dst_network="${IPV4_NET16_UNUSED}.${dst_network_postfix}.0"
> > +		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_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${rhost_part}"
> > +			gateway2="${IPV4_NET16_UNUSED}.${OCTET_3_IPV4_UNUSED}.${pre_rhost_part}"
> > +		elif [ "$test_field" = "if" ]; then
> > +			link_num=$(($link_num + 1))
> > +			[ $link_num -ge $LINK_TOTAL ] && link_num=0
> > +			lhost_ifname="$(tst_iface lhost $link_num)"
> > +			gateway="${IPV4_NET16_UNUSED}.${link_num}.${RHOST_IPV4_HOST}"
> > +			rhost_ip="${IPV4_NET16_UNUSED}.${link_num}.${OCTET_4_RHOST_IPV4_HOST_UNUSED}"
> > +		fi
> > +
> > +		manipulate_route $cmd_name 'add' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway $lhost_ifname

> Looking at the original test-case, after new route added, the
> test tries to send a single UDP datagram in order to load it.
> But now all the tests have a background traffic on that
> interface and route not used, correct?
I intended to replace ns-udpsender with make_background_tcp_traffic call. But that
probably not covering the test scenario. But, even the code in ns-udpsender.c is very
simple I'm not sure if it's possible to do this replacement.
Generally, I'd like to get rid of these old C programs and use netstress as much as possible.

> > +		manipulate_route $cmd_name 'del' $dst_network $IPV4_NETMASK_NUM $IPV4_NETMASK $gateway2 $lhost_ifname2
> > +
> > +		check_connectivity_interval $cnt false $lhost_ifname $rhost_ip || return
> > +
> > +		cnt=$(($cnt + 1))
> > +	done
> > +

...
> > -    # Set the variables for destination network
> > -    dst_addr=${DST_NETWORK}.${DST_HOST}
> > -    dst_network=${DST_NETWORK}.0
> > +	route_setup
> > +	tst_check_cmds ethtool
> > +
> > +	tst_add_ipaddr_stress

> tst_add_ipaddr_stress() should be after all the checks. Also I doubt
> that we need to add a new address in every test. Could you check again
> if we really need it?
I'll do.

> > +		# Remove and reload the network driver
> > +		rmmod $lhost_module && modprobe $lhost_module

> ROD modprobe -r $module
> ROD modprobe $module
OK.


> > +		if [ $? -ne 0 ]; then
> > +			tst_resm TFAIL "failed to unload/reload the network driver '$lhost_module'"
> > +			return
> > +		fi
> > +		tst_sleep 100ms

> Are you sure we need sleep here?
Yes. It's because loading driver takes some time, test was failing without that.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables
  2017-07-26 15:17   ` Alexey Kodanev
@ 2017-07-27  8:35     ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-07-27  8:35 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> On 21.07.2017 7:04, Petr Vorel wrote:
> > New tools:
> > * tst_net_ip_prefix
> > Strip prefix from IP address and save both
> > If no prefix found sets default prefix.

> > * tst_net_iface_prefix
> > tst_net_iface_prefix reads prefix and interface from rtnetlink.

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

> Have you checked my comments for the previous version?
Sure :-). I've spent quite some time to think about that and test it, but of course I
might overlook something.
Anything particular you don't agree with?

...
> > +int main(int argc, char *argv[])
> > +{
> > +	char *ip_str = NULL, *prefix_str = NULL;
> > +	int is_ipv6, is_rhost = 0;
> > +
> > +	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
> > +		!strcmp(argv[1], "--help"));
> > +	if (argc < 2 || is_usage) {
> > +		usage(argv[0]);
> > +		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
> > +	}
> > +	if (!strcmp(argv[1], "-r"))
> > +		is_rhost = 1;
> > +
> > +	ip_str = argv[is_rhost ? 2 : 1];
> > +	is_ipv6 = !!strchr(ip_str, ':');
> > +
> > +	prefix_str = strchr(ip_str, '/');
> > +	if (prefix_str)
> > +		vars.prefix = get_prefix(ip_str, is_ipv6);
> > +	else {
> > +		vars.prefix = is_ipv6 ? DEFAULT_IPV6_PREFIX : DEFAULT_IPV4_PREFIX;
> > +		tst_res_comment(TBROK,
> > +				"prefix and interface not found for '%s'. Using default value %d.\n",
> > +				ip_str, vars.prefix);

> The message is misleading, after tst_net_ip_prefix the script
> calls tst_net_iface_prefix.So better remove it, looks like
> it will be printed every time if you relies on auto configuration.
OK.

...
> > +static void print_vars(int is_ipv6)
> > +{
> > +	if (is_ipv6) {
> > +		print_svar("IPV6_LHOST", vars.ipv6_lhost);
> > +		print_svar("IPV6_RHOST", vars.ipv6_rhost);

> It is already done by tst_net_ip_prefix
Oh, good catch, sorry.

> > +		print_svar("IPV6_LNETMASK", vars.ipv6_lnetmask);
> > +		print_svar_change("IPV6_RNETMASK", vars.ipv6_rnetmask);
> > +		print_svar("IPV6_LNETWORK", vars.ipv6_lnetwork);
> > +		print_svar("IPV6_RNETWORK", vars.ipv6_rnetwork);
> > +		print_svar("LHOST_IPV6_HOST", vars.lhost_ipv6_host);
> > +		print_svar("RHOST_IPV6_HOST", vars.rhost_ipv6_host);
> > +		print_svar("IPV6_NET32_UNUSED", vars.ipv6_net32_unused);
> > +	} else {
> > +		print_svar("IPV4_LHOST", vars.ipv4_lhost);
> > +		print_svar("IPV4_RHOST", vars.ipv4_rhost);

> Here the same.

Thanks for your review!

Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-07-26 15:32   ` Alexey Kodanev
@ 2017-07-27  9:03     ` Petr Vorel
  2017-07-31 16:53       ` Alexey Kodanev
  0 siblings, 1 reply; 36+ messages in thread
From: Petr Vorel @ 2017-07-27  9:03 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > +# For full list of exported environment variables see:
> > +# tst_net_ip_prefix -h
> > +# tst_net_iface_prefix -h
> > +# tst_net_vars -h
> > +if [ -z "$TST_PARSE_VARIABLES" ]; then
> > +	tst_resm TINFO "Parsing IP and prefixes"
> > +	set -x

> It might be useful just for debugging, please remove it.
OK, I'll remove it, because you don't like it. But I have to admit, I think it's important
to see values of automatic setup.
If user reports a bug/problem we have ver_linux, which is suitable for most of the
scripts, but not for networking.  And printing values of automatic configuration doesn't
have to be by 'set -x', that was just a quick way how to achieve it.

> > +	eval "$(tst_net_ip_prefix $IPV4_LHOST)" || exit $?

> Not quite right, if you want to deal with the status of
> tst_net_ip_prefix, you have to set 'exit' on error inside $(...)

> eval "$(tst_net_ip_prefix $IPV4_LHOST || echo 'exit $?')"
Am I missing something? Are you sure, you're right? POSIX defines [1]:
EXIT STATUS
If there are no arguments, or only null arguments, eval shall return a zero exit status;
otherwise, it shall return the exit status of the command defined by the string of
concatenated arguments separated by <space> characters, or a non-zero exit status if the
concatenation could not be parsed as a command and the shell is interactive (and therefore
did not abort).

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_19

And bash, dash and busybox shell all implement this behaviour correctly. So both ways
deals correctly with tst_net_ip_prefix exit status and I consider mine form a bit clearer.


> > +	if [ "$TST_USE_NETNS" != "yes" ]; then
> > +		tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
> > +		set -x
> > +		eval "$(tst_net_iface_prefix $IPV4_LHOST)" || exit $?
> > +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST)" || exit $?
> > +		eval "$(tst_net_iface_prefix $IPV6_LHOST)" || exit $?
> > +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST)" || exit $?
> > +		set +x
> > +	fi

> Why netns is not working in the above case or it's an optimization?
Chicken or the egg problem. We need tst_rhost_run, but it requires LTP_NETNS being set =>
that requires init_ltp_netspace() call. But in init_ltp_netspace() we set remote IP. Does
it make sense to move tst_net_iface_prefix behind netns initialization and call 'tst_restore_ipaddr'
and 'tst_restore_ipaddr rhost' again?

...
> > diff --git a/testcases/network/stress/interface/if4-addr-change b/testcases/network/stress/interface/if4-addr-change
> > index 567f86643..a7469c252 100644
> > --- a/testcases/network/stress/interface/if4-addr-change
> > +++ b/testcases/network/stress/interface/if4-addr-change
> > @@ -48,12 +48,19 @@ while [ $cnt -lt $NS_TIMES ]; do

> >  	[ $num -eq $RHOST_IPV4_HOST ] && continue

> > -	# Change IPv4 address
> > -	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
> > +	# check prefix and fix values for prefix != 24
> > +	add_to_net=
> > +	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
> > +		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
> > +	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
> > +		add_to_net=".0.1"
> > +	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
> > +		add_to_net=".1"
> > +	fi

> > -	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
> > -		broadcast 255.255.255.255 || \
> > -		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
> > +	# Change IPv4 address
> > +	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
> > +		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST


> Could you make a separate patch for this? It looks completely
> unrelated to the rest in this patch.
No, it is related: IPV4_NETWORK disappeared and was replaced by IPV4_LNETWORK and
IPV4_RNETWORK. If we split the commit into two, if4-addr-change will not work in the first
commit (and we break principle of atomic commits).
Of course, we can temporarily (for one commit) define IPV4_NETWORK locally in
if4-addr-change in the first commit in order not to break the script, but does it make
much sense?
I didn't mention in commit message that I'm updating all scripts which use old variables
(the ones which disappeared) with new ones. If you agree to keep it all in one commit, I
put the info in the message.

Thanks for your review, I really appreciate it!

Kind regards,
Petr

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

* [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-07-27  9:03     ` Petr Vorel
@ 2017-07-31 16:53       ` Alexey Kodanev
  2017-08-14  9:55         ` Petr Vorel
  0 siblings, 1 reply; 36+ messages in thread
From: Alexey Kodanev @ 2017-07-31 16:53 UTC (permalink / raw)
  To: ltp

Hi,
On 07/27/2017 12:03 PM, Petr Vorel wrote:
> Hi Alexey,
>
>>> +# For full list of exported environment variables see:
>>> +# tst_net_ip_prefix -h
>>> +# tst_net_iface_prefix -h
>>> +# tst_net_vars -h
>>> +if [ -z "$TST_PARSE_VARIABLES" ]; then
>>> +	tst_resm TINFO "Parsing IP and prefixes"
>>> +	set -x
>> It might be useful just for debugging, please remove it.
> OK, I'll remove it, because you don't like it. But I have to admit, I think it's important
> to see values of automatic setup.
> If user reports a bug/problem we have ver_linux, which is suitable for most of the
> scripts, but not for networking.  And printing values of automatic configuration doesn't
> have to be by 'set -x', that was just a quick way how to achieve it.
>
>>> +	eval "$(tst_net_ip_prefix $IPV4_LHOST)" || exit $?
>> Not quite right, if you want to deal with the status of
>> tst_net_ip_prefix, you have to set 'exit' on error inside $(...)
>> eval "$(tst_net_ip_prefix $IPV4_LHOST || echo 'exit $?')"
> Am I missing something? Are you sure, you're right? POSIX defines [1]:
> EXIT STATUS
> If there are no arguments, or only null arguments, eval shall return a zero exit status;
> otherwise, it shall return the exit status of the command defined by the string of
> concatenated arguments separated by <space> characters, or a non-zero exit status if the
> concatenation could not be parsed as a command and the shell is interactive (and therefore
> did not abort).


eval executes the output of tst_net_ip_prefix command there, not $(...),
so basically it's the same as if we write:

cmd="$(tst_net_ip_prefix)"

On error $cmd is empty because you write to stderr, so eval returns 0.

eval "$cmd"

Or you could use '$(...)' instead of "$(...)", but in that case eval is
kind of redundant.


>
> [1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_19
>
> And bash, dash and busybox shell all implement this behaviour correctly. So both ways
> deals correctly with tst_net_ip_prefix exit status and I consider mine form a bit clearer.
>
>
>>> +	if [ "$TST_USE_NETNS" != "yes" ]; then
>>> +		tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
>>> +		set -x
>>> +		eval "$(tst_net_iface_prefix $IPV4_LHOST)" || exit $?
>>> +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST)" || exit $?
>>> +		eval "$(tst_net_iface_prefix $IPV6_LHOST)" || exit $?
>>> +		eval "$(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST)" || exit $?
>>> +		set +x
>>> +	fi
>> Why netns is not working in the above case or it's an optimization?
> Chicken or the egg problem. We need tst_rhost_run, but it requires LTP_NETNS being set =>
> that requires init_ltp_netspace() call. But in init_ltp_netspace() we set remote IP. Does
> it make sense to move tst_net_iface_prefix behind netns initialization and call 'tst_restore_ipaddr'
> and 'tst_restore_ipaddr rhost' again?

I see, it could be solved by moving init_ltp_netspace() between
tst_net_ip_prefix() calls and "parsing prefixes and ifaces from rtnetlink".

Thanks,
Alexey


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

* [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module
  2017-07-21  4:03 ` [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module Petr Vorel
@ 2017-08-03 11:45   ` Alexey Kodanev
  0 siblings, 0 replies; 36+ messages in thread
From: Alexey Kodanev @ 2017-08-03 11:45 UTC (permalink / raw)
  To: ltp

On 07/21/2017 07:03 AM, Petr Vorel wrote:
> From: Alexey Kodanev <alexey.kodanev@oracle.com>
>
> This patch fixes problems with dhcp based tests run via netns when they
> call TCONF:
>
> $ /opt/ltp/testscripts/network.sh -6
> dhcpd 1 TCONF: 'dhcpd' not found
> ...
> cat: /sys/class/net/ltp_ns_veth2/address: No such file or directory
>
> This also fixes other tests run after dhcp tests which are broken as
> netns setup got broken.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> Tested-by: Petr Vorel <pvorel@suse.cz>

Applied.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
  2017-07-31 16:53       ` Alexey Kodanev
@ 2017-08-14  9:55         ` Petr Vorel
  0 siblings, 0 replies; 36+ messages in thread
From: Petr Vorel @ 2017-08-14  9:55 UTC (permalink / raw)
  To: ltp

Hi Alexey,


> eval executes the output of tst_net_ip_prefix command there, not $(...),
> so basically it's the same as if we write:

> cmd="$(tst_net_ip_prefix)"

> On error $cmd is empty because you write to stderr, so eval returns 0.

> eval "$cmd"

> Or you could use '$(...)' instead of "$(...)", but in that case eval is
> kind of redundant.

Thanks for detailed explanation. We need eval (for export variables), so I'll use your
original version.


Kind regards,
Petr

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

end of thread, other threads:[~2017-08-14  9:55 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-21  4:03 [LTP] [RFC PATCH v7 0/7] Simplify network setup + fix some network stress tests Petr Vorel
2017-07-21  4:03 ` [LTP] [RFC PATCH v7 01/11] network/dhcp: Fix removing veth kernel module Petr Vorel
2017-08-03 11:45   ` Alexey Kodanev
2017-07-21  4:03 ` [LTP] [RFC PATCH v7 02/11] network/stress: Add library test_net_stress.sh Petr Vorel
2017-07-24 15:54   ` Alexey Kodanev
2017-07-25  9:57     ` Petr Vorel
2017-07-25 10:48       ` Alexey Kodanev
2017-07-25 14:52         ` Petr Vorel
2017-07-25 16:01           ` Alexey Kodanev
2017-07-25 16:37             ` Petr Vorel
2017-07-21  4:03 ` [LTP] [RFC PATCH v7 03/11] network/stress: Simplify make_background_tcp_traffic usage Petr Vorel
2017-07-24 15:57   ` Alexey Kodanev
2017-07-25 10:12     ` Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 04/11] network/stress: Reduce the default number of cycles for various tests Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 05/11] lib/test_net.sh: tst_rhost_run: Add testcases/bin into PATH for SSH/RSH Petr Vorel
2017-07-25 12:50   ` Alexey Kodanev
2017-07-25 14:28     ` Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 06/11] network/stress: Fix and cleanup part of multicast IPv4 tests Petr Vorel
2017-07-25 15:21   ` Alexey Kodanev
2017-07-25 16:19     ` Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 07/11] lib/test_net.sh: Add function reset_ltp_netspace() Petr Vorel
2017-07-26 14:44   ` Alexey Kodanev
2017-07-26 14:55     ` Petr Vorel
2017-07-26 15:00       ` Alexey Kodanev
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 08/11] network/stress: Fix and cleanup route IPv4 tests Petr Vorel
2017-07-26 14:58   ` Alexey Kodanev
2017-07-26 23:29     ` Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 09/11] network/stress: Further enhancements for route4-rmmod Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 10/11] network: Add tools for setup IP related environment variables Petr Vorel
2017-07-26 15:17   ` Alexey Kodanev
2017-07-27  8:35     ` Petr Vorel
2017-07-21  4:04 ` [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables Petr Vorel
2017-07-26 15:32   ` Alexey Kodanev
2017-07-27  9:03     ` Petr Vorel
2017-07-31 16:53       ` Alexey Kodanev
2017-08-14  9:55         ` Petr Vorel

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.