Skip to content

Commit f54ea6b

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#2110 from ARMmbed/IOTTHD-3577
Iotthd 3577
2 parents b878bd9 + 18dbac2 commit f54ea6b

File tree

7 files changed

+142
-2
lines changed

7 files changed

+142
-2
lines changed

nanostack/ws_management_api.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ extern "C" {
8686
*/
8787
#define WS_MANAGEMENT_API_VER_2
8888

89+
/**
90+
* \brief Struct ws_statistics defines the Wi-SUN statistics storage structure.
91+
*/
92+
typedef struct ws_statistics {
93+
/** Asynch TX counter */
94+
uint32_t asynch_tx_count;
95+
/** Asynch RX counter */
96+
uint32_t asynch_rx_count;
97+
} ws_statistics_t;
98+
8999
/**
90100
* Initialize Wi-SUN stack.
91101
*
@@ -256,6 +266,30 @@ int ws_management_fhss_broadcast_channel_function_configure(
256266
uint8_t dwell_interval,
257267
uint32_t broadcast_interval);
258268

269+
/**
270+
* Start collecting Wi-SUN statistics.
271+
*
272+
* \param interface_id Network interface ID.
273+
* \param stats_ptr Pointer to stored statistics.
274+
*
275+
* \return 0 Success.
276+
* \return <0 Failure.
277+
*/
278+
int ws_statistics_start(
279+
int8_t interface_id,
280+
ws_statistics_t *stats_ptr);
281+
282+
/**
283+
* Stop collecting Wi-SUN statistics.
284+
*
285+
* \param interface_id Network interface ID.
286+
*
287+
* \return 0 Success.
288+
* \return <0 Failure.
289+
*/
290+
int ws_statistics_stop(
291+
int8_t interface_id);
292+
259293
#ifdef __cplusplus
260294
}
261295
#endif

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "6LoWPAN/ws/ws_llc.h"
5454
#include "6LoWPAN/ws/ws_neighbor_class.h"
5555
#include "6LoWPAN/ws/ws_ie_lib.h"
56+
#include "6LoWPAN/ws/ws_stats.h"
5657
#include "6LoWPAN/lowpan_adaptation_interface.h"
5758
#include "Service_Libs/etx/etx.h"
5859
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
@@ -1214,7 +1215,7 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c
12141215
default:
12151216
return;
12161217
}
1217-
1218+
ws_stats_update(cur, STATS_WS_ASYNCH_RX, 1);
12181219
//UTT-IE and US-IE are mandatory for all Asynch Messages
12191220
ws_utt_ie_t ws_utt;
12201221
if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) {
@@ -1267,6 +1268,7 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c
12671268

12681269
static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message)
12691270
{
1271+
ws_stats_update(interface, STATS_WS_ASYNCH_TX, 1);
12701272
(void)interface;
12711273
(void)asynch_message;
12721274
}

source/6LoWPAN/ws/ws_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef struct ws_info_s {
9393
ws_nud_table_list_t free_nud_entries;
9494
struct ws_pan_information_s pan_information;
9595
ws_hopping_schedule_t hopping_schdule;
96+
struct ws_statistics *stored_stats_ptr;
9697
struct ws_neighbor_class_s neighbor_storage;
9798
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
9899
struct fhss_api *fhss_api;

source/6LoWPAN/ws/ws_stats.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2018-2019, 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+
#include "nsconfig.h"
18+
#include "ns_types.h"
19+
#include "ns_trace.h"
20+
#include "NWK_INTERFACE/Include/protocol.h"
21+
#include "6LoWPAN/ws/ws_stats.h"
22+
#include "6LoWPAN/ws/ws_common.h"
23+
#include "ws_management_api.h"
24+
25+
#define TRACE_GROUP "wsst"
26+
27+
#ifdef HAVE_WS
28+
29+
int ws_statistics_start(int8_t interface_id, ws_statistics_t *stats_ptr)
30+
{
31+
if (!stats_ptr) {
32+
return -1;
33+
}
34+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
35+
if (!cur || !ws_info(cur)) {
36+
return -1;
37+
}
38+
cur->ws_info->stored_stats_ptr = stats_ptr;
39+
return 0;
40+
}
41+
42+
int ws_statistics_stop(int8_t interface_id)
43+
{
44+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
45+
if (!cur || !ws_info(cur)) {
46+
return -1;
47+
}
48+
cur->ws_info->stored_stats_ptr = NULL;
49+
return 0;
50+
}
51+
52+
void ws_stats_update(protocol_interface_info_entry_t *cur, ws_stats_type_t type, uint32_t update_val)
53+
{
54+
if (!cur || !ws_info(cur)) {
55+
return;
56+
}
57+
ws_statistics_t *stored_stats = cur->ws_info->stored_stats_ptr;
58+
59+
if (stored_stats) {
60+
switch (type) {
61+
case STATS_WS_ASYNCH_TX:
62+
stored_stats->asynch_tx_count += update_val;
63+
break;
64+
case STATS_WS_ASYNCH_RX:
65+
stored_stats->asynch_rx_count += update_val;
66+
break;
67+
}
68+
}
69+
}
70+
#endif // HAVE_WS

source/6LoWPAN/ws/ws_stats.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2018-2019, 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_STATS_H_
19+
#define WS_STATS_H_
20+
21+
#ifdef HAVE_WS
22+
23+
typedef enum {
24+
STATS_WS_ASYNCH_TX,
25+
STATS_WS_ASYNCH_RX
26+
} ws_stats_type_t;
27+
28+
void ws_stats_update(protocol_interface_info_entry_t *cur, ws_stats_type_t type, uint32_t update_val);
29+
30+
#endif // HAVE_WS
31+
32+
#endif // WS_STATS_H_

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
861861
drift_per_ms_tmp = -MAX_DRIFT_COMPENSATION_STEP;
862862
}
863863
fhss_structure->ws->drift_per_millisecond_ns += drift_per_ms_tmp;
864-
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->ws->drift_per_millisecond_ns * bc_timing_info->broadcast_dwell_interval);
864+
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, NS_TO_US(fhss_structure->ws->drift_per_millisecond_ns * bc_timing_info->broadcast_dwell_interval));
865865
}
866866
tr_debug("synch to parent: %s, drift: %"PRIi32"ms in %"PRIu32" seconds, compensation: %"PRIi32"ns per ms", trace_array(eui64, 8), true_bc_interval_offset - own_bc_interval_offset + ((int32_t)(fhss_structure->ws->bc_slot - own_bc_slot) * bc_timing_info->broadcast_interval), US_TO_S(time_since_last_synch_us), fhss_structure->ws->drift_per_millisecond_ns);
867867
}

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SRCS += \
3939
source/6LoWPAN/ws/ws_eapol_auth_relay.c \
4040
source/6LoWPAN/ws/ws_eapol_relay_lib.c \
4141
source/6LoWPAN/ws/ws_eapol_pdu.c \
42+
source/6LoWPAN/ws/ws_stats.c \
4243
source/BorderRouter/border_router.c \
4344
source/Common_Protocols/icmpv6.c \
4445
source/Common_Protocols/icmpv6_prefix.c \

0 commit comments

Comments
 (0)