1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

rpl: use global ip addresses instead of link-local ones

This commit is contained in:
Cenk Gündoğan 2015-03-10 20:51:58 +01:00
parent b9f4cdc3ae
commit 5d382b4ac8
4 changed files with 46 additions and 33 deletions

View File

@ -96,42 +96,46 @@ void rpl_udp_init(int argc, char **argv)
printf("Channel set to %" PRIi32 "\n", chan); 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') { if (command != 'h') {
DEBUGF("Initializing RPL for interface 0\n"); DEBUGF("Initializing RPL for interface 0\n");
uint8_t state = rpl_init(0);
uint8_t state;
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) { if (state != SIXLOWERROR_SUCCESS) {
printf("Error initializing RPL\n"); puts("Error initializing RPL");
} }
else { else {
puts("6LoWPAN and RPL initialized."); puts("6LoWPAN and RPL initialized.");
} }
if (command == 'r') { ipv6_iface_set_routing_provider(rpl_get_next_hop);
/* add global address */
ipv6_addr_t tmp;
/* initialize prefix */
ipv6_addr_init(&tmp, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
rpl_options_t rpl_opts = {
.instance_id = 0,
.prefix = tmp,
.prefix_len = 64,
.prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF, /* autonomous address-configuration */
};
tmp.uint16[7] = HTONS(id);
/* set host suffix */
ipv6_addr_set_by_eui64(&tmp, 0, &tmp);
ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);
rpl_init_root(&rpl_opts);
ipv6_iface_set_routing_provider(rpl_get_next_hop);
is_root = 1;
}
else {
ipv6_iface_set_routing_provider(rpl_get_next_hop);
}
} }
else { else {
puts("6LoWPAN initialized."); puts("6LoWPAN initialized.");

View File

@ -73,12 +73,13 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
* corresponding objective functions and sixlowpan (including own address). * corresponding objective functions and sixlowpan (including own address).
* *
* @param[in] if_id ID of the interface, which correspond to the network under RPL-control * @param[in] if_id ID of the interface, which correspond to the network under RPL-control
* @param[in] address Global IPv6 address to use
* *
* @return 1 if initialization was successful * @return 1 if initialization was successful
* @return 0 if initialization was not successful * @return 0 if initialization was not successful
* *
*/ */
uint8_t rpl_init(int if_id); uint8_t rpl_init(int if_id, ipv6_addr_t *address);
/** /**
* @brief Initialization of RPL-root. * @brief Initialization of RPL-root.

View File

@ -73,7 +73,7 @@ ipv6_addr_t my_address;
/* IPv6 message buffer */ /* IPv6 message buffer */
static ipv6_hdr_t *ipv6_buf; static ipv6_hdr_t *ipv6_buf;
uint8_t rpl_init(int if_id) uint8_t rpl_init(int if_id, ipv6_addr_t *address)
{ {
rpl_if_id = if_id; rpl_if_id = if_id;
rpl_instances_init(); rpl_instances_init();
@ -89,12 +89,13 @@ uint8_t rpl_init(int if_id)
rpl_process, NULL, "rpl_process"); rpl_process, NULL, "rpl_process");
sixlowpan_lowpan_init_interface(if_id); 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_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 */ /* add all-RPL-nodes address */
ipv6_addr_t all_rpl_nodes; ipv6_addr_t all_rpl_nodes;
ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes); ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes);

View File

@ -426,7 +426,14 @@ void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifet
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->flags = 0x00;
rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN;
memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t)); if (!ipv6_addr_is_unspecified(&my_dodag->prefix)) {
ipv6_addr_t tmp;
ipv6_addr_set_by_eui64(&tmp, rpl_if_id, &my_dodag->prefix);
memcpy(&rpl_send_opt_target_buf->target, &tmp, sizeof(ipv6_addr_t));
}
else {
memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t));
}
opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN;
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);