Skip to content

Commit 4356ae8

Browse files
author
Mika Tervonen
authored
separated BBR to own file (ARMmbed#1567)
fixed dodagID added seconds timer support
1 parent 75d93f8 commit 4356ae8

File tree

10 files changed

+257
-43
lines changed

10 files changed

+257
-43
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <string.h>
19+
#include "nsconfig.h"
20+
#include "ns_types.h"
21+
#include "ns_trace.h"
22+
#include "net_interface.h"
23+
#include "eventOS_event.h"
24+
#include "NWK_INTERFACE/Include/protocol.h"
25+
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
26+
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
27+
#include "6LoWPAN/ws/ws_config.h"
28+
#include "6LoWPAN/ws/ws_common.h"
29+
#include "RPL/rpl_control.h"
30+
#include "RPL/rpl_data.h"
31+
#include "Common_Protocols/icmpv6.h"
32+
#include "Common_Protocols/icmpv6_radv.h"
33+
#include "net_rpl.h"
34+
35+
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
36+
37+
#define TRACE_GROUP "wsbs"
38+
39+
#ifdef HAVE_WS
40+
41+
static void ws_bbr_rpl_root_activate(uint8_t *dodag_prefix, uint8_t *dodag_id)
42+
{
43+
tr_debug("RPL root Activate");
44+
rpl_dodag_conf_t new_conf;
45+
46+
// Lifetime values
47+
new_conf.default_lifetime = 120;
48+
new_conf.lifetime_unit = 60;
49+
new_conf.objective_code_point = 1;
50+
new_conf.authentication = 0;
51+
new_conf.path_control_size = 0;
52+
53+
54+
// TODO temporary values spec says 0
55+
new_conf.dag_max_rank_increase = 3072;
56+
new_conf.min_hop_rank_increase = 128;// 24 Hop networks 3072/128 == 24
57+
58+
59+
// DIO configuration
60+
new_conf.dio_interval_min = WS_RPL_DIO_IMIN;
61+
new_conf.dio_interval_doublings = WS_RPL_DIO_DOUBLING;
62+
new_conf.dio_redundancy_constant = WS_RPL_DIO_REDUDANCY;
63+
64+
rpl_data_init_root();
65+
protocol_6lowpan_rpl_root_dodag = rpl_control_create_dodag_root(protocol_6lowpan_rpl_domain, 1, dodag_id, &new_conf, new_conf.min_hop_rank_increase, RPL_GROUNDED | RPL_MODE_NON_STORING | RPL_DODAG_PREF(0));
66+
if (!protocol_6lowpan_rpl_root_dodag) {
67+
tr_err("RPL dodag init failed");
68+
}
69+
uint8_t t_flags = PIO_A;
70+
71+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, t_flags, 0xffffffff, 0xffffffff, false);
72+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, 0, 0xffffffff, false);
73+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0xffffffff, false);
74+
}
75+
76+
static uint8_t static_dodag_prefix[8] = {0xfd,0x00,0x61, 0x72, 0x6d};
77+
78+
static void ws_bbr_root_start(protocol_interface_info_entry_t *cur)
79+
{
80+
uint8_t *bbr_prefix_ptr = NULL;
81+
uint8_t *bbr_dodag_id_ptr = NULL;
82+
83+
/*if (arm_net_address_get(this->backbone_interface_id, ADDR_IPV6_GP, global_address) == 0) {
84+
bbr_prefix_ptr = global_address;
85+
}*/
86+
87+
if (!bbr_prefix_ptr) {
88+
// Start static ula prefix
89+
if_address_entry_t *add_entry = icmpv6_slaac_address_add(cur, static_dodag_prefix, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_FIXED);
90+
if (!add_entry) {
91+
return;
92+
}
93+
bbr_dodag_id_ptr = add_entry->address;
94+
bbr_prefix_ptr = add_entry->address;
95+
}
96+
97+
if (!bbr_prefix_ptr || !bbr_dodag_id_ptr) {
98+
return;
99+
}
100+
ws_bbr_rpl_root_activate(bbr_prefix_ptr, bbr_dodag_id_ptr);
101+
}
102+
103+
void ws_bbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
104+
{
105+
(void)seconds;
106+
107+
if (!ws_info(cur)) {
108+
return;
109+
}
110+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
111+
// Not a border router
112+
return;
113+
}
114+
if (!cur->rpl_domain) {
115+
// RPL not started
116+
return;
117+
}
118+
119+
if (protocol_6lowpan_rpl_root_dodag) {
120+
// RPL configured
121+
return;
122+
}
123+
// 1. Wait for backend connection
124+
// 2. request own prefix if available
125+
// 3. check if connected to RPL root
126+
// 3.1 check if Globally connected root available (Backend with own mesh prefix)
127+
// 3.2 check if Globally connected root available (ND proxy)
128+
// 3.3 Check if grounded root available (Backend connectivity to static config in backend)
129+
// 3.4 only local connectivity (No backend)
130+
// 4. If I can provide better connectivity start root
131+
// 4.1. If no other roots or backend start static root
132+
// 4.2. If backend gets connectivity add global root
133+
// 4.3. If backend loses connectivity remove global root, leave static
134+
// 5. if someone has offered better connected root remove own
135+
// 6. if multiple same level roots
136+
// 6.1 lower connectivity must drop
137+
// 6.2 lowest dodag ID remains
138+
139+
ws_bbr_root_start(cur);
140+
}
141+
142+
143+
#endif //HAVE_WS
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WS_BBR_API_PRIVATE_H_
19+
#define WS_BBR_API_PRIVATE_H_
20+
21+
22+
#ifdef HAVE_WS
23+
24+
void ws_bbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
25+
26+
#else
27+
28+
#define ws_bbr_seconds_timer( cur, seconds)
29+
30+
#endif //HAVE_WS
31+
32+
#endif /* WS_BBR_API_PRIVATE_H_ */

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -246,38 +246,8 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
246246
}
247247
tr_warn("RPL callback event %d", event);
248248
}
249-
static uint8_t dodag_id[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
250-
static uint8_t dodag_prefix[16] = {0xfd,00,0xaa};
251249

252-
static void ws_bootstrap_rpl_root_activate(protocol_interface_info_entry_t *cur)
253-
{
254-
tr_debug("RPL root Activate");
255-
rpl_dodag_conf_t new_conf;
256-
new_conf.default_lifetime = 64;
257-
new_conf.lifetime_unit = 60;
258-
new_conf.dag_max_rank_increase = 3072;
259-
new_conf.min_hop_rank_increase = 128;// 24 HOP?
260-
new_conf.dio_interval_min = 9;
261-
new_conf.dio_interval_doublings = 12;
262-
new_conf.dio_redundancy_constant = 10;
263-
new_conf.objective_code_point = 1;
264-
new_conf.authentication = 0;
265-
new_conf.path_control_size = 0;
266-
rpl_data_init_root();
267-
protocol_6lowpan_rpl_root_dodag = rpl_control_create_dodag_root(protocol_6lowpan_rpl_domain, 1, dodag_id, &new_conf, new_conf.min_hop_rank_increase, RPL_GROUNDED | RPL_MODE_NON_STORING | RPL_DODAG_PREF(0));
268-
if (!protocol_6lowpan_rpl_root_dodag) {
269-
tr_err("RPL dodag init failed");
270-
}
271-
uint8_t t_flags = PIO_A;
272-
273-
icmpv6_slaac_address_add(cur, dodag_prefix, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_FIXED);
274-
275-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, t_flags, 0xffffffff, 0xffffffff, false);
276-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_prefix, 64, 0, 0xffffffff, false);
277-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0xffffffff, false);
278-
}
279-
280-
static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
250+
static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
281251
{
282252
tr_debug("RPL Activate");
283253
bool downstream = true;
@@ -291,19 +261,7 @@ static void ws_bootstrap_rpl_root_activate(protocol_interface_info_entry_t *cur)
291261

292262
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) {
293263
rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_ROUTERS);
294-
} else if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
295-
ws_bootstrap_rpl_root_activate(cur);
296264
}
297-
298-
}
299-
300-
301-
static void ws_bootstrap_icmp_rs_msg_tx(protocol_interface_info_entry_t *cur)
302-
{
303-
tr_debug("send RS");
304-
buffer_t *buf = icmpv6_build_rs(cur, NULL);
305-
306-
protocol_push(buf);
307265
}
308266

309267
/*

source/6LoWPAN/ws/ws_common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <nsdynmemLIB.h>
2222
#include "NWK_INTERFACE/Include/protocol.h"
2323
#include "6LoWPAN/ws/ws_common.h"
24+
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
2425
#include "ws_management_api.h"
2526

2627
#ifdef HAVE_WS
@@ -134,6 +135,10 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
134135
return 0;
135136
}
136137

138+
void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
139+
{
140+
ws_bbr_seconds_timer(cur, seconds);
141+
}
137142

138143

139144
#endif // HAVE_WS

source/6LoWPAN/ws/ws_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
typedef struct ws_info_s {
2525
char network_name[33]; // Network name max 32 octets + terminating 0.
26+
uint16_t network_pan_id;
2627

2728
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
2829
uint8_t fhss_uc_dwell_interval;
@@ -47,10 +48,13 @@ int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur);
4748

4849
int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur);
4950

51+
void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
52+
5053
#define ws_info(cur) ((cur)->ws_info)
5154
#else
5255

5356
#define ws_info(cur) ((ws_info_t *) NULL)
57+
#define ws_common_seconds_timer(cur, seconds)
5458

5559

5660
#endif //HAVE_WS

source/6LoWPAN/ws/ws_config.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WS_CONFIG_H_
19+
#define WS_CONFIG_H_
20+
21+
22+
/*RPL parameters for DIO messages
23+
*
24+
* Small scale values imin 15, doubling 2, redudancy 1
25+
* Large scale network imin 19, doubling 1, redudancy 1
26+
*
27+
*/
28+
29+
#define WS_RPL_DIO_IMIN 15
30+
#define WS_RPL_DIO_DOUBLING 2
31+
#define WS_RPL_DIO_REDUDANCY 1
32+
33+
#endif /* WS_CONFIG_H_ */

source/NWK_INTERFACE/protocol_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ void core_timer_event_handle(uint16_t ticksUpdate)
244244
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
245245
if (thread_info(cur)) {
246246
thread_seconds_timer(cur, seconds);
247+
} else if (ws_info(cur)) {
248+
ws_common_seconds_timer(cur, seconds);
247249
} else if (cur->lowpan_info & INTERFACE_NWK_ROUTER_DEVICE) {
248250
beacon_join_priority_update(cur->id);
249251
}

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SRCS += \
2424
source/6LoWPAN/ws/ws_bootstrap.c \
2525
source/6LoWPAN/ws/ws_common.c \
2626
source/6LoWPAN/ws/ws_management_api.c \
27+
source/6LoWPAN/ws/ws_bbr_api.c \
2728
source/BorderRouter/border_router.c \
2829
source/Common_Protocols/icmpv6.c \
2930
source/Common_Protocols/icmpv6_prefix.c \

test/nanostack/unittest/nwk_interface/protocol_core/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST_SRC_FILES = \
3636
../../stub/thread_common_stub.c \
3737
../../stub/thread_bootstrap_stub.c \
3838
../../stub/ws_bootstrap_stub.c \
39+
../../stub/ws_common_stub.c \
3940
../../stub/mld_stub.c \
4041
../../stub/mpl_stub.c \
4142
../../stub/rpl_control_stub.c \
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "nsconfig.h"
19+
#include "ns_types.h"
20+
#include "ns_trace.h"
21+
#include "net_interface.h"
22+
#include "eventOS_event.h"
23+
#include "NWK_INTERFACE/Include/protocol.h"
24+
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
25+
#include "6LoWPAN/ws/ws_common.h"
26+
27+
#include "mac_api.h"
28+
29+
void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
30+
{
31+
(void) cur;
32+
(void) seconds;
33+
34+
return;
35+
}

0 commit comments

Comments
 (0)