Esempio n. 1
0
def main(simulated_time):

    random.seed(RANDOM_SEED)
    """
    TOPOLOGY from a json
    """
    t = Topology()
    t_json = create_json_topology()
    t.load(t_json)
    t.write("network.gexf")
    """
    APPLICATION
    """
    app = create_application()
    """
    PLACEMENT algorithm
    """
    placement = CloudPlacement(
        "onCloud")  # it defines the deployed rules: module-device
    placement.scaleService({"ServiceA": 1})
    """
    POPULATION algorithm
    """
    #In ifogsim, during the creation of the application, the Sensors are assigned to the topology, in this case no. As mentioned, YAFS differentiates the adaptive sensors and their topological assignment.
    #In their case, the use a statical assignment.
    pop = Statical("Statical")
    #For each type of sink modules we set a deployment on some type of devices
    #A control sink consists on:
    #  args:
    #     model (str): identifies the device or devices where the sink is linked
    #     number (int): quantity of sinks linked in each device
    #     module (str): identifies the module from the app who receives the messages
    pop.set_sink_control({
        "model": "actuator-device",
        "number": 1,
        "module": app.get_sink_modules()
    })

    #In addition, a source includes a distribution function:
    dDistribution = deterministicDistribution(name="Deterministic", time=100)
    pop.set_src_control({
        "model": "sensor-device",
        "number": 1,
        "message": app.get_message("M.A"),
        "distribution": dDistribution
    })
    """--
    SELECTOR algorithm
    """
    #Their "selector" is actually the shortest way, there is not type of orchestration algorithm.
    #This implementation is already created in selector.class,called: First_ShortestPath
    selectorPath = MinimunPath()
    """
    SIMULATION ENGINE
    """

    stop_time = simulated_time
    s = Sim(t, default_results_path="Results")
    s.deploy_app(app, placement, pop, selectorPath)
    s.run(stop_time, show_progress_monitor=False)
Esempio n. 2
0
def main(simulated_time):

    random.seed(RANDOM_SEED)
    np.random.seed(RANDOM_SEED)

    """
    TOPOLOGY from a json
    """
    t = Topology()
    t_json = create_json_topology()
    t.load(t_json)
    t.write("network.gexf")

    """
    APPLICATION
    """
    app = create_application()

    """
    PLACEMENT algorithm
    """
    # MINHA IMPLEMENTACAO DO ALGORITMO PARA PLACEMENT.
    # UTILIZA A PROPRIEDADE model:node
    placement = UCPlacement(name="UCPlacement")

    # Para criar replicas dos servicos
    placement.scaleService({"MLTTask": 1, "FLTTask":1, "DLTTask":1})

    """
    POPULATION algorithm
    """
    #In ifogsim, during the creation of the application, the Sensors are assigned to the topology, in this case no. As mentioned, YAFS differentiates the adaptive sensors and their topological assignment.
    #In their case, the use a statical assignment.
    pop = Statical("Statical")
    #For each type of sink modules we set a deployment on some type of devices
    #A control sink consists on:
    #  args:
    #     model (str): identifies the device or devices where the sink is linked
    #     number (int): quantity of sinks linked in each device
    #     module (str): identifies the module from the app who receives the messages
    pop.set_sink_control({"model": "sink","number":0,"module":app.get_sink_modules()})

    #In addition, a source includes a distribution function:
    dDistribution = deterministicDistribution(name="Deterministic",time=10)
    # delayDistribution = deterministicDistributionStartPoint(400, 100, name="DelayDeterministic")
    
    # number:quantidade de replicas
    pop.set_src_control({"model": "camera", "number":1,"message": app.get_message("M.Cam"), "distribution": dDistribution})
    # pop.set_src_control({"type": "mlt", "number":1,"message": app.get_message("M.MLT"), "distribution": dDistribution})
    

    """
    SELECTOR algorithm
    """
    #Their "selector" is actually the shortest way, there is not type of orchestration algorithm.
    #This implementation is already created in selector.class,called: First_ShortestPath
    selectorPath = MinimunPath()
    # selectorPath = MinPath_RoundRobin()
    

    """
    SIMULATION ENGINE
    """

    stop_time = simulated_time
    s = Sim(t, default_results_path="Results")
    s.deploy_app(app, placement, pop, selectorPath)
    s.run(stop_time,show_progress_monitor=False)

    s.draw_allocated_topology() # for debugging
Esempio n. 3
0
File: main.py Progetto: SiNa88/YAFS
def main(simulated_time, depth, police):

    random.seed(RANDOM_SEED)
    """
    TOPOLOGY from a json
    """
    numOfDepts = depth
    numOfMobilesPerDept = 4  # Thus, this variable is used in the population algorithm
    # In YAFS simulator, entities representing mobiles devices (sensors or actuactors) are not necessary because they are simple "abstract" links to the  access points
    # in any case, they can be implemented with node entities with no capacity to execute services.
    #

    t = Topology()
    t_json = create_json_topology(numOfDepts, numOfMobilesPerDept)
    t.load(t_json)

    t.write("network_%s.gexf" % depth)
    """
    APPLICATION
    """
    app = create_application()
    """
    PLACEMENT algorithm
    """
    #In this case: it will deploy all app.modules in the cloud
    if police == "cloud":
        print "cloud"
        placement = CloudPlacement("onCloud")
        placement.scaleService({
            "Calculator": numOfDepts * numOfMobilesPerDept,
            "Coordinator": 1
        })
    else:
        print "EDGE"
        placement = FogPlacement("onProxies")
        placement.scaleService({
            "Calculator": numOfMobilesPerDept,
            "Coordinator": 1
        })

    # placement = ClusterPlacement("onCluster", activation_dist=next_time_periodic, time_shift=600)
    """
    POPULATION algorithm
    """
    #In ifogsim, during the creation of the application, the Sensors are assigned to the topology, in this case no. As mentioned, YAFS differentiates the adaptive sensors and their topological assignment.
    #In their case, the use a statical assignment.
    pop = Statical("Statical")
    #For each type of sink modules we set a deployment on some type of devices
    #A control sink consists on:
    #  args:
    #     model (str): identifies the device or devices where the sink is linked
    #     number (int): quantity of sinks linked in each device
    #     module (str): identifies the module from the app who receives the messages
    pop.set_sink_control({
        "model": "a",
        "number": 1,
        "module": app.get_sink_modules()
    })

    #In addition, a source includes a distribution function:
    dDistribution = deterministicDistribution(name="Deterministic", time=100)
    pop.set_src_control({
        "model": "s",
        "number": 1,
        "message": app.get_message("M.EGG"),
        "distribution": dDistribution
    })
    """--
    SELECTOR algorithm
    """
    #Their "selector" is actually the shortest way, there is not type of orchestration algorithm.
    #This implementation is already created in selector.class,called: First_ShortestPath
    if police == "cloud":
        selectorPath = CloudPath_RR()
    else:
        selectorPath = BroadPath(numOfMobilesPerDept)
    """
    SIMULATION ENGINE
    """

    stop_time = simulated_time
    s = Sim(t,
            default_results_path="Results_%s_%i_%i" %
            (police, stop_time, depth))
    s.deploy_app(app, placement, pop, selectorPath)

    s.run(stop_time, test_initial_deploy=False, show_progress_monitor=False)
Esempio n. 4
0
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
Esempio n. 5
0
            for key in keys_DES:
                sim.stop_process(key)
        except IndexError:
            None

    else:
        sim.stop = True  ## We stop the simulation


def main(simulated_time, path, pathResults, case, it):
    """
    TOPOLOGY from a json
    """
    t = Topology()
    dataNetwork = json.load(open(path + 'networkDefinition.json'))
    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)
Esempio n. 6
0
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()
Esempio n. 7
0
    "WATT": 20.0
}
sensor_dev = {
    "id": 1,
    "model": "sensor-device",
    "IPT": 100 * 10 ^ 6,
    "RAM": 4000,
    "COST": 3,
    "WATT": 40.0
}
actuator_dev = {
    "id": 2,
    "model": "actuator-device",
    "IPT": 100 * 10 ^ 6,
    "RAM": 4000,
    "COST": 3,
    "WATT": 40.0
}

link1 = {"s": 0, "d": 1, "BW": 1, "PR": 10}
link2 = {"s": 0, "d": 2, "BW": 1, "PR": 1}

topology_json["entity"].append(cloud_dev)
topology_json["entity"].append(sensor_dev)
topology_json["entity"].append(actuator_dev)
topology_json["link"].append(link1)
topology_json["link"].append(link2)

t = Topology()
t.load(topology_json)
Esempio n. 8
0
def main(simulated_time):
    random.seed(RANDOM_SEED)
    np.random.seed(RANDOM_SEED)
    """
    TOPOLOGY from a json
    """
    topology = Topology()
    t_json = create_json_topology(numMLO=3, numBroker=1, numFLO=2, numDLO=1)
    topology.load(t_json)
    # t.write("network.gexf")
    """
    APPLICATIONS
    """
    app = create_application(name="Workflow1",
                             params={
                                 "max_latency": 100,
                                 "FPS_total": 120
                             })
    app2 = create_application(name="Workflow2",
                              params={
                                  "max_latency": 100,
                                  "FPS_total": 120
                              })
    """
    PLACEMENT algorithm
    """
    # MELINDA's placement algorithm
    # It uses model:node
    placement = UCPlacement(name="UCPlacement")

    # Which services will be necessary
    placement.scaleService({"MLO": 3, "Broker": 1, "FLO": 2, "DLO": 1})
    """
    POPULATION algorithm
    """
    # In ifogsim, during the creation of the application, the Sensors are assigned to the topology,
    # in this case no. As mentioned, YAFS differentiates the adaptive sensors and their topological assignment.
    # In their case, the use a statical assignment.
    pop = Statical("Statical")
    # For each type of sink modules we set a deployment on some type of devices
    # A control sink consists on:
    #  args:
    #     model (str): identifies the device or devices where the sink is linked
    #     number (int): quantity of sinks linked in each device
    #     module (str): identifies the module from the app who receives the messages
    pop.set_sink_control({
        "model": "sink",
        "number": 1,
        "module": app.get_sink_modules()
    })

    # In addition, a source includes a distribution function:
    dDistribution = deterministicDistribution(name="Deterministic", time=5)
    # delayDistribution = deterministicDistributionStartPoint(400, 100, name="DelayDeterministic")

    # number:quantidade de replicas
    pop.set_src_control({
        "model": "camera",
        "number": 1,
        "message": app.get_message("RawVideo"),
        "distribution": dDistribution
    })
    # pop.set_src_control({"type": "mlt", "number":1,"message": app.get_message("M.MLT"),
    #                     "distribution": dDistribution})
    """
    SELECTOR algorithm
    """
    # Their "selector" is actually the shortest way, there is not type of orchestration algorithm.
    # This implementation is already created in selector.class,called: First_ShortestPath
    # selectorPath = MinimunPath()
    selectorPath = MinPath_RoundRobin()
    """
    SIMULATION ENGINE
    """

    stop_time = simulated_time
    s = Sim(topology, default_results_path="Results")
    s.deploy_app(app, placement, pop, selectorPath)
    s.run(stop_time, show_progress_monitor=False)

    s.draw_allocated_topology()  # for debugging
Esempio n. 9
0
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