📄 test_peering2.sh
字号:
#!/usr/bin/env bash## $XORP: xorp/bgp/harness/test_peering2.sh,v 1.55 2006/08/16 22:10:14 atanu Exp $### Feed saved data to our BGP process.## This script started with no arguments will start all required process and# terminate them at the end of the tests.## Preconditons# 1) Run a finder process# 2) Run a FEA process.# 3) Run a RIB process.# 4) Run xorp "../xorp_bgp"# 5) Run "./test_peer -s peer1"# 6) Run "./test_peer -s peer2"# 7) Run "./test_peer -s peer3"# 8) Run "./coord"#set -e# srcdir is set by make for check targetif [ "X${srcdir}" = "X" ] ; then srcdir=`dirname $0` ; fi. ${srcdir}/xrl_shell_funcs.sh "". ${srcdir}/../xrl_shell_funcs.sh "". ${srcdir}/../../rib/xrl_shell_funcs.sh "". ${srcdir}/notification_codes.shonexit(){ last=$? if [ $last = "0" ] then echo "$0: Tests Succeeded" else echo "$0: Tests Failed" fi trap '' 0 2}trap onexit 0 2HOST=127.0.0.1LOCALHOST=$HOSTID=192.150.187.78AS=65008# IBGPPORT1=10001PEER1_PORT=20001PEER1_AS=$AS# EBGPPORT2=10002PEER2_PORT=20002PEER2_AS=65000# EBGPPORT3=10003PEER3_PORT=20003PEER3_AS=65003HOLDTIME=5TRAFFIC_DIR="${srcdir}/../../../data/bgp"TRAFFIC_FILES="${TRAFFIC_DIR}/icsi1.mrtd"# NOTE: The Win32 versions of coord and peer will perform# path conversion and expansion of /tmp internally.TMPDIR=${TMPDIR:-/tmp}EXT=${LOGNAME:-unknown}configure_bgp(){ local_config $AS $ID # Don't try and talk to the rib. register_rib "" PEER=$HOST NEXT_HOP=192.150.187.78 add_peer $LOCALHOST $PORT1 $PEER $PEER1_PORT $PEER1_AS $NEXT_HOP $HOLDTIME set_parameter $LOCALHOST $PORT1 $PEER $PEER1_PORT MultiProtocol.IPv4.Unicast true enable_peer $LOCALHOST $PORT1 $PEER $PEER1_PORT PEER=$HOST NEXT_HOP=192.150.187.78 add_peer $LOCALHOST $PORT2 $PEER $PEER2_PORT $PEER2_AS $NEXT_HOP $HOLDTIME set_parameter $LOCALHOST $PORT2 $PEER $PEER2_PORT MultiProtocol.IPv4.Unicast true enable_peer $LOCALHOST $PORT2 $PEER $PEER2_PORT PEER=$HOST NEXT_HOP=192.150.187.78 add_peer $LOCALHOST $PORT3 $PEER $PEER3_PORT $PEER3_AS $NEXT_HOP $HOLDTIME set_parameter $LOCALHOST $PORT3 $PEER $PEER3_PORT MultiProtocol.IPv4.Unicast true enable_peer $LOCALHOST $PORT3 $PEER $PEER3_PORT}wait_for_peerdown(){ # Interact with the BGP process itself to find out when the peerings have # gone down. If we are not testing the XORP bgp then replace with the # sleep. while ../tools/print_peers -v | grep 'Peer State' | grep ESTABLISHED do sleep 2 done # SLEEPY=30 # echo "sleeping for $SLEEPY seconds" # sleep $SLEEPY}reset(){ coord reset coord target $HOST $PORT1 coord initialise attach peer1 coord target $HOST $PORT2 coord initialise attach peer2 coord target $HOST $PORT3 coord initialise attach peer3 bgp_not_established while pending | grep true do sleep 2 done # The test_peer has closed its connection to the BGP process. # If the test_peer was injecting a lot of data to the BGP process only # when all the data has been read and processed by the BGP process will it # see the end of the stream. So add an arbitary delay until the BGP process # sees the end of the stream. If we don't do this connection attempts will # be rejected by the the BGP process, causing the tests to fail. wait_for_peerdown}bgp_not_established(){ for i in peer1 peer2 peer3 do status $i while status $i | grep established do sleep 2 done done}bgp_peer_unchanged(){ while : do # debug status $1 a=$(status $1) sleep 2 b=$(status $1) if [ "$a" = "$b" ] then break fi done}delay(){ # XXX - decrementing the counter to zero generates an error? # So count down to one echo "Sleeping for $1 seconds" let counter=$1+1 while [ $counter != 1 ] do sleep 1 let counter=counter-1 echo -e " $counter \r\c" done return 0}test1(){ TFILE=$1 echo "TEST1 - Inject a saved feed then drop peering - $TFILE" # Reset the peers reset coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established NOBLOCK=true coord peer2 send dump mrtd update $TFILE # Wait for the file to be transmitted by the test peer. bgp_peer_unchanged peer2 coord peer2 assert established # Reset the connection reset if [ x"$OSTYPE" != xmsys ]; then uptime echo "NOTE: Occasionally, we fail to make a connection. See the comment in the reset function." fi # Establish the new connection. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established}test2(){ TFILE=$1 echo "TEST2 - Inject a saved feed then toggle another peering - $TFILE" # Reset the peers reset # Establish the EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # send in the saved file NOBLOCK=true coord peer2 send dump mrtd update $TFILE # Wait for the file to be transmitted by the test peer. bgp_peer_unchanged peer2 # Bring up peer1 and wait for it to receive all the updates coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 bgp_peer_unchanged peer1 # Bring up another peering to test the dump code. for i in 1 2 do coord reset coord target $HOST $PORT1 coord initialise attach peer1 # Wait for the peering to be dropped while status peer1 | grep established do sleep 2 done sleep 2 coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 coord peer1 assert established # Wait for the BGP process to send all the updates to peer1 bgp_peer_unchanged peer1 done # The reset above will have removed state about peer2 from the coordinator # but the tcp connection between test_peer2 and the bgp process will not # have been dropped. So by re-initialising like this we will toggle the # original connection. coord target $HOST $PORT2 coord initialise attach peer2 coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # Tearing out peer2 will cause all the routes to be withdrawn, wait bgp_peer_unchanged peer1 # Make sure that the connections are still established. coord peer1 assert established coord peer2 assert established}test3(){ TFILE=$1 echo "TEST3:" echo " 1) Start injecting a saved feed (peer2) - $TFILE" echo " 2) Bring in a second peering (peer1) " echo " 3) Drop the injecting feed (peer2) " # Reset the peers reset # Establish the EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # send in the saved file NOBLOCK=true coord peer2 send dump mrtd update $TFILE # Bring up another peering NOBLOCK=true coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 # Allow some routes to be loaded sleep 5 # Drop the injecting feed NOBLOCK=true coord peer2 disconnect # Wait for the BGP to stabilise bgp_peer_unchanged peer1 # Add a delay so if the BGP process core dumps we detect it. sleep 5 # Make sure that the peer1 connection is still established coord peer1 assert established}test4(){ TFILE=$1 echo "TEST4:" echo " 1) Start injecting a saved feed (peer2) - $TFILE" echo " 2) Immediately bring up a second peering (peer1) " # Reset the peers reset result=$(status peer1) echo "$result" # Establish the EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # send in the saved file NOBLOCK=true coord peer2 send dump mrtd update $TFILE # Bring up a second peering and wait for all the updates to arrive coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 while : do # debug status peer1 status peer2 a=$(status peer1) sleep 2 b=$(status peer1) if [ "$a" = "$b" ] then break fi done # Make sure that the peer1 connection is still established coord peer1 assert established coord peer2 assert established}test5(){ TFILE=$1 echo "TEST5:" echo " 1) Start injecting a saved feed (peer2) - $TFILE" echo " 2) Immediately bring up a second peering (peer1) " echo " 3) Wait for all the updates to arrive at (peer1) " echo " 4) Drop both peerings " echo " 5) Bring up (peer1) " echo " 6) Peer1 should not receive any update traffic " # Reset the peers reset result=$(status peer1) echo "$result" # Establish the EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # send in the saved file NOBLOCK=true coord peer2 send dump mrtd update $TFILE # Bring up a second peering and wait for all the updates to arrive coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 while : do # debug status peer1 status peer2 a=$(status peer1) sleep 2 b=$(status peer1) if [ "$a" = "$b" ] then break fi done coord reset # Debugging to demonstrate that the BGP process believes that both peerings # have been taken down. ../tools/print_peers -v # debug status peer1 status peer2 # Establish peer1 coord target $HOST $PORT1 coord initialise attach peer1 coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 # If peer1 receives any updates this is an error a=$(status peer1) sleep 2 b=$(status peer1) if [ "$a" = "$b" ] then : else echo "Peer1 received updates, but this is the only peering?" echo $a echo $b return -1 fi}test6(){ TFILE=$1 UPDATE_COUNT=10 echo "TEST6 (testing sending only $UPDATE_COUNT updates):" echo " 1) Start injecting a saved feed (peer2) - $TFILE" echo " 2) Immediately bring up a second peering (peer1) " echo " 3) Wait for all the updates to arrive at (peer1) " echo " 4) Verify that both peering still exist." # Reset the peers reset status peer1 status peer1 # Establish the EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # send in the saved file NOBLOCK=true coord peer2 send dump mrtd update $TFILE $UPDATE_COUNT # Bring up a second peering and wait for all the updates to arrive coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 while : do # debug status peer1 status peer2 a=$(status peer1) sleep 2 b=$(status peer1) if [ "$a" = "$b" ] then break fi done status peer1 status peer2 coord peer2 assert established coord peer2 assert established}test7(){ echo "TEST7 (Simple route propogation test - searching for memory leak):" echo " 1) Bring up peering (peer2) and introduce one route" echo " 2) Bring up a second peering (peer1) check route" echo " 3) Tear down both peerings" reset # Establish an EBGP peering. coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # Inject a route coord peer2 send packet update \ origin 2 \ aspath "$PEER2_AS" \ nexthop 10.10.10.10 \ nlri 10.10.10.0/24 sleep 1 # Bring up a second peering coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 sleep 1 coord peer1 assert established coord peer2 assert established reset}test8(){ echo "TEST8 (Simple route propogation test - searching for memory leak):" echo " 1) Bring up peering (peer1)" echo " 2) Bring up a second peering (peer2) and introduce a route" echo " 3) Tear down both peerings" reset coord peer1 establish AS $PEER1_AS holdtime 0 id 192.150.187.101 coord peer1 assert established coord peer2 establish AS $PEER2_AS holdtime 0 id 192.150.187.102 coord peer2 assert established # Inject a route
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -