1#!/bin/ksh 2# $OpenBSD: eval_all.sh,v 1.3 2021/05/10 10:29:04 claudio Exp $ 3 4set -e 5 6BGPD=$1 7BGPDCONFIGDIR=$2 8RDOMAIN1=$3 9RDOMAIN2=$4 10PAIR1=$5 11PAIR2=$6 12 13RDOMAINS="${RDOMAIN1} ${RDOMAIN2}" 14PAIRS="${PAIR1} ${PAIR2}" 15PAIR1IP=10.12.57.1 16PAIR2IP=10.12.57.2 17PAIR2IP2=10.12.57.3 18PAIR2IP3=10.12.57.4 19PAIR2IP4=10.12.57.5 20 21error_notify() { 22 echo cleanup 23 pkill -T ${RDOMAIN1} bgpd || true 24 pkill -T ${RDOMAIN2} -f exabgp || true 25 sleep 1 26 ifconfig ${PAIR2} destroy || true 27 ifconfig ${PAIR1} destroy || true 28 route -qn -T ${RDOMAIN1} flush || true 29 route -qn -T ${RDOMAIN2} flush || true 30 ifconfig lo${RDOMAIN1} destroy || true 31 ifconfig lo${RDOMAIN2} destroy || true 32 if [ $1 -ne 0 ]; then 33 echo FAILED 34 exit 1 35 else 36 echo SUCCESS 37 fi 38} 39 40run_exabgp() { 41 local _t=$1 42 43 shift 44 env exabgp.log.destination=stdout \ 45 exabgp.log.packets=true \ 46 exabgp.log.parser=true \ 47 exabgp.log.level=DEBUG \ 48 exabgp.api.cli=false \ 49 exabgp.daemon.user=build \ 50 route -T ${RDOMAIN2} exec exabgp -1 ${1+"$@"} > ./exabgp.$_t.log 51} 52 53exacmd() { 54 echo "${1+"$@"}" > eval_all.fifo 55 sleep .1 # give exabgp a bit of time 56} 57 58if [ ! -x /usr/local/bin/exabgp ]; then 59 echo install exabgp from ports for this test >&2 60 exit 1 61fi 62 63if [ "$(id -u)" -ne 0 ]; then 64 echo need root privileges >&2 65 exit 1 66fi 67 68trap 'error_notify $?' EXIT 69 70echo check if rdomains are busy 71for n in ${RDOMAINS}; do 72 if /sbin/ifconfig | grep -v "^lo${n}:" | grep " rdomain ${n} "; then 73 echo routing domain ${n} is already used >&2 74 exit 1 75 fi 76done 77 78echo check if interfaces are busy 79for n in ${PAIRS}; do 80 /sbin/ifconfig "${n}" >/dev/null 2>&1 && \ 81 ( echo interface ${n} is already used >&2; exit 1 ) 82done 83 84set -x 85 86echo setup 87ifconfig ${PAIR1} rdomain ${RDOMAIN1} ${PAIR1IP}/29 up 88ifconfig ${PAIR2} rdomain ${RDOMAIN2} ${PAIR2IP}/29 up 89ifconfig ${PAIR2} alias ${PAIR2IP2}/32 90ifconfig ${PAIR2} alias ${PAIR2IP3}/32 91ifconfig ${PAIR2} alias ${PAIR2IP4}/32 92ifconfig ${PAIR1} patch ${PAIR2} 93ifconfig lo${RDOMAIN1} inet 127.0.0.1/8 94ifconfig lo${RDOMAIN2} inet 127.0.0.1/8 95 96[ -p eval_all.fifo ] || mkfifo eval_all.fifo 97 98echo run bgpd 99route -T ${RDOMAIN1} exec ${BGPD} \ 100 -v -f ${BGPDCONFIGDIR}/bgpd.eval_all.conf 101 102sleep 1 103 104echo run exabgp 105run_exabgp eval_all exabgp.eval_all.conf 2>&1 & 106sleep 2 107 108# initial announcements 109echo test 1 110 111# no filtering 112exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.1.0/24 next-hop self' 113exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.1.0/24 next-hop self' 114# filter from 64501 115exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.2.0/24 next-hop self community [ 64500:64503 64500:64504 ]' 116exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.2.0/24 next-hop self' 117# filter from both 118exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.3.0/24 next-hop self community [ 64500:64503 64500:64504 ]' 119exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.3.0/24 next-hop self community [ 64500:64503 64500:64504 ]' 120# similar with aspath and prepends 121exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.0.1.0/24 next-hop self as-path [ 64501 101 ] community [ 64500:64503 64500:64504 ]' 122exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.0.1.0/24 next-hop self as-path [ 64502 101 101 101 ]' 123 124sleep 3 125route -T ${RDOMAIN1} exec bgpctl sh rib 126(route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.4 detail; 127route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.5 detail ) | \ 128 grep -v 'Last update:' | tee eval_all.out 129sleep .2 130diff -u ${BGPDCONFIGDIR}/eval_all.test1.ok eval_all.out 131echo OK 132 133# withdraw hidden route 134echo 'test 2 (withdraw hidden)' 135 136exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 withdraw route 10.12.2.0/24' 137exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 withdraw route 10.0.1.0/24' 138 139sleep 3 140route -T ${RDOMAIN1} exec bgpctl sh rib 141(route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.4 detail; 142route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.5 detail ) | \ 143 grep -v 'Last update:' | tee eval_all.out 144sleep .2 145diff -u ${BGPDCONFIGDIR}/eval_all.test2.ok eval_all.out 146echo OK 147 148# readd route should give use same result as 1 149echo 'test 3 (readd hidden)' 150 151exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.12.2.0/24 next-hop self' 152exacmd 'neighbor 10.12.57.1 router-id 10.12.57.3 announce route 10.0.1.0/24 next-hop self as-path [ 64502 101 101 101 ]' 153 154sleep 3 155route -T ${RDOMAIN1} exec bgpctl sh rib 156(route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.4 detail; 157route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.5 detail ) | \ 158 grep -v 'Last update:' | tee eval_all.out 159sleep .2 160diff -u ${BGPDCONFIGDIR}/eval_all.test1.ok eval_all.out 161echo OK 162 163# withdraw primary route (should not change output) 164echo 'test 4 (withdraw best)' 165 166exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 withdraw route 10.12.2.0/24' 167exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 withdraw route 10.0.1.0/24' 168 169sleep 3 170route -T ${RDOMAIN1} exec bgpctl sh rib 171(route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.4 detail; 172route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.5 detail ) | \ 173 grep -v 'Last update:' | tee eval_all.out 174sleep .2 175diff -u ${BGPDCONFIGDIR}/eval_all.test4.ok eval_all.out 176echo OK 177 178# readd route should give use same result as 1 179echo 'test 5 (readd best)' 180 181exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.12.2.0/24 next-hop self community [ 64500:64503 64500:64504 ]' 182exacmd 'neighbor 10.12.57.1 router-id 10.12.57.2 announce route 10.0.1.0/24 next-hop self as-path [ 64501 101 ] community [ 64500:64503 64500:64504 ]' 183 184sleep 3 185route -T ${RDOMAIN1} exec bgpctl sh rib 186(route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.4 detail; 187route -T ${RDOMAIN1} exec bgpctl sh rib out nei 10.12.57.5 detail ) | \ 188 grep -v 'Last update:' | tee eval_all.out 189sleep .2 190diff -u ${BGPDCONFIGDIR}/eval_all.test1.ok eval_all.out 191echo OK 192 193exacmd 'shutdown' 194exit 0 195