Esempio n. 1
0
                     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,
            topology=t,
            case='one',
Esempio n. 2
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