3 #==================================================================================
4 # Copyright (c) 2019 Nokia
5 # Copyright (c) 2018-2019 AT&T Intellectual Property.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #==================================================================================
21 # ---------------------------------------------------------------------------------
22 # Mnemonic: run_multi_test.ksh
23 # Abstract: This is a simple script to set up and run the basic send/receive
24 # processes for some library validation on top of nng. This
25 # particular tests starts several receivers and creates a route table
26 # which causes messages to be sent round robin to all of the receivers.
27 # The number of messages command line parameter (-n) will be the number
28 # of messages that each receiver should expect; the sender will be asked
29 # to send r times that many messages so that as they are round robbined
30 # each receiver should get the same number of messages.
32 # Example command line:
33 # ksh ./run_rr_test.ksh # default 10 messages at 1 msg/sec
34 # ksh ./run_rr_test.ksh -d 100 -n 10000 # send 10k messages with 100ms delay between
37 # Author: E. Scott Daniels
38 # ---------------------------------------------------------------------------------
41 # The sender and receivers are run asynch. Their exit statuses are captured in a
42 # file in order for the 'main' to pick them up easily.
45 export RMR_RTG_SVC=8990
46 ./sender $(( nmsg * nrcvrs )) $delay $max_mtype
47 echo $? >/tmp/PID$$.src # must communicate state back via file b/c asynch
50 # $1 is the instance so we can keep logs separate
54 port=$(( 4560 + ${1:-0} ))
55 export RMR_RTG_SVC=$(( 9990 + $1 ))
56 ./receiver $nmsg $port
57 echo $? >/tmp/PID$$.$1.rrc
61 # Drop a contrived route table in such that the sender sends each message to n
66 typeset endpoints="localhost:4560"
67 for (( i=1; i < ${1:-3}; i++ ))
69 endpoints="$endpoints,localhost:$((port+i))"
74 rte |0 | $endpoints |0
75 rte |1 | $endpoints |10
76 mse |2 | 20 | $endpoints # new style mtype/subid entry
77 rte |3 | $endpoints | -1
78 rte |4 | $endpoints | -1
79 rte |5 | $endpoints | -1
80 rte |6 | $endpoints | -1
81 rte |7 | $endpoints | -1
82 rte |8 | $endpoints | -1
83 rte |9 | $endpoints | -1
84 rte |10 | $endpoints | -1
85 rte |11 | $endpoints | -1
91 # ---------------------------------------------------------
93 if [[ ! -f local.rt ]] # we need the real host name in the local.rt; build one from mask if not there
96 sed "s!%%hostname%%!$hn!" rt.mask >local.rt
99 nmsg=10 # total number of messages to be exchanged (-n value changes)
100 delay=1000 # microsec sleep between msg 1,000,000 == 1s (shorter than others b/c/ we are sending to multiple)
105 max_mtype=1 # causes all msgs to go with type 1; use -M to set up, but likely harder to validate
106 nrcvrs=3 # this is sane, but -r allows it to be set up
112 -b) rebuild=1; nopull="nopull";; # build without pulling
113 -d) delay=$2; shift;;
114 -m) max_mtype=$2; shift;;
116 -r) nrcvrs=$2; shift;;
119 *) echo "unrecognised option: $1"
120 echo "usage: $0 [-B] [-d micor-sec-delay] [-n num-msgs]"
121 echo " -B forces a rebuild which will use .build"
132 export RMR_VCTL_FILE=".verbose"
138 ksh ./rebuild.ksh $nopull | read build_path
141 build_path=${BUILD_PATH:-"../../.build"} # we prefer .build at the root level, but allow user option
143 if [[ ! -d $build_path ]]
145 echo "cannot find build in: $build_path"
146 echo "either create, and then build RMr, or set BUILD_PATH as an evironment var before running this"
151 if [[ -d $build_path/lib64 ]]
153 export LD_LIBRARY_PATH=$build_path:$build_path/lib64
155 export LD_LIBRARY_PATH=$build_path:$build_path/lib
157 export LIBRARY_PATH=$LD_LIBRARY_PATH
158 export RMR_SEED_RT=./rr.rt
162 if [[ ! -f ./sender ]]
164 if ! make >/dev/null 2>&1
166 echo "[FAIL] cannot find sender binary, and cannot make it.... humm?"
171 for (( i=0; i < nrcvrs; i++ )) # start the receivers with an instance number
176 sleep 2 # wait to start sender else we might send before receivers up and drop messages
182 for (( i=0; i < nrcvrs; i++ )) # collect return codes
184 head -1 /tmp/PID$$.$i.rrc | read x
188 head -1 /tmp/PID$$.src | read src
190 if (( !! (src + rrc) ))
192 echo "[FAIL] sender rc=$src receiver rc=$rrc"
194 echo "[PASS] sender rc=$src receiver rc=$rrc"
201 exit $(( !! (src + rrc) ))