Example #1
0
def get_nodes_selection(username, password, experiment_id, nodes_list,
                        *_args, **_kwargs):  # pylint:disable=unused-argument
    """ Return the requested nodes from 'experiment_id', and 'nodes_list """
    username, password = iotlabcli.get_user_credentials(username, password)
    api = iotlabcli.Api(username, password)
    nodes = query_nodes(api, experiment_id, nodes_list)
    return nodes
Example #2
0
def main():
    """ Start experiments on all sites/nodes and get the nodes uids """
    opts = PARSER.parse_args()

    user, passwd = get_user_credentials(opts.username, opts.password)
    api = iotlabcli.Api(user, passwd)
    use_custom_ssh_config(user)

    fabric.utils.puts("Get platform nodes...")
    sites_dict = RunExperiment.site_archi_dict(api)
    targets = RunExperiment.targets_list(sites_dict, opts.site)

    # Generate config for all targets
    config = {}
    for site, archi in targets:
        # replace ':' in host to prevent it being interpreted as port
        host = '%s-%s' % (archi.replace(':', '+'), site)
        if vars(opts).get(archi, False):
            config[host] = {
                'site': site,
                'archi': archi,
                'firmware': FW_DICT[archi],
            }
        else:
            fabric.utils.puts("Ignore %s %s" % (site, archi))

    if len(config) == 0:
        fabric.utils.abort("No valid hosts")

    try:
        result_dict = fabric.tasks.execute(run_exp,
                                           api,
                                           opts.name,
                                           opts.duration,
                                           config,
                                           opts.all_bookable,
                                           hosts=sorted(config.keys()))

        result = {}
        for ret in result_dict.values():
            if ret is not None:
                if ret.endswith(ANSI_RESET):
                    # Remove ANSI_RESET if at the end, got it on devlille
                    ret = ret.replace(ANSI_RESET, '')
                try:
                    result.update(json.loads(ret))
                except ValueError:
                    print >> sys.stderr, 'Error loading ret as json %r' % ret

        result_str = json.dumps(result, indent=4, sort_keys=True)

        print result_str
        with open(opts.outfile, 'w') as outfile:
            outfile.write(result_str)

    except:  # pylint:disable=bare-except
        traceback.print_exc()
        print >> sys.stderr, sys.exc_info()
    finally:
        fabric.network.disconnect_all()
def main():
    """ Reads nodes from ressource json in stdin and
    aggregate serial links of all nodes
    """
    parser = opts_parser()
    opts = parser.parse_args()

    try:
        username, password = iotlabcli.get_user_credentials(
            opts.username, opts.password)
        api = iotlabcli.Api(username, password)
        nodes_list = serial_aggregator.get_nodes(api,
                                                 opts.experiment_id,
                                                 opts.nodes_list,
                                                 with_a8=True)
        print "Using algorith: %r" % opts.algo
        algorithm = ALGOS[opts.algo]
    except (ValueError, RuntimeError) as err:
        sys.stderr.write("%s\n" % err)
        exit(1)

    # Connect to the nodes
    results = NodeResults(opts.outfile)
    aggregator = serial_aggregator.NodeAggregator(
        nodes_list, print_lines=True, line_handler=results.handle_line)
    aggregator.start()
    time.sleep(2)

    # Run the algorithm
    try:
        algorithm(aggregator, opts.num_loop)
        time.sleep(3)
    finally:
        aggregator.stop()
        results.write_results(opts.algo == 'syncronous')
def main():
    """ Start experiment"""
    opts = PARSER.parse_args()
    user, passwd = get_user_credentials(opts.username, opts.password)
    # Fabric configuration with env environment
    env.use_ssh_config = True
    env.ssh_config_path = './ssh_config'
    # use IoT-LAB login for ssh connexion
    env.user = user
    api = iotlabcli.Api(user, passwd)
    exp_id = _submit_exp(api,
                         opts.name,
                         opts.duration,
                         opts.nodes_list)
    _wait_exp(api, exp_id)
    exp_nodes = _get_exp_nodes(api, exp_id)
    exp_results = _get_exp_results(api, exp_id)
    # We choose a border router (BR)
    br_node = exp_results.pop(0)
    # br_node = m3-<id>.site.iot-lab.info
    br_node_site = br_node.split('.')[1]
    fabric.tasks.execute(_launch_tunslip6_interface, opts.ipv6prefix,
                         br_node, hosts=[br_node_site])
    # flash BR firmware on the border router
    _update_firm_nodes(api, exp_id, [br_node], FW_DICT['border_router'])
    # flash Coap server firmware on the other nodes
    _update_firm_nodes(api, exp_id, exp_results, FW_DICT['coap_server'])
    print 'Border router :'
    print '%s - %s::%s' % (br_node,
                           opts.ipv6prefix,
                           exp_nodes[br_node]['uid'])
def submit_experiment(testbed_name, board, firmware, duration):
    """
    Reserve nodes in the given site.
    The function uses the json experiment file corresponding to the site.
    :param str firmware: the name of the firmware as it is in the code/firmware/ folder
    :param str board: the type of board (ex: m3)
    :param str testbed_name: The name of the testbed (ex: grenoble)
    :param int duration: The duration of the experiment in minutes
    :return: The id of the experiment
    """

    # use the file created by auth-cli command
    usr, pwd = iotlab.get_user_credentials()

    # authenticate through the REST interface
    api = iotlab.rest.Api(usr, pwd)

    # load the experiment
    tb_file = open("{0}states.json".format(METAS_PATH))
    tb_json = json.load(tb_file)
    nodes = [x for x in tb_json[testbed_name] if board in x]
    firmware = FIRMWARE_PATH + firmware
    profile = "mercator"
    resources = [experiment.exp_resources(nodes, firmware, profile)]

    # submit experiment
    logconsole.info("Submitting experiment.")
    expid = experiment.submit_experiment(api, "mercatorExp", duration,
                                         resources)["id"]

    logconsole.info("Experiment submited with id: %u", expid)
    logconsole.info("Waiting for experiment to be running.")
    experiment.wait_experiment(api, expid)

    return expid
Example #6
0
def get_node_uids_lookup():
    api = iotlabcli.Api(*iotlabcli.get_user_credentials())
    info = iotlabcli.experiment.info_experiment(api)
    return {
        x["uid"]: x["network_address"].split('.')[0]
        for x in info["items"]
    }
Example #7
0
def get_nodes_selection(username, password, experiment_id, nodes_list, *_args,
                        **_kwargs):  # pylint:disable=unused-argument
    """ Return the requested nodes from 'experiment_id', and 'nodes_list """
    username, password = iotlabcli.get_user_credentials(username, password)
    api = iotlabcli.Api(username, password)
    nodes = query_nodes(api, experiment_id, nodes_list)
    return nodes
def main():
    """ Start experiments on all sites/nodes and get the nodes uids """
    opts = PARSER.parse_args()

    user, passwd = get_user_credentials(opts.username, opts.password)
    api = iotlabcli.Api(user, passwd)
    use_custom_ssh_config(user)

    fabric.utils.puts("Get platform nodes...")
    sites_dict = RunExperiment.site_archi_dict(api)
    targets = RunExperiment.targets_list(sites_dict, opts.site)

    # Generate config for all targets
    config = {}
    for site, archi in targets:
        # replace ':' in host to prevent it being interpreted as port
        host = '%s-%s' % (archi.replace(':', '+'), site)
        if vars(opts).get(archi.replace('-', '_'), False):
            config[host] = {
                'site': site, 'archi': archi, 'firmware': FW_DICT[archi],
            }
        else:
            fabric.utils.puts("Ignore %s %s" % (site, archi))

    if len(config) == 0:
        fabric.utils.abort("No valid hosts")

    try:
        result_dict = fabric.tasks.execute(
            run_exp, api, opts.name, opts.duration, config, opts.all_bookable,
            hosts=sorted(config.keys()))

        result = {}
        for ret in result_dict.values():
            if ret is not None:
                if ret.endswith(ANSI_RESET):
                    # Remove ANSI_RESET if at the end, got it on devlille
                    ret = ret.replace(ANSI_RESET, '')
                try:
                    result.update(json.loads(ret))
                except ValueError:
                    print >> sys.stderr, 'Error loading ret as json %r' % ret

        result_str = json.dumps(result, indent=4, sort_keys=True)

        print result_str
        with open(opts.outfile, 'w') as outfile:
            outfile.write(result_str)

    except:  # pylint:disable=bare-except
        traceback.print_exc()
        print >> sys.stderr, sys.exc_info()
    finally:
        fabric.network.disconnect_all()
def get_motes(expid):
    # use the file created by auth-cli command
    usr, pwd = iotlab.get_user_credentials()

    # authenticate through the REST interface
    api = iotlab.rest.Api(usr, pwd)

    # get experiment resources
    data = experiment.get_experiment(api, expid, 'resources')

    return (map(lambda x: x["network_address"].split('.')[0], data["items"]),
            data["items"][0]["network_address"].split('.')[1])
Example #10
0
def get_motes(expid):
    # use the file created by auth-cli command
    usr, pwd    = iotlab.get_user_credentials()

    # authenticate through the REST interface
    api = iotlab.rest.Api(usr, pwd)

    # get experiment resources
    data = experiment.get_experiment(api, expid, 'resources')

    return (map(lambda x: x["network_address"].split('.')[0], data["items"]),
            data["items"][0]["network_address"].split('.')[1])
Example #11
0
def main():
    """ Start experiments on all sites/nodes and get the nodes uids """
    opts = PARSER.parse_args()
    try:
        user, passwd = get_user_credentials(opts.username, opts.password)
        api = iotlabcli.Api(user, passwd)
        env.user = user

        sites_dict = RunExperiment.site_archi_dict(api)
        targets = RunExperiment.targets_list(sites_dict, opts.site, opts.archi)

        # Generate config for all targets
        config = {}
        for site, archi in targets:
            firmware = vars(opts)['fw_%s' % archi]
            if firmware is None:
                fabric.utils.puts("No firmware for %s %s" % (site, archi))
            else:
                # replace ':' in host to prevent it being interpreted as port
                config['%s-%s' % (archi.replace(':', '+'), site)] = {
                    'site': site,
                    'archi': archi,
                    'firmware': firmware
                }

        if len(config) == 0:
            raise ValueError("No valid hosts")

        result_dict = fabric.tasks.execute(run_exp,
                                           api,
                                           opts.name,
                                           opts.duration,
                                           config,
                                           opts.all_bookable,
                                           hosts=sorted(config.keys()))

        result = {}
        for ret in result_dict.values():
            if ret is not None:
                result.update(json.loads(ret))
        result_str = json.dumps(result, indent=4, sort_keys=True)

        print result_str
        with open(opts.outfile, 'w') as outfile:
            outfile.write(result_str)

    except:  # pylint:disable=bare-except
        traceback.print_exc()
        print >> sys.stderr, sys.exc_info()
    finally:
        fabric.network.disconnect_all()
Example #12
0
def main():
    """
    Main serial sensors script.
    """
    opts = PARSER.parse_args()
    user, passwd = get_user_credentials(opts.username, opts.password)
    iotlab_api = iotlabcli.Api(user, passwd)
    exp_id = _get_exp_id(iotlab_api, opts.exp_id)
    exp_nodes = _get_exp_nodes(iotlab_api, exp_id)
    broker_api = _get_broker_api(opts)

    if (opts.flash):
        _update_fw_exp_nodes(iotlab_api,
                             exp_id,
                             exp_nodes,
                             FW_DICT['serial_sensors'])
        return
    if (opts.unregister):
        _unregister_broker_devices(broker_api, exp_nodes)
        return

    node_type = 'iotlab_sensors'
    if (opts.iotlab_sensors):
        cmd = opts.iotlab_sensors
    if (opts.parking):
        cmd = opts.parking
        node_type = 'parking'
    if (opts.traffic):
        cmd = None
        node_type = 'traffic'
    if (opts.pollution):
        cmd = None
        node_type = 'pollution'

    set_gateway_uuid(node_type)

    # reset nodes to be sure of init firmware execution
    _reset_exp_nodes(iotlab_api, exp_id, exp_nodes)
    attr_nodes = utils.get_attr_nodes(opts, node_type, exp_nodes)
    broker_devices = _register_broker_devices(broker_api, attr_nodes)
    if opts.traffic:
        _handle_traffic_data(broker_api, broker_devices, attr_nodes)
    elif opts.pollution:
        _handle_pollution_data(broker_api, broker_devices, attr_nodes)
    else:
        _aggregate_measure(broker_api, cmd, broker_devices)
def main():
    """ Start experiments on all sites/nodes and get the nodes uids """
    opts = PARSER.parse_args()
    try:
        user, passwd = get_user_credentials(opts.username, opts.password)
        api = iotlabcli.Api(user, passwd)
        env.user = user

        sites_dict = RunExperiment.site_archi_dict(api)
        targets = RunExperiment.targets_list(sites_dict, opts.site, opts.archi)

        # Generate config for all targets
        config = {}
        for site, archi in targets:
            firmware = vars(opts)['fw_%s' % archi]
            if firmware is None:
                fabric.utils.puts("No firmware for %s %s" % (site, archi))
            else:
                # replace ':' in host to prevent it being interpreted as port
                config['%s-%s' % (archi.replace(':', '+'), site)] = {
                    'site': site, 'archi': archi, 'firmware': firmware
                }

        if len(config) == 0:
            raise ValueError("No valid hosts")

        result_dict = fabric.tasks.execute(
            run_exp, api, opts.name, opts.duration, config, opts.all_bookable,
            hosts=sorted(config.keys()))

        result = {}
        for ret in result_dict.values():
            if ret is not None:
                result.update(json.loads(ret))
        result_str = json.dumps(result, indent=4, sort_keys=True)

        print result_str
        with open(opts.outfile, 'w') as outfile:
            outfile.write(result_str)

    except:  # pylint:disable=bare-except
        traceback.print_exc()
        print >> sys.stderr, sys.exc_info()
    finally:
        fabric.network.disconnect_all()
Example #14
0
def exp(exp_id=None):
    """ Extract nodes from `exp_id` experiment and set them as commands targets
    Following roles are set:
     * nodes: all the a8 nodes of the experiment
     * frontends: each sites where there are a8 nodes

    """
    username, password = iotlabcli.get_user_credentials()
    api = iotlabcli.Api(username, password)
    exp_id = iotlabcli.get_current_experiment(api, exp_id)

    env.user = username

    nodes = _get_exp_a8_nodes(api, exp_id)
    env.roledefs['nodes'] = nodes

    sites = list(set([url.split('.', 1)[1] for url in nodes]))
    env.roledefs['frontends'] = sites
def submit_experiment(args):
    """
    Reserve nodes in the given site.
    The function uses the json experiment file corresponding to the site.
    :param str firmware: the name of the firmware as it is in the code/firmware/ folder
    :param str board: the type of board (ex: m3)
    :param str testbed: The name of the testbed (ex: grenoble)
    :param int duration: The duration of the experiment in minutes
    :param int nbnodes: The number of nodes to use
    :return: The id of the experiment
    """

    # use the file created by auth-cli command
    usr, pwd    = iotlab.get_user_credentials()

    # authenticate through the REST interface
    api         = iotlab.rest.Api(usr, pwd)

    # load the experiment
    firmware    = FIRMWARE_PATH + args.firmware
    profile     = "mercator"
    if args.nbnodes != 0:
        if args.board == "m3":
            args.board = "m3:at86rf231"
        nodes = experiment.AliasNodes(args.nbnodes, args.testbed, args.board)
    else:
        tb_file = open("{0}states.json".format(METAS_PATH))
        tb_json = json.load(tb_file)
        nodes = [x for x in tb_json[args.testbed] if args.board in x]
    resources = [experiment.exp_resources(nodes, firmware, profile)]

    # submit experiment
    logconsole.info("Submitting experiment.")
    expid       = experiment.submit_experiment(
                    api, "mercatorExp", args.duration,
                    resources)["id"]

    logconsole.info("Experiment submited with id: %u", expid)
    logconsole.info("Waiting for experiment to be running.")
    experiment.wait_experiment(api, expid)

    return expid
Example #16
0
def main():
    """ Check the oar uids using given jsons dicts """

    parser = opts_parser()
    opts = parser.parse_args()
    os.listdir(opts.outdir)  # existing directory

    try:
        username, password = iotlabcli.get_user_credentials(
            opts.username, opts.password)
        api = iotlabcli.Api(username, password)
        server_uids = oar_uids(api)
    except RuntimeError as err:
        sys.stderr.write("%s\n" % err)
        exit(1)

    nodes_uids = nodes_read_uids(opts.uids_json_files)

    nodes_cmp = compare_nodes_uids(server_uids, nodes_uids)
    write_outputs(nodes_cmp, os.path.join(opts.outdir, 'uid_cmp'))
Example #17
0
def main():
    """ Check the oar uids using given jsons dicts """

    parser = opts_parser()
    opts = parser.parse_args()
    os.listdir(opts.outdir)  # existing directory

    try:
        username, password = iotlabcli.get_user_credentials(
            opts.username, opts.password)
        api = iotlabcli.Api(username, password)
        server_uids = oar_uids(api)
    except RuntimeError as err:
        sys.stderr.write("%s\n" % err)
        exit(1)

    nodes_uids = nodes_read_uids(opts.uids_json_files)

    nodes_cmp = compare_nodes_uids(server_uids, nodes_uids)
    write_outputs(nodes_cmp, os.path.join(opts.outdir, 'uid_cmp'))
Example #18
0
def push_iotlab(name):
    experiment_path = pj(EXPERIMENT_FOLDER, name)
    results_folder = pj(experiment_path, "results", "iotlab")
    if not os.path.exists(results_folder):
        os.makedirs(results_folder)

    # gets user password from credentials file None, None
    user, passwd = iotlabcli.get_user_credentials()
    api = iotlabcli.Api(user, passwd)

    # describe the resources
    resources = None
    with open(pj(experiment_path, "iotlab.json")) as f:
        config = json.loads(f.read())
        resources = [experiment.exp_resources(**c) for c in config]

    print(resources)
    # actually submit the experiment
    exp_id = None
    # We move to the folder to have a portable iotlab.json
    with lcd(experiment_path):
        exp_res = experiment.submit_experiment(
            api, 'dummy_experiment', 1, resources)
        exp_id = exp_wres["id"]
        with open("results/iotlab/iotlab.json", "w") as f:
            f.write(json.dumps({"id": exp_id}))

    # get the content
    print("Exp submited with id: %u" % exp_id)

    run("experiment-cli wait -i %d" % exp_id)

    with open(pj(results_folder, "serial.log"), 'w') as f:
        run("./iot-lab/tools_and_scripts/serial_aggregator.py -i %d" % exp_id,
            stdout=f)
    print("Written serial logs to %s" % pj(results_folder, "serial.log"))
    def __init__(self, args, serialports, site="local"):

        # local variables
        self.dataLock        = threading.Lock()
        self.transctr        = 0
        self.motes           = {}
        self.isTransmitting  = False
        self.site            = site
        self.freq            = self.FREQUENCIES[0]
        self.transmitterPort = ""
        self.nbtrans         = args.nbtrans
        self.nbpackets       = args.nbpackets
        self.txpksize        = args.txpksize
        self.txpower         = args.txpower
        self.experiment_id   = args.expid

        # use the file created by auth-cli command
        usr, pwd = iotlab.get_user_credentials()

        # authenticate through the REST interface
        self.api = iotlab.rest.Api(usr, pwd)

        # connect to motes
        for s in serialports:
            logfile.debug("connected to %s", s)
            self.motes[s]    = MoteHandler.MoteHandler(s, self._cb, reset_cb=self._reset_cb)
            if not self.motes[s].isActive:
                raise Exception("Mote {0} is not responding.".format(s))

        # get current datetime
        now = datetime.datetime.now().strftime("%Y.%m.%d-%H.%M.%S")

        # open file
        self.file = gzip.open(
            '{0}{1}-{2}_raw.csv.gz'.format(
                DATASET_PATH,
                self.site,
                now
            ),
            'wb'
        )

        # write settings
        settings = {
            "interframe_duration": self.TXIFDUR,
            "fill_byte": self.TXFILLBYTE,
            "tx_length": self.txpksize,
            "tx_count": self.nbpackets,
            "transaction_count": self.nbtrans,
            "node_count": len(self.motes),
            "location": self.site,
            "channel_count": len(self.FREQUENCIES),
            "start_date": now,
            "txpower": self.txpower
        }
        json.dump(settings, self.file)
        self.file.write('\n')

        # write csv header
        self.file.write('datetime,src,dst,channel,rssi,crc,expected,' +
                        'transaction_id,pkctr\n')

        try:
            # start transactions
            for self.transctr in range(0, self.nbtrans):
                logconsole.info("Current transaction: %s", self.transctr)
                self._do_transaction()
        except (KeyboardInterrupt, socket.error):
            # print error
            print('\nExperiment ended before all transactions were done.')
        else:
            # print all OK
            print('\nExperiment ended normally.')
        finally:
            self.file.close()
    def __init__(self, args, serialports, site="local"):

        # local variables
        self.dataLock = threading.Lock()
        self.transctr = 0
        self.motes = {}
        self.isTransmitting = False
        self.site = site
        self.freq = self.FREQUENCIES[0]
        self.transmitterPort = ""
        self.nbtrans = args.nbtrans
        self.nbpackets = args.nbpackets
        self.txpksize = args.txpksize
        self.txpower = args.txpower
        self.experiment_id = args.expid

        # use the file created by auth-cli command
        usr, pwd = iotlab.get_user_credentials()

        # authenticate through the REST interface
        self.api = iotlab.rest.Api(usr, pwd)

        # connect to motes
        for s in serialports:
            logfile.debug("connected to %s", s)
            self.motes[s] = MoteHandler.MoteHandler(s,
                                                    self._cb,
                                                    reset_cb=self._reset_cb)
            if not self.motes[s].isActive:
                raise Exception("Mote {0} is not responding.".format(s))

        # get current datetime
        now = datetime.datetime.now().strftime("%Y.%m.%d-%H.%M.%S")

        # open file
        self.file = gzip.open(
            '{0}{1}-{2}_raw.csv.gz'.format(DATASET_PATH, self.site, now), 'wb')

        # write settings
        settings = {
            "interframe_duration": self.TXIFDUR,
            "fill_byte": self.TXFILLBYTE,
            "tx_length": self.txpksize,
            "tx_count": self.nbpackets,
            "transaction_count": self.nbtrans,
            "node_count": len(self.motes),
            "location": self.site,
            "channel_count": len(self.FREQUENCIES),
            "start_date": now,
            "txpower": self.txpower
        }
        json.dump(settings, self.file)
        self.file.write('\n')

        # write csv header
        self.file.write('datetime,src,dst,channel,rssi,crc,expected,' +
                        'transaction_id,pkctr\n')

        try:
            # start transactions
            for self.transctr in range(0, self.nbtrans):
                logconsole.info("Current transaction: %s", self.transctr)
                self._do_transaction()
        except (KeyboardInterrupt, socket.error):
            # print error
            print('\nExperiment ended before all transactions were done.')
        else:
            # print all OK
            print('\nExperiment ended normally.')
        finally:
            self.file.close()
Example #21
0
def get_node_uids_lookup():
    api = iotlabcli.Api(* iotlabcli.get_user_credentials())
    info = iotlabcli.experiment.info_experiment(api)
    return  { x["uid"]: x["network_address"].split('.')[0]
                  for x in info["items"] }
Example #22
0
def get_nodes_list(opts):
    api = iotlabcli.Api(* iotlabcli.get_user_credentials())
    exp_id = iotlabcli.helpers.get_current_experiment(api, opts.experiment_id)
    return iotlabcli.parser.common._get_experiment_nodes_list(api, exp_id)
Example #23
0
def get_nodes_list(opts):
    api = iotlabcli.Api(*iotlabcli.get_user_credentials())
    exp_id = iotlabcli.helpers.get_current_experiment(api, opts.experiment_id)
    return iotlabcli.parser.common._get_experiment_nodes_list(api, exp_id)