def main(simulated_time,experimento,file,study,it): random.seed(it) np.random.seed(it) """ TOPOLOGY from a json """ t = Topology() dataNetwork = json.load(open(experimento+file+'-network.json')) t.load(dataNetwork) attNodes = {} for k in t.G.nodes(): attNodes[k] = {"IPT": 1} nx.set_node_attributes(t.G, values=attNodes) # t.write("network.gexf") """ APPLICATION """ studyApp = study if study=="FstrRep": studyApp="Replica" elif study == "Cloud": studyApp="Single" dataApp = json.load(open(experimento+file+'-app%s.json'%studyApp)) apps = create_applications_from_json(dataApp) #for app in apps: # print apps[app] """ PLACEMENT algorithm """ placementJson = json.load(open(experimento+file+'-alloc%s.json'%study)) placement = JSONPlacement(name="Placement",json=placementJson) ### Placement histogram # listDevices =[] # for item in placementJson["initialAllocation"]: # listDevices.append(item["id_resource"]) # import matplotlib.pyplot as plt # print listDevices # print np.histogram(listDevices,bins=range(101)) # plt.hist(listDevices, bins=100) # arguments are passed to np.histogram # plt.title("Placement Histogram") # plt.show() ## exit() """ POPULATION algorithm """ studyUser = study if study == "FstrRep": studyUser = "******" elif study == "Cloud": studyUser = "******" dataPopulation = json.load(open(experimento+file+'-users%s.json'%studyUser)) pop = JSONPopulation(name="Statical",json=dataPopulation,it=it) """ SELECTOR algorithm """ selectorPath = DeviceSpeedAwareRouting() """ SIMULATION ENGINE """ stop_time = simulated_time s = Sim(t, default_results_path=experimento + "Results_%i_%s_%s_%i" % (it,file,study,stop_time)) """ Failure process """ # time_shift = 10000 # distribution = deterministicDistributionStartPoint(name="Deterministic", time=time_shift,start=10000) # failurefilelog = open(experimento+"Failure_%s_%i.csv" % (ilpPath,stop_time),"w") # failurefilelog.write("node, module, time\n") # idCloud = t.find_IDs({"type": "CLOUD"})[0] #[0] -> In this study there is only one CLOUD DEVICE # centrality = np.load(pathExperimento+"centrality.npy") # randomValues = np.load(pathExperimento+"random.npy") # # s.deploy_monitor("Failure Generation", failureControl, distribution,sim=s,filelog=failurefilelog,ids=centrality) # s.deploy_monitor("Failure Generation", failureControl, distribution,sim=s,filelog=failurefilelog,ids=randomValues) #For each deployment the user - population have to contain only its specific sources for aName in apps.keys(): #print "Deploying app: ",aName pop_app = JSONPopulation(name="Statical_%s"%aName,json={},it=it) data = [] for element in pop.data["sources"]: if element['app'] == aName: data.append(element) pop_app.data["sources"]=data s.deploy_app(apps[aName], placement, pop_app, selectorPath) s.run(stop_time, test_initial_deploy=False, show_progress_monitor=False) #TEST to TRUE
t.load(dataNetwork) t.write(path + "network.gexf") # t = loadTopology(path + 'test_GLP.gml') """ APPLICATION """ dataApp = json.load(open(path + 'appDefinition.json')) apps = create_applications_from_json(dataApp) # for app in apps: # print apps[app] """ PLACEMENT algorithm """ # In our model only initial cloud placements are enabled placementJson = json.load(open(path + 'allocDefinition.json')) placement = JSONPlacement(name="Placement", json=placementJson) """ SELECTOR and Deploying algorithm """ selectorPath = DeviceSpeedAwareRouting() """ SIMULATION ENGINE """ stop_time = simulated_time s = Sim(t, default_results_path=pathResults + "Results_%s_%i_%i" % (case, stop_time, it)) """ POPULATION algorithm """ dataPopulation = json.load(open(path + 'usersDefinition.json'))
def main(simulated_time): random.seed(RANDOM_SEED) """ TOPOLOGY from a json """ t = Topology() data = json.load(open('egg_infrastructure.json')) pprint(data["entity"]) t.load(data) t.write("network.gexf") """ APPLICATION """ app = create_application() """ PLACEMENT algorithm """ #This adaptation can be done manually or automatically. # We make a simple manual allocation from the FogTorch output #8 - [client_0_0->sp_0_0][client_0_1->sp_0_1][client_0_2->sp_0_2][client_0_3->sp_0_3][client_1_0->sp_1_0][client_1_1->sp_1_1][client_1_2->sp_1_2] # [client_1_3->sp_1_3] # [concentrator->gw_0][coordinator->gw_1]; 0.105; 2.5; 6.01 placementJson = { "initialAllocation": [ {"app": "EGG_GAME", "module_name": "Calculator", "id_resource": 3}, {"app": "EGG_GAME", "module_name": "Coordinator", "id_resource": 8}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 4}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 5}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 6}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 7}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 9}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 10}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 11}, {"app": "EGG_GAME", "module_name": "Client", "id_resource": 12}, ] } placement = JSONPlacement(name="Places",json=placementJson) """ POPULATION algorithm """ populationJSON = { "sinks": [ {"app": "EGG_GAME", "module_name": "Display", "id_resource": 4}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 5}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 6}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 7}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 9}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 10}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 11}, {"app": "EGG_GAME", "module_name": "Display", "id_resource": 12} ], "sources":[ {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":4}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":5}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":6}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":7}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":9}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":10}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":11}, {"app": "EGG_GAME", "message":"M.EGG", "lambda":100,"id_resource":12}, ] } pop = JSONPopulation(name="Statical",json=populationJSON,iteration=0) """ SELECTOR algorithm """ selectorPath = MinShortPath() """ SIMULATION ENGINE """ stop_time = simulated_time s = Sim(t, default_results_path="Results_%i" % (stop_time)) s.deploy_app(app, placement, pop, selectorPath) s.run(stop_time, test_initial_deploy=False, show_progress_monitor=False) s.print_debug_assignaments()
def main(stop_time, it): ''' TOPOLOGY DEFINITION (from JSON file) ''' THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) topology_json = json.load( open(THIS_FOLDER + '/data/topology_definition.json')) t = Topology() t.load_all_node_attr(topology_json) nx.write_gexf(t.G, THIS_FOLDER + "/results/topology.gexf" ) # exported .gexf file for visualizing it with Gephi print(t.G.nodes()) ''' APPLICATION DEFINITION (from JSON file) ''' THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) app_json = json.load(open(THIS_FOLDER + '/data/app_definition.json')) apps = create_applications_from_json( app_json) # this array will consist of only one app ''' MODULE PLACEMENT (from JSON file) ''' placement_json = json.load( open(THIS_FOLDER + '/data/alloc_definition.json')) placement = JSONPlacement(name="Placement", json=placement_json) ''' ROUTING ALGORITHM (of messages along the topology) ''' selector_path = DeviceSpeedAwareRouting() ''' SIMULATION ENGINE ''' THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) s = Sim(t, default_results_path=THIS_FOLDER + "/results/s_trace") ''' DEPLOY OF THE APP'S MODULES (from JSON file) ''' for app in apps.keys(): s.deploy_app(apps[app], placement, selector_path) print(apps["water_pipe_control"]) ''' DEPLOY INITIAL WORKLOAD (from JSON file) ''' population_json = json.load( open(THIS_FOLDER + '/data/population_definition.json')) for source in population_json["sources"]: app_name = source["app"] app = s.apps[app_name] msg = app.get_message(source["message"]) node = source["id_resource"] dist = deterministic_distribution(100, name="Deterministic") idDES = s.deploy_source(app_name, id_node=node, msg=msg, distribution=dist) ''' RUNNING - last step ''' s.run(stop_time) # To test deployments put test_initial_deploy a TRUE
def main(simulated_time,experimento,ilpPath): random.seed(RANDOM_SEED) np.random.seed(RANDOM_SEED) """ TOPOLOGY from a json """ t = Topology() dataNetwork = json.load(open(experimento+'networkDefinition.json')) t.load(dataNetwork) t.write("network.gexf") """ APPLICATION """ dataApp = json.load(open(experimento+'appDefinition.json')) apps = create_applications_from_json(dataApp) #for app in apps: # print apps[app] """ PLACEMENT algorithm """ placementJson = json.load(open(experimento+'allocDefinition%s.json'%ilpPath)) placement = JSONPlacement(name="Placement",json=placementJson) ### Placement histogram # listDevices =[] # for item in placementJson["initialAllocation"]: # listDevices.append(item["id_resource"]) # import matplotlib.pyplot as plt # print listDevices # print np.histogram(listDevices,bins=range(101)) # plt.hist(listDevices, bins=100) # arguments are passed to np.histogram # plt.title("Placement Histogram") # plt.show() ## exit() """ POPULATION algorithm """ dataPopulation = json.load(open(experimento+'usersDefinition.json')) pop = JSONPopulation(name="Statical",json=dataPopulation) """ SELECTOR algorithm """ selectorPath = DeviceSpeedAwareRouting() """ SIMULATION ENGINE """ stop_time = simulated_time s = Sim(t, default_results_path=experimento + "Results_%s_%i" % (ilpPath, stop_time)) #For each deployment the user - population have to contain only its specific sources for aName in apps.keys(): print "Deploying app: ",aName pop_app = JSONPopulation(name="Statical_%s"%aName,json={}) data = [] for element in pop.data["sources"]: if element['app'] == aName: data.append(element) pop_app.data["sources"]=data s.deploy_app(apps[aName], placement, pop_app, selectorPath) s.run(stop_time, test_initial_deploy=False, show_progress_monitor=False) #TEST to TRUE