serval-dna/tests/routing
2013-05-02 14:29:31 +09:30

406 lines
13 KiB
Bash
Executable File

#!/bin/bash
# Tests for Route discovery
#
# 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"
add_interface() {
>$SERVALD_VAR/dummy$1
executeOk_servald config \
set interfaces.$1.file dummy$1 \
set interfaces.$1.dummy_address 127.0.$1.$instance_number \
set interfaces.$1.dummy_netmask 255.255.255.224
}
interface_up() {
grep "Interface .* is up" $instance_servald_log || return 1
return 0
}
start_routing_instance() {
executeOk_servald config \
set server.interface_path "$SERVALD_VAR" \
set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" \
set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" \
set log.console.level debug \
set log.console.show_pid on \
set log.console.show_time on \
set debug.mdprequests yes \
set debug.linkstate yes \
set debug.verbose yes \
set rhizome.enable no
start_servald_server
wait_until interface_up
}
log_routing_table() {
executeOk_servald route print
tfw_cat --stdout --stderr
}
teardown() {
foreach_instance_with_pidfile log_routing_table
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
doc_single_link="Start 2 instances on one link"
setup_single_link() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +A +B start_routing_instance
}
test_single_link() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST UNICAST :"
}
doc_multiple_ids="Route between multiple identities"
setup_multiple_ids() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_identities 2
foreach_instance +A +B add_interface 1
foreach_instance +A +B start_routing_instance
}
test_multiple_ids() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB2 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB1:BROADCAST UNICAST :dummy.*:0*"
assertStdoutGrep --matches=1 "^$SIDB2:INDIRECT ::$SIDB1"
set_instance +B
executeOk_servald mdp ping --timeout=3 $SIDA2 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA1:BROADCAST UNICAST :dummy.*:0*"
assertStdoutGrep --matches=1 "^$SIDA2:INDIRECT ::$SIDA1"
}
doc_single_mdp="Use single MDP per packet encapsulation"
setup_single_mdp() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +A +B executeOk_servald config set interfaces.1.encapsulation single
foreach_instance +A +B start_routing_instance
}
test_single_mdp() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST UNICAST :"
}
doc_mismatched_encap="Mismatched MDP packet encapsulation"
setup_mismatched_encap() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +A executeOk_servald config set interfaces.1.encapsulation single
foreach_instance +A +B start_routing_instance
}
test_mismatched_encap() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST UNICAST :"
}
doc_slip_encoding="Test slip encoding and decoding"
setup_slip_encoding() {
setup_servald
assert_no_servald_processes
}
test_slip_encoding() {
executeOk_servald test slip --seed=1 --iterations=2000
}
doc_multiple_nodes="Multiple nodes on one link"
setup_multiple_nodes() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C +D add_interface 1
foreach_instance +A +B +C +D start_routing_instance
}
test_multiple_nodes() {
foreach +A +B +C +D \
wait_until has_seen_instances +A +B +C +D
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
executeOk_servald mdp ping --timeout=3 $SIDD 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST "
assertStdoutGrep --matches=1 "^$SIDC:BROADCAST "
assertStdoutGrep --matches=1 "^$SIDD:BROADCAST "
}
doc_scan="Simulate isolated clients"
setup_scan() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
set_instance +B
executeOk_servald config \
set interfaces.1.dummy_address 127.0.1.11
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.drop_broadcasts 1
foreach_instance +A +B start_routing_instance
}
test_scan() {
set_instance +A
executeOk_servald scan
wait_until scan_completed
wait_until has_seen_instances +B
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:UNICAST :"
}
scan_completed() {
grep "Scan completed" $LOG||return1
return 0
}
doc_broadcast_only="Broadcast packets only"
setup_broadcast_only() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +A +B \
executeOk_servald config set interfaces.1.drop_unicasts 1
foreach_instance +A +B start_routing_instance
}
test_broadcast_only() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST :"
}
doc_prefer_unicast="Prefer unicast packets"
setup_prefer_unicast() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.prefer_unicast 1 \
set debug.overlayframes 1
foreach_instance +A +B start_routing_instance
}
test_prefer_unicast() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST UNICAST :"
assertGrep "$instance_servald_log" 'Choosing to send via unicast'
}
doc_multihop_linear="Start 4 instances in a linear arrangement"
setup_multihop_linear() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +B +C add_interface 2
foreach_instance +C +D add_interface 3
foreach_instance +A +B +C +D start_routing_instance
}
test_multihop_linear() {
foreach_instance +A +B +C +D \
wait_until has_seen_instances +A +B +C +D
set_instance +A
executeOk_servald --stdout --stderr mdp ping --timeout=3 $SIDD 1
tfw_cat --stdout --stderr
executeOk_servald mdp trace $SIDD
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST UNICAST :"
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT :"
assertStdoutGrep --matches=1 "^$SIDD:INDIRECT :"
}
setup_offline() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C add_interface 1
foreach_instance +A +B +D add_interface 2
foreach_instance +A +B +C +D start_routing_instance
}
instance_offline() {
local I N
for I; do
[ $I = $instance_arg ] && continue
for ((N=1; 1; ++N)); do
local sidvar=SID${I#+}$N
[ -n "${!sidvar}" ] || break
if ! grep "LINK STATE.*${!sidvar}.*UNREACHABLE" $instance_servald_log; then
return 1
fi
done
done
}
doc_offline="One node going offline"
test_offline() {
foreach_instance +A +B +C +D \
wait_until has_seen_instances +A +B +C +D
stop_servald_server +C
foreach_instance +A +B +D \
wait_until --timeout=30 instance_offline +C
}
setup_multi_interface() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
>$SERVALD_VAR/dummywifi
>$SERVALD_VAR/dummyeth
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.file dummywifi \
set interfaces.1.dummy_address 127.0.1.$instance_number \
set interfaces.1.dummy_netmask 255.255.255.224 \
set interfaces.1.type wifi \
set interfaces.1.drop_unicasts on \
set interfaces.2.file dummyeth \
set interfaces.2.dummy_address 127.0.2.$instance_number \
set interfaces.2.dummy_netmask 255.255.255.224 \
set interfaces.2.type ethernet \
set interfaces.2.drop_unicasts on
foreach_instance +A +B start_routing_instance
}
doc_multi_interface="Multiple links of different types to the same neighbour"
test_multi_interface() {
foreach_instance +A +B \
wait_until has_seen_instances +A +B
sleep 5
set_instance +A
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDB:BROADCAST :dummyeth"
set_instance +B
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDA:BROADCAST :dummyeth"
}
setup_circle() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D +E +F +G +H create_single_identity
foreach_instance +A +B add_interface 1
foreach_instance +B +C add_interface 2
foreach_instance +C +D add_interface 3
foreach_instance +D +E add_interface 4
foreach_instance +E +F add_interface 5
foreach_instance +F +G add_interface 6
foreach_instance +G +H add_interface 7
foreach_instance +H +A add_interface 8
foreach_instance +A +B +C +D +E +F +G +H start_routing_instance
}
doc_circle="Circle of nodes with one going offline"
test_circle() {
foreach_instance +A +B +C +D +E +F +G +H \
wait_until has_seen_instances +A +B +C +D +E +F +G +H
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT :"
stop_servald_server +B
foreach_instance +A +C \
wait_until --timeout=10 instance_offline +B
foreach_instance +A +C \
wait_until --timeout=10 has_seen_instances +A +C
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDC:INDIRECT :"
}
setup_crowded_mess() {
setup_servald
assert_no_servald_processes
# BCDE & DEFG form squares, ABC & FGH form triangles
foreach_instance +A +B +C +D +E +F +G +H create_single_identity
foreach_instance +A +B +C add_interface 1
foreach_instance +B +D add_interface 2
foreach_instance +C +E add_interface 3
foreach_instance +D +E add_interface 4
foreach_instance +D +F add_interface 5
foreach_instance +E +G add_interface 6
foreach_instance +F +G +H add_interface 7
foreach_instance +A +B +C +D +E +F +G +H start_routing_instance
}
doc_crowded_mess="Multiple possible paths"
test_crowded_mess() {
foreach_instance +A +H \
wait_until has_seen_instances +A +H
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDH 1
tfw_cat --stdout --stderr
executeOk_servald route print
assertStdoutGrep --matches=1 "^$SIDH:INDIRECT :"
}
runTests "$@"