-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_centralized.py
140 lines (114 loc) · 5.5 KB
/
main_centralized.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
from sim.Simulator import *
from sim.Application import *
from sim.Distribution import *
from sim.Selector import *
from sim.DataCentre import *
from sim.Ingress import *
from sim.Substrate import *
from sim.SubstrateSelector import *
from library import *
from pathlib import Path
import sys
import json
import random
import logging
def main_centralized(randomSeed, appArgs, runtime, argument, DCPos, IngressPos):
np.random.seed(randomSeed)
random.seed(randomSeed)
# selector = WaxmanSelector()
# selector = VNFG()
# selector = ONP_SFO(15)
selector = MIX_ver2(30)
selector = HRE_ver2()
subSelector = ShortestPath()
# subSelector = AlphaSubsel()
# subSelector = BetaSubsel()
# app = SequenceApp(dist, selector, subSelector, *appArgs)
app = WaxmanApp(dist, selector, subSelector, *appArgs)
apps = [app]
# substrate = Abilene(DCPos=[2], IngressPos=[5, 7, 9, 10], linkCap=100,
# DCArgs=[2], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = Abilene(DCPos=[], IngressPos=[5, 7, 9, 10], linkCap=100,
# DCArgs=[], IngressArgs=[apps, apps, apps, apps], n_clusters=1)
# substrate = Abilene(DCPos=[10], IngressPos=IngressPos, linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = Europe(DCPos=[], IngressPos=[5, 7, 9, 10], linkCap=100,
# DCArgs=[], IngressArgs=[apps, apps, apps, apps], n_clusters=1)
# substrate = Atlanta(DCPos=[], IngressPos=[5, 7, 9, 10], linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=1)
# substrate = France(DCPos=[], IngressPos=[5, 7, 9, 10], linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=1)
substrate = Abilene(DCPos=DCPos, IngressPos=IngressPos, linkCap=100,
DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = BigAbilene(DCPos=DCPos, IngressPos=IngressPos, linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = Europe(DCPos=DCPos, IngressPos=IngressPos, linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = France(DCPos=DCPos, IngressPos=IngressPos, linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
# substrate = Atlanta(DCPos=DCPos, IngressPos=IngressPos, linkCap=100,
# DCArgs=[10], IngressArgs=[apps, apps, apps, apps], n_clusters=0)
######################################## folder name
# spec = f"{n_VNFs[0]}{n_VNFs[1]}_{demand_VNF[0]}{demand_VNF[1]}_{bw[0]}{bw[1]}_{runtime}"
spec = f"{DCPos[0]}/{IngressPos[0]}{IngressPos[1]}{IngressPos[2]}{IngressPos[3]}"
folder_result = f"{selector.name}/cent/{spec}"
########################################
folder_log = Path(f"results/{folder_result}")
folder_log.mkdir(parents=True, exist_ok=True)
folder_log = str(folder_log) + "/cent_"
if(len(argument) == 1):
folder_log = str(folder_log) + f"{argument[0]}"
if(len(argument) == 2):
folder_log = str(folder_log) + f"{argument[0]}{argument[1]}"
sim = Simulator(substrate, folder_log, logging.DEBUG, True, *argument)
sim.run(runtime)
logging.warning("CENTRALIZED")
logging.warning(f"L = {dist.lamda}, TTL = {avg_TTL}")
logging.warning(f"nvnf = {n_VNFs}, bw = {bw}")
logging.warning(f"runtime = {runtime}, strategy = {argument[0]}")
logging.warning(f"randomSeed = {randomSeed}")
if(len(argument) == 2):
logging.warning(f"sortmode = {argument[1]}")
if __name__ == "__main__":
print("-----START SIMULATION-----")
strategy = int(sys.argv[1])
if(len(sys.argv) == 3):
sortmode = sys.argv[2]
arg = [strategy, sortmode]
else:
arg = [strategy]
randomSeed = 1111
dist = Poisson(lamda=2)
avg_TTL = 120
n_VNFs = [4, 10]
demand_VNF = [15, 30]
bw = [10, 90]
runtime = 200
appArgs = [avg_TTL, n_VNFs, demand_VNF, bw, [0.5, 0.5]]
# brute force
# # N_NODES = 12 # Abilene
# # N_NODES = 39 # BigAbilene
# # N_NODES = 37 # Europe
# N_NODES = 25 # France
# # N_NODES = 15 # Atlanta
# BUFFER = 5
# IGR_PER_DC_CASE = 10
# nodes = list(range(1, N_NODES + 1))
# shell = int(sys.argv[2])
# DCPos = list(itertools.combinations(nodes, 1))
# dcCount = BUFFER * (shell-1)
# for _dcpos in DCPos[BUFFER*(shell-1) : BUFFER*shell]:
# dcCount += 1
# ingressSpace = [node for node in nodes if not node in _dcpos]
# ingressPos = list(itertools.combinations(ingressSpace, 4))
# ingCount = 0
# # for i in range(1, IGR_PER_DC_CASE + 1):
# # ingCount += 1
# # print(f"DC: {dcCount}/{len(DCPos)} ({round(dcCount % BUFFER / BUFFER * 100, )}%), Ingress: {ingCount}/{IGR_PER_DC_CASE}")
# # main_centralized(randomSeed, appArgs, runtime, arg, list(_dcpos), list(ingressPos[random.randint(0, len(ingressPos) + 1)]))
# for _ingpos in ingressPos:
# ingCount += 1
# print(f"DC: {dcCount}/{len(DCPos)} ({round(dcCount % BUFFER / BUFFER * 100, )}%), Ingress: {ingCount}/{len(ingressPos)}")
# main_centralized(randomSeed, appArgs, runtime, arg, list(_dcpos), list(_ingpos))
# run one case
main_centralized(randomSeed, appArgs, runtime, arg, [10], [5, 7, 9, 10])