diff options
author | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2016-10-07 02:06:58 +0000 |
---|---|---|
committer | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2016-10-07 02:06:58 +0000 |
commit | 996d18fcb37e9ac4ce32fe2b583d1689147d48b5 (patch) | |
tree | 3ad08e2ff190b7aab4bc248abcfc0440b19ee450 /regress/sys | |
parent | 1bd2a27ee6865247aac69267173d941a0cda2826 (diff) |
Add simple regress test for vxlan(4) and etherip(4).
ok bluhm
Diffstat (limited to 'regress/sys')
-rw-r--r-- | regress/sys/net/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/net/etherip/Makefile | 12 | ||||
-rw-r--r-- | regress/sys/net/etherip/etherip_1.sh | 91 | ||||
-rw-r--r-- | regress/sys/net/etherip/etherip_subr | 79 | ||||
-rw-r--r-- | regress/sys/net/vxlan/Makefile | 12 | ||||
-rw-r--r-- | regress/sys/net/vxlan/vxlan_1.sh | 84 | ||||
-rw-r--r-- | regress/sys/net/vxlan/vxlan_subr | 79 |
7 files changed, 360 insertions, 2 deletions
diff --git a/regress/sys/net/Makefile b/regress/sys/net/Makefile index 40f49cc8580..ac652db3cb5 100644 --- a/regress/sys/net/Makefile +++ b/regress/sys/net/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.9 2016/09/21 10:40:39 mpi Exp $ +# $OpenBSD: Makefile,v 1.10 2016/10/07 02:06:57 yasuoka Exp $ -SUBDIR += pf_divert pf_forward pf_fragment pf_print rdomains rtable +SUBDIR += etherip pf_divert pf_forward pf_fragment pf_print rdomains +SUBDIR += rtable vxlan .include <bsd.subdir.mk> diff --git a/regress/sys/net/etherip/Makefile b/regress/sys/net/etherip/Makefile new file mode 100644 index 00000000000..04dc3293f29 --- /dev/null +++ b/regress/sys/net/etherip/Makefile @@ -0,0 +1,12 @@ +# $OpenBSD: Makefile,v 1.1 2016/10/07 02:06:57 yasuoka Exp $ + +REGRESS_TARGETS= etherip_1 +REGRESS_ROOT_TARGETS= etherip_1 + +RDOMAINS= 11 12 +IFACE_NUMS= 11 12 + +etherip_1: + ${SUDO} ksh ${.CURDIR}/$@.sh -R "${RDOMAINS}" -I "${IFACE_NUMS}" + +.include <bsd.regress.mk> diff --git a/regress/sys/net/etherip/etherip_1.sh b/regress/sys/net/etherip/etherip_1.sh new file mode 100644 index 00000000000..3e8bb5335f3 --- /dev/null +++ b/regress/sys/net/etherip/etherip_1.sh @@ -0,0 +1,91 @@ +#!/bin/ksh +# $OpenBSD: etherip_1.sh,v 1.1 2016/10/07 02:06:57 yasuoka Exp $ + + +cleanup() +{ + for if in $ALL_IFS; do + ifconfig $if destroy 2>/dev/null + done +} + +CURDIR=$(cd $(dirname $0); pwd) + +. ${CURDIR}/etherip_subr + +# rdomains +set -- $RDOMAINS +if [ $# -lt 2 ]; then + echo "2 rdomain(-R option) is required" >&2 + exit 64 +fi +RD1=$1 +RD2=$2 + +# interface minor numbers +set -- $IFACE_NUMS +if [ $# -lt 2 ]; then + echo "2 interface numbers(-I option) is required" >&2 + exit 64 +fi +IFNO1=$1 +IFNO2=$2 + +ALL_IFS="bridge$IFNO2 bridge$IFNO1 vether$IFNO2 vether$IFNO1 etherip$IFNO2 + etherip$IFNO1 pair$IFNO2 pair$IFNO1" + +[ $CLEANUP -gt 0 ] && cleanup +# +# Check pre-conditions +# +# etherip is enabled by sysctl? +VAL=$(sysctl -n net.inet.etherip.allow) +VAL=${VAL:-0} +if [ $VAL -eq 0 ]; then + echo "SKIPPED Disabled etherip by sysctl net.inet.etherip.allow" >&2 + exit 255 +fi +# interfaces are busy? +for if in $ALL_IFS; do + if iface_exists $if; then + echo "Aborted. interface \`$if' is used already." >&2 + exit 255 + fi +done +# rdomains are busy? +for rt in $RD1 $RD2; do + if ! rdomain_is_used $rt; then + echo "Aborted. rdomain \`$rt' is used already." >&2 + exit 255 + fi +done + +# +# Prepeare the test +# +[ $VERBOSE -gt 0 ] && set -x +ifconfig pair$IFNO1 rdomain $RD1 172.31.0.1/24 +ifconfig pair$IFNO2 rdomain $RD2 172.31.0.2/24 patch pair$IFNO1 +ifconfig vether$IFNO1 rdomain $RD1 192.168.0.1 +ifconfig vether$IFNO2 rdomain $RD2 192.168.0.2 +ifconfig etherip$IFNO1 rdomain $RD1 tunneldomain $RD1 || abort_test +ifconfig etherip$IFNO2 rdomain $RD2 tunneldomain $RD2 || abort_test +ifconfig bridge$IFNO1 rdomain $RD1 add vether$IFNO1 add etherip$IFNO1 up +ifconfig bridge$IFNO2 rdomain $RD2 add vether$IFNO2 add etherip$IFNO2 up + +# +# Test config +# +ifconfig etherip$IFNO1 tunnel 172.31.0.1 172.31.0.2 up || abort_test +ifconfig etherip$IFNO2 tunnel 172.31.0.2 172.31.0.1 up || abort_test + +# +# Test behavior +# +test ping -w 1 -c 1 -V $RD1 192.168.0.2 +test ping -w 1 -c 1 -V $RD2 192.168.0.1 +set +x + +# Done +cleanup +exit $FAILS diff --git a/regress/sys/net/etherip/etherip_subr b/regress/sys/net/etherip/etherip_subr new file mode 100644 index 00000000000..a45d2535f4a --- /dev/null +++ b/regress/sys/net/etherip/etherip_subr @@ -0,0 +1,79 @@ +# +# Copyright (c) 2015 Vincent Gross <vgross@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +CLEANUP=0 +VERBOSE=0 +FAILS=0 + +iface_exists() +{ + ifconfig_out=`ifconfig "$1" 2>&1` + [ "${ifconfig_out}" != "$1: no such interface" ] +} + +rdomain_is_used() +{ + _rdomains=$(ifconfig | sed -n '/^[a-z].* rdomain \([0-9]*\).*/s//\1/p' \ + | sort | uniq) + for _r in $_rdomains; do + if [ $_r = $1 ]; then + return 1 + fi + done + return 0 +} + +abort_test() +{ + echo "** Aborted" >&2 + [ $# -ge 0 ] && echo "$1" >&2 + cleanup + exit 1 +} + +test() +{ + if [ $VERBOSE -gt 0 ]; then + "$@" + else + "$@" > /dev/null 2>&1 + fi + if [ $? -ne 0 ]; then + FAILS=$((FAILS + 1)) + fi +} + +RDOMAINS="" +IFACE_NUMS="" +while getopts 'cvR:I:' ch "$@"; do + case $ch in + c) + CLEANUP=1 + ;; + v) + VERBOSE=$((VERBOSE + 1)) + ;; + R) + RDOMAINS="$RDOMAINS $OPTARG" + ;; + I) + IFACE_NUMS="$IFACE_NUMS $OPTARG" + ;; + *) + echo "usage: $(basename $0) [-cv][-R rodmains][-I iface_nums]" + exit 64 + ;; + esac +done diff --git a/regress/sys/net/vxlan/Makefile b/regress/sys/net/vxlan/Makefile new file mode 100644 index 00000000000..1563d3d9790 --- /dev/null +++ b/regress/sys/net/vxlan/Makefile @@ -0,0 +1,12 @@ +# $OpenBSD: Makefile,v 1.1 2016/10/07 02:06:57 yasuoka Exp $ + +REGRESS_TARGETS= vxlan_1 +REGRESS_ROOT_TARGETS= vxlan_1 + +RDOMAINS= 11 12 +IFACE_NUMS= 11 12 + +vxlan_1: + ${SUDO} ksh ${.CURDIR}/$@.sh -R "${RDOMAINS}" -I "${IFACE_NUMS}" + +.include <bsd.regress.mk> diff --git a/regress/sys/net/vxlan/vxlan_1.sh b/regress/sys/net/vxlan/vxlan_1.sh new file mode 100644 index 00000000000..eef41c5a36a --- /dev/null +++ b/regress/sys/net/vxlan/vxlan_1.sh @@ -0,0 +1,84 @@ +#!/bin/ksh +# $OpenBSD: vxlan_1.sh,v 1.1 2016/10/07 02:06:57 yasuoka Exp $ + + +cleanup() +{ + for if in $ALL_IFS; do + ifconfig $if destroy 2>/dev/null + done +} + +CURDIR=$(cd $(dirname $0); pwd) + +. ${CURDIR}/vxlan_subr + +# rdomains +set -- $RDOMAINS +if [ $# -lt 2 ]; then + echo "2 rdomain(-R option) is required" >&2 + exit 64 +fi +RD1=$1 +RD2=$2 + +# interface minor numbers +set -- $IFACE_NUMS +if [ $# -lt 2 ]; then + echo "2 interface numbers(-I option) is required" >&2 + exit 64 +fi +IFNO1=$1 +IFNO2=$2 + +ALL_IFS="bridge$IFNO2 bridge$IFNO1 vether$IFNO2 vether$IFNO1 vxlan$IFNO2 + vxlan$IFNO1 pair$IFNO2 pair$IFNO1" + +[ $CLEANUP -gt 0 ] && cleanup +# +# Check pre-conditions +# +# interfaces are busy? +for if in $ALL_IFS; do + if iface_exists $if; then + echo "Aborted. interface \`$if' is used already." >&2 + exit 255 + fi +done +# rdomains are busy? +for rt in $RD1 $RD2; do + if ! rdomain_is_used $rt; then + echo "Aborted. rdomain \`$rt' is used already." >&2 + exit 255 + fi +done + +# +# Prepeare the test +# +[ $VERBOSE -gt 0 ] && set -x +ifconfig pair$IFNO1 rdomain $RD1 172.31.0.1/24 +ifconfig pair$IFNO2 rdomain $RD2 172.31.0.2/24 patch pair$IFNO1 +ifconfig vether$IFNO1 rdomain $RD1 192.168.0.1 +ifconfig vether$IFNO2 rdomain $RD2 192.168.0.2 +ifconfig vxlan$IFNO1 rdomain $RD1 tunneldomain $RD1 || abort_test +ifconfig vxlan$IFNO2 rdomain $RD2 tunneldomain $RD2 || abort_test +ifconfig bridge$IFNO1 rdomain $RD1 add vether$IFNO1 add vxlan$IFNO1 up +ifconfig bridge$IFNO2 rdomain $RD2 add vether$IFNO2 add vxlan$IFNO2 up + +# +# Test config +# +ifconfig vxlan$IFNO1 tunnel 172.31.0.1 172.31.0.2 vnetid 100 up || abort_test +ifconfig vxlan$IFNO2 tunnel 172.31.0.2 172.31.0.1 vnetid 100 up || abort_test + +# +# Test behavior +# +test ping -w 1 -c 1 -V $RD1 192.168.0.2 +test ping -w 1 -c 1 -V $RD2 192.168.0.1 +set +x + +# Done +cleanup +exit $FAILS diff --git a/regress/sys/net/vxlan/vxlan_subr b/regress/sys/net/vxlan/vxlan_subr new file mode 100644 index 00000000000..a45d2535f4a --- /dev/null +++ b/regress/sys/net/vxlan/vxlan_subr @@ -0,0 +1,79 @@ +# +# Copyright (c) 2015 Vincent Gross <vgross@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +CLEANUP=0 +VERBOSE=0 +FAILS=0 + +iface_exists() +{ + ifconfig_out=`ifconfig "$1" 2>&1` + [ "${ifconfig_out}" != "$1: no such interface" ] +} + +rdomain_is_used() +{ + _rdomains=$(ifconfig | sed -n '/^[a-z].* rdomain \([0-9]*\).*/s//\1/p' \ + | sort | uniq) + for _r in $_rdomains; do + if [ $_r = $1 ]; then + return 1 + fi + done + return 0 +} + +abort_test() +{ + echo "** Aborted" >&2 + [ $# -ge 0 ] && echo "$1" >&2 + cleanup + exit 1 +} + +test() +{ + if [ $VERBOSE -gt 0 ]; then + "$@" + else + "$@" > /dev/null 2>&1 + fi + if [ $? -ne 0 ]; then + FAILS=$((FAILS + 1)) + fi +} + +RDOMAINS="" +IFACE_NUMS="" +while getopts 'cvR:I:' ch "$@"; do + case $ch in + c) + CLEANUP=1 + ;; + v) + VERBOSE=$((VERBOSE + 1)) + ;; + R) + RDOMAINS="$RDOMAINS $OPTARG" + ;; + I) + IFACE_NUMS="$IFACE_NUMS $OPTARG" + ;; + *) + echo "usage: $(basename $0) [-cv][-R rodmains][-I iface_nums]" + exit 64 + ;; + esac +done |