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