-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathSampleNetworkModel.java
More file actions
361 lines (325 loc) · 14 KB
/
SampleNetworkModel.java
File metadata and controls
361 lines (325 loc) · 14 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
* Title: EdgeCloudSim - Network Model
*
* Description:
* SampleNetworkModel uses
* -> the result of an empirical study for the WLAN and WAN delays
* The experimental network model is developed
* by taking measurements from the real life deployments.
*
* -> MMPP/MMPP/1 queue model for MAN delay
* MAN delay is observed via a single server queue model with
* Markov-modulated Poisson process (MMPP) arrivals.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.tutorial1;
import org.cloudbus.cloudsim.core.CloudSim;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.edge_client.Task;
import edu.boun.edgecloudsim.network.NetworkModel;
import edu.boun.edgecloudsim.utils.Location;
import edu.boun.edgecloudsim.utils.SimLogger;
public class SampleNetworkModel extends NetworkModel {
// Overview:
// - Maintains concurrent user counts per WLAN (edge AP) and WAN link.
// - Uses empirical per-user aggregate throughput tables (Kbps) to derive transfer delay.
// - MAN (edge-to-edge relay) modeled with constant internal LAN delay (from settings).
// - Upload and download assumed symmetric for WAN and WLAN in this simplified model.
// Delay formula: delay_seconds = (data_size_KB * 8 bits_per_byte) / effective_throughput_Kbps
// WLAN adjustment: divides by (throughput * 3) to approximate 802.11ac vs 802.11n speed gain.
public static enum NETWORK_TYPE {WLAN, LAN};
public static enum LINK_TYPE {DOWNLOAD, UPLOAD};
@SuppressWarnings("unused")
private int manClients; // active MAN relay transfers (edge<->edge); single shared queue abstraction
private int[] wanClients; // active WAN sessions per WLAN zone (indexed by servingWlanId)
private int[] wlanClients; // active WLAN sessions per WLAN zone
// Empirical per-user WLAN aggregate throughput (Kbps).
// Index == number of concurrent WLAN clients. Used to approximate contention impact.
// Note: duplicate comment "15 Clients" in source preserved; second value actually for 16? Kept intact for compatibility.
public static final double[] experimentalWlanDelay = {
/*1 Client*/ 88040.279 /*(Kbps)*/,
/*2 Clients*/ 45150.982 /*(Kbps)*/,
/*3 Clients*/ 30303.641 /*(Kbps)*/,
/*4 Clients*/ 27617.211 /*(Kbps)*/,
/*5 Clients*/ 24868.616 /*(Kbps)*/,
/*6 Clients*/ 22242.296 /*(Kbps)*/,
/*7 Clients*/ 20524.064 /*(Kbps)*/,
/*8 Clients*/ 18744.889 /*(Kbps)*/,
/*9 Clients*/ 17058.827 /*(Kbps)*/,
/*10 Clients*/ 15690.455 /*(Kbps)*/,
/*11 Clients*/ 14127.744 /*(Kbps)*/,
/*12 Clients*/ 13522.408 /*(Kbps)*/,
/*13 Clients*/ 13177.631 /*(Kbps)*/,
/*14 Clients*/ 12811.330 /*(Kbps)*/,
/*15 Clients*/ 12584.387 /*(Kbps)*/,
/*15 Clients*/ 12135.161 /*(Kbps)*/,
/*16 Clients*/ 11705.638 /*(Kbps)*/,
/*17 Clients*/ 11276.116 /*(Kbps)*/,
/*18 Clients*/ 10846.594 /*(Kbps)*/,
/*19 Clients*/ 10417.071 /*(Kbps)*/,
/*20 Clients*/ 9987.549 /*(Kbps)*/,
/*21 Clients*/ 9367.587 /*(Kbps)*/,
/*22 Clients*/ 8747.625 /*(Kbps)*/,
/*23 Clients*/ 8127.663 /*(Kbps)*/,
/*24 Clients*/ 7907.701 /*(Kbps)*/,
/*25 Clients*/ 7887.739 /*(Kbps)*/,
/*26 Clients*/ 7690.831 /*(Kbps)*/,
/*27 Clients*/ 7393.922 /*(Kbps)*/,
/*28 Clients*/ 7297.014 /*(Kbps)*/,
/*29 Clients*/ 7100.106 /*(Kbps)*/,
/*30 Clients*/ 6903.197 /*(Kbps)*/,
/*31 Clients*/ 6701.986 /*(Kbps)*/,
/*32 Clients*/ 6500.776 /*(Kbps)*/,
/*33 Clients*/ 6399.565 /*(Kbps)*/,
/*34 Clients*/ 6098.354 /*(Kbps)*/,
/*35 Clients*/ 5897.143 /*(Kbps)*/,
/*36 Clients*/ 5552.127 /*(Kbps)*/,
/*37 Clients*/ 5207.111 /*(Kbps)*/,
/*38 Clients*/ 4862.096 /*(Kbps)*/,
/*39 Clients*/ 4517.080 /*(Kbps)*/,
/*40 Clients*/ 4172.064 /*(Kbps)*/,
/*41 Clients*/ 4092.922 /*(Kbps)*/,
/*42 Clients*/ 4013.781 /*(Kbps)*/,
/*43 Clients*/ 3934.639 /*(Kbps)*/,
/*44 Clients*/ 3855.498 /*(Kbps)*/,
/*45 Clients*/ 3776.356 /*(Kbps)*/,
/*46 Clients*/ 3697.215 /*(Kbps)*/,
/*47 Clients*/ 3618.073 /*(Kbps)*/,
/*48 Clients*/ 3538.932 /*(Kbps)*/,
/*49 Clients*/ 3459.790 /*(Kbps)*/,
/*50 Clients*/ 3380.649 /*(Kbps)*/,
/*51 Clients*/ 3274.611 /*(Kbps)*/,
/*52 Clients*/ 3168.573 /*(Kbps)*/,
/*53 Clients*/ 3062.536 /*(Kbps)*/,
/*54 Clients*/ 2956.498 /*(Kbps)*/,
/*55 Clients*/ 2850.461 /*(Kbps)*/,
/*56 Clients*/ 2744.423 /*(Kbps)*/,
/*57 Clients*/ 2638.386 /*(Kbps)*/,
/*58 Clients*/ 2532.348 /*(Kbps)*/,
/*59 Clients*/ 2426.310 /*(Kbps)*/,
/*60 Clients*/ 2320.273 /*(Kbps)*/,
/*61 Clients*/ 2283.828 /*(Kbps)*/,
/*62 Clients*/ 2247.383 /*(Kbps)*/,
/*63 Clients*/ 2210.939 /*(Kbps)*/,
/*64 Clients*/ 2174.494 /*(Kbps)*/,
/*65 Clients*/ 2138.049 /*(Kbps)*/,
/*66 Clients*/ 2101.604 /*(Kbps)*/,
/*67 Clients*/ 2065.160 /*(Kbps)*/,
/*68 Clients*/ 2028.715 /*(Kbps)*/,
/*69 Clients*/ 1992.270 /*(Kbps)*/,
/*70 Clients*/ 1955.825 /*(Kbps)*/,
/*71 Clients*/ 1946.788 /*(Kbps)*/,
/*72 Clients*/ 1937.751 /*(Kbps)*/,
/*73 Clients*/ 1928.714 /*(Kbps)*/,
/*74 Clients*/ 1919.677 /*(Kbps)*/,
/*75 Clients*/ 1910.640 /*(Kbps)*/,
/*76 Clients*/ 1901.603 /*(Kbps)*/,
/*77 Clients*/ 1892.566 /*(Kbps)*/,
/*78 Clients*/ 1883.529 /*(Kbps)*/,
/*79 Clients*/ 1874.492 /*(Kbps)*/,
/*80 Clients*/ 1865.455 /*(Kbps)*/,
/*81 Clients*/ 1833.185 /*(Kbps)*/,
/*82 Clients*/ 1800.915 /*(Kbps)*/,
/*83 Clients*/ 1768.645 /*(Kbps)*/,
/*84 Clients*/ 1736.375 /*(Kbps)*/,
/*85 Clients*/ 1704.106 /*(Kbps)*/,
/*86 Clients*/ 1671.836 /*(Kbps)*/,
/*87 Clients*/ 1639.566 /*(Kbps)*/,
/*88 Clients*/ 1607.296 /*(Kbps)*/,
/*89 Clients*/ 1575.026 /*(Kbps)*/,
/*90 Clients*/ 1542.756 /*(Kbps)*/,
/*91 Clients*/ 1538.544 /*(Kbps)*/,
/*92 Clients*/ 1534.331 /*(Kbps)*/,
/*93 Clients*/ 1530.119 /*(Kbps)*/,
/*94 Clients*/ 1525.906 /*(Kbps)*/,
/*95 Clients*/ 1521.694 /*(Kbps)*/,
/*96 Clients*/ 1517.481 /*(Kbps)*/,
/*97 Clients*/ 1513.269 /*(Kbps)*/,
/*98 Clients*/ 1509.056 /*(Kbps)*/,
/*99 Clients*/ 1504.844 /*(Kbps)*/,
/*100 Clients*/ 1500.631 /*(Kbps)*/
};
// Empirical per-user WAN throughput (Kbps) for upstream/downstream symmetry assumption.
public static final double[] experimentalWanDelay = {
/*1 Client*/ 20703.973 /*(Kbps)*/,
/*2 Clients*/ 12023.957 /*(Kbps)*/,
/*3 Clients*/ 9887.785 /*(Kbps)*/,
/*4 Clients*/ 8915.775 /*(Kbps)*/,
/*5 Clients*/ 8259.277 /*(Kbps)*/,
/*6 Clients*/ 7560.574 /*(Kbps)*/,
/*7 Clients*/ 7262.140 /*(Kbps)*/,
/*8 Clients*/ 7155.361 /*(Kbps)*/,
/*9 Clients*/ 7041.153 /*(Kbps)*/,
/*10 Clients*/ 6994.595 /*(Kbps)*/,
/*11 Clients*/ 6653.232 /*(Kbps)*/,
/*12 Clients*/ 6111.868 /*(Kbps)*/,
/*13 Clients*/ 5570.505 /*(Kbps)*/,
/*14 Clients*/ 5029.142 /*(Kbps)*/,
/*15 Clients*/ 4487.779 /*(Kbps)*/,
/*16 Clients*/ 3899.729 /*(Kbps)*/,
/*17 Clients*/ 3311.680 /*(Kbps)*/,
/*18 Clients*/ 2723.631 /*(Kbps)*/,
/*19 Clients*/ 2135.582 /*(Kbps)*/,
/*20 Clients*/ 1547.533 /*(Kbps)*/,
/*21 Clients*/ 1500.252 /*(Kbps)*/,
/*22 Clients*/ 1452.972 /*(Kbps)*/,
/*23 Clients*/ 1405.692 /*(Kbps)*/,
/*24 Clients*/ 1358.411 /*(Kbps)*/,
/*25 Clients*/ 1311.131 /*(Kbps)*/
};
public SampleNetworkModel(int _numberOfMobileDevices, String _simScenario) {
super(_numberOfMobileDevices, _simScenario);
}
@Override
public void initialize() {
// One WAN and WLAN access point per edge datacenter (servingWlanId acts as index).
// Arrays store current concurrent session counts used to pick throughput entries.
wanClients = new int[SimSettings.getInstance().getNumOfEdgeDatacenters()]; //we have one access point for each datacenter
wlanClients = new int[SimSettings.getInstance().getNumOfEdgeDatacenters()]; //we have one access point for each datacenter
}
/**
* Upload delay from mobile to target device.
* Branches:
* - MAN relay (edge->edge): constant internal LAN delay
* - Cloud: WAN empirical table
* - Edge: WLAN empirical table
*/
@Override
public double getUploadDelay(int sourceDeviceId, int destDeviceId, Task task) {
double delay = 0;
//special case for man communication
if(sourceDeviceId == destDeviceId && sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
// Special MAN case: same generic edge ID used as placeholder (relay hop)
return delay = getManUploadDelay();
}
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(sourceDeviceId,CloudSim.clock());
//mobile device to cloud server
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID){
delay = getWanUploadDelay(accessPointLocation, task.getCloudletFileSize());
}
//mobile device to edge device (wifi access point)
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID) {
// Fetch current WLAN zone of mobile for throughput lookup
delay = getWlanUploadDelay(accessPointLocation, task.getCloudletFileSize());
}
return delay;
}
/**
* Download delay to mobile from source device.
* Symmetric logic to upload with MAN shortcut.
*/
@Override
public double getDownloadDelay(int sourceDeviceId, int destDeviceId, Task task) {
double delay = 0;
//special case for man communication
if(sourceDeviceId == destDeviceId && sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
// Special MAN case
return delay = getManDownloadDelay();
}
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(destDeviceId,CloudSim.clock());
//cloud server to mobile device
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID){
delay = getWanDownloadDelay(accessPointLocation, task.getCloudletOutputSize());
}
//edge device (wifi access point) to mobile device
else{
// Destination (mobile) current WLAN determines contention level
delay = getWlanDownloadDelay(accessPointLocation, task.getCloudletOutputSize());
}
return delay;
}
@Override
public void uploadStarted(Location accessPointLocation, int destDeviceId) {
// Increment concurrent session counters to reflect resource occupation.
// Consistency: every started must have matching finished for accurate contention.
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]++;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]++;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients++;
else {
SimLogger.printLine("Error - unknown device id in uploadStarted(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void uploadFinished(Location accessPointLocation, int destDeviceId) {
// Decrement counters; negative values would indicate logic errors (not checked here).
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]--;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]--;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients--;
else {
SimLogger.printLine("Error - unknown device id in uploadFinished(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void downloadStarted(Location accessPointLocation, int sourceDeviceId) {
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]++;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]++;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients++;
else {
SimLogger.printLine("Error - unknown device id in downloadStarted(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void downloadFinished(Location accessPointLocation, int sourceDeviceId) {
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]--;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]--;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients--;
else {
SimLogger.printLine("Error - unknown device id in downloadFinished(). Terminating simulation...");
System.exit(0);
}
}
private double getWlanDownloadDelay(Location accessPointLocation, double dataSize) {
// Convert KB -> Kb, then divide by empirical throughput (adjusted x3 for 802.11ac uplift).
// If #users exceeds table length => result stays 0 (interpreted as bandwidth failure upstream).
int numOfWlanUser = wlanClients[accessPointLocation.getServingWlanId()];
double taskSizeInKb = dataSize * (double)8; //KB to Kb
double result=0;
if(numOfWlanUser < experimentalWlanDelay.length)
result = taskSizeInKb /*Kb*/ / (experimentalWlanDelay[numOfWlanUser] * (double) 3 ) /*Kbps*/; //802.11ac is around 3 times faster than 802.11n
//System.out.println("--> " + numOfWlanUser + " user, " + taskSizeInKb + " KB, " +result + " sec");
return result;
}
// WLAN upload mirrors download (symmetric assumption).
private double getWlanUploadDelay(Location accessPointLocation, double dataSize) {
return getWlanDownloadDelay(accessPointLocation, dataSize);
}
private double getWanDownloadDelay(Location accessPointLocation, double dataSize) {
// Similar to WLAN formula without 802.11ac multiplier (table already calibrated).
int numOfWanUser = wanClients[accessPointLocation.getServingWlanId()];
double taskSizeInKb = dataSize * (double)8; //KB to Kb
double result=0;
if(numOfWanUser < experimentalWanDelay.length)
result = taskSizeInKb /*Kb*/ / (experimentalWanDelay[numOfWanUser]) /*Kbps*/;
//System.out.println("--> " + numOfWanUser + " user, " + taskSizeInKb + " KB, " +result + " sec");
return result;
}
// WAN upload mirrors download (symmetric assumption).
private double getWanUploadDelay(Location accessPointLocation, double dataSize) {
return getWanDownloadDelay(accessPointLocation, dataSize);
}
private double getManDownloadDelay() {
// Constant latency model for internal MAN (could be replaced by queue model).
return SimSettings.getInstance().getInternalLanDelay();
}
private double getManUploadDelay() {
return SimSettings.getInstance().getInternalLanDelay();
}
}