From: David Ahern <hidden> Date: 2018-03-02 16:45:59
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.
Signed-off-by: David Ahern <redacted>
---
.../net/forwarding/forwarding.config.sample | 5 ++++
tools/testing/selftests/net/forwarding/lib.sh | 33 ++++++++++++++++++++++
2 files changed, 38 insertions(+)
@@ -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
@@ -76,6 +76,39 @@ done############################################################################### Network interfaces configuration+create_netif_veth()+{+locali++foriin$(evalecho{1..$NUM_NETIFS});do+j=$((i+1))+iplinkshowdev${NETIFS[p$i]}&>/dev/null+if[[$?-ne0]];then+iplinkadd${NETIFS[p$i]}typevethpeername${NETIFS[p$j]}+if[[$?-ne0]];then+echo"Failed to create netif"+exit1+fi+fi+i=$j+done+}++create_netif()+{+case"$NETIF_TYPE"in+veth)create_netif_veth+;;+*)echo"Can not create interfaces of type \'$NETIF_TYPE\'"+exit1+;;+esac+}++if[["$NETIF_CREATE"="yes"]];then+create_netif+fi+foriin$(evalecho{1..$NUM_NETIFS});doiplinkshowdev${NETIFS[p$i]}&>/dev/nullif[[$?-ne0]];then
On Fri, Mar 02, 2018 at 08:45:53AM -0800, David Ahern wrote:
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.
Signed-off-by: David Ahern <redacted>
+ 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.
+ 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
--
2.11.0
From: David Ahern <hidden> Date: 2018-03-05 01:22:23
On 3/4/18 1:14 AM, Ido Schimmel wrote:
On Fri, Mar 02, 2018 at 08:45:53AM -0800, David Ahern wrote:
quoted
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.
Signed-off-by: David Ahern <redacted>
not sure how it drops a line but added the 'local' for j since it was
missing.
quoted
+ 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.
$ cat ~/.vim/after/ftplugin/sh.vim
...
highlight OverLength ctermbg=red ctermfg=white
match OverLength /\%81v.\+/
Cool patch! Tested on my machine.
quoted
+ 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
--
2.11.0