Beispiel #1
0
def exec_experiment(topology, workload, netconf, strategy, cache_policy,
                    collectors):
    """Execute the simulation of a specific scenario.

    Parameters
    ----------
    topology : Topology
        The FNSS Topology object modelling the network topology on which
        experiments are run.
    workload : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    netconf : dict
        Dictionary of attributes to inizialize the network model
    strategy : tree
        Strategy definition. It is tree describing the name of the strategy
        to use and a list of initialization attributes
    cache_policy : tree
        Cache policy definition. It is tree describing the name of the cache
        policy to use and a list of initialization attributes
    collectors: dict
        The collectors to be used. It is a dictionary in which keys are the
        names of collectors to use and values are dictionaries of attributes
        for the collector they refer to.

    Returns
    -------
    results : Tree
        A tree with the aggregated simulation results from all collectors
    """
    netconf['n_contents'] = workload.n_contents
    model = NetworkModel(topology, cache_policy, **netconf)
    view = NetworkView(model)
    controller = NetworkController(model)

    collectors_inst = [
        DATA_COLLECTOR[name](view, **params)
        for name, params in collectors.items()
    ]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)

    strategy_name = strategy['name']
    strategy_args = {k: v for k, v in strategy.items() if k != 'name'}
    strategy_inst = STRATEGY[strategy_name](view, controller, **strategy_args)
    i = 0
    for time, event in workload:
        strategy_inst.process_event(time, **event)
        # i+=1
        # if not i%30:
        #     results = collector.results()
        #     logger.info('Mean hit ratio: %f | Mean latency: %f | Reward: %f.'%(results['CACHE_HIT_RATIO']['MEAN'], results['LATENCY']['MEAN'], controller.get_avg_reward()))

    # workload.reward = controller.get_avg_reward()

    return collector.results()
Beispiel #2
0
def exec_experiment(topology, workload, netconf, strategy, cache_policy, collectors, desc):
    """Execute the simulation of a specific scenario.
    
    Parameters
    ----------
    topology : Topology
        The FNSS Topology object modelling the network topology on which
        experiments are run.
    workload : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    netconf : dict
        Dictionary of attributes to inizialize the network model
    strategy : tree
        Strategy definition. It is tree describing the name of the strategy
        to use and a list of initialization attributes
    cache_policy : tree
        Cache policy definition. It is tree describing the name of the cache
        policy to use and a list of initialization attributes
    collectors: dict
        The collectors to be used. It is a dictionary in which keys are the
        names of collectors to use and values are dictionaries of attributes
        for the collector they refer to.
         
    Returns
    -------
    results : Tree
        A tree with the aggregated simulation results from all collectors
    """
    model = NetworkModel(topology, cache_policy, **netconf)
    view = NetworkView(model)
    controller = NetworkController(model)
    
    collectors_inst = [DATA_COLLECTOR[name](view, **params)
                       for name, params in list(collectors.items())]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)
    
    strategy_name = strategy['name']
    strategy_args = {k: v for k, v in list(strategy.items()) if k != 'name'}
    strategy_inst = STRATEGY[strategy_name](view, controller, **strategy_args)

    processed_events = 0

    for time, event in workload:
        strategy_inst.process_event(time, **event)
        processed_events += 1

        if processed_events % 1000000 == 0:
            logger.info('Progress: %s, %f' % (desc, float(processed_events) / float(workload.n_measured)))

    return collector.results()
Beispiel #3
0
def exec_experiment(topology, workload, netconf, strategy, cache_policy, collectors, desc):
    """Execute the simulation of a specific scenario.
    
    Parameters
    ----------
    topology : Topology
        The FNSS Topology object modelling the network topology on which
        experiments are run.
    workload : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    netconf : dict
        Dictionary of attributes to inizialize the network model
    strategy : tree
        Strategy definition. It is tree describing the name of the strategy
        to use and a list of initialization attributes
    cache_policy : tree
        Cache policy definition. It is tree describing the name of the cache
        policy to use and a list of initialization attributes
    collectors: dict
        The collectors to be used. It is a dictionary in which keys are the
        names of collectors to use and values are dictionaries of attributes
        for the collector they refer to.
         
    Returns
    -------
    results : Tree
        A tree with the aggregated simulation results from all collectors
    """
    model = NetworkModel(topology, cache_policy, **netconf)
    view = NetworkView(model)
    controller = NetworkController(model)
    
    collectors_inst = [DATA_COLLECTOR[name](view, **params)
                       for name, params in collectors.items()]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)
    
    strategy_name = strategy['name']
    strategy_args = {k: v for k, v in strategy.items() if k != 'name'}
    strategy_inst = STRATEGY[strategy_name](view, controller, **strategy_args)

    processed_events = 0

    for time, event in workload:
        strategy_inst.process_event(time, **event)
        processed_events += 1

        if processed_events % 1000000 == 0:
            logger.info('Progress: %s, %f' % (desc, float(processed_events) / float(workload.n_measured)))

    return collector.results()
Beispiel #4
0
def exec_experiment(topology, workload, netconf, strategy, cache_policy,
                    collectors):
    """Execute the simulation of a specific scenario.

    Parameters
    ----------
    topology : Topology
        The FNSS Topology object modelling the network topology on which
        experiments are run.
    workload : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    netconf : dict
        Dictionary of attributes to inizialize the network model
    strategy : tree
        Strategy definition. It is tree describing the name of the strategy
        to use and a list of initialization attributes
    cache_policy : tree
        Cache policy definition. It is tree describing the name of the cache
        policy to use and a list of initialization attributes
    collectors: dict
        The collectors to be used. It is a dictionary in which keys are the
        names of collectors to use and values are dictionaries of attributes
        for the collector they refer to.

    Returns
    -------
    results : Tree
        A tree with the aggregated simulation results from all collectors
    """
    model = NetworkModel(topology, cache_policy, **netconf)
    view = NetworkView(model)
    controller = NetworkController(model)

    collectors_inst = [
        DATA_COLLECTOR[name](view, **params)
        for name, params in collectors.items()
    ]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)

    strategy_name = strategy['name']
    strategy_args = {k: v for k, v in strategy.items() if k != 'name'}
    strategy_inst = STRATEGY[strategy_name](view, controller, **strategy_args)

    for time, event in workload:  # e.g. time: 1520036461364, event: {'receiver': 'battery3/receiver', 'content': '/agent4/battery3/charging/v0', 'log': True}
        # print('calling process_event with time:', time, '  event', event)
        # write_to_file(time)
        strategy_inst.process_event(time, **event)
    return collector.results()
Beispiel #5
0
def exec_experiment(topology, events, strategy, collectors):
    """
    Execute the simulation of a specific scenario
    
    Parameters
    ----------
    topology : Topology
        An FNSS topology object with the network topology used for the
        simulation
    events : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    strategy : 2-tuple
        Strategy definition. It is a 2-tuple where the first element is the
        name of the strategy and the second element is a dictionary of
        strategy attributes
    collectors: list of tuples
        The collectors to be used. It is a list of 2-tuples. Each tuple has as
        first element the name of the collector and as second element a
        dictionary of collector parameters
         
    Returns
    -------
    results : dict
        A dictionary with the aggregated simulation results from all collectors.
    """
    model = NetworkModel(topology)
    view = NetworkView(model)
    controller = NetworkController(model)
    
    collectors_inst = [data_collector_register[name](view, **params)
                  for name, params in collectors]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)
    
    str_name, str_params = strategy
    strategy_inst = strategy_register[str_name](view, controller, **str_params)
    
    for time, event in events:
        strategy_inst.process_event(time, **event)
    return collector.results()
Beispiel #6
0
def exec_experiment(topology,
                    workload,
                    netconf,
                    strategy,
                    cache_policy,
                    repo_policy,
                    collectors,
                    warmup_strategy,
                    sched_policy={'name': 'EDF'}):
    """Execute the simulation of a specific scenario.

    Parameters
    ----------
    topology : Topology
        The FNSS Topology object modelling the network topology on which
        experiments are run.
    workload : iterable
        An iterable object whose elements are (time, event) tuples, where time
        is a float type indicating the timestamp of the event to be executed
        and event is a dictionary storing all the attributes of the event to
        execute
    netconf : dict
        Dictionary of attributes to inizialize the network model
    strategy : tree
        Strategy definition. It is tree describing the name of the strategy
        to use and a list of initialization attributes
    cache_policy : tree
        Cache policy definition. It is tree describing the name of the cache
        policy to use and a list of initialization attributes
    collectors: dict
        The collectors to be used. It is a dictionary in which keys are the
        names of collectors to use and values are dictionaries of attributes
        for the collector they refer to.

    Returns
    -------
    results : Tree
        A tree with the aggregated simulation results from all collectors
    """
    model = NetworkModel(topology, cache_policy, repo_policy,
                         sched_policy['name'], workload.n_services,
                         workload.rate, **netconf)
    workload.model = model
    view = NetworkView(model)
    controller = NetworkController(model)

    collectors_inst = [
        DATA_COLLECTOR[name](view, **params)
        for name, params in collectors.items()
    ]
    collector = CollectorProxy(view, collectors_inst)
    controller.attach_collector(collector)

    strategy_name = strategy['name']
    warmup_strategy_name = warmup_strategy['name']
    strategy_args = {k: v for k, v in strategy.items() if k != 'name'}
    warmup_strategy_args = {
        k: v
        for k, v in warmup_strategy.iteritems() if k != 'name'
    }
    strategy_inst = STRATEGY[strategy_name](view, controller, **strategy_args)
    warmup_strategy_inst = STRATEGY[warmup_strategy_name](
        view, controller, **warmup_strategy_args)

    n = 0
    for time, event in workload:
        #continue
        strategy_inst.process_event(time, **event)
        if n % 500 == 0 and n:
            collector.results()
        if event['status'] == 1:
            n += 1

    return collector.results()
    """