-
Notifications
You must be signed in to change notification settings - Fork 0
/
djaminit
executable file
·178 lines (146 loc) · 5.23 KB
/
djaminit
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
178
#!/bin/bash
IDIR="${BASH_SOURCE%/*}"
if [[ ! -d "$IDIR" ]]; then IDIR="$PWD"; fi
source "$IDIR/inc/pumba_tools.sh"
source "$IDIR/inc/misc_tools.sh"
show_usage() {
cat << EOF
djaminit --ideal
The inter-container delays are not manipulated. They are set at the natural values
to get a packet transmitted from container A to container B. No other option
should be specified with this one.
djaminit --zones=num_of_zones --indelay=delay:jitter --outdelay=delay:jitter
Inside a zone we have small delays and between zones we have large delays.
The '--indelay' option tells the delay and jitter within a zone and '--outdelay'
tells the delay and jitter between zones.
djaminit --cldelay=delay:jitter
Is the delay and jitter to the cloud from the zones.
The pumba is started if the option is not '--ideal'.
All delay and jitter values are in milliseconds. IMPORTANT: Just numbers should
be specified - no units.
EOF
}
# Show the usage
if [ -z $1 ]; then
show_usage
exit
fi
# Check the __jamruns folder
jamfolder=$HOME"/__jamruns"
create_missingdir $jamfolder
ideal=
zones=1
cldelay=0:0
indelay=0:0
outdelay=0:0
while :; do
case $1 in
-h|-\?|--help)
show_usage # Display a usage synopsis.
exit
;;
-c|--cldelay) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
cldelay=$2
shift
else
die 'ERROR: "--cldelay" requires a non-empty option argument.'
fi
;;
--cldelay=?*)
cldelay=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--cldelay=) # Handle the case of an empty
die 'ERROR: "--cldelay" requires a non-empty option argument.'
;;
-i|--indelay) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
indelay=$2
shift
else
die 'ERROR: "--indelay" requires a non-empty option argument.'
fi
;;
--indelay=?*)
indelay=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--indelay=) # Handle the case of an empty
die 'ERROR: "--indelay" requires a non-empty option argument.'
;;
-o|--outdelay) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
outdelay=$2
shift
else
die 'ERROR: "--outdelay" requires a non-empty option argument.'
fi
;;
--outdelay=?*)
outdelay=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--outdelay=) # Handle the case of an empty
die 'ERROR: "--outdelay" requires a non-empty option argument.'
;;
-z|--zones) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
zones=$2
shift
else
die 'ERROR: "--zones" requires a non-empty option argument.'
fi
;;
--zones=?*)
zones=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--zones=) # Handle the case of an empty
die 'ERROR: "--zones" requires a non-empty option argument.'
;;
-d|--ideal)
ideal=1
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
create_missingdir $jamfolder/pumba
if [ ! -z $ideal ]; then
echo "off" > $jamfolder/pumba/status
create_missingdir $jamfolder/zones
echo "1" > $jamfolder/zones/count
killrouterpumba
killcloudpumba
killfogpumba
exit
fi
check_prog pumba "Pumba not installed. Download it from https://github.com/gaia-adm/pumba/releases"
pversion=`pumba -v | cut -d ' ' -f 3 | cut -d '.' -f 1,2`
if (( $(echo "$pversion < 0.5" | bc -l) )); then
echo "Pumba version 0.5 or new is needed. Exiting."
exit
fi
# We are using pumba - validate parameters
clddelay="${cldelay%:*}"
cldjitter="${cldelay##*:}"
inpdelay="${indelay%:*}"
inpjitter="${indelay##*:}"
outpdelay="${outdelay%:*}"
outpjitter="${outdelay##*:}"
save "on" $jamfolder/pumba/status
# Set delay between cloud and fogs
# we are setting for 1 hour recurrent delay. There is one minute every 1hr where the delay is not in effect
save "pumba -l fatal --interval 1h netem --duration 59m delay -t $clddelay -j $cldjitter " $jamfolder/pumba/cloud_cmd
# Set delay inside fog zones
save "pumba -l fatal --interval 1h netem --duration 59m delay -t $inpdelay -j $inpjitter " $jamfolder/pumba/infog_cmd
# Set delay between fog zones
save "pumba -l fatal --interval 1h netem --duration 59m delay -t $outpdelay -j $outpjitter " $jamfolder/pumba/outfog_cmd
# Write the number of num_of_zones
create_missingdir $jamfolder/zones
save $zones $jamfolder/zones/count