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
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??"
Esempio n. 4
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. 5
0
        input_directory = temporal_folder + "normalized_trajectories.csv"  #
        logging.info("Loading trajectories from (cached file): %s" %
                     input_directory)
        tracks = trackanimation.read_track(input_directory)
    else:
        input_directory = trajectories_path  # can load csv files
        logging.info("Loading trajectories from (raw files): %s" %
                     input_directory)
        tracks = trackanimation.read_track(input_directory)
        tracks = tracks.time_video_normalize(
            time=number_simulation_steps, framerate=1)  # framerate must be one
        tracks.export(temporal_folder + "normalized_trajectories")

    # 1.2 Network infrastructure
    # Endpoint entities must have three attributes: level(=0) and lat/lng coordinates
    t = Topology()
    dataNetwork = json.load(open(experiment_path + 'networkDefinition.json'))
    t.load_all_node_attr(dataNetwork)

    # Performing multiple simulations
    for i in range(nSimulations):
        random.seed(i)
        np.random.seed(i)
        logging.info("Running Mobility Case - %s" % experiment_path)
        start_time = time.time()

        main(
            path=experiment_path,
            path_results=temporal_folder,
            number_simulation_steps=number_simulation_steps,
            tracks=tracks,
Esempio n. 6
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. 7
0
            sim.remove_node(node_to_remove)
            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
Esempio n. 8
0
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
Esempio n. 9
0
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")


    """
    PLACEMENT algorithm
    """
    #There are not modules to place.
    placement = NoPlacementOfModules("NoPlacement")

    """
    POPULATION algorithm
    """
    number_generators = int(len(t.G)*0.1)
    print number_generators

    #you can use whatever funciton to change the topology
    dStart = deterministicDistributionStartPoint(0, 100, name="Deterministic")
    dStart2 = exponentialDistributionStartPoint(500, 100.0, name="Deterministic")
    pop = Pop_and_Failures(name="mttf-nodes",srcs = number_generators,activation_dist=dStart2 )
    pop.set_sink_control({"ids": top20_devices, "number": 1, "module": app1.get_sink_modules()})

    dDistribution = deterministicDistribution(name="Deterministic", time=10)
    pop.set_src_control(
        {"number": 1, "message": app1.get_message("M.Action"), "distribution": dDistribution})

    #In addition, a source includes a distribution function:


    """--
    SELECTOR algorithm
    """
    selectorPath = BroadPath()


    """
    SIMULATION ENGINE
    """
    s = Sim(t, default_results_path="Results_%s_exp" % (simulated_time))
    s.deploy_app(app1, placement, pop, selectorPath)


    s.run(simulated_time,test_initial_deploy=False,show_progress_monitor=False)
    # s.draw_allocated_topology() # for debugging
    print "Total nodes available in the  toopology %i" %len(s.topology.G.nodes())
    print "Total edges available in the  toopology %i" %len(s.topology.G.edges())

    print pop.nodes_removed
Esempio n. 10
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. 11
0
File: main.py Progetto: 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)
Esempio n. 12
0
    "COST": 3,
    "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. 13
0
def main(simulated_time):

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

    t = Topology()
    t.G = nx.read_graphml("Euclidean.graphml")

    ls = list(t.G.nodes)
    li = {x: int(x) for x in ls}
    nx.relabel_nodes(t.G, li, False)  #Transform str-labels to int-labels

    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[0:20]
    main_fog_device = copy.copy(top20_devices[0][0])

    # df = pd.read_csv("pos_network.csv")
    # pos = {}
    # for r in df.iterrows():
    #     lat = r[1].x
    #     lng = r[1].y
    #     pos[r[0]] = (lat, lng)

    # fig = plt.figure(figsize=(10, 8), dpi=100)
    # nx.draw(t.G, with_labels=True,pos=pos,node_size=60,node_color="orange", font_size=8)
    # plt.savefig('labels.png')
    # exit()

    print "-" * 20
    print "Best top centralized device: ", main_fog_device
    print "-" * 20
    """
    APPLICATION
    """
    app1 = create_application("app1")
    """
    PLACEMENT algorithm
    """
    #There are not modules to place.
    placement = NoPlacementOfModules("NoPlacement")
    """
    POPULATION algorithm
    """
    number_generators = int(len(t.G) * 0.1)
    print "Number of generators %i" % number_generators

    #you can use whatever funciton to change the topology
    dStart = deterministicDistributionStartPoint(500,
                                                 400,
                                                 name="Deterministic")
    pop = Population_Move(name="mttf-nodes",
                          srcs=number_generators,
                          node_dst=main_fog_device,
                          activation_dist=dStart)
    pop.set_sink_control({
        "id": main_fog_device,
        "number": number_generators,
        "module": app1.get_sink_modules()
    })

    dDistribution = deterministicDistribution(name="Deterministic", time=100)
    pop.set_src_control({
        "number": 1,
        "message": app1.get_message("M.Action"),
        "distribution": dDistribution
    })

    #In addition, a source includes a distribution function:
    """--
    SELECTOR algorithm
    """
    selectorPath = CloudPath_RR()
    """
    SIMULATION ENGINE
    """
    s = Sim(t, default_results_path="Results_%s" % (simulated_time))
    s.deploy_app(app1, placement, pop, selectorPath)

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

    # s.draw_allocated_topology() # for debugging
    s.print_debug_assignaments()
Esempio n. 14
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. 15
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