335e4fff27d3c68329bb37f43f135342ebc93c4e
[anna.git] / example / diameter / launcher / resources_lite / configure.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6
7 # Diameter dictionary:
8 STD_DICTIONARY=stacks/avps_etsi.xml,stacks/avps_ietf.xml,stacks/avps_tgpp.xml,stacks/commands_baseProtocol.xml
9 APP_DICTIONARY=stacks/commands_pccPS_EricssonSAPC_se.xml
10 DICTIONARY=$STD_DICTIONARY,$APP_DICTIONARY
11 # Perhaps the stack is not fully defined:
12 KINDNESS=-ignoreErrors
13
14 # Communication endpoints:
15 LOCAL_STANDARD_ENDPOINT=localhost:3868
16 EXAMPLE_ENTITY_4_BALANCER=192.168.12.11:3868,192.168.12.21:3868
17 CONNS=10
18
19 # General
20 EXE_BN=ADL-launcher
21
22 # Tracing:
23 TRACING="-cntDir counters"
24 # need detailed traces ?:
25 #TRACING="$TRACING -trace debug"
26
27 #############
28 # FUNCTIONS #
29 #############
30
31 _exit () {
32   echo
33   echo $1
34   echo
35   exit 1
36 }
37
38 # $1: process name
39 createRunScript () {
40
41   cat << EOF > run.sh
42 #!/bin/bash
43 cd \`dirname \$0\`
44 EXE=\`cat .exe 2>/dev/null\`
45 STARTED=\`pgrep $1 2>/dev/null\`
46 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
47 echo $1 > .exe
48 0> launcher.traces
49 # Execution line:
50 ./$@ &
51 echo \$! > .pid
52 EOF
53
54   chmod a+x run.sh
55 }
56
57 # $1: input option (c, s, b, d)
58 # Retuns the type of launcher logical name for the input option
59 get_tol () {
60   [ "$1" = "c" ] && echo client
61   [ "$1" = "s" ] && echo server
62   [ "$1" = "b" ] && echo balancer
63   [ "$1" = "d" ] && echo dummy
64 }
65
66 #############
67 # EXECUTION #
68 #############
69 cd `dirname $0`
70 SCR_DIR=`pwd`
71 echo
72 echo
73 echo "Configure a (c)lient, (s)erver, (b)alancer or (d)ummy [c]:"
74 read option
75 [ "$option" = "" ] && option=c
76 tol=$(get_tol $option)
77 [ "$tol" = "" ] && _exit "Option '$option' not implemented !!"
78
79 # Run script:
80 EXE_LINK=ADL-$tol
81 ln -sf $EXE_BN $EXE_LINK
82
83 case $tol in
84
85   client)
86     ENTITY=$LOCAL_STANDARD_ENDPOINT
87     createRunScript $EXE_LINK -dictionary $DICTIONARY -entity $ENTITY -entityServerSessions $CONNS -diameterServerSessions 0 $KINDNESS $TRACING &
88     ;;
89
90   server)
91     SERVER=$LOCAL_STANDARD_ENDPOINT
92     createRunScript $EXE_LINK -dictionary $DICTIONARY -diameterServer $SERVER -diameterServerSessions $CONNS -entityServerSessions 0 $KINDNESS $TRACING &
93     ;;
94
95   balancer)
96     SERVER=$LOCAL_STANDARD_ENDPOINT
97     ENTITY=$EXAMPLE_ENTITY_4_BALANCER
98     createRunScript $EXE_LINK -dictionary $DICTIONARY -entity $ENTITY -entityServerSessions $CONNS -diameterServer $SERVER -diameterServerSessions $CONNS -balance $KINDNESS $TRACING &
99     ;;
100
101   dummy)
102     createRunScript $EXE_LINK -dictionary $DICTIONARY -entityServerSessions 0 -diameterServerSessions 0 $KINDNESS $TRACING &
103     ;;
104
105 esac
106
107 echo "Created 'run.sh' script !"
108 echo