Move integration tests into a subdirectory
[tinc] / test / integration / ns-ping.test
1 #!/bin/sh
2
3 # shellcheck disable=SC1090
4 . "$TESTLIB_PATH"
5
6 require_root "$0" "$@"
7 test -e /dev/net/tun || exit "$EXIT_SKIP_TEST"
8 ip netns list || exit "$EXIT_SKIP_TEST"
9
10 ip_foo=192.168.1.1
11 ip_bar=192.168.1.2
12 mask=24
13
14 echo [STEP] Create network namespaces
15
16 ip netns add ping.test1
17 ip netns add ping.test2
18
19 cleanup_hook() {
20   ip netns del ping.test1
21   ip netns del ping.test2
22 }
23
24 echo [STEP] Initialize two nodes
25
26 tinc foo <<EOF
27 init foo
28 set Subnet $ip_foo
29 set Interface ping.test1
30 set Port 30090
31 set Address localhost
32 set AutoConnect no
33 EOF
34
35 # shellcheck disable=SC2016
36 create_script foo tinc-up "
37   ip link set dev \$INTERFACE netns ping.test1
38   ip netns exec ping.test1 ip addr add $ip_foo/$mask dev \$INTERFACE
39   ip netns exec ping.test1 ip link set \$INTERFACE up
40 "
41
42 tinc bar <<EOF
43 init bar
44 set Subnet $ip_bar
45 set Interface ping.test2
46 set Port 30091
47 set AutoConnect no
48 EOF
49
50 # shellcheck disable=SC2016
51 create_script bar tinc-up "
52   ip link set dev \$INTERFACE netns ping.test2
53   ip netns exec ping.test2 ip addr add $ip_bar/$mask dev \$INTERFACE
54   ip netns exec ping.test2 ip link set \$INTERFACE up
55 "
56
57 echo [STEP] Exchange configuration files
58
59 tinc foo export | tinc bar exchange | tinc foo import
60
61 echo [STEP] Start tinc
62
63 start_tinc foo
64 start_tinc bar
65
66 wait_script foo tinc-up
67 wait_script bar tinc-up
68
69 echo [STEP] The nodes should not be able to ping each other if there is no connection
70
71 must_fail ip netns exec ping.test1 ping -W1 -c3 $ip_bar
72
73 echo [STEP] After connecting they should be
74
75 create_script bar hosts/foo-up
76
77 tinc bar add ConnectTo foo
78 wait_script bar hosts/foo-up
79
80 ip netns exec ping.test1 ping -W1 -c3 $ip_bar