Skip to content

Commit 4e01969

Browse files
author
Jarkko Paso
committed
Merge branch 'koli' into ws_start_bc
* koli: Added version number increase in border router
2 parents 27c8b65 + 97200b3 commit 4e01969

File tree

6 files changed

+168
-56
lines changed

6 files changed

+168
-56
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 121 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "6LoWPAN/MAC/mpx_api.h"
3636
#include "6LoWPAN/MAC/mac_ie_lib.h"
3737
#include "6LoWPAN/ws/ws_common_defines.h"
38+
#include "6LoWPAN/ws/ws_config.h"
3839
#include "6LoWPAN/ws/ws_common.h"
3940
#include "6LoWPAN/ws/ws_bootstrap.h"
4041
#include "RPL/rpl_protocol.h"
@@ -80,22 +81,50 @@ static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur)
8081
static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur);
8182
static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cur);
8283
static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t interface_id, arm_library_event_priority_e priority, void *event_data);
83-
static mac_neighbor_table_entry_t * ws_bootstrap_add_neighbor(struct protocol_interface_info_entry *interface, const uint8_t *src64)
84+
85+
static mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
8486
{
8587
mac_neighbor_table_entry_t *neighbor = mac_neighbor_table_address_discover(interface->mac_parameters->mac_neighbor_table, src64, MAC_ADDR_MODE_64_BIT);
8688
if (!neighbor) {
8789
neighbor = mac_neighbor_table_entry_allocate(interface->mac_parameters->mac_neighbor_table, src64);
88-
if (neighbor) {
89-
mlme_device_descriptor_t device_desc;
90-
tr_debug("Added new neighbor %s : index:%u", trace_array(src64, 8), neighbor->index);
91-
mac_helper_device_description_write(interface, &device_desc, neighbor->mac64, neighbor->mac16,0, false);
92-
mac_helper_devicetable_set(&device_desc, interface,neighbor->index, interface->mac_parameters->mac_default_key_index, true);
93-
}
9490
}
91+
if (!neighbor) {
92+
return NULL;
93+
}
94+
mlme_device_descriptor_t device_desc;
95+
tr_debug("Added new neighbor %s : index:%u", trace_array(src64, 8), neighbor->index);
96+
mac_helper_device_description_write(interface, &device_desc, neighbor->mac64, neighbor->mac16,0, false);
97+
mac_helper_devicetable_set(&device_desc, interface,neighbor->index, interface->mac_parameters->mac_default_key_index, true);
9598
return neighbor;
9699
}
97100

101+
static ws_neighbor_class_entry_t * ws_bootstrap_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
102+
{
103+
mac_neighbor_table_entry_t *neighbor = ws_bootstrap_mac_neighbor_add(interface, src64);
104+
if (!neighbor) {
105+
return NULL;
106+
}
98107

108+
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index);
109+
if (!ws_neighbor) {
110+
mac_neighbor_table_neighbor_remove(interface->mac_parameters->mac_neighbor_table, neighbor);
111+
return NULL;
112+
}
113+
return ws_neighbor;
114+
}
115+
116+
static void ws_bootstrap_neighbor_delete(struct protocol_interface_info_entry *interface, uint8_t attribute_index)
117+
{
118+
mac_helper_devicetable_remove(interface->mac_api, attribute_index);
119+
etx_neighbor_remove(interface->id, attribute_index);
120+
ws_neighbor_class_entry_remove(&interface->ws_info->neighbor_storage, attribute_index);
121+
}
122+
123+
static void ws_bootstrap_neighbor_list_clean(struct protocol_interface_info_entry *interface)
124+
{
125+
126+
mac_neighbor_table_neighbor_list_clean(interface->mac_parameters->mac_neighbor_table);
127+
}
99128

100129
static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_entry *interface, const struct if_address_entry *addr, if_address_callback_t reason)
101130
{
@@ -334,19 +363,14 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
334363
}
335364
//TODO smarter Neighbor allocate system
336365

337-
mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr);
366+
ws_neighbor_class_entry_t *neighbor = ws_bootstrap_neighbor_add(cur, data->SrcAddr);
338367
if (!neighbor) {
339368
return;
340369
}
341370

342-
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
343-
if (!ws_neighbor) {
344-
return;
345-
}
346-
347-
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor->index);
348-
ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp);
349-
ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us);
371+
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, ws_neighbor_class_entry_index_get(&cur->ws_info->neighbor_storage,neighbor));
372+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor, ws_utt, data->timestamp);
373+
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor, ws_us);
350374

351375
// Save the best network parent
352376

@@ -388,16 +412,13 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
388412
static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us)
389413
{
390414

391-
mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr);
415+
ws_neighbor_class_entry_t *neighbor = ws_bootstrap_neighbor_add(cur, data->SrcAddr);
392416
if (!neighbor) {
393417
return;
394418
}
395-
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
396-
if (!ws_neighbor) {
397-
return;
398-
}
399-
ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp);
400-
ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us);
419+
420+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor, ws_utt, data->timestamp);
421+
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor, ws_us);
401422

402423
/*
403424
* An inconsistent transmission is defined as:
@@ -463,20 +484,17 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
463484
return;
464485
}
465486

466-
mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr);
487+
ws_neighbor_class_entry_t *neighbor = ws_bootstrap_neighbor_add(cur, data->SrcAddr);
467488
if (!neighbor) {
468489
return;
469490
}
470-
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
471-
if (!ws_neighbor) {
472-
return;
473-
}
474-
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor->index);
491+
492+
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, ws_neighbor_class_entry_index_get(&cur->ws_info->neighbor_storage,neighbor));
475493
//Update Neighbor Broadcast and Unicast Parameters
476-
ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp);
477-
ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us);
478-
ws_neighbor_class_neighbor_broadcast_time_info_update(ws_neighbor, &ws_bt_ie, data->timestamp);
479-
ws_neighbor_class_neighbor_broadcast_schedule_set(ws_neighbor, &ws_bs_ie);
494+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor, ws_utt, data->timestamp);
495+
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor, ws_us);
496+
ws_neighbor_class_neighbor_broadcast_time_info_update(neighbor, &ws_bt_ie, data->timestamp);
497+
ws_neighbor_class_neighbor_broadcast_schedule_set(neighbor, &ws_bs_ie);
480498

481499

482500
if (cur->ws_info->configuration_learned &&
@@ -504,6 +522,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
504522
*/
505523
tr_info("Updated PAN configuration heard");
506524

525+
cur->ws_info->pan_version_timeout_timer = PAN_VERSION_TIMEOUT;
507526
cur->ws_info->pan_configuration.pan_version = pan_version;
508527
memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32);
509528

@@ -531,17 +550,13 @@ static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_in
531550
return;
532551
}
533552

534-
mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr);
553+
ws_neighbor_class_entry_t *neighbor = ws_bootstrap_neighbor_add(cur, data->SrcAddr);
535554
if (!neighbor) {
536555
return;
537556
}
538-
ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index);
539-
if (!ws_neighbor) {
540-
return;
541-
}
542557

543-
ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp);
544-
ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us);
558+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor, ws_utt, data->timestamp);
559+
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor, ws_us);
545560

546561
/*
547562
* A consistent transmission is defined as a PAN Configuration Solicit with
@@ -643,6 +658,7 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
643658

644659
protocol_interface_info_entry_t *cur = user_data;
645660

661+
topo_trace(TOPOLOGY_MLE, entry_ptr->ext64, TOPO_REMOVE);
646662
// Sleepy host
647663
if (cur->lowpan_info & INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE) {
648664
mac_data_poll_protocol_poll_mode_decrement(cur);
@@ -654,14 +670,7 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
654670
protocol_6lowpan_release_short_link_address_from_neighcache(cur, entry_ptr->mac16);
655671
protocol_6lowpan_release_long_link_address_from_neighcache(cur, entry_ptr->mac64);
656672
}
657-
mac_helper_devicetable_remove(cur->mac_api, entry_ptr->index);
658-
659-
//Remove WS neighbor data
660-
ws_neighbor_class_entry_remove(&cur->ws_info->neighbor_storage, entry_ptr->index);
661-
topo_trace(TOPOLOGY_MLE, entry_ptr->ext64, TOPO_REMOVE);
662-
663-
//SET ETX to infinity
664-
etx_neighbor_remove(cur->id, entry_ptr->index);
673+
ws_bootstrap_neighbor_delete(cur,entry_ptr->index);
665674
}
666675

667676

@@ -850,6 +859,8 @@ static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur)
850859
tr_debug("ip stack init");
851860
clear_power_state(ICMP_ACTIVE);
852861
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ACTIVE;
862+
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
863+
853864
}
854865
static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
855866
{
@@ -865,7 +876,11 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
865876
} else if(event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS) {
866877
// RPL gave up so we need to re-trigger network scan.
867878
// TODO is this correct?
879+
// TODO no! ws_bootstrap_event_configuration_start(cur); causes failure to
880+
// We could send solicit for configuration and then select new parent when those arrive
881+
/* This is done after address deletion, so RPL can act on them */
868882
ws_bootstrap_event_configuration_start(cur);
883+
869884
}
870885
cur->ws_info->rpl_state = event;
871886
tr_info("RPL event %d", event);
@@ -917,12 +932,40 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
917932
tr_debug("router discovery start");
918933
ws_bootstrap_state_change(cur, ER_ACTIVE_SCAN);
919934
cur->nwk_nd_re_scan_count = 0;
935+
cur->ws_info->configuration_learned = false;
936+
cur->ws_info->pan_version_timeout_timer = 0;
937+
// Clear parent info
938+
memset(cur->ws_info->parent_info.addr,0,8);
939+
940+
// Clear learned neighbours
941+
ws_bootstrap_neighbor_list_clean(cur);
942+
920943
// Reset advertisement solicit trickle to start discovering network
921944
trickle_start(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_configuration);
922945
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_configuration);
946+
947+
}
948+
// Start configuration learning
949+
static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry_t *cur)
950+
{
951+
tr_debug("router configuration learn start");
952+
ws_bootstrap_state_change(cur, ER_SCAN);
953+
954+
cur->ws_info->configuration_learned = false;
955+
cur->ws_info->pan_version_timeout_timer = 0;
956+
rpl_control_remove_domain_from_interface(cur);
957+
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
923958
// Clear parent info
924959
memset(cur->ws_info->parent_info.addr,0,8);
925960

961+
// Clear learned neighbours
962+
ws_bootstrap_neighbor_list_clean(cur);
963+
964+
// Reset advertisement solicit trickle to start discovering network
965+
trickle_start(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);
966+
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);
967+
968+
926969
}
927970

928971
/*
@@ -1070,6 +1113,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
10701113
cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0;
10711114
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
10721115
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
1116+
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
10731117
ws_bootstrap_fhss_activate(cur);
10741118
ws_bootstrap_event_operation_start(cur);
10751119
break;
@@ -1087,13 +1131,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
10871131
break;
10881132
case WS_CONFIGURATION_START:
10891133
tr_info("Configuration start");
1090-
// TODO temporary learn from parent
1091-
// Start solicit tricklle
1092-
// TODO process state after first Config go to operation
1093-
trickle_start(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);
1094-
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);
1095-
ws_bootstrap_state_change(cur, ER_SCAN);
1096-
cur->ws_info->configuration_learned = false;
1134+
trickle_stop(&cur->ws_info->trickle_pan_advertisement);
1135+
trickle_stop(&cur->ws_info->trickle_pan_config);
1136+
1137+
// Build list of possible neighbours and learn first broadcast schedule
1138+
1139+
ws_bootstrap_start_configuration_learn(cur);
10971140
break;
10981141
case WS_OPERATION_START:
10991142
tr_info("operation start");
@@ -1253,7 +1296,29 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
12531296
tr_info("Send PAN configuration");
12541297
ws_bootstrap_pan_config(cur);
12551298
}
1299+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1300+
// update version number
1301+
if (cur->ws_info->pan_version_timer > seconds ) {
1302+
cur->ws_info->pan_version_timer -= seconds;
1303+
} else {
1304+
// Border router has timed out
1305+
tr_debug("Border router version number update");
1306+
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
1307+
cur->ws_info->pan_configuration.pan_version++;
1308+
// Inconsistent for border router to make information distribute faster
1309+
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration);
1310+
}
1311+
}
1312+
if (cur->ws_info->pan_version_timeout_timer){
1313+
// PAN version timer running
1314+
if (cur->ws_info->pan_version_timeout_timer > seconds ) {
1315+
cur->ws_info->pan_version_timeout_timer -= seconds;
1316+
} else {
1317+
// Border router has timed out
1318+
tr_warn("Border router has timed out");
1319+
ws_bootstrap_event_discovery_start(cur);
1320+
}
1321+
}
12561322
}
12571323

1258-
12591324
#endif //HAVE_WS

source/6LoWPAN/ws/ws_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ typedef struct ws_info_s {
4949
trickle_t trickle_pan_advertisement;
5050
uint8_t rpl_state; // state from rpl_event_t
5151
parent_info_t parent_info;
52+
uint32_t pan_version_timer; /**< border router version udate timeout */
53+
uint32_t pan_version_timeout_timer; /**< routers will fallback to previous state after this */
5254
uint8_t gtkhash[32];
5355
bool configuration_learned:1;
5456

source/6LoWPAN/ws/ws_config.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@
3030
#define WS_RPL_DIO_DOUBLING 2
3131
#define WS_RPL_DIO_REDUDANCY 1
3232

33+
34+
/* Border router version change interval
35+
*
36+
* Minimum interval at which a Border Router shall increment its PAN Version value.
37+
*/
38+
39+
#define PAN_VERSION_LIFETIME 240
40+
41+
/* Border router connection lost timeout
42+
*
43+
* Interval within which a node expects to detect a change in PAN Version
44+
* (delivered via a PAN Configuration frame / PAN-IE).
45+
*
46+
* the maximum Trickle interval specified for DISC_IMAX (32 minutes).
47+
*
48+
*/
49+
50+
#define PAN_VERSION_TIMEOUT 1920
51+
3352
#endif /* WS_CONFIG_H_ */

source/6LoWPAN/ws/ws_neighbor_class.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ ws_neighbor_class_entry_t * ws_neighbor_class_entry_get(ws_neighbor_class_t *cla
5959
return entry;
6060
}
6161

62+
uint8_t ws_neighbor_class_entry_index_get(ws_neighbor_class_t *class_data, ws_neighbor_class_entry_t *entry)
63+
{
64+
if (!class_data->neigh_info_list) {
65+
return 0xff;
66+
}
67+
return entry - class_data->neigh_info_list;
68+
}
69+
6270
void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t attribute_index)
6371
{
6472
ws_neighbor_class_entry_t *entry = ws_neighbor_class_entry_get(class_data, attribute_index);

source/6LoWPAN/ws/ws_neighbor_class.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ void ws_neighbor_class_dealloc(ws_neighbor_class_t *class_data);
6464
*
6565
*/
6666
ws_neighbor_class_entry_t * ws_neighbor_class_entry_get(ws_neighbor_class_t *class_data, uint8_t attribute_index);
67+
68+
/**
69+
* ws_neighbor_class_entry_t a function for search hopping info for giving neighbor attribute index
70+
*
71+
* \param class_data pointer to structure which will be initialized by this function
72+
* \param entry which attribute index is counted.
73+
*
74+
* \return Attribute index of entry
75+
*
76+
*/
77+
uint8_t ws_neighbor_class_entry_index_get(ws_neighbor_class_t *class_data, ws_neighbor_class_entry_t *entry);
78+
6779
/**
6880
* ws_neighbor_class_entry_remove a function for clean information should be call when neighbor is removed
6981
*

test/nanostack/unittest/stub/ws_neighbour_class_stub.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ ws_neighbor_class_entry_t * ws_neighbor_class_entry_get(ws_neighbor_class_t *cla
5858
return ws_neighbor_stub.neigh_entry;
5959
}
6060

61+
uint8_t ws_neighbor_class_entry_index_get(ws_neighbor_class_t *class_data, ws_neighbor_class_entry_t *entry)
62+
{
63+
return 0;
64+
}
65+
66+
6167
void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t attribute_index)
6268
{
6369

0 commit comments

Comments
 (0)