All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables
Date: Fri, 21 Jul 2017 06:04:07 +0200	[thread overview]
Message-ID: <20170721040407.868-12-pvorel@suse.cz> (raw)
In-Reply-To: <20170721040407.868-1-pvorel@suse.cz>

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


  parent reply	other threads:[~2017-07-21  4:04 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Petr Vorel [this message]
2017-07-26 15:32   ` [LTP] [RFC PATCH v7 11/11] network: Use tools to set up IPv4 and IPv6 related variables Alexey Kodanev
2017-07-27  9:03     ` Petr Vorel
2017-07-31 16:53       ` Alexey Kodanev
2017-08-14  9:55         ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170721040407.868-12-pvorel@suse.cz \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.