Skip to content

Commit 6cb78ff

Browse files
author
Mika Tervonen
committed
Distribute and learn network size
added test api to set net size in border router
1 parent bc4f46f commit 6cb78ff

File tree

6 files changed

+172
-8
lines changed

6 files changed

+172
-8
lines changed

nanostack/net_ws_test.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2014-2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the name of the copyright holder nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
#ifndef NET_WS_TEST_H_
31+
#define NET_WS_TEST_H_
32+
33+
/* Prevent this file being inserted in public Doxygen generated file
34+
* this is not part of our external API. */
35+
#ifndef DOXYGEN
36+
37+
/**
38+
* \file net_ws_test.h
39+
* \brief Wi-SUN Library Test API.
40+
*
41+
* \warning NOTICE! This is test API must not be used externally.
42+
*
43+
* \warning This file is not part of the version number control and can change any time.
44+
*
45+
*/
46+
47+
48+
#ifdef __cplusplus
49+
extern "C" {
50+
#endif
51+
52+
#include "ns_types.h"
53+
54+
/**
55+
* \brief Set extension name.
56+
*
57+
* Pan size is reported to advertisement. Using this function
58+
* actual value can be overridden.
59+
*
60+
* Set pan_size to 0xffff to stop override
61+
*
62+
* \param interface_id Network Interface
63+
* \param pan_size Pan size reported in advertisements
64+
*
65+
* \return 0 OK
66+
* \return <0 Failure
67+
*/
68+
int ws_test_pan_size_set(int8_t interface_id, uint16_t pan_size);
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif /* DOXYGEN */
74+
#endif /* NET_THREAD_TEST_H_ */

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#define TRACE_GROUP "wsbs"
3838

39+
#define RPL_INSTANCE_ID 1
40+
3941
#ifdef HAVE_WS
4042

4143
static void ws_bbr_rpl_root_activate(uint8_t *dodag_prefix, uint8_t *dodag_id)
@@ -62,7 +64,7 @@ static void ws_bbr_rpl_root_activate(uint8_t *dodag_prefix, uint8_t *dodag_id)
6264
new_conf.dio_redundancy_constant = WS_RPL_DIO_REDUDANCY;
6365

6466
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));
67+
protocol_6lowpan_rpl_root_dodag = rpl_control_create_dodag_root(protocol_6lowpan_rpl_domain, RPL_INSTANCE_ID, dodag_id, &new_conf, new_conf.min_hop_rank_increase, RPL_GROUNDED | RPL_MODE_NON_STORING | RPL_DODAG_PREF(0));
6668
if (!protocol_6lowpan_rpl_root_dodag) {
6769
tr_err("RPL dodag init failed");
6870
}
@@ -139,5 +141,17 @@ void ws_bbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds
139141
ws_bbr_root_start(cur);
140142
}
141143

144+
uint16_t test_pan_size_override = 0xffff;
145+
146+
uint16_t ws_bbr_pan_size(protocol_interface_info_entry_t *cur)
147+
{
148+
uint16_t result = 0;
149+
if (test_pan_size_override != 0xffff) {
150+
return test_pan_size_override;
151+
}
152+
153+
rpl_control_get_instance_dao_target_count(cur->rpl_domain, RPL_INSTANCE_ID, NULL, &result);
154+
return result;
155+
}
142156

143157
#endif //HAVE_WS

source/6LoWPAN/ws/ws_bbr_api_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121

2222
#ifdef HAVE_WS
2323

24+
extern uint16_t test_pan_size_override;
25+
2426
void ws_bbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
2527

28+
uint16_t ws_bbr_pan_size(protocol_interface_info_entry_t *cur);
29+
30+
2631
#else
2732

2833
#define ws_bbr_seconds_timer( cur, seconds)
34+
#define ws_bbr_pan_size(cur)
2935

3036
#endif //HAVE_WS
3137

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "6LoWPAN/ws/ws_config.h"
3939
#include "6LoWPAN/ws/ws_common.h"
4040
#include "6LoWPAN/ws/ws_bootstrap.h"
41+
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
4142
#include "RPL/rpl_protocol.h"
4243
#include "RPL/rpl_control.h"
4344
#include "RPL/rpl_data.h"
@@ -404,12 +405,17 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
404405
cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,30);
405406

406407
tr_info("New possible parent found addr:%s", trace_array(cur->ws_info->parent_info.addr, 8));
407-
} else {
408-
// Active state processing
409-
ws_bootstrap_pan_advertisement_analyse_active(cur, &pan_information);
408+
return;
409+
}
410+
// Active state processing
411+
ws_bootstrap_pan_advertisement_analyse_active(cur, &pan_information);
412+
413+
// TODO Learn routing cost per neighbour
414+
415+
// Learn latest network information
416+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
417+
cur->ws_info->pan_configuration = pan_information;
410418
}
411-
// Parent valid store information
412-
cur->ws_info->parent_info.ws_utt = *ws_utt;
413419
}
414420

415421
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)
@@ -509,7 +515,8 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
509515
//Border router does not learn network information
510516
return;
511517
}
512-
if (cur->ws_info->pan_configuration.pan_version == pan_version) {
518+
if (cur->ws_info->configuration_learned &&
519+
cur->ws_info->pan_configuration.pan_version == pan_version) {
513520
// No new information
514521
return;
515522
}
@@ -1077,6 +1084,11 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
10771084
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
10781085
async_req.security.SecurityLevel = 0;
10791086

1087+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1088+
// Border routers write the NW size
1089+
cur->ws_info->pan_configuration.pan_size = ws_bbr_pan_size(cur);
1090+
}
1091+
10801092
ws_llc_asynch_request(cur, &async_req);
10811093
}
10821094

@@ -1136,7 +1148,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
11361148
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
11371149
tr_debug("Border router start network");
11381150
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
1139-
cur->ws_info->pan_configuration.pan_size = 3;
1151+
cur->ws_info->pan_configuration.pan_size = 0;
11401152
cur->ws_info->pan_configuration.pan_version = randLIB_get_random_in_range(0,0xffff);
11411153
cur->ws_info->pan_configuration.routing_cost = 0;
11421154
cur->ws_info->pan_configuration.rpl_routing_method = true;

source/6LoWPAN/ws/ws_test_api.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2014-2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the name of the copyright holder nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
#include "nsconfig.h"
30+
31+
#include <string.h>
32+
#include <ns_list.h>
33+
#include <nsdynmemLIB.h>
34+
#include <net_ws_test.h>
35+
#include "NWK_INTERFACE/Include/protocol.h"
36+
#include "6LoWPAN/ws/ws_config.h"
37+
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
38+
#include "randLIB.h"
39+
40+
#include "ns_trace.h"
41+
#include "common_functions.h"
42+
43+
#define TRACE_GROUP "wste"
44+
45+
46+
int ws_test_pan_size_set(int8_t interface_id, uint16_t pan_size)
47+
{
48+
#ifdef HAVE_WS
49+
(void) interface_id;
50+
test_pan_size_override = pan_size;
51+
return 0;
52+
#else
53+
(void) interface_id;
54+
(void) pan_size;
55+
return -1;
56+
#endif
57+
}

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SRCS += \
2626
source/6LoWPAN/ws/ws_common.c \
2727
source/6LoWPAN/ws/ws_management_api.c \
2828
source/6LoWPAN/ws/ws_bbr_api.c \
29+
source/6LoWPAN/ws/ws_test_api.c \
2930
source/BorderRouter/border_router.c \
3031
source/Common_Protocols/icmpv6.c \
3132
source/Common_Protocols/icmpv6_prefix.c \

0 commit comments

Comments
 (0)