forked from servalproject/serval-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory_service
executable file
·170 lines (156 loc) · 5.32 KB
/
directory_service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# Tests for Directory Services.
#
# Copyright 2012 Serval Project, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
configure_servald_server() {
executeOk_servald config \
set log.console.show_pid on \
set log.console.show_time on \
set rhizome.enable No \
set debug.mdprequests Yes \
set debug.overlayframes Yes
}
teardown() {
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
is_published() {
tfw_log "grep \"PUBLISHED.*$1\" $instance_servald_log"
grep "PUBLISHED.*$1" $instance_servald_log
}
sent_directory_request() {
grep "Sending directory registration" $instance_servald_log
}
setup_publish() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
set_instance +D
executeOk_servald keyring set did $SIDD $DIDC "Agent D Smith"
DIDD1=$DIDC
NAMED1="Agent D Smith"
DIDD=$DIDC1
NAMED=$NAMED1
set_instance +A
executeOk_servald config \
set dna.helper.executable "$servald_build_root/directory_service" \
set debug.dnahelper on
foreach_instance +B +C +D executeOk_servald config set directory.service $SIDA
foreach_instance +A +B +C +D add_servald_interface
start_servald_instances +A +B +C +D
}
doc_publish="Publish and retrieve a directory entry"
test_publish() {
wait_until grep "DNAHELPER got STARTED ACK" $LOGA
foreach_instance +B +C +D wait_until sent_directory_request
wait_until is_published $SIDB
wait_until is_published $SIDC
wait_until is_published $SIDD
stop_servald_server +B
stop_servald_server +C
stop_servald_server +D
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
executeOk_servald dna lookup "$DIDC"
assertStdoutLineCount '==' 4
assertStdoutGrep --matches=1 "^sid://$SIDC/local/$DIDC:$DIDC:$NAMEC\$"
assertStdoutGrep --matches=1 "^sid://$SIDD/local/$DIDD:$DIDD:$NAMED\$"
assert_status_all_servald_servers running
}
interface_up() {
grep "Interface .* is up" $instance_servald_log || return 1
return 0
}
start_routing_instance() {
start_servald_server
wait_until interface_up
}
configure_node() {
executeOk_servald config \
set server.interface_path "$SERVALD_VAR" \
set rhizome.enable No \
set log.console.show_pid on \
set log.console.show_time on \
set debug.mdprequests Yes \
set debug.overlayframes Yes \
set debug.overlayinterfaces Yes \
set debug.linkstate Yes \
set interfaces.0.file dummy1 \
set interfaces.0.socket_type file \
set interfaces.0.broadcast.send off \
set interfaces.0.broadcast.drop on \
set interfaces.0.broadcast.reachable_timeout_ms 10000 \
set interfaces.0.unicast.route off \
set interfaces.0.default_route 1 \
set interfaces.0.dummy_address 10.0.${instance_number}.1 \
set interfaces.0.dummy_netmask 255.255.255.0
}
setup_routing() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C create_single_identity
>$SERVALD_VAR/dummy1
foreach_instance +A +B +C \
configure_node
set_instance +A
executeOk_servald config \
set dna.helper.executable "$servald_build_root/directory_service" \
set debug.dnahelper on
foreach_instance +B +C \
executeOk_servald config \
set directory.service $SIDA \
set hosts.$SIDA.address 10.0.1.1
set_instance +A
start_routing_instance
wait_until grep "DNAHELPER got STARTED ACK" $instance_servald_log
foreach_instance +B +C start_routing_instance
}
doc_routing="Ping via relay node"
test_routing() {
foreach_instance +B +C \
wait_until sent_directory_request
set_instance +A
wait_until is_published $SIDB
wait_until is_published $SIDC
set_instance +B
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA:UNICAST:"
assertStdoutGrep --matches=0 "^$SIDC:"
executeOk_servald dna lookup "$DIDC"
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "^sid://$SIDC/local/$DIDC:$DIDC:$NAMEC\$"
set_instance +C
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA:UNICAST:"
assertStdoutGrep --matches=0 "^$SIDB:"
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
executeOk_servald mdp ping $SIDB 3
tfw_cat --stdout --stderr
executeOk_servald route print
tfw_cat --stdout
set_instance +B
executeOk_servald route print
tfw_cat --stdout
assert_status_all_servald_servers running
}
runTests "$@"