コード例 #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)
コード例 #2
0
ファイル: main.py プロジェクト: yangdz161/YAFS
def create_application():
    # APLICATION
    a = Application(name="EGG_GAME")

    a.set_modules([{"EGG":{"Type":Application.TYPE_SOURCE}},
                   {"Display": {"Type": Application.TYPE_SINK}},
                   {"Client": {"RAM": 10, "Type": Application.TYPE_MODULE}},
                   {"Calculator": {"RAM": 10, "Type": Application.TYPE_MODULE}},
                   {"Coordinator": {"RAM": 10, "Type": Application.TYPE_MODULE}}
                   ])
    """
    Messages among MODULES (AppEdge in iFogSim)
    """
    m_egg = Message("M.EGG", "EGG", "Client", instructions=2000*10^6, bytes=500)
    m_sensor = Message("M.Sensor", "Client", "Calculator", instructions=3500*10^6, bytes=500)
    m_player_game_state = Message("M.Player_Game_State", "Calculator", "Coordinator", instructions=1000*10^6, bytes=1000)
    m_concentration = Message("M.Concentration", "Calculator", "Client", instructions=14*10^6, bytes=500)           # This message is sent to all client modules
    m_global_game_state = Message("M.Global_Game_State", "Coordinator", "Client", instructions=28*10^6, bytes=1000, broadcasting=True) # This message is sent to all client modules
    m_global_state_update = Message("M.Global_State_Update", "Client", "Display",instructions=1000*10^6,bytes=500)
    m_self_state_update = Message("M.Self_State_Update", "Client", "Display",instructions=1000*10^6,bytes=500)

    """
    Defining which messages will be dynamically generated # the generation is controlled by Population algorithm
    """
    a.add_source_messages(m_egg)

    """
    MODULES/SERVICES: Definition of Generators and Consumers (AppEdges and TupleMappings in iFogSim)
    """
    # MODULE SOURCES: only periodic messages
    dDistribution = deterministicDistribution(name="Deterministic", time=100)

    a.add_service_source("Calculator", dDistribution, m_player_game_state) #According with the comments on VRGameFog.java, the period is 100ms
    a.add_service_source("Coordinator", dDistribution, m_global_game_state)
    # # MODULE SERVICES
    a.add_service_module("Client", m_egg, m_sensor, fractional_selectivity, threshold=0.9)
    a.add_service_module("Client", m_concentration, m_self_state_update, fractional_selectivity, threshold=1.0)
    a.add_service_module("Client", m_global_game_state, m_global_state_update, fractional_selectivity, threshold=1.0)
    a.add_service_module("Calculator", m_sensor, m_concentration, fractional_selectivity, threshold=1.0)
    a.add_service_module("Coordinator", m_player_game_state)

    return a
コード例 #3
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
コード例 #4
0
ファイル: experiment2.py プロジェクト: yangdz161/YAFS
def main():

    random.seed(RANDOM_SEED)
    np.random.seed(RANDOM_SEED)
    """
    Detalles
    """

    topologies = {
        "Grid": "data/grid200.graphml",
        "BarabasiAlbert": "data/BarabasiAlbert2.graphml",
        "RandomEuclidean": "data/RandomEuclidean.graphml",
        "Lobster": "data/Lobster.graphml",
    }
    community_size = [50, 100, 150, 200, 300]
    threshold_population_edge = 0.010

    ltopo = []
    lnodes = []
    ledges = []
    lavepath = []
    leddev = []

    try:
        for key_topo in topologies.keys():
            """
            TOPOLOGY from a json
            """
            t = Topology()
            # t_json = create_json_topology()
            # t.load(t_json)

            t.load_graphml(topologies[key_topo])
            print "TOPOLOGY: %s" % key_topo
            print "Total Nodes: %i" % len(t.G.nodes())
            print "Total Vertexs: %i" % len(t.G.edges())
            print "Average shortest path: %s" % nx.average_shortest_path_length(
                t.G)
            # t.write("network_ex2.gexf")

            ltopo.append(key_topo)
            lnodes.append(len(t.G.nodes()))
            ledges.append(len(t.G.edges()))
            lavepath.append(nx.average_shortest_path_length(t.G))

            ### COMPUTING Node degrees
            ### Stablish the Edge devices (acc. with Algoritm.nodedegree >... 1)
            ### Identify Cloud Device (max. degree)
            deg = {}
            edge = {}
            cloud_device = 0
            bestDeg = -1
            for n in t.G.nodes():
                d = t.G.degree(n)
                if d > bestDeg:
                    bestDeg = d
                    cloud_device = int(n)
                deg[n] = {"degree": d}
                #### MUST BE IMPROVED
                if key_topo in ["BarabasiAlbert", "Lobster"]:
                    if d == 1:
                        edge[n] = -1

                elif key_topo in ["Grid"]:
                    if d <= 3:
                        edge[n] = -1

                elif key_topo in ["RandomEuclidean"]:
                    if d > 14:
                        edge[n] = -1

            print "Total Edge-Devices: %i" % len(edge.keys())
            leddev.append(len(edge.keys()))
            """
            OJO
            """
            #TODO
            if key_topo in ["Grid"]:
                cloud_device = 320

            print "ID of Cloud-Device: %i" % cloud_device
            continue

            #print "Total edges devices: %i" % len(edge.keys())
            #nx.set_node_attributes(t.G, values=deg)

            ## COMPUTING MATRIX SHORTEST PATH among EDGE-devices
            minPath = {}
            minDis = {}
            for d in edge.keys():
                minDis[d] = []
                for d1 in edge.keys():
                    if d == d1: continue
                    path = list(nx.shortest_path(t.G, source=d, target=d1))
                    minPath[(d, d1)] = path
                    minDis[d].append(len(path))
            """
            WORKLOAD DEFINITION & REGION SENSORS (=Communities)
            """

            for size in community_size:

                print "SIZE Of Community: %i" % size

                communities, com = generate_communities(
                    size, edge, minPath, minDis, threshold_population_edge,
                    cloud_device)
                #print "Computed Communities"
                # print communities
                #for idx,c in enumerate(communities):
                #    print "\t %i - size: %i -: %s" %(idx,len(c),c)
                ### WRITING NETWORK
                nx.set_node_attributes(t.G, values=com)
                t.write("tmp/network-communities-%s-%i.gexf" %
                        (key_topo, size))

                # exit()

                #TODO suposicion cada comunidad es un tipo de carga
                sensor_workload_types = communities

                lambdas_wl = np.random.randint(low=5,
                                               high=10,
                                               size=len(sensor_workload_types))
                id_lambdas = zip(range(0, len(lambdas_wl)), lambdas_wl)
                id_lambdas.sort(key=lambda tup: tup[1],
                                reverse=True)  # sorts in place
                #print id_lambdas # [(1, 9), (0, 8)]
                """
                topology.Centricity
                """
                # Both next ids be extracted from topology.entities
                all_nodes_dev = t.G.nodes()
                edge_dev = edge.keys()

                weights = computingWeights(t, all_nodes_dev, edge_dev,
                                           sensor_workload_types)
                print "Computed weights"
                """
                APPLICATION
                """
                apps = []
                pops = []
                for idx in range(0, len(sensor_workload_types)):
                    apps.append(create_application(idx))
                    pops.append(Statical("Statical-%i" % idx))
                """
                PLACEMENT algorithm
                """
                #There is not modules thus placement.functions are empty
                placement = NoPlacementOfModules("empty")
                """--
                SELECTOR algorithm
                """
                # This implementation is already created in selector.class,called: First_ShortestPath
                selectorPath = First_ShortestPath()

                #In this point, the study analizes the behaviour of the deployment of (sink, src) modules (population) in different set of centroide algorithms
                #functions = {"Cluster":"Cluster","Eigenvector":nx.eigenvector_centrality,"Current_flow_betweenness_centrality":nx.current_flow_betweenness_centrality,
                #            "Betweenness_centrality":nx.betweenness_centrality,"load_centrality":nx.load_centrality} #"katz_centrality":nx.katz_centrality,
                #functions = {"Current_flow_betweenness_centrality":nx.current_flow_betweenness_centrality}

                functions = {
                    "Cluster": "Cluster",
                    "Eigenvector": nx.eigenvector_centrality,
                    "Current_flow_betweenness_centrality":
                    nx.current_flow_betweenness_centrality,
                    "Betweenness_centrality": nx.betweenness_centrality,
                    #"Load_centrality": nx.load_centrality
                }  # "katz_centrality":nx.katz_centrality,

                for f in functions:

                    print "Analysing network with algorithm: %s " % f
                    """
                    POPULATION algorithm
                    """
                    pops = []
                    for idx in range(0, len(sensor_workload_types)):
                        pops.append(Statical("Statical-%i" % idx))
                    # print "-"*20
                    # print "Function: %s" %f
                    # print "-"*20
                    if "Cluster" in f:
                        for idWL in id_lambdas:
                            idx = idWL[0]
                            # print idx
                            ## idWL[0] #index WL
                            ## idWL[1] #lambda

                            ### ALL SINKS  goes to Cluster ID: NODE 0
                            # print "\t", "SINK"
                            pops[idx].set_sink_control({
                                "id": [cloud_device],
                                "number":
                                1,
                                "module":
                                apps[idx].get_sink_modules()
                            })
                            # print "\t", "SOURCE"
                            # In addition, a source includes a distribution function:

                            dDistribution = deterministicDistribution(
                                name="Deterministic", time=idWL[1])
                            pops[idx].set_src_control({
                                "id":
                                sensor_workload_types[idx],
                                "number":
                                1,
                                "message":
                                apps[idx].get_message("m-st"),
                                "distribution":
                                dDistribution
                            })

                    else:
                        #Computing best device for each WL-type and each centrality function
                        print "\t Computando centralidad "
                        centralWL = range(0, len(weights))
                        for idx, v in enumerate(sensor_workload_types):
                            if idx % 20 == 0:
                                print "\t\t%i%%", idx
                            nx.set_edge_attributes(t.G,
                                                   values=weights[idx],
                                                   name="weight")
                            centrality = functions[f](t.G, weight="weight")
                            # print(['%s %0.2f' % (node, centrality[node]) for node in centrality])
                            centralWL[idx] = centrality

                        print "\t Generando SINK/SRCs centralidad "
                        previous_deploy = {}  ## DEV -> ID:load
                        for idWL in id_lambdas:
                            idx = idWL[0]
                            ## idWL[0] #index WL
                            ## idWL[1] #lambda

                            for dev, value in sorted(
                                    centralWL[idx].iteritems(),
                                    key=lambda (k, v): (v, k),
                                    reverse=True):
                                # print "%s: %s" % (dev, value)
                                #TODO CONTTOLAR LA CAPACIDAD DEL DISPOSITO HERE
                                if not dev in previous_deploy.values():
                                    previous_deploy[idx] = dev
                                    break
                            #TODO chequear que dEV es un device
                            # print "\t Previous deploy: ",previous_deploy
                            # print "\t NameApp: ",apps[idx].name
                            # print "\t Device:",dev
                            #Each application have a correspondence SRC/SINK among APPS

                            pops[idx].set_sink_control({
                                "id": [dev],
                                "number":
                                1,
                                "module":
                                apps[idx].get_sink_modules()
                            })
                            dDistribution = deterministicDistribution(
                                name="Deterministic", time=idWL[1])
                            #In addition, a source includes a distribution function:
                            pops[idx].set_src_control({
                                "id":
                                sensor_workload_types[idx],
                                "number":
                                1,
                                "message":
                                apps[idx].get_message("m-st"),
                                "distribution":
                                dDistribution
                            })
                    """
                    SIMULATION ENGINE
                    """
                    stop_time = 100  #CHECK
                    s = Sim(t)
                    for idx, app in enumerate(apps):
                        s.deploy_app(app, placement, pops[idx], selectorPath)

                    s.run(stop_time,
                          test_initial_deploy=False,
                          show_progress_monitor=False)

                #end for algorithms
            #end for communities size
        #end for topology change

        print ltopo
        print lnodes
        print ledges
        print lavepath
        print leddev

    #end try

    except:
        print "Some error??"
コード例 #5
0
ファイル: main.py プロジェクト: 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)
コード例 #6
0
ファイル: main.py プロジェクト: SiNa88/YAFS
def main(simulated_time):

    random.seed(RANDOM_SEED)
    """
    TOPOLOGY from a json
    """

    t = Topology()
    t.G = nx.read_graphml("Euclidean.graphml")
    t.G = nx.convert_node_labels_to_integers(t.G,
                                             first_label=0,
                                             ordering='default',
                                             label_attribute=None)

    print "Nodes: %i" % len(t.G.nodes())
    print "Edges: %i" % len(t.G.edges())
    #MANDATORY fields of a link
    # Default values =  {"BW": 1, "PR": 1}
    valuesOne = dict(itertools.izip(t.G.edges(), np.ones(len(t.G.edges()))))

    nx.set_edge_attributes(t.G, name='BW', values=valuesOne)
    nx.set_edge_attributes(t.G, name='PR', values=valuesOne)

    centrality = nx.betweenness_centrality(t.G)
    nx.set_node_attributes(t.G, name="centrality", values=centrality)

    sorted_clustMeasure = sorted(centrality.items(),
                                 key=operator.itemgetter(1),
                                 reverse=True)

    top20_devices = sorted_clustMeasure[:20]
    main_fog_device = copy.copy(top20_devices[0][0])

    print "-" * 20
    print "Top 20 centralised nodes:"
    for item in top20_devices:
        print item
    print "-" * 20
    """
    APPLICATION
    """
    app1 = create_application("app1")
    app2 = create_application("app2")
    """
    PLACEMENT algorithm
    """
    #There are not modules to place.
    placement = NoPlacementOfModules("NoPlacement")
    """
    POPULATION algorithm
    """
    number_generators = int(len(t.G) * 0.1)
    print number_generators
    dDistribution = deterministicDistributionStartPoint(3000,
                                                        300,
                                                        name="Deterministic")
    dDistributionSrc = deterministicDistribution(name="Deterministic", time=10)
    pop1 = Evolutive(top20_devices,
                     number_generators,
                     name="top",
                     activation_dist=dDistribution)
    pop1.set_sink_control({
        "app": app1.name,
        "number": 1,
        "module": app1.get_sink_modules()
    })
    pop1.set_src_control({
        "number": 1,
        "message": app1.get_message("M.Action"),
        "distribution": dDistributionSrc
    })

    pop2 = Statical(number_generators, name="Statical")
    pop2.set_sink_control({
        "id": main_fog_device,
        "number": number_generators,
        "module": app2.get_sink_modules()
    })

    pop2.set_src_control({
        "number": 1,
        "message": app2.get_message("M.Action"),
        "distribution": dDistributionSrc
    })

    #In addition, a source includes a distribution function:
    """--
    SELECTOR algorithm
    """
    selectorPath1 = BroadPath()

    selectorPath2 = CloudPath_RR()
    """
    SIMULATION ENGINE
    """

    s = Sim(t, default_results_path="Results_%s_singleApp1" % (simulated_time))
    s.deploy_app(app1, placement, pop1, selectorPath1)
    # s.deploy_app(app2, placement, pop2,  selectorPath2)

    s.run(simulated_time,
          test_initial_deploy=False,
          show_progress_monitor=False)
コード例 #7
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