-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTotalNetwork.py
More file actions
325 lines (213 loc) · 11.1 KB
/
TotalNetwork.py
File metadata and controls
325 lines (213 loc) · 11.1 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
import Substrate as sbs
import RAN_Slice as ran
import AlgorithmOne as algoOne
import AlgorithmTwo as algoTwo
import AlgorithmThree as algoThree
import AlgorithmFour as algoFour
from graph_tool.all import *
import random
iterCount = 5
randUpBoundSbs = -2
randUpBoundVnf = 4
intervalFactor = 20
varSbsDeg = 2
varSbsBand = -2
# Substrate Global Variables
numSubsNodes = 60
resCapList = []
resCtPerSbs = 4
sbsDegree = 4
substrateNetwork = 0
sbsBandValue = 5
# RAN Global Variables
ranSlices = 0
resList = []
numRnSlices = 1
vnfBandValue = 3
vnfDegree = 2
numVnfFunctions = 200
resCtPerVnf = 2
vnfCncList = []
vnfTotalAccList = []
# Other Global
totalNetwork = 0
def createSbsNetwork(numSubsNodes= 10, resCapList = [], resCtPerSbs=4, connectivity=2, random_range = randUpBoundSbs): # Default Parameters
# substrateNetwork = random_graph(numSubsNodes, randomDegreeSbs, directed=False, parallel_edges=False, self_loops=False, random=True)
# substrateNetwork = complete_graph(numSubsNodes, self_loops=False, directed=False)
substrateNetwork = circular_graph(numSubsNodes, k= connectivity, self_loops=False, directed=False)
for idx in range(numSubsNodes):
resCapList.append(random.randint(resCtPerSbs, resCtPerSbs + random_range)) #+2
sbs.setSbsNetworkProperties(substrateNetwork)
sbs.setSbsTowerProperties(substrateNetwork, resCapList)
graph_draw(substrateNetwork, output="Graph-Figures/sbs.png", vertex_text = substrateNetwork.vp.get("resourceCapacity"))
return substrateNetwork;
# Setting up the RAN Slice
def createRANSlice(numRnSlices = 1, numVnfFunctions = 10, resList = [], resCtPerVnf = 2, connectivity = 2, random_range =randUpBoundVnf):
# for loopIter in range(numRnSlices):
# ranSlices.append(random_graph(numVnfFunctions, randomDegreeVnf, directed=False, parallel_edges=False, self_loops=False, random=True))
ranSlices = Graph(directed=False)
networkSlices = []
numVnfFunctions *= numRnSlices
for loopIter in range(numRnSlices):
ranSlice = circular_graph(numVnfFunctions, k= connectivity, self_loops=False, directed=False)
for idx in range(numVnfFunctions):
resList.append(random.randint(resCtPerVnf, resCtPerVnf)) # +2
ran.setRANSliceProperties(ranSlice)
ran.setVNFFunctionProperties(ranSlice, resList, loopIter)
networkSlices.append(ranSlice)
for slices in networkSlices:
graph_union(ranSlices, slices, include = True, internal_props=True)
graph_draw(ranSlices, output="Graph-Figures/ran.png")
return ranSlices;
def createTotalNetwork(substrateNetwork, ranSlices, vnfCncList = [], vnfTotalAccList = []) :
# Creating the Total Network
totalNetwork = Graph(directed=False)
totalNetwork = graph_union(totalNetwork, substrateNetwork, include = True, internal_props=True)
totalNetwork = graph_union(totalNetwork, ranSlices, include = True, internal_props=True)
# Testing the Created Network
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resourceCapacity"), output="Graph-Figures/test_total_resCap.png", output_size= (1920, 1080))
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("binaryMappingVar"), output="Graph-Figures/test_total_binaryMapVar.png", output_size= (1920, 1080))
vnfCncList = getUpdatedCncList(totalNetwork)
vnfTotalAccList = getUpdatedResourcesAcc(totalNetwork)
return totalNetwork;
# Can only find if the
def getUpdatedResourcesAcc(totalNetwork, layer = "RAN"):
resAccList = []
if layer == "RAN":
vnfList = getLayerList(totalNetwork)
# updating the total resources Acc
for node in vnfList:
resAcc = totalNetwork.vp.resources[node]
for neighborNode in node.all_neighbors():
if totalNetwork.vp.binaryMappingVar[neighborNode] >= 0:
resAcc += totalNetwork.vp.resources[neighborNode]
totalNetwork.vp.totalResourcesAcc[node] = resAcc
resAccList.append(resAcc)
elif layer == "Substrate": # Substrate Towers
sbsList = getLayerList(totalNetwork, layer = "Substrate")
# Updating Total Resources for Sbs
for node in sbsList:
resAcc = totalNetwork.vp.resourceCapacity[node]
for neighborNode in node.all_neighbors():
if totalNetwork.vp.binaryMappingVar[neighborNode] < 0:
resAcc += totalNetwork.vp.resourceCapacity[neighborNode]
totalNetwork.vp.totalResourcesAcc[node] = resAcc
resAccList.append(resAcc)
else:
print("Wrong Layer name entered for the getUpdatesResourcesAcc Function")
return resAccList;
def resetNetwork(totalNetwork, substrateNetwork, ranSlices):
eraseMappedEdges = find_edge(totalNetwork, totalNetwork.ep.bandwidth, 0)
# Removing all the mapped Edges
for mappedEdge in eraseMappedEdges:
totalNetwork.remove_edge(mappedEdge)
# Resetting the connections
totalNetwork = Graph(directed=False)
totalNetwork = graph_union(totalNetwork, substrateNetwork, include = True, internal_props=True)
totalNetwork = graph_union(totalNetwork, ranSlices, include = True, internal_props=True)
def algoOneTest(totalNetwork, substrateNetwork = Graph(directed=False), ranSlices = Graph(directed=False), resList = [], resCapList = []):
resList = getUpdatedResList(totalNetwork)
resCapList = getUpdatedResList(totalNetwork, layer = "Substrate")
# Testing Algorithm One
maxGreedyMapping = algoOne.algorithmOne(totalNetwork, resList, resCapList, True)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resourceCapacity"), output="Graph-Figures/algo_one_sbs.png", inline_scale=10)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resources"), output="Graph-Figures/algo_one_vnf.png", inline_scale=10)
# Outputting the values for the Algorithm
print("Algo One Embeddings - " + str(maxGreedyMapping))
return maxGreedyMapping;
def getUpdatedResList(totalNetwork, layer = "RAN"):
resList = []
if layer == "RAN":
vnfList = getLayerList(totalNetwork)
for vnf in vnfList:
resList.append(totalNetwork.vp.resources[vnf])
elif layer == "Substrate": # Substrate Layer
sbsList = getLayerList(totalNetwork, layer = "Substrate")
for sbs in sbsList:
resList.append(totalNetwork.vp.resourceCapacity[sbs])
else:
print("Wrong layer name enteredfor the getUpdatedResList function")
return resList;
# Algorithm Two
def algoTwoTest(totalNetwork, vnfCncList = []):
vnfCncList = getUpdatedCncList(totalNetwork)
neighborhoodMapping = algoTwo.algorithmTwo(totalNetwork, vnfCncList)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resourceCapacity"), output="Graph-Figures/algo_two_sbs.png", inline_scale=10)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resources"), output="Graph-Figures/algo_two_vnf.png", inline_scale=10)
print("Algo Two Mapping - " + str(neighborhoodMapping))
return neighborhoodMapping;
def getLayerList(totalNetwork, layer ="RAN"):
layerList = []
if layer == "RAN":
for node in totalNetwork.vertices():
if totalNetwork.vp.binaryMappingVar[node] >= 0:
layerList.append(node)
elif layer == "Substrate":
for node in totalNetwork.vertices():
if totalNetwork.vp.binaryMappingVar[node] < 0:
layerList.append(node)
else:
print("Wrong Layer Name Entered for the getLayer Function")
return layerList;
def getUpdatedCncList(totalNetwork, layer = "RAN"):
cncList = []
if layer == 'RAN':
vnfList = getLayerList(totalNetwork)
# Updating the Degree
for node in vnfList:
vnfNeighborCount = 0
for neighborNode in node.all_neighbors():
if totalNetwork.vp.binaryMappingVar[neighborNode] >= 0:
vnfNeighborCount += 1
totalNetwork.vp.degree[node] = vnfNeighborCount
cncList.append(vnfNeighborCount)
elif layer == "Substrate":
sbsList = getLayerList(totalNetwork, layer = "Substrate")
for node in sbsList:
sbsNeighborCount = 0
for neighborNode in node.all_neighbors():
if totalNetwork.vp.binaryMappingVar[neighborNode] < 0:
sbsNeighborCount += 1
totalNetwork.vp.degree[node] = sbsNeighborCount
cncList.append(sbsNeighborCount)
else:
print("Wrong Layer Name Given for the getUpdatedCncList function")
return cncList;
# Algorithm Three
def algoThreeTest(totalNetwork, vnfTotalAccList = []):
vnfTotalAccList = getUpdatedResourcesAcc(totalNetwork)
neighborhoodMappingTwo = algoThree.algorithmThree(totalNetwork, vnfTotalAccList)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resourceCapacity"), output="Graph-Figures/algo_three_sbs.png", inline_scale=10)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resources"), output="Graph-Figures/algo_three_vnf.png", inline_scale=10)
print("Algo Three Mapping - " + str(neighborhoodMappingTwo))
return neighborhoodMappingTwo;
def algoFourTest(totalNetwork, substrateNetwork = Graph(directed=False), ranSlices = Graph(directed=False), resCapList = [], vnfCncList = []):
resCapList = getUpdatedResList(totalNetwork, layer = "Substrate")
vnfCncList = getUpdatedCncList(totalNetwork)
# Testing Algorithm One
maxGreedyMapping = algoFour.algorithmFour(totalNetwork, resCapList, vnfCncList, True)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resourceCapacity"), output="Graph-Figures/algo_one_sbs.png", inline_scale=10)
graph_draw(totalNetwork, vertex_text = totalNetwork.vertex_properties.get("resources"), output="Graph-Figures/algo_one_vnf.png", inline_scale=10)
# Outputting the values for the Algorithm
print("Algo Four Mapping considering max. connections: " + str(maxGreedyMapping))
return maxGreedyMapping;
def findTotalSbsMapped(totalNetwork):
totalSbsMapped = 0
sbsNetwork = find_vertex(totalNetwork, totalNetwork.vp.graphName, "Substrate")
for sbsTower in sbsNetwork:
for edgeConnection in sbsTower.all_edges():
if totalNetwork.ep.bandwidth[edgeConnection] == 0:
totalSbsMapped += 1
break
return totalSbsMapped;
def sbsAvailableRes(totalNetwork):
resAvail = 0
sbsNetwork = find_vertex(totalNetwork, totalNetwork.vp.graphName, "Substrate")
for sbsTower in sbsNetwork:
resAvail += totalNetwork.vp.resourceCapacity[sbsTower]
return resAvail;
def updateVnfMapVar(totalNetwork, ranSlices = 0):
# Trying to update the ranSlices network with the Total Network
for networkNode in totalNetwork.vertices():
if totalNetwork.vp.binaryMappingVar[networkNode] == 2 or totalNetwork.vp.binaryMappingVar[networkNode] == 3:
totalNetwork.vp.binaryMappingVar[networkNode] = 0