def make_all(exp_file, **kwargs): """ Make a campaign of experiments. :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ global reuse_bin_path console = kwargs.get('console') clean_all(exp_file, silent=True) if console is None else console.do_clean_all(exp_file, silent=True) experiments = get_experiments(exp_file) sim_json, motes = None, None # if a simulation named 'BASE' is present, use it as a template simulation for all the other simulations if 'BASE' in experiments.keys(): experiments['BASE']['silent'] = True sim_json = dict(experiments['BASE']['simulation']) motes = generate_motes(defaults=DEFAULTS, **validated_parameters(experiments['BASE'])) del experiments['BASE'] for name, params in sorted(experiments.items(), key=lambda x: x[0]): params['campaign'] = splitext(basename(exp_file))[0] if sim_json is not None: params.setdefault('simulation', {}) for k, v in sim_json.items(): if k not in params['simulation'].keys(): params['simulation'][k] = v params['motes'] = motes make(name, ask=False, **params) if console is None else console.do_make(name, ask=False, **params)
def cooja(name, with_malicious=True, **kwargs): """ Start an experiment in Cooja with/without the malicious mote and updates the experiment if motes' positions were changed. :param name: experiment name :param with_malicious: use the simulation WITH the malicious mote or not :param path: expanded path of the experiment (dynamically filled in through 'command' decorator with 'expand' """ sim_path = join(kwargs['path'], 'with{}-malicious'.format(['out', ''][with_malicious is True])) motes_before = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True) with hide(*HIDDEN_ALL): with lcd(sim_path): local("make cooja") motes_after = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True) # if there was a change, update the other simulation in this experiment if len(set(motes_before.items()) & set(motes_after.items())) > 0: other_sim_path = join(kwargs['path'], 'with{}-malicious'.format(['', 'out'][with_malicious is True])) set_motes_to_simulation(join(other_sim_path, 'simulation.csc'), motes_after) # if this experiment is part of a campaign, update this campaign = read_config(kwargs['path']).get('campaign') if campaign is not None: for experiment in get_experiments(campaign): if experiment in ['BASE', name]: continue exp_path = join(EXPERIMENT_FOLDER, experiment) set_motes_to_simulation(join(exp_path, 'with-malicious', 'simulation.csc'), motes_after) set_motes_to_simulation(join(exp_path, 'without-malicious', 'simulation.csc'), motes_after)
def make_all(exp_file, **kwargs): """ Make a campaign of experiments. :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ global reuse_bin_path console = kwargs.get('console') clean_all(exp_file, silent=True) if console is None else console.do_clean_all( exp_file, silent=True) experiments = get_experiments(exp_file, silent=True) sim_json, motes = None, None # if a simulation named 'BASE' is present, use it as a template simulation for all the other simulations if 'BASE' in experiments.keys(): experiments['BASE']['silent'] = True sim_json = dict(experiments['BASE']['simulation']) motes = generate_motes(defaults=DEFAULTS, **validated_parameters(experiments['BASE'])) del experiments['BASE'] for name, params in sorted(experiments.items(), key=lambda x: x[0]): params['campaign'] = splitext(basename(exp_file))[0] if sim_json is not None: params.setdefault('simulation', {}) for k, v in sim_json.items(): if k not in params['simulation'].keys(): params['simulation'][k] = v params['motes'] = motes make(name, ask=False, ** params) if console is None else console.do_make( name, ask=False, **params)
def run_all(exp_file, **kwargs): """ Run a campaign of experiments. :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ console = kwargs.get('console') for name in get_experiments(exp_file).keys(): if name != 'BASE': run(name) if console is None else console.do_run(name)
def remake_all(exp_file, **kwargs): """ Remake a campaign of experiments (that is, rebuild the malicious for each experiment). :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ console = kwargs.get('console') experiments = {k: v for k, v in get_experiments(exp_file).items() if k != 'BASE'} for name, params in sorted(experiments.items(), key=lambda x: x[0]): remake(name, **params) if console is None else console.do_remake(name, **params)
def clean_all(exp_file, **kwargs): """ Make a campaign of experiments. :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ console = kwargs.get('console') silent = kwargs.get('silent', False) experiments = {k: v for k, v in get_experiments(exp_file).items() if k != 'BASE'} for name, params in experiments.items(): clean(name, ask=False, silent=silent) if console is None else console.do_clean(name, ask=False, silent=silent)
def remake_all(exp_file, **kwargs): """ Remake a campaign of experiments (that is, rebuild the malicious for each experiment). :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ console = kwargs.get('console') experiments = { k: v for k, v in get_experiments(exp_file).items() if k != 'BASE' } for name, params in sorted(experiments.items(), key=lambda x: x[0]): remake(name, **params) if console is None else console.do_remake( name, **params)
def clean_all(exp_file, **kwargs): """ Make a campaign of experiments. :param exp_file: experiments JSON filename or basename (absolute or relative path ; if no path provided, the JSON file is searched in the experiments folder) """ console = kwargs.get('console') silent = kwargs.get('silent', False) experiments = { k: v for k, v in get_experiments(exp_file).items() if k != 'BASE' } for name, params in experiments.items(): clean(name, ask=False, silent=silent) if console is None else console.do_clean( name, ask=False, silent=silent)
def cooja(name, with_malicious=True, **kwargs): """ Start an experiment in Cooja with/without the malicious mote and updates the experiment if motes' positions were changed. :param name: experiment name :param with_malicious: use the simulation WITH the malicious mote or not :param path: expanded path of the experiment (dynamically filled in through 'command' decorator with 'expand' """ sim_path = join( kwargs['path'], 'with{}-malicious'.format(['out', ''][with_malicious is True])) motes_before = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True) with hide(*HIDDEN_ALL): with lcd(sim_path): local("make cooja TASK={}".format(kwargs['task'])) motes_after = get_motes_from_simulation(join(sim_path, 'simulation.csc'), as_dictionary=True) # if there was a change, update the other simulation in this experiment if len(set(motes_before.items()) & set(motes_after.items())) > 0: other_sim_path = join( kwargs['path'], 'with{}-malicious'.format(['', 'out'][with_malicious is True])) set_motes_to_simulation(join(other_sim_path, 'simulation.csc'), motes_after) # if this experiment is part of a campaign, update this campaign = read_config(kwargs['path']).get('campaign') if campaign is not None: for experiment in get_experiments(campaign): if experiment in ['BASE', name]: continue exp_path = join(EXPERIMENT_FOLDER, experiment) set_motes_to_simulation( join(exp_path, 'with-malicious', 'simulation.csc'), motes_after) set_motes_to_simulation( join(exp_path, 'without-malicious', 'simulation.csc'), motes_after)