-
Notifications
You must be signed in to change notification settings - Fork 0
/
domainConfiguration.py
444 lines (319 loc) · 15.4 KB
/
domainConfiguration.py
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue May 22 15:58:58 2018
@author: carlos
"""
import networkx as nx
import random
import operator
import json
import numpy
# random.seed(8)
#random_state = numpy.random.RandomState(8)
verbose_log = False
generatePlots = True
graphicTerminal =True
myConfiguration_ = 'newage'
myConfiguration_ = "toguapho"
myConfiguration_ = "journal"
storageFolder = ''
def initializeRandom(seed_):
random.seed(seed_)
def setRandomState(value):
random_state = numpy.random.RandomState(value)
#****************************************************************************************************
#Generacion de la topologia de red
#****************************************************************************************************
def networkModel(filePrefix):
#TOPOLOGY GENERATION
global G
global nodeResources
global nodeFreeResources
global devices
global gatewaysDevices
global cloudgatewaysDevices
global cloudId
global Gfdev
G = eval(func_NETWORKGENERATION)
#G = nx.barbell_graph(5, 1)
# if graphicTerminal:
# nx.draw(G)
# #nx.draw_networkx_labels(G,pos=nx.spring_layout(G,seed=2022))
# nx.draw_networkx_labels(G,pos=nx.spring_layout(G))
Gfdev=G.copy()
devices = list()
nodeResources = {}
nodeFreeResources = {}
for i in G.nodes:
nodeResources[i]=eval(func_NODERESOURECES)
nodeFreeResources[i] = nodeResources[i]
for e in G.edges:
G[e[0]][e[1]]['PR']=eval(func_PROPAGATIONTIME)
G[e[0]][e[1]]['BW']=eval(func_BANDWITDH)
Gfdev[e[0]][e[1]]['PR'] = G[e[0]][e[1]]['PR']
Gfdev[e[0]][e[1]]['BW'] = G[e[0]][e[1]]['BW']
#JSON EXPORT
netJson={}
for i in G.nodes:
myNode ={}
myNode['id']=i
myNode['RAM']=nodeResources[i]
myNode['HD']=1
myNode['IPT']=1
devices.append(myNode)
myEdges = list()
for e in G.edges:
myLink={}
myLink['s']=e[0]
myLink['d']=e[1]
myLink['PR']=G[e[0]][e[1]]['PR']
myLink['BW']=G[e[0]][e[1]]['BW']
myEdges.append(myLink)
#TODO, debería de estar con weight='weight' ??????
#the centrality value is used to choose the nodes connected to the cloud (highest centrality) and
#the nodes where the clients are connected to (lowest centrality)
#gatewaysDevices is the set of devices where user can be connected to
#and cloudgatewaysDevices is the set of devices that has the highest centrality (usually one device)
#centralityValuesNoOrdered = nx.betweenness_centrality(G,weight="weight",seed=2022)
centralityValuesNoOrdered = nx.betweenness_centrality(G,weight="weight")
centralityValues=sorted(centralityValuesNoOrdered.items(), key=operator.itemgetter(1), reverse=True)
gatewaysDevices = set()
cloudgatewaysDevices = set()
highestCentrality = centralityValues[0][1]
for device in centralityValues:
if device[1]==highestCentrality:
cloudgatewaysDevices.add(device[0])
#centralityValues has the nodes ordered from the higher centrality to the lowest
#to choose the edges devices (gateways) the structure is iterated only in the percentatge
#number of devices at the end of the list
initialIndx = int((1-PERCENTATGEOFGATEWAYS)*len(G.nodes)) #Indice del final para los X tanto por ciento nodos
for idDev in range(initialIndx,len(G.nodes)):
gatewaysDevices.add(centralityValues[idDev][0])
cloudId = len(G.nodes)
myNode ={}
myNode['id']=cloudId
myNode['RAM']=CLOUDCAPACITY
myNode['HD']=1
myNode['IPT']=1
myNode['type']='CLOUD'
devices.append(myNode)
G.add_node(cloudId)
for cloudGtw in cloudgatewaysDevices:
myLink={}
myLink['s']=cloudGtw
myLink['d']=cloudId
myLink['PR']=CLOUDPR
myLink['BW']=CLOUDBW
G.add_edge(cloudId,cloudGtw)
G[cloudId][cloudGtw]['PR']=CLOUDPR
G[cloudId][cloudGtw]['BW']=CLOUDBW
myEdges.append(myLink)
netJson['entity']=devices
netJson['link']=myEdges
#file = open(filePrefix+"network.json","w")
file = open(storageFolder+"network.json","w")
file.write(json.dumps(netJson))
file.close()
def setConfigurations():
global CLOUDCAPACITY
global CLOUDBW
global CLOUDPR
global func_NETWORKGENERATION
global PERCENTATGEOFGATEWAYS
global func_PROPAGATIONTIME
global func_BANDWITDH
global func_NODERESOURECES
global TOTALNUMBEROFAPPS
global TOTALNUMBEROFNODES
global func_APPMESSAGESIZE
global func_APPRESOURCES
global func_SERVICEINSTR
global func_USERREQRAT
global func_REQUESTPROB
#****************************************************************************************************
#INICIALIZACIONES Y CONFIGURACIONES
#****************************************************************************************************
if myConfiguration_ == 'newage':
#CLOUD
CLOUDCAPACITY = 9999999999999999 #MB RAM
CLOUDBW = 125000 # BYTES / MS --> 1000 Mbits/s
CLOUDPR = 1 # MS
#NETWORK
PERCENTATGEOFGATEWAYS = 0.25
#TOTALNUMBEROFNODES = 10 # se queda en loop infinito en GAcolonyPartition2 metodo createPopulationCol
TOTALNUMBEROFNODES = 17
func_PROPAGATIONTIME = "random.randint(1,5)" #MS
func_BANDWITDH = "random.randint(50000,75000)" # BYTES / MS
#func_NETWORKGENERATION = "nx.barabasi_albert_graph(seed=2022,n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
func_NETWORKGENERATION = "nx.barabasi_albert_graph(n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
#func_NODERESOURECES = "random.randint(10,25)" #MB RAM #random distribution for the resources of the fog devices
func_NODERESOURECES = "random.randint(10,15)" #MB RAM #random distribution for the resources of the fog devices
#APSS
TOTALNUMBEROFAPPS = 5
func_APPMESSAGESIZE = "random.randint(1500000,4500000)" #BYTES y teniendo en cuenta net bandwidth nos da entre 20 y 60 MS
func_APPRESOURCES = "random.randint(1,6)" #MB de ram que consume el servicio, teniendo en cuenta noderesources y appgeneration tenemos que nos caben aprox 1 app por nodo o unos 10 servicios
func_SERVICEINSTR = "random.randint(400000,600000)"
func_SERVICEINSTR = "4"
#USERS and IoT DEVICES
#func_REQUESTPROB="random.random()/4" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_REQUESTPROB="random.random()/2" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_USERREQRAT="random.randint(200,1000)" #MS
if myConfiguration_ == "toguapho":
#CLOUD
CLOUDCAPACITY = 9999999999999999 #MB RAM
CLOUDBW = 125000 # BYTES / MS --> 1000 Mbits/s
CLOUDPR = 1 # MS
#NETWORK
PERCENTATGEOFGATEWAYS = 0.25
TOTALNUMBEROFNODES = 200
func_PROPAGATIONTIME = "random.randint(1,5)" #MS
func_BANDWITDH = "random.randint(50000,75000)" # BYTES / MS
#func_NETWORKGENERATION = "nx.barabasi_albert_graph(seed=2022,n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
func_NETWORKGENERATION = "nx.barabasi_albert_graph(n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
#func_NODERESOURECES = "random.randint(10,25)" #MB RAM #random distribution for the resources of the fog devices
func_NODERESOURECES = "random.randint(10,15)" #MB RAM #random distribution for the resources of the fog devices
#APSS
TOTALNUMBEROFAPPS = 20
func_APPMESSAGESIZE = "random.randint(1500000,4500000)" #BYTES y teniendo en cuenta net bandwidth nos da entre 20 y 60 MS
func_APPRESOURCES = "random.randint(1,6)" #MB de ram que consume el servicio, teniendo en cuenta noderesources y appgeneration tenemos que nos caben aprox 1 app por nodo o unos 10 servicios
func_SERVICEINSTR = "random.randint(400000,600000)"
#USERS and IoT DEVICES
#func_REQUESTPROB="random.random()/4" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_REQUESTPROB="3*random.random()/4" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_USERREQRAT="random.randint(200,1000)" #MS
if myConfiguration_ == "journal":
#CLOUD
CLOUDCAPACITY = 9999999999999999 #MB RAM
CLOUDBW = 125000 # BYTES / MS --> 1000 Mbits/s
CLOUDPR = 100 # MS
#NETWORK
PERCENTATGEOFGATEWAYS = 0.25
TOTALNUMBEROFNODES = 200
func_PROPAGATIONTIME = "random.randint(2,6)" #MS
func_BANDWITDH = "random.randint(50000,75000)" # BYTES / MS
#func_NETWORKGENERATION = "nx.barabasi_albert_graph(seed=2022,n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
func_NETWORKGENERATION = "nx.barabasi_albert_graph(n="+str(TOTALNUMBEROFNODES)+", m=2)" #algorithm for the generation of the network topology
#func_NODERESOURECES = "random.randint(10,25)" #MB RAM #random distribution for the resources of the fog devices
func_NODERESOURECES = "random.randint(1,4)" #MB RAM #random distribution for the resources of the fog devices
#APSS
TOTALNUMBEROFAPPS = 20
func_APPMESSAGESIZE = "random.randint(100,20000)" #BYTES y teniendo en cuenta net bandwidth nos da entre 20 y 60 MS
func_APPRESOURCES = "random.randint(1,2)" #MB de ram que consume el servicio, teniendo en cuenta noderesources y appgeneration tenemos que nos caben aprox 1 app por nodo o unos 10 servicios
func_SERVICEINSTR = "random.randint(1000,3500)"
#USERS and IoT DEVICES
#func_REQUESTPROB="random.random()/4" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_REQUESTPROB="3*random.random()/4" #Popularidad de la app. threshold que determina la probabilidad de que un dispositivo tenga asociado peticiones a una app. tle threshold es para cada ap
func_USERREQRAT="random.randint(5,10)" #MS
def appsGeneration():
global appsResources
global appsPacketsSize
global ReadPacketsSize
global filesReadRatio
global apps
appJson=list()
appsResources = [0 for j in range(TOTALNUMBEROFAPPS)]
appsPacketsSize = [0 for j in range(TOTALNUMBEROFAPPS)]
appsInstructions = [0 for j in range(TOTALNUMBEROFAPPS)]
apps = [0 for j in range(TOTALNUMBEROFAPPS)]
for j in range(0,TOTALNUMBEROFAPPS):
appsResources[j]=eval(func_APPRESOURCES)
appsPacketsSize[j]=eval(func_APPMESSAGESIZE)
appsInstructions[j]=eval(func_SERVICEINSTR)
apps[j]={}
apps[j]['app']=j
apps[j]['resources']=appsResources[j]
apps[j]['packetsize']=appsPacketsSize[j]
apps[j]['instructions']=appsInstructions[j]
#all the lines below for json generation
oneApp = {}
oneApp['name']=str(j)
oneApp['id']=0
oneApp['deadline']=999999
#adding modules
oneApp['module']=list()
moduleCoord ={}
moduleCoord['RAM'] = 0
moduleCoord['type'] = 'MANAGEMENT'
moduleCoord['id'] = j*2
moduleCoord['name'] = "C_"+str(j)
oneApp['module'].append(moduleCoord)
moduleApp ={}
moduleApp['RAM'] = apps[j]['resources']
moduleApp['type'] = 'APP'
moduleApp['id'] = j*2+1
moduleApp['name'] = "A_"+str(j)
oneApp['module'].append(moduleApp)
#adding transmissions
oneApp['transmission']=list()
transUserCoord ={}
transUserCoord['message_out'] = 'MCA.'+str(j)
transUserCoord['message_in'] = 'MUC.'+str(j)
transUserCoord['module'] = "C_"+str(j)
oneApp['transmission'].append(transUserCoord)
transCoordApp ={}
transCoordApp['message_in'] = 'MCA.'+str(j)
transCoordApp['module'] = "A_"+str(j)
oneApp['transmission'].append(transCoordApp)
#adding messages
oneApp['message']=list()
messUserCoord ={}
messUserCoord['name'] = 'MUC.'+str(j)
messUserCoord['bytes'] = apps[j]['packetsize']
messUserCoord['d'] = "C_"+str(j)
messUserCoord['s'] = "None"
messUserCoord['id'] = j*2
messUserCoord['instructions'] = 0
oneApp['message'].append(messUserCoord)
messCoordApp ={}
messCoordApp['name'] = 'MCA.'+str(j)
messCoordApp['bytes'] = apps[j]['packetsize']
messCoordApp['d'] = "A_"+str(j)
messCoordApp['s'] = "C_"+str(j)
messCoordApp['id'] = j*2+1
messCoordApp['instructions'] = apps[j]['instructions']
oneApp['message'].append(messCoordApp)
appJson.append(oneApp)
file = open(storageFolder+"appDefinition.json","w")
file.write(json.dumps(appJson))
file.close()
def usersConnectionGeneration():
#****************************************************************************************************
#Generacion de los IoT devices (users) que requestean cada aplciacion
#****************************************************************************************************
global myUsers
global appsRequests
userJson ={}
myUsers=list()
appsRequests = list()
for i in range(0,TOTALNUMBEROFAPPS):
userRequestList = set()
probOfRequested = eval(func_REQUESTPROB)
atLeastOneAllocated = False
for j in gatewaysDevices:
if random.random()<probOfRequested:
myOneUser={}
myOneUser['app']=str(i)
myOneUser['message']="MUC."+str(i)
myOneUser['id_resource']=j
myOneUser['lambda']=eval(func_USERREQRAT)
userRequestList.add(j)
myUsers.append(myOneUser)
atLeastOneAllocated = True
if not atLeastOneAllocated:
j=random.randint(0,len(gatewaysDevices)-1)
myOneUser={}
myOneUser['app']=str(i)
myOneUser['message']="MUC."+str(i)
myOneUser['id_resource']=j
myOneUser['lambda']=eval(func_USERREQRAT)
userRequestList.add(j)
myUsers.append(myOneUser)
appsRequests.append(userRequestList)
userJson['sources']=myUsers
file = open(storageFolder+"usersDefinition.json","w")
file.write(json.dumps(userJson))
file.close()
#****************************************************************************************************
#FIN GENERACION MODELO
#****************************************************************************************************