Skip to content

Commit 1ef8dd6

Browse files
author
Mika Tervonen
committed
Added public configuration API for Wi-SUN BBR
New modes for differenet RPL conficuration added No ULA prefix No GUA prefix Wait backbone interface before start Wait Wi-SUN network startup before backbone
1 parent 16d52fb commit 1ef8dd6

File tree

5 files changed

+166
-38
lines changed

5 files changed

+166
-38
lines changed

nanostack/ws_bbr_api.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@
4545
*/
4646
int ws_bbr_start(int8_t interface_id, int8_t backbone_interface_id);
4747

48+
/**
49+
* Border router configuration options
50+
*/
51+
#define BBR_ULA_C 0x0001 /**< Static ULA prefix created automatically */
52+
#define BBR_GUA_C 0x0002 /**< Routable prefix is learned from the backbone */
53+
#define BBR_GUA_ROUTE 0x0004 /**< More specific route is added for GUA prefix */
54+
#define BBR_GUA_SLAAC 0x0008 /**< Use SLAAC addressing in routable prefix */
55+
#define BBR_GUA_WAIT 0x0010 /**< Wait backbone availability before starting RPL dodag */
56+
#define BBR_BB_WAIT 0x0020 /**< Wait backbone availability before starting Wi-SUN network */
57+
/**
58+
* Configure border router features.
59+
*
60+
* \param interface_id interface ID of the Wi-SUN network
61+
* \param options Options configured to Border router
62+
* BBR_ULA_C Configure Mesh local ULA prefix with SLAAC address (default)
63+
* BBR_GUA_C Configure GUA/ULA prefix from backbone to RPL (default)
64+
* BBR_GUA_ROUTE Add more specific route for GUA (default)
65+
* BBR_GUA_SLAAC Use SLAAC address generation in GUA prefix
66+
* BBR_GUA_WAIT Start RPL root only when GUA is available
67+
* BBR_BB_WAIT Start Wi-SUN network only when backbone is ready
68+
*
69+
* By default Wi-SUN network is started and is treated as separate interface even if backbone is not available.
70+
*
71+
* Default route RPL options when backbone is set up. RPL root is always Grounded
72+
*
73+
* \return 0 on success
74+
* \return <0 in case of errors
75+
*
76+
*/
77+
int ws_bbr_configure(int8_t interface_id, uint16_t options);
4878
/**
4979
* Stop backbone Border router.
5080
*

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 121 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
3838
#include "DHCPv6_Server/DHCPv6_server_service.h"
3939

40+
#include "ws_bbr_api.h"
41+
4042
#define TRACE_GROUP "wsbs"
4143

4244
#define RPL_INSTANCE_ID 1
@@ -49,6 +51,7 @@
4951
*
5052
*/
5153
static int8_t backbone_interface_id = -1; // BBR backbone information
54+
static uint16_t configuration = BBR_ULA_C | BBR_GUA_C | BBR_GUA_ROUTE;
5255

5356
static uint8_t static_dodag_prefix[8] = {0xfd, 0x00, 0x61, 0x72, 0x6d};
5457
static uint8_t static_ula_address[16] = {0};
@@ -109,15 +112,10 @@ static void ws_bbr_rpl_root_start(uint8_t *dodag_id)
109112
tr_err("RPL dodag init failed");
110113
return;
111114
}
112-
memcpy(static_dodag_id, dodag_id, 16);
113-
114115
// RPL memory limits set larger for Border router
115116
rpl_control_set_memory_limits(64 * 1024, 0);
116-
117-
uint8_t t_flags = PIO_A;
118-
119-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, t_flags, 7200, 7200, false);
120-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, 0x18, 7200, false);
117+
// Save configured static id to check for changes later
118+
memcpy(static_dodag_id, dodag_id, 16);
121119
}
122120

123121
static void ws_bbr_rpl_root_stop(void)
@@ -130,6 +128,17 @@ static void ws_bbr_rpl_root_stop(void)
130128
memset(global_dodag_id, 0, 16);
131129
}
132130

131+
static void ws_bbr_ula_prefix_enable(uint8_t *dodag_id)
132+
{
133+
tr_info("RPL ula prefix start");
134+
135+
uint8_t t_flags = PIO_A;
136+
137+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, t_flags, 7200, 7200, false);
138+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, 0x18, 7200, false);
139+
}
140+
141+
133142
static int ws_border_router_proxy_validate(int8_t interface_id, uint8_t *address)
134143
{
135144

@@ -267,6 +276,35 @@ static bool wisun_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_upd
267276
return true;
268277
}
269278

279+
static void ws_bbr_dhcp_server_start(protocol_interface_info_entry_t *cur, uint8_t *global_id)
280+
{
281+
uint8_t ll[16];
282+
memcpy(ll, ADDR_LINK_LOCAL_PREFIX, 8);
283+
memcpy(&ll[8], cur->mac, 8);
284+
ll[8] ^= 2;
285+
286+
tr_debug("DHCP server activate %s", trace_ipv6(global_id));
287+
288+
if (DHCPv6_server_service_init(cur->id, global_id, cur->mac, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE) != 0) {
289+
tr_error("DHCPv6 Server create fail");
290+
return;
291+
}
292+
DHCPv6_server_service_callback_set(cur->id, global_id, NULL, wisun_dhcp_address_add_cb);
293+
294+
DHCPv6_server_service_set_address_autonous_flag(cur->id, global_id, true);
295+
DHCPv6_server_service_set_address_validlifetime(cur->id, global_id, 7200);
296+
297+
ws_dhcp_client_address_request(cur, global_id, ll);
298+
}
299+
static void ws_bbr_dhcp_server_stop(protocol_interface_info_entry_t *cur, uint8_t *global_id)
300+
{
301+
tr_debug("DHCP server deactivate %s", trace_ipv6(global_id));
302+
DHCPv6_server_service_delete(cur->id, global_id, false);
303+
304+
// Set old addresses to deferred and timeout
305+
ws_dhcp_client_address_delete(cur, global_id);
306+
307+
}
270308

271309
static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
272310
{
@@ -278,56 +316,64 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
278316

279317
ws_bbr_dodag_get(cur, static_id, global_id);
280318

319+
// Check if we need to wait for Global ID
320+
if (configuration & BBR_GUA_WAIT) {
321+
if (memcmp(global_dodag_id, ADDR_UNSPECIFIED, 16) == 0 &&
322+
memcmp(global_id, ADDR_UNSPECIFIED, 16) == 0) {
323+
// We need to wait for Global connectivity to start anything
324+
return;
325+
}
326+
}
327+
281328
if (memcmp(static_dodag_id, static_id, 16) != 0) {
282329
// Static id updated or first setup
283330
ws_bbr_rpl_root_start(static_id);
331+
if (configuration & BBR_ULA_C) {
332+
// Start static ULA prefix and routing always
333+
ws_bbr_ula_prefix_enable(static_id);
334+
}
284335
}
336+
285337
if (memcmp(global_dodag_id, global_id, 16) != 0) {
286338
// Global prefix changed
287339
if (memcmp(global_dodag_id, ADDR_UNSPECIFIED, 16) != 0) {
288340
// TODO remove old global prefix
289341
tr_info("RPL GUA deactivate %s", trace_ipv6(global_dodag_id));
290342

291-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 7200, false);
292-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
293-
294343
// Old backbone information is deleted after 120 seconds
295344
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 120, true);
296345
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, 0, true);
297346
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, true);
298347
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 120, 0);
299-
DHCPv6_server_service_delete(cur->id, global_dodag_id, false);
300348

301-
// Set old addresses to deferred and timeout
302-
ws_dhcp_client_address_delete(cur, global_dodag_id);
349+
ws_bbr_dhcp_server_stop(cur, global_dodag_id);
303350
}
304351
// TODO add global prefix
305352
if (memcmp(global_id, ADDR_UNSPECIFIED, 16) != 0) {
306-
//DHCPv6 Server set here
307-
//Interface LL64 address
308-
uint8_t ll[16];
309-
memcpy(ll, ADDR_LINK_LOCAL_PREFIX, 8);
310-
memcpy(&ll[8], cur->mac, 8);
311-
ll[8] ^= 2;
312-
313-
if (DHCPv6_server_service_init(cur->id, global_id, cur->mac, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE) != 0) {
314-
tr_error("DHCPv6 Server create fail");
315-
return;
316-
}
317-
DHCPv6_server_service_callback_set(cur->id, global_id, NULL, wisun_dhcp_address_add_cb);
318-
319-
DHCPv6_server_service_set_address_autonous_flag(cur->id, global_id, true);
320-
DHCPv6_server_service_set_address_validlifetime(cur->id, global_id, 7200);
321-
322-
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
323-
ws_dhcp_client_address_request(cur, global_id, ll);
353+
//DHCPv6 Server flags set 0 by default
354+
uint8_t t_flags = 0;
324355

356+
// Add default route to RPL
325357
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 7200, false);
326-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 7200, false);
327-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
328-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, 7200, false);
329-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, false);
358+
// Enable default routing to backbone
330359
ipv6_route_add_with_info(global_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 0xffffffff, 0);
360+
361+
if (configuration & BBR_GUA_SLAAC) {
362+
// GUA prefix is using SLAAC so no DHCP started and set correct flags for prefix
363+
t_flags = PIO_A;
364+
} else {
365+
ws_bbr_dhcp_server_start(cur, global_id);
366+
}
367+
368+
if (configuration & BBR_GUA_C) {
369+
// Add also global prefix and route to RPL
370+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, t_flags, 7200, 7200, false);
371+
}
372+
if (configuration & BBR_GUA_ROUTE) {
373+
// Add also global prefix and route to RPL
374+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, false);
375+
}
376+
331377
}
332378
memcpy(global_dodag_id, global_id, 16);
333379
rpl_control_increment_dodag_version(protocol_6lowpan_rpl_root_dodag);
@@ -426,7 +472,29 @@ uint16_t ws_bbr_pan_size(protocol_interface_info_entry_t *cur)
426472
return result;
427473
}
428474

475+
bool ws_bbr_ready_to_start(protocol_interface_info_entry_t *cur)
476+
{
429477

478+
(void)cur;
479+
uint8_t global_address[16];
480+
481+
if (backbone_interface_id < 0) {
482+
// No need to wait for backbone
483+
return true;
484+
}
485+
486+
if ((configuration & BBR_BB_WAIT) != BBR_BB_WAIT) {
487+
// No need to wait for backbone
488+
return true;
489+
}
490+
491+
if (arm_net_address_get(backbone_interface_id, ADDR_IPV6_GP, global_address) != 0) {
492+
// No global prefix available
493+
return false;
494+
}
495+
496+
return true;
497+
}
430498
#endif //HAVE_WS_BORDER_ROUTER
431499

432500
/* Public APIs
@@ -472,6 +540,24 @@ void ws_bbr_stop(int8_t interface_id)
472540
(void)interface_id;
473541
#endif
474542
}
543+
int ws_bbr_configure(int8_t interface_id, uint16_t options)
544+
{
545+
#ifdef HAVE_WS_BORDER_ROUTER
546+
547+
(void)interface_id;
548+
if (protocol_6lowpan_rpl_root_dodag &&
549+
options != configuration) {
550+
//Configuration changed delete previus setup
551+
ws_bbr_rpl_root_stop();
552+
}
553+
configuration = options;
554+
return 0;
555+
#else
556+
(void)interface_id;
557+
(void)options;
558+
return -1;
559+
#endif
560+
}
475561

476562
int ws_bbr_node_keys_remove(int8_t interface_id, uint8_t *eui64)
477563
{

source/6LoWPAN/ws/ws_bbr_api_internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ uint16_t ws_bbr_pan_size(protocol_interface_info_entry_t *cur);
2929

3030
void ws_bbr_rpl_config(uint8_t imin, uint8_t doubling, uint8_t redundancy);
3131

32+
bool ws_bbr_ready_to_start(protocol_interface_info_entry_t *cur);
3233

3334

3435
#else
3536

3637
#define ws_bbr_seconds_timer( cur, seconds)
3738
#define ws_bbr_pan_size(cur) 0
38-
#define ws_bbr_rpl_config( imin, doubling, redundancy);
39+
#define ws_bbr_rpl_config( imin, doubling, redundancy)
40+
#define ws_bbr_ready_to_start(cur) true
3941

4042
#endif //HAVE_WS_BORDER_ROUTER
4143

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,13 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
22112211

22122212
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
22132213
tr_debug("Border router start network");
2214+
2215+
if (!ws_bbr_ready_to_start(cur)) {
2216+
// Wi-SUN not started yet we wait for Border router permission
2217+
ws_bootstrap_state_change(cur, ER_WAIT_RESTART);
2218+
cur->nwk_nd_re_scan_count = randLIB_get_random_in_range(40, 100);
2219+
return;
2220+
}
22142221
ws_pae_controller_auth_init(cur);
22152222

22162223
// Randomize fixed channels. Only used if channel plan is fixed.
@@ -2437,6 +2444,10 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
24372444
{
24382445

24392446
switch (cur->nwk_bootstrap_state) {
2447+
case ER_WAIT_RESTART:
2448+
tr_debug("WS SM:Wait for startup");
2449+
ws_bootstrap_event_discovery_start(cur);
2450+
break;
24402451
case ER_ACTIVE_SCAN:
24412452
tr_debug("WS SM:Active Scan");
24422453
ws_bootstrap_network_scan_process(cur);
@@ -2454,10 +2465,8 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
24542465
// Bootstrap_done event to application
24552466
nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur);
24562467
break;
2457-
24582468
default:
24592469
tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state);
2460-
24612470
}
24622471
}
24632472

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ typedef enum icmp_state {
121121
ER_BOOTSTRAP_SCAN_FAIL,
122122
ER_BOOTSTRAP_LEADER_UP,
123123
ER_BOOTSTRAP_NEW_FRAGMENT_START,
124+
ER_WAIT_RESTART,
124125
ER_RPL_LOCAL_REPAIR,
125126
} icmp_state_t;
126127

0 commit comments

Comments
 (0)