Skip to content

Commit 08d5584

Browse files
author
Juha Heiskanen
authored
Merge pull request ARMmbed#1794 from ARMmbed/rpl_address_learn
Rpl address learn
2 parents 5bbc86f + a48254c commit 08d5584

File tree

7 files changed

+66
-22
lines changed

7 files changed

+66
-22
lines changed

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,8 @@ static void protocol_6lowpan_bootstrap_rpl_callback(rpl_event_t event, void *han
20732073
tr_error("RPL Local repair fail-->interface to idle");
20742074
nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur);
20752075
break;
2076+
default:
2077+
break;
20762078
}
20772079
}
20782080

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
126126
}
127127

128128
if (reason == ADDR_CALLBACK_DAD_COMPLETE) {
129-
ws_bootsrap_event_trig(WS_ADDRESS_ADDED, interface->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, (void *)addr);
129+
//Trig Address Registartion only when Bootstrap is ready
130+
if (interface->nwk_bootstrap_state == ER_BOOTSRAP_DONE) {
131+
ws_bootsrap_event_trig(WS_ADDRESS_ADDED, interface->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, (void *)addr);
132+
}
130133
} else if (reason == ADDR_CALLBACK_DELETED) {
131134
// What to do?
132135
}
@@ -1194,6 +1197,9 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
11941197
*
11951198
*/
11961199

1200+
} else if (event == RPL_EVENT_DAO_PARENT_SWITCH) {
1201+
tr_info("RPL parent update ... register ARO");
1202+
ws_bootsrap_event_trig(WS_ADDRESS_ADDED, cur->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, NULL);
11971203
}
11981204
cur->ws_info->rpl_state = event;
11991205
tr_info("RPL event %d", event);

source/RPL/rpl_control.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -677,28 +677,16 @@ static void rpl_control_process_prefix_options(protocol_interface_info_entry_t *
677677
const uint8_t *prefix = ptr + 16;
678678

679679
if (!pref_parent || neighbour == pref_parent) {
680-
//Check is L Flag active
681-
if (flags & PIO_L) {
682-
//define ONLink Route Information
683-
//tr_debug("Register On Link Prefix to routing table");
684-
ipv6_route_add(prefix, prefix_len, cur->id, NULL, ROUTE_RADV, valid, 0);
685-
}
686-
/* Check if A-Flag.
687-
* A RPL node may use this option for the purpose of Stateless Address Autoconfiguration (SLAAC)
688-
* from a prefix advertised by a parent.
689-
*/
690-
if (pref_parent && (flags & PIO_A)) {
691-
if (icmpv6_slaac_prefix_update(cur, prefix, prefix_len, valid, preferred) != 0) {
692-
ipv6_interface_slaac_handler(cur, prefix, prefix_len, valid, preferred);
693-
}
694-
}
695680

696681
/* Store prefixes for possible forwarding */
697682
/* XXX if leaf - don't bother? Or do we want to remember them for
698683
* when we switch DODAG, as mentioned above?
699684
*/
700685

701-
rpl_dodag_update_dio_prefix(dodag, prefix, prefix_len, flags, valid, preferred, false, true);
686+
prefix_entry_t *prefix_entry = rpl_dodag_update_dio_prefix(dodag, prefix, prefix_len, flags, valid, preferred, false, true);
687+
if (prefix_entry && pref_parent) {
688+
rpl_control_process_prefix_option(prefix_entry, cur);
689+
}
702690
}
703691

704692
if ((flags & PIO_R) && !router_addr_set) {
@@ -715,6 +703,26 @@ static void rpl_control_process_prefix_options(protocol_interface_info_entry_t *
715703
}
716704
}
717705

706+
void rpl_control_process_prefix_option(prefix_entry_t *prefix, protocol_interface_info_entry_t *cur)
707+
{
708+
//Check is L Flag active
709+
if (prefix->options & PIO_L) {
710+
//define ONLink Route Information
711+
//tr_debug("Register On Link Prefix to routing table");
712+
ipv6_route_add(prefix->prefix, prefix->prefix_len, cur->id, NULL, ROUTE_RADV, prefix->lifetime, 0);
713+
}
714+
/* Check if A-Flag.
715+
* A RPL node may use this option for the purpose of Stateless Address Autoconfiguration (SLAAC)
716+
* from a prefix advertised by a parent.
717+
*/
718+
if (prefix->options & PIO_A) {
719+
if (icmpv6_slaac_prefix_update(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime) != 0) {
720+
ipv6_interface_slaac_handler(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime);
721+
}
722+
}
723+
}
724+
725+
718726
/*
719727
* 0 1 2 3
720728
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

source/RPL/rpl_control.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ struct rpl_dodag;
2929
struct buffer;
3030
struct protocol_interface_info_entry;
3131
struct rpl_dodag_info_t;
32+
struct prefix_entry_t;
3233

3334
typedef enum rpl_event {
3435
RPL_EVENT_DAO_DONE, /* Simplistic trigger for bootstrap advance - a DAO registration completed */
3536
RPL_EVENT_LOCAL_REPAIR_START, /* RPL start scanning new parent by multicast DIS user can disable beacon request responser here*/
3637
RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS, /* RPL not sending DIS anymore user can report bootstrap error */
38+
RPL_EVENT_DAO_PARENT_SWITCH, /* RPL indicate that DAO downward Parent state have been updated */
3739
} rpl_event_t;
3840

3941
typedef void rpl_domain_callback_t(rpl_event_t event, void *handle);
@@ -100,6 +102,7 @@ void rpl_control_transmit_dio(struct rpl_domain *domain, struct protocol_interfa
100102
bool rpl_control_transmit_dao(struct rpl_domain *domain, struct protocol_interface_info_entry *cur, struct rpl_instance *instance, uint8_t instance_id, uint8_t dao_sequence, const uint8_t dodagid[16], const uint8_t *opts, uint16_t opts_size, const uint8_t *dst);
101103
void rpl_control_disable_ra_routes(struct rpl_domain *domain);
102104
void rpl_control_event(struct rpl_domain *domain, rpl_event_t event);
105+
void rpl_control_process_prefix_option(struct prefix_entry_t *prefix, struct protocol_interface_info_entry *cur);
103106

104107
/*********************** RPL control API to rest of system *******************/
105108

@@ -160,7 +163,6 @@ const rpl_dodag_conf_t *rpl_control_get_dodag_config(const struct rpl_instance *
160163
const uint8_t *rpl_control_preferred_parent_addr(const struct rpl_instance *instance, bool global);
161164
uint16_t rpl_control_current_rank(const struct rpl_instance *instance);
162165

163-
164166
#else /* HAVE_RPL */
165167

166168
#define rpl_control_fast_timer(ticks) ((void) 0)

source/RPL/rpl_downward.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ void rpl_downward_process_dao_parent_changes(rpl_instance_t *instance)
243243
}
244244
}
245245
}
246+
//GENERATE PARENT Update event
247+
rpl_control_event(instance->domain, RPL_EVENT_DAO_PARENT_SWITCH);
246248
rpl_instance_dao_trigger(instance, 0);
247249
}
248250
}

source/RPL/rpl_upward.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,6 @@ bool rpl_instance_purge(rpl_instance_t *instance)
11741174
void rpl_instance_neighbours_changed(rpl_instance_t *instance)
11751175
{
11761176
instance->neighbours_changed = true;
1177-
if (!rpl_instance_preferred_parent(instance)) {
1178-
rpl_instance_set_local_repair(instance, true);
1179-
}
11801177
rpl_instance_trigger_parent_selection(instance, rpl_policy_dio_parent_selection_delay(instance->domain));
11811178
}
11821179

@@ -1366,7 +1363,18 @@ void rpl_instance_run_parent_selection(rpl_instance_t *instance)
13661363
}
13671364
}
13681365

1369-
rpl_instance_set_local_repair(instance, preferred_parent == NULL);
1366+
//Control Local repair state
1367+
if (preferred_parent) {
1368+
// Always stop repair if we find a parent
1369+
rpl_instance_set_local_repair(instance, false);
1370+
} else if (original_preferred) {
1371+
// Only start repair if we just lost a parent
1372+
rpl_instance_set_local_repair(instance, true);
1373+
} else {
1374+
// !preferred_parent && !original_preferred - didn't have a parent,
1375+
// still don't. Leave repair flag as-is (would be off on initial start
1376+
// up, may be on if having problems mid-session).
1377+
}
13701378

13711379
if (rpl_instance_mop(instance) != RPL_MODE_NO_DOWNWARD) {
13721380
rpl_downward_process_dao_parent_changes(instance);
@@ -1384,6 +1392,17 @@ void rpl_instance_run_parent_selection(rpl_instance_t *instance)
13841392
rpl_control_print(trace_info_print);
13851393
/* Changing DODAG version is an inconsistency */
13861394
if (original_version != instance->current_dodag_version) {
1395+
//learn Routes an Prefixes
1396+
if (preferred_parent && instance->current_dodag_version) {
1397+
rpl_dodag_t *dodag = instance->current_dodag_version->dodag;
1398+
protocol_interface_info_entry_t *rpl_interface = protocol_stack_interface_info_get_by_id(preferred_parent->interface_id);
1399+
if (rpl_interface) {
1400+
ns_list_foreach(prefix_entry_t, prefix, &dodag->prefixes) {
1401+
rpl_control_process_prefix_option(prefix, rpl_interface);
1402+
}
1403+
}
1404+
}
1405+
13871406
rpl_instance_inconsistency(instance);
13881407
return;
13891408
}

test/nanostack/unittest/stub/rpl_control_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,8 @@ void rpl_control_address_register_done(struct buffer *buf, uint8_t status)
233233
{
234234

235235
}
236+
237+
void rpl_control_process_prefix_option(struct prefix_entry_t *prefix, struct protocol_interface_info_entry *cur)
238+
{
239+
240+
}

0 commit comments

Comments
 (0)