Example #1
0
uint8_t rpl_init(int if_id)
{
    rpl_instances_init();

    /* initialize routing table */
    rpl_clear_routing_table();

    if (RPL_DEFAULT_MOP == RPL_STORING_MODE_NO_MC) {
        rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES_STORING;
        rpl_clear_routing_table();
    }
    else {
        rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES_NON_STORING;
        rpl_clear_routing_table();
    }

    if (rpl_routing_table == NULL) {
        DEBUGF("Routing table init failed!\n");
        return SIXLOWERROR_NULLPTR;
    }
    else {
        DEBUGF("Routing table init finished!\n");
    }

    init_trickle();
    rpl_process_pid = thread_create(rpl_process_buf, RPL_PROCESS_STACKSIZE,
                                    PRIORITY_MAIN - 1, CREATE_STACKTEST,
                                    rpl_process, NULL, "rpl_process");

    sixlowpan_lowpan_init_interface(if_id);
    /* need link local prefix to query _our_ corresponding address  */
    ipv6_addr_t ll_address;
    ipv6_addr_set_link_local_prefix(&ll_address);
    ipv6_net_if_get_best_src_addr(&my_address, &ll_address);
    ipv6_register_rpl_handler(rpl_process_pid);
    ipv6_iface_set_srh_indicator(rpl_is_root);
    ipv6_iface_set_routing_provider(rpl_get_next_hop);
    DEBUGF("All addresses set!\n");

    /* initialize objective function manager */
    rpl_of_manager_init(&my_address);
    rpl_init_mode(&my_address);
    return SIXLOWERROR_SUCCESS;
}
Example #2
0
File: rpl.c Project: mm3/RIOT
uint8_t rpl_init(int if_id, ipv6_addr_t *address)
{
    rpl_if_id = if_id;

    /* initialize routing table */
#if RPL_MAX_ROUTING_ENTRIES != 0
    rpl_max_routing_entries = RPL_MAX_ROUTING_ENTRIES;
#endif

    rpl_process_pid = thread_create(rpl_process_buf, sizeof(rpl_process_buf),
                                    THREAD_PRIORITY_MAIN - 1, CREATE_STACKTEST,
                                    rpl_process, NULL, "rpl_process");

    sixlowpan_lowpan_init_interface(if_id);
    ipv6_register_rpl_handler(rpl_process_pid);

    if (address) {
        my_address = *address;
        ipv6_net_if_add_addr(if_id, &my_address, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);
    }

    /* add all-RPL-nodes address */
    ipv6_addr_t all_rpl_nodes;
    ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes);
    ipv6_net_if_add_addr(if_id, &all_rpl_nodes, NDP_ADDR_STATE_ANY, 0, 0, 0);

#if (RPL_DEFAULT_MOP == RPL_MOP_NON_STORING_MODE)
    ipv6_iface_set_srh_indicator(rpl_is_root);
#endif
    ipv6_iface_set_routing_provider(rpl_get_next_hop);
    DEBUGF("All addresses set!\n");

    /* initialize objective function manager */
    rpl_of_manager_init(&my_address);

    rt_time = timex_set(RPL_LIFETIME_STEP, 0);
    vtimer_set_msg(&rt_timer, rt_time, rpl_process_pid, RPL_MSG_TYPE_ROUTING_ENTRY_UPDATE, NULL);

    return SIXLOWERROR_SUCCESS;
}
Example #3
0
File: rpl.c Project: nandojve/RIOT
void rpl_udp_init(int argc, char **argv)
{
    transceiver_command_t tcmd;
    msg_t m;
    int32_t chan = UNASSIGNED_CHANNEL;

    if (argc != 2) {
        printf("Usage: %s (r|n|h)\n", argv[0]);
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
        printf("\th\tinitialize as non-routing node (host-mode)\n");
        return;
    }

    char command = argv[1][0];
    if ((command == 'n') || (command == 'r') || (command == 'h')) {
        printf("INFO: Initialize as %srouting %s on address %d\n",
               ((command == 'h') ? "non-" : ""),
               (((command == 'n') || (command == 'h')) ? "node" : "root"), id);

#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA))
        if (!id || (id > 255)) {
            printf("ERROR: address not a valid 8 bit integer\n");
            return;
        }
#endif

        DEBUGF("Setting HW address to %u\n", id);
        net_if_set_hardware_address(0, id);

        tcmd.transceivers = TRANSCEIVER;
        tcmd.data = &chan;
        m.type = GET_CHANNEL;
        m.content.ptr = (void *) &tcmd;

        msg_send_receive(&m, &m, transceiver_pid);
        if( chan == UNASSIGNED_CHANNEL ) {
            DEBUGF("The channel has not been set yet.");

            /* try to set the channel to 10 (RADIO_CHANNEL) */
            chan = RADIO_CHANNEL;
        }

        m.type = SET_CHANNEL;
        msg_send_receive(&m, &m, transceiver_pid);
        if( chan == UNASSIGNED_CHANNEL ) {
            puts("ERROR: channel NOT set! Aborting initialization.");
            return;
        }

        printf("Channel set to %" PRIi32 "\n", chan);

        /* global address */
        ipv6_addr_t global_addr, global_prefix;
        ipv6_addr_init(&global_prefix, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
        ipv6_addr_set_by_eui64(&global_addr, 0, &global_prefix);

        if (command != 'h') {
            DEBUGF("Initializing RPL for interface 0\n");

            uint8_t state = SIXLOWERROR_VALUE;
            if (command == 'n') {
                /*
                 * no global address specified, we'll use auto address config
                 * initiated by the root node
                 */
                state = rpl_init(0, NULL);
            }
            else if (command == 'r') {
                rpl_options_t rpl_opts = {
                    .instance_id = 0,
                    .prefix = global_prefix,
                    .prefix_len = 64,
                    .prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF,
                    /* autonomous address-configuration */
                };

                /* use specific global address */
                state = rpl_init(0, &global_addr);
                rpl_init_root(&rpl_opts);
                is_root = 1;
            }

            if (state != SIXLOWERROR_SUCCESS) {
                puts("Error initializing RPL");
            }
            else {
                puts("6LoWPAN and RPL initialized.");
            }

            ipv6_iface_set_routing_provider(rpl_get_next_hop);

        }
Example #4
0
void init(char *str)
{
    transceiver_command_t tcmd;
    msg_t m;
    uint8_t chan = RADIO_CHANNEL;

    char command;

    int res = sscanf(str, "init %c", &command);

    if (res < 1) {
        printf("Usage: init (r|n)\n");
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
    }

    uint8_t state;

    if ((command == 'n') || (command == 'r')) {
        printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);
        if (!id || (id > 255)) {
            printf("ERROR: address not a valid 8 bit integer\n");
            return;
        }

        state = rpl_init(TRANSCEIVER, id);

        if (state != SIXLOWERROR_SUCCESS) {
            printf("Error initializing RPL\n");
        }
        else {
            puts("6LoWPAN and RPL initialized.");
        }

        if (command == 'r') {
            rpl_init_root();
            is_root = 1;
        }
        else {
            ipv6_iface_set_routing_provider(rpl_get_next_hop);
        }
        int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, monitor, "monitor");
        transceiver_register(TRANSCEIVER, monitor_pid);
        ipv6_register_packet_handler(monitor_pid);
        //sixlowpan_lowpan_register(monitor_pid);
    }
    else {
        printf("ERROR: Unknown command '%c'\n", command);
        return;
    }

    /* TODO: check if this works as intended */
    ipv6_addr_t prefix, tmp;
    ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id);
    ipv6_addr_init_prefix(&prefix, &std_addr, 64);
    plist_add(&prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, 0, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM);
    ipv6_init_iface_as_router();
    /* add global address */
    ipv6_addr_set_by_eui64(&tmp, &std_addr);
    ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_GLOBAL, NDP_ADDR_STATE_PREFERRED, 0, 0);
            
    /* set channel to 10 */
    tcmd.transceivers = TRANSCEIVER;
    tcmd.data = &chan;
    m.type = SET_CHANNEL;
    m.content.ptr = (void *) &tcmd;

    msg_send_receive(&m, &m, transceiver_pid);
    printf("Channel set to %u\n", RADIO_CHANNEL);

    destiny_init_transport_layer();
    puts("Destiny initialized");
    /* start transceiver watchdog */
}
Example #5
0
void rpl_udp_init(int argc, char **argv)
{
    transceiver_command_t tcmd;
    msg_t m;
    uint8_t chan = RADIO_CHANNEL;

    if (argc != 2) {
        printf("Usage: %s (r|n)\n", argv[0]);
        printf("\tr\tinitialize as root\n");
        printf("\tn\tinitialize as node router\n");
        return;
    }

    uint8_t state;

    char command = argv[1][0];
    if ((command == 'n') || (command == 'r')) {
        printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id);

        if (!id || (id > 255)) {
            printf("ERROR: address not a valid 8 bit integer\n");
            return;
        }

        DEBUGF("Setting HW address to %u\n", id);
        net_if_set_hardware_address(0, id);

        DEBUGF("Initializing RPL for interface 0\n");
        state = rpl_init(0);

        if (state != SIXLOWERROR_SUCCESS) {
            printf("Error initializing RPL\n");
        }
        else {
            puts("6LoWPAN and RPL initialized.");
        }

        if (command == 'r') {
            rpl_init_root();
            is_root = 1;
        }
        else {
            ipv6_iface_set_routing_provider(rpl_get_next_hop);
        }

        DEBUGF("Start monitor\n");
        int monitor_pid = thread_create(
                monitor_stack_buffer, sizeof(monitor_stack_buffer),
                PRIORITY_MAIN - 2, CREATE_STACKTEST,
                rpl_udp_monitor, NULL, "monitor");
        DEBUGF("Register at transceiver %02X\n", TRANSCEIVER);
        transceiver_register(TRANSCEIVER, monitor_pid);
        ipv6_register_packet_handler(monitor_pid);
        //sixlowpan_lowpan_register(monitor_pid);
    }
    else {
        printf("ERROR: Unknown command '%c'\n", command);
        return;
    }

    /* TODO: check if this works as intended */
    ipv6_addr_t prefix, tmp;
    ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id);
    ipv6_addr_init_prefix(&prefix, &std_addr, 64);
    ndp_add_prefix_info(0, &prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE,
                        NDP_OPT_PI_PLIFETIME_INFINITE, 1,
                        ICMPV6_NDP_OPT_PI_FLAG_AUTONOM);
    ipv6_init_as_router();
    /* add global address */
    ipv6_addr_set_by_eui64(&tmp, 0, &std_addr);
    ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);

    /* set channel to 10 */
    tcmd.transceivers = TRANSCEIVER;
    tcmd.data = &chan;
    m.type = SET_CHANNEL;
    m.content.ptr = (void *) &tcmd;

    msg_send_receive(&m, &m, transceiver_pid);
    printf("Channel set to %u\n", RADIO_CHANNEL);

    puts("Destiny initialized");
    /* start transceiver watchdog */
}