mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #2543 from cgundogan/rpl_use_global_address
rpl: use global ip addresses instead of link-local ones
This commit is contained in:
commit
569d291838
@ -96,42 +96,46 @@ void rpl_udp_init(int argc, char **argv)
|
||||
|
||||
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 = 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) {
|
||||
printf("Error initializing RPL\n");
|
||||
puts("Error initializing RPL");
|
||||
}
|
||||
else {
|
||||
puts("6LoWPAN and RPL initialized.");
|
||||
}
|
||||
|
||||
if (command == 'r') {
|
||||
/* add global address */
|
||||
ipv6_addr_t tmp;
|
||||
/* initialize prefix */
|
||||
ipv6_addr_init(&tmp, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
|
||||
ipv6_iface_set_routing_provider(rpl_get_next_hop);
|
||||
|
||||
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 {
|
||||
puts("6LoWPAN initialized.");
|
||||
|
@ -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).
|
||||
*
|
||||
* @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 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.
|
||||
|
@ -73,7 +73,7 @@ ipv6_addr_t my_address;
|
||||
/* IPv6 message buffer */
|
||||
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_instances_init();
|
||||
@ -89,12 +89,13 @@ uint8_t rpl_init(int if_id)
|
||||
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);
|
||||
|
||||
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);
|
||||
|
@ -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->flags = 0x00;
|
||||
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;
|
||||
|
||||
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
|
||||
|
Loading…
Reference in New Issue
Block a user