xref: /openbsd-src/regress/sys/net/vxlan/vxlan_1.sh (revision 427e22f8e717ab4da23953ab98ce4d9a9be2c052)
1#!/bin/ksh
2#	$OpenBSD: vxlan_1.sh,v 1.2 2023/10/19 18:36:41 anton Exp $
3
4
5cleanup()
6{
7	for if in $ALL_IFS; do
8		ifconfig $if destroy 2>/dev/null
9	done
10	for id in $RDOMAINS; do
11		ifconfig lo$id destroy 2>/dev/null
12	done
13}
14
15CURDIR=$(cd $(dirname $0); pwd)
16
17. ${CURDIR}/vxlan_subr
18
19# rdomains
20set -- $RDOMAINS
21if [ $# -lt 2 ]; then
22	echo "2 rdomain(-R option) is required" >&2
23	exit 64
24fi
25RD1=$1
26RD2=$2
27
28# interface minor numbers
29set -- $IFACE_NUMS
30if [ $# -lt 2 ]; then
31	echo "2 interface numbers(-I option) is required" >&2
32	exit 64
33fi
34IFNO1=$1
35IFNO2=$2
36
37ALL_IFS="bridge$IFNO2 bridge$IFNO1 vether$IFNO2 vether$IFNO1 vxlan$IFNO2
38    vxlan$IFNO1 pair$IFNO2 pair$IFNO1"
39
40[ $CLEANUP -gt 0 ] && cleanup
41#
42# Check pre-conditions
43#
44# interfaces are busy?
45for if in $ALL_IFS; do
46	if iface_exists $if; then
47		echo "Aborted.  interface \`$if' is used already." >&2
48		exit 255
49	fi
50done
51# rdomains are busy?
52for rt in $RD1 $RD2; do
53	if ! rdomain_is_used $rt; then
54		echo "Aborted.  rdomain \`$rt' is used already." >&2
55		exit 255
56	fi
57done
58
59#
60# Prepeare the test
61#
62[ $VERBOSE -gt 0 ] && set -x
63ifconfig pair$IFNO1    rdomain $RD1 172.31.0.1/24
64ifconfig pair$IFNO2    rdomain $RD2 172.31.0.2/24 patch pair$IFNO1
65ifconfig vether$IFNO1  rdomain $RD1 192.168.0.1
66ifconfig vether$IFNO2  rdomain $RD2 192.168.0.2
67ifconfig vxlan$IFNO1 rdomain $RD1 tunneldomain $RD1 || abort_test
68ifconfig vxlan$IFNO2 rdomain $RD2 tunneldomain $RD2 || abort_test
69ifconfig bridge$IFNO1  rdomain $RD1 add vether$IFNO1 add vxlan$IFNO1 up
70ifconfig bridge$IFNO2  rdomain $RD2 add vether$IFNO2 add vxlan$IFNO2 up
71
72#
73# Test config
74#
75ifconfig vxlan$IFNO1 tunnel 172.31.0.1 172.31.0.2 vnetid 100 up || abort_test
76ifconfig vxlan$IFNO2 tunnel 172.31.0.2 172.31.0.1 vnetid 100 up || abort_test
77
78#
79# Test behavior
80#
81test ping -w 1 -c 1 -V $RD1 192.168.0.2
82test ping -w 1 -c 1 -V $RD2 192.168.0.1
83set +x
84
85# Done
86cleanup
87exit $FAILS
88