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