commands.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:rpl-attacks 作者: dhondta 项目源码 文件源码
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')
    :param kwargs: simulation keyword arguments (see the documentation for more information)
    """
    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.get('task', "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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号