-
Notifications
You must be signed in to change notification settings - Fork 13
/
ops-simu-run.sh
executable file
·179 lines (149 loc) · 4.63 KB
/
ops-simu-run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# Bash script to run a developed ops model either as
# only command line (cmdenv) or with GUI (tkenv).
#
# @author: Asanga Udugama ([email protected])
# @author: Jens Dede ([email protected])
# @date: 15-January-2018
#
source ./res/tools/shell-functions.sh
loadSettings
# Show help message
showUsage(){
echo "Usage:"
echo " $0 [PARAMS]"
echo ""
echo " -m cmdenv|qtenv : Mandatory, set the simulation type (command line vs. GUI)"
echo " -c <ini file> : Optional, set the simulation ini file"
echo " -o <output dir> : Optional, set the simulation output directory"
echo " -b <backup dir> : Optional, backup results to this directory (beta)"
}
if [[ "$OSTYPE" == "darwin"* ]]; then
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$KEETCHI_API_LIB:$INET_LIB
elif [[ "$OSTYPE" == "linux"* ]]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$KEETCHI_API_LIB:$INET_LIB
fi
# Check if the simulation executable exists
if [[ -x ./$OPS_MODEL_NAME ]]; then
echo "Found simulation \"./$OPS_MODEL_NAME\""
else
echo "Cannot find the simulation executable \"./$OPS_MODEL_NAME\". Have you run \"make\"?"
exit 1
fi
while [ "$#" -gt 0 ]; do
case "$1" in
-m)
if [ -z ${2+x} ]; then
echo "Missing parameter for \"$1\""
showUsage
exit 1
fi
modeval="$2"
shift 2
;;
-h)
showUsage
exit 0
;;
-c)
if [ -z ${2+x} ]; then
echo "Missing parameter for \"$1\""
showUsage
exit 1
fi
OMNET_INI_FILE="$2"
shift 2
;;
-o)
if [ -z ${2+x} ]; then
echo "Missing parameter for \"$1\""
showUsage
exit 1
fi
SIM_OUTPUT_DIR="$2"
shift 2
;;
-b)
if [ -z ${2+x} ]; then
echo "Missing parameter for \"$1\""
showUsage
exit 1
fi
BACKUP_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1" >&2
showUsage
exit 1
;;
esac
done
# Check if the ini file exists and is accessible
if [ ! -f $OMNET_INI_FILE ]; then
echo "Simulation configuration file \"$OMNETPP_INI_FILE\" not found. Aborting"
exit 1
fi
case "$modeval" in
cmdenv)
SIMTYPE="Cmdenv"
;;
qtenv)
SIMTYPE="Qtenv"
;;
*)
echo "Mode not specified" >&2
showUsage
exit 1
;;
esac
# Is a default output directory defined in the settings? Use this one.
# Otherwise create a generic one
GENERIC_SIM_OUTPUT_DIR=$(basename $OMNET_INI_FILE)
GENERIC_SIM_OUTPUT_DIR="$OMNET_OUTPUT_DIR$(date +"%Y-%m-%d_%H-%M-%S")_${GENERIC_SIM_OUTPUT_DIR%.*}"
if [ -z ${SIM_OUTPUT_DIR+x} ]; then
SIM_OUTPUT_DIR=$GENERIC_SIM_OUTPUT_DIR
fi
mkdir -p simulations/$SIM_OUTPUT_DIR
# Keep the ini file in the output directory
cp $OMNET_INI_FILE simulations/$SIM_OUTPUT_DIR
echo ""
echo "############################# Simulation Settings #############################"
echo "#"
echo "# \$OMNET_INI_FILE : $OMNET_INI_FILE"
echo "# \$SIM_OUTPUT_DIR : simulations/$SIM_OUTPUT_DIR"
echo "#"
echo "# Simulation mode : $SIMTYPE"
echo "#"
echo "# Post processing : $PARSERS_FILE"
echo "#"
echo "# Simulation command:"
echo "# ./$OPS_MODEL_NAME -u $SIMTYPE -f $OMNET_INI_FILE -n simulations/:src/:$INET_NED/ -l keetchi -l INET --result-dir=$SIM_OUTPUT_DIR" | tee simulations/$SIM_OUTPUT_DIR/sim_command.txt
echo "#"
echo "###############################################################################"
echo ""
SIM_START_DAY=$(date +%Y%m%d) # For later logfile localization
./$OPS_MODEL_NAME -u $SIMTYPE -f $OMNET_INI_FILE -n simulations/:src/:$INET_NED/ -l keetchi -l INET --result-dir=$SIM_OUTPUT_DIR
ret=$?
# Did the simulation return something else than "0"? -> Error
if [ $ret -ne 0 ]; then
echo "Error during simulation run. Simulation returned code $ret"
exit $ret
fi
# Simulation done. Perform post-processing steps
echo "Simulation ended successfully"
if [ -z ${BACKUP_DIR+x} ]; then
echo "Not backing up the data!"
else
if [ -d $BACKUP_DIR ]; then
INPUTDIR="simulations/$SIM_OUTPUT_DIR"
BACKUPFILE="$BACKUP_DIR/$HOSTNAME-$(basename $GENERIC_SIM_OUTPUT_DIR).tar.gz"
mkdir -p outdir
tar -cvzf "$BACKUPFILE" "$INPUTDIR"
else
echo "##########"
echo "\"$BACKUP_DIR\" is not a valid directory. Canceling backup..."
echo "##########"
fi
fi