| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
hostA=$1 |
| 4 |
shift |
| 5 |
hostB=$1 |
| 6 |
shift |
| 7 |
|
| 8 |
############################################################################### |
| 9 |
|
| 10 |
function r_both { |
| 11 |
echo "$hostA: ssh $hostA $*" >&2 |
| 12 |
ssh $hostA "$*" |
| 13 |
[ $? -gt 0 ] && return $? |
| 14 |
echo |
| 15 |
echo "$hostB: ssh $hostB $*" >&2 |
| 16 |
ssh $hostB "$*" |
| 17 |
return $? |
| 18 |
} |
| 19 |
function r_a { |
| 20 |
echo "$hostA: ssh $hostA $*" >&2 |
| 21 |
ssh $hostA "$*" |
| 22 |
return $? |
| 23 |
} |
| 24 |
function r_b { |
| 25 |
echo "$hostB: ssh $hostB $*" >&2 |
| 26 |
ssh $hostB "$*" |
| 27 |
return $? |
| 28 |
} |
| 29 |
|
| 30 |
############################################################################### |
| 31 |
|
| 32 |
|
| 33 |
if [ -z "$hostA" -o -z "$hostB" ]; then |
| 34 |
echo "You need to specify the two bagpipe-bgp hosts to use on the command line (you specified: $hostA $hostB)" |
| 35 |
echo " e.g. $0 myserverA myserverB" |
| 36 |
exit -1 |
| 37 |
fi |
| 38 |
|
| 39 |
r_a echo foo || (echo "ssh must be setup for $hostA with public-key login" && false) || exit -1 |
| 40 |
r_b echo foo || (echo "ssh must be setup for $hostB with public-key login" && false) || exit -1 |
| 41 |
|
| 42 |
scp $(dirname $0)/setup-cross-routing $hostA: |
| 43 |
scp $(dirname $0)/setup-cross-routing $hostB: |
| 44 |
|
| 45 |
############################################################################### |
| 46 |
|
| 47 |
function clean_netns_all { |
| 48 |
for netns in $*; do |
| 49 |
r_both "ip netns delete $netns" 2> /dev/null |
| 50 |
done |
| 51 |
} |
| 52 |
|
| 53 |
function clean_start { |
| 54 |
r_both /etc/init.d/bagpipe-bgp start |
| 55 |
if r_a 'test $(bagpipe-looking-glass summary vpn_instances_count) -ge 1'; then |
| 56 |
r_a /etc/init.d/bagpipe-bgp restart |
| 57 |
fi |
| 58 |
|
| 59 |
if r_b 'test $(bagpipe-looking-glass summary vpn_instances_count) -ge 1'; then |
| 60 |
r_b /etc/init.d/bagpipe-bgp restart |
| 61 |
fi |
| 62 |
} |
| 63 |
|
| 64 |
function wait_ready { |
| 65 |
if [[ $hostA == $hostB ]]; then |
| 66 |
return 0 |
| 67 |
fi |
| 68 |
while (test $(r_a bagpipe-looking-glass summary BGP_established_peers) -eq 0); do |
| 69 |
echo . |
| 70 |
sleep 1 |
| 71 |
done |
| 72 |
} |
| 73 |
|
| 74 |
function clean_stop { |
| 75 |
sleep 2 |
| 76 |
if (test $(r_a bagpipe-looking-glass summary local_routes_count) -ne 0); then |
| 77 |
echo "warning: $hostA not cleaned up" |
| 78 |
fi |
| 79 |
if (test $(r_a bagpipe-looking-glass summary received_routes_count) -ne 0); then |
| 80 |
echo "warning: $hostA not cleaned up" |
| 81 |
fi |
| 82 |
if (test $(r_b bagpipe-looking-glass summary local_routes_count) -ne 0); then |
| 83 |
echo "warning: $hostB not cleaned up" |
| 84 |
fi |
| 85 |
if (test $(r_b bagpipe-looking-glass summary received_routes_count) -ne 0); then |
| 86 |
echo "warning: $hostB not cleaned up" |
| 87 |
fi |
| 88 |
# r_both /etc/init.d/bagpipe-bgp stop |
| 89 |
} |
| 90 |
|