-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-simulation.sh
executable file
·170 lines (139 loc) · 4.3 KB
/
run-simulation.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
#!/usr/bin/bash
# Color and paths vars are imported
source "paths.cfg"
# Get the system type
system_type=$(uname)
# Start time
tic=$(date +%s)
# Default values
serverType='Edge'
tcpTypeId='UDP'
build_ns3=1
pass_through=""
custom_name=""
open_folder=0
helpFunction()
{
echo ""
echo "Usage: $0 -t $tcpTypeId -s $serverType -b -o -p \"--arg=val\""
echo -e "\t-t 'TcpNewReno' or 'TcpBbr' or 'TcpCubic' or 'TcpHighSpeed' or 'TcpBic' or 'TcpLinuxReno' or 'UDP'"
echo -e "\t-s 'Remote' or 'Edge'"
echo -e "\t-b Skips the build step of ns3, it always builds by default"
echo -e "\t-p Pass through commands to the simulation, args must be inside quotes \"--arg=value\""
echo -e "\t-c Custom folder name for the simulation data"
echo -e "\t-o Open folder with results at the end of simulation and processing"
exit 1 # Exit script after printing help
}
while getopts "t:r:s:bp:c:o" opt
do
case "$opt" in
t ) tcpTypeId="$OPTARG" ;;
s ) serverType="$OPTARG" ;;
b ) build_ns3=0 ;;
p ) pass_through="$OPTARG" ;;
c ) custom_name="$OPTARG" ;;
o ) open_folder=1 ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
# Validations
if [ "$serverType" != "Remote" ] && [ "$serverType" != "Edge" ]
then
echo "ServerType \"$serverType\" not available";
helpFunction
fi
if [ "$tcpTypeId" != "UDP" ] && [ "$tcpTypeId" != "TcpNewReno" ] && [ "$tcpTypeId" != "TcpBbr" ] && [ "$tcpTypeId" != "TcpCubic" ] && [ "$tcpTypeId" != "TcpHighSpeed" ] && [ "$tcpTypeId" != "TcpBic" ] && [ "$tcpTypeId" != "TcpLinuxReno" ]
then
echo "tcpTypeId \"$tcpTypeId\" not available";
helpFunction
fi
if [ "$build_ns3" == "1" ]
then
"${RUTA_NS3}/ns3" build
if [ "$?" != "0" ]; then
printf "${red}Error while building, simulation cancelled! ${clear}\n"
exit 1
fi
clear
echo "NS3 was built!"
fi
printf "\nRunning ${magenta}$0 -t ${tcpTypeId} -s ${serverType}${clear}\n"
if [ "$tcpTypeId" == "UDP" ]
then
flowType='UDP'
else
flowType='TCP'
fi
servertag=${serverType:0:1}
#backup run-sim and cc
outfolder="${RUTA_PROBE}/out"
oldname_path=""
if ([ "$custom_name" == "" ] || [[ $custom_name = *" "* ]])
then
bkfolder=$tcpTypeId"-"$servertag"-"`date +%Y%m%d%H%M`
else
bkfolder=$custom_name
oldname_path=$outfolder/$bkfolder/$tcpTypeId"-"$servertag"-"`date +%Y%m%d%H%M`".oldname"
fi
me=`basename "$0"`
if [ ! -d "$outfolder" ];
then
mkdir -p $outfolder
fi
if [ ! -d "$outfolder/$bkfolder" ];
then
mkdir -p $outfolder/$bkfolder
if [[ $oldname_path != "" ]]
then
touch $oldname_path
fi
else
printf "${magenta}Directory already exists, using default name...${clear}\n"
bkfolder=$tcpTypeId"-"$servertag"-"`date +%Y%m%d%H%M`
mkdir $outfolder/$bkfolder
fi
echo
printf "Argument values... \n tcpTypeId: ${magenta}${tcpTypeId}${clear}\tServer: ${green}${serverType}${clear}\n"
printf "Destination Folder: ${blue}${bkfolder}${clear}\n"
echo
backupfolder="scriptsBackup"
mkdir $outfolder/$bkfolder/$backupfolder
cp $me $outfolder/$bkfolder/$backupfolder/$me.txt
cp $RUTA_CC $outfolder/$bkfolder/$backupfolder/$FILENAME.txt
cp "${RUTA_PROBE}/packet-error-rate.sh" $outfolder/$bkfolder/$backupfolder/packet-error-rate.sh.txt
cp "${RUTA_PROBE}/graph.py" $outfolder/$bkfolder/$backupfolder/graph.py.txt
"${RUTA_NS3}/ns3" run "${FILENAME}
--flowType=$flowType
--tcpTypeId=$tcpTypeId
--serverType=$serverType
$pass_through
" --cwd "$outfolder/$bkfolder" --no-build
exit_status=$?
echo
printf "Running... Packet Error Rate Script\n"
echo
sh "${RUTA_PROBE}/packet-error-rate.sh" $outfolder/$bkfolder
if [ "$exit_status" != "0" ]; then
printf "${red}Error ${exit_status} while simulating, simulation cancelled! ${clear}\n"
echo "Graphs scripts were not run."
exit $exit_status
fi
echo
printf "Running... Graph Script\n"
echo
python3 "${RUTA_PROBE}/graph.py" $outfolder/$bkfolder $RUTA_PROBE
toc=$(date +%s)
printf "Simulation Processed in: "${magenta}$(($toc-$tic))${clear}" seconds\n"
if [ "$open_folder" != "0" ]
then
# Check if the system is macOS
if [[ "$system_type" == "Darwin" ]]; then
open $outfolder/$bkfolder
# Check if the system is Linux
elif [[ "$system_type" == "Linux" ]]; then
explorer $outfolder/$bkfolder
# If neither macOS nor Linux
else
echo "Unable to open folder."
fi
fi