Skip to contentSkip to conversation

selftests: forwarding: Add suppport to create veth interfaces

PATCH Superseded David Ahern 2 participants 3 messages Mar 2, 2018 – Mar 5, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: forwarding: Add suppport to create veth interfaces

For tests using veth interfaces, the test infrastructure can create the netdevs if they do not exist. Arguably this is a preferred approach since the tests require p$N and p$(N+1) to be pairs.

---
 .../net/forwarding/forwarding.config.sample        |  5 ++++
 tools/testing/selftests/net/forwarding/lib.sh      | 33 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)
tools/testing/selftests/net/forwarding/forwarding.config.sample +5 -0
index ab235c124f20..df54c9eb5100 100644
@@ -14,6 +14,11 @@ NETIFS[p6]=veth5
 NETIFS[p7]=veth6
 NETIFS[p8]=veth7
 
+NETIF_TYPE=veth
+
+# only virtual interfaces (veth) can be created by test infra
+#NETIF_CREATE=yes
+
 ##############################################################################
 # Defines
 
tools/testing/selftests/net/forwarding/lib.sh +33 -0
index d0af52109360..2ce98c6a8c25 100644
@@ -76,6 +76,39 @@ done
 ##############################################################################
 # Network interfaces configuration
 
+create_netif_veth()
+{
+	local i
+
+	for i in $(eval echo {1..$NUM_NETIFS}); do
+		j=$((i+1))
+		ip link show dev ${NETIFS[p$i]} &> /dev/null
+		if [[ $? -ne 0 ]]; then
+			ip link add ${NETIFS[p$i]} type veth peer name ${NETIFS[p$j]}
+			if [[ $? -ne 0 ]]; then
+				echo "Failed to create netif"
+				exit 1
+			fi
+		fi
+		i=$j
+	done
+}
+
+create_netif()
+{
+	case "$NETIF_TYPE" in
+	veth) create_netif_veth
+	      ;;
+	*) echo "Can not create interfaces of type \'$NETIF_TYPE\'"
+	   exit 1
+	   ;;
+	esac
+}
+
+if [[ "$NETIF_CREATE" = "yes" ]]; then
+	create_netif
+fi
+
 for i in $(eval echo {1..$NUM_NETIFS}); do
 	ip link show dev ${NETIFS[p$i]} &> /dev/null
 	if [[ $? -ne 0 ]]; then
Signature · 1 line
2.11.0
#1 lore raw
Quoted 5 lines · David Ahern

For tests using veth interfaces, the test infrastructure can create the netdevs if they do not exist. Arguably this is a preferred approach since the tests require p$N and p$(N+1) to be pairs.

[...]

Quoted 5 lines
tools/testing/selftests/net/forwarding/lib.sh +0 -0
index d0af52109360..2ce98c6a8c25 100644

tools/testing/selftests/net/forwarding/lib.sh done · line 84

Quoted 9 lines
tools/testing/selftests/net/forwarding/lib.sh +6 -0
@@ -76,6 +76,39 @@ done
 ##############################################################################
 # Network interfaces configuration
 
+create_netif_veth()
+{
+	local i
+
+	for i in $(eval echo {1..$NUM_NETIFS}); do
+		j=$((i+1))

local j=$((i+1)) and drop a line.

tools/testing/selftests/net/forwarding/lib.sh done · line 87

Quoted 3 lines
tools/testing/selftests/net/forwarding/lib.sh +3 -0
+		ip link show dev ${NETIFS[p$i]} &> /dev/null
+		if [[ $? -ne 0 ]]; then
+			ip link add ${NETIFS[p$i]} type veth peer name ${NETIFS[p$j]}

Need to break this one. FWIW, I have this in my config:

$ cat ~/.vim/after/ftplugin/sh.vim
...
highlight OverLength ctermbg=red ctermfg=white
match OverLength /\%81v.\+/

Cool patch! Tested on my machine.

Quoted 30 lines
tools/testing/selftests/net/forwarding/lib.sh +24 -0
+			if [[ $? -ne 0 ]]; then
+				echo "Failed to create netif"
+				exit 1
+			fi
+		fi
+		i=$j
+	done
+}
+
+create_netif()
+{
+	case "$NETIF_TYPE" in
+	veth) create_netif_veth
+	      ;;
+	*) echo "Can not create interfaces of type \'$NETIF_TYPE\'"
+	   exit 1
+	   ;;
+	esac
+}
+
+if [[ "$NETIF_CREATE" = "yes" ]]; then
+	create_netif
+fi
+
 for i in $(eval echo {1..$NUM_NETIFS}); do
 	ip link show dev ${NETIFS[p$i]} &> /dev/null
 	if [[ $? -ne 0 ]]; then
Signature · 1 line
2.11.0
#2 lore raw
Quoted 17 lines · Ido Schimmel
Quoted 5 lines · David Ahern

For tests using veth interfaces, the test infrastructure can create the netdevs if they do not exist. Arguably this is a preferred approach since the tests require p$N and p$(N+1) to be pairs.

[...]

Quoted 8 lines
tools/testing/selftests/net/forwarding/lib.sh +0 -0
index d0af52109360..2ce98c6a8c25 100644
@@ -76,6 +76,39 @@ done
 ##############################################################################
 # Network interfaces configuration
 
Quoted 8 lines

tools/testing/selftests/net/forwarding/lib.sh done · line 84

Quoted 6 lines
tools/testing/selftests/net/forwarding/lib.sh +6 -0
+create_netif_veth()
+{
+	local i
+
+	for i in $(eval echo {1..$NUM_NETIFS}); do
+		j=$((i+1))

local j=$((i+1)) and drop a line.

not sure how it drops a line but added the 'local' for j since it was missing.

Quoted 6 lines

tools/testing/selftests/net/forwarding/lib.sh done · line 87

Quoted 4 lines
tools/testing/selftests/net/forwarding/lib.sh +3 -0
+		ip link show dev ${NETIFS[p$i]} &> /dev/null
+		if [[ $? -ne 0 ]]; then
+			ip link add ${NETIFS[p$i]} type veth peer name ${NETIFS[p$j]}

Need to break this one. FWIW, I have this in my config:

going for readability over strict line lengths. Wrapped in v2.

Quoted 38 lines
$ cat ~/.vim/after/ftplugin/sh.vim
...
highlight OverLength ctermbg=red ctermfg=white
match OverLength /\%81v.\+/

Cool patch! Tested on my machine.

Quoted 30 lines
tools/testing/selftests/net/forwarding/lib.sh +24 -0
+			if [[ $? -ne 0 ]]; then
+				echo "Failed to create netif"
+				exit 1
+			fi
+		fi
+		i=$j
+	done
+}
+
+create_netif()
+{
+	case "$NETIF_TYPE" in
+	veth) create_netif_veth
+	      ;;
+	*) echo "Can not create interfaces of type \'$NETIF_TYPE\'"
+	   exit 1
+	   ;;
+	esac
+}
+
+if [[ "$NETIF_CREATE" = "yes" ]]; then
+	create_netif
+fi
+
 for i in $(eval echo {1..$NUM_NETIFS}); do
 	ip link show dev ${NETIFS[p$i]} &> /dev/null
 	if [[ $? -ne 0 ]]; then
Signature · 1 line
2.11.0