Skip to content

Commit

Permalink
WS: Implemented ws statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jun 11, 2019
1 parent 3ce95fa commit 18dbac2
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
34 changes: 34 additions & 0 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ extern "C" {
*/
#define WS_MANAGEMENT_API_VER_2

/**
* \brief Struct ws_statistics defines the Wi-SUN statistics storage structure.
*/
typedef struct ws_statistics {
/** Asynch TX counter */
uint32_t asynch_tx_count;
/** Asynch RX counter */
uint32_t asynch_rx_count;
} ws_statistics_t;

/**
* Initialize Wi-SUN stack.
*
Expand Down Expand Up @@ -256,6 +266,30 @@ int ws_management_fhss_broadcast_channel_function_configure(
uint8_t dwell_interval,
uint32_t broadcast_interval);

/**
* Start collecting Wi-SUN statistics.
*
* \param interface_id Network interface ID.
* \param stats_ptr Pointer to stored statistics.
*
* \return 0 Success.
* \return <0 Failure.
*/
int ws_statistics_start(
int8_t interface_id,
ws_statistics_t *stats_ptr);

/**
* Stop collecting Wi-SUN statistics.
*
* \param interface_id Network interface ID.
*
* \return 0 Success.
* \return <0 Failure.
*/
int ws_statistics_stop(
int8_t interface_id);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "6LoWPAN/ws/ws_llc.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"
#include "6LoWPAN/ws/ws_ie_lib.h"
#include "6LoWPAN/ws/ws_stats.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
Expand Down Expand Up @@ -1214,7 +1215,7 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c
default:
return;
}

ws_stats_update(cur, STATS_WS_ASYNCH_RX, 1);
//UTT-IE and US-IE are mandatory for all Asynch Messages
ws_utt_ie_t ws_utt;
if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) {
Expand Down Expand Up @@ -1267,6 +1268,7 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c

static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message)
{
ws_stats_update(interface, STATS_WS_ASYNCH_TX, 1);
(void)interface;
(void)asynch_message;
}
Expand Down
1 change: 1 addition & 0 deletions source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef struct ws_info_s {
ws_nud_table_list_t free_nud_entries;
struct ws_pan_information_s pan_information;
ws_hopping_schedule_t hopping_schdule;
struct ws_statistics *stored_stats_ptr;
struct ws_neighbor_class_s neighbor_storage;
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
struct fhss_api *fhss_api;
Expand Down
70 changes: 70 additions & 0 deletions source/6LoWPAN/ws/ws_stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018-2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nsconfig.h"
#include "ns_types.h"
#include "ns_trace.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/ws/ws_stats.h"
#include "6LoWPAN/ws/ws_common.h"
#include "ws_management_api.h"

#define TRACE_GROUP "wsst"

#ifdef HAVE_WS

int ws_statistics_start(int8_t interface_id, ws_statistics_t *stats_ptr)
{
if (!stats_ptr) {
return -1;
}
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur || !ws_info(cur)) {
return -1;
}
cur->ws_info->stored_stats_ptr = stats_ptr;
return 0;
}

int ws_statistics_stop(int8_t interface_id)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur || !ws_info(cur)) {
return -1;
}
cur->ws_info->stored_stats_ptr = NULL;
return 0;
}

void ws_stats_update(protocol_interface_info_entry_t *cur, ws_stats_type_t type, uint32_t update_val)
{
if (!cur || !ws_info(cur)) {
return;
}
ws_statistics_t *stored_stats = cur->ws_info->stored_stats_ptr;

if (stored_stats) {
switch (type) {
case STATS_WS_ASYNCH_TX:
stored_stats->asynch_tx_count += update_val;
break;
case STATS_WS_ASYNCH_RX:
stored_stats->asynch_rx_count += update_val;
break;
}
}
}
#endif // HAVE_WS
32 changes: 32 additions & 0 deletions source/6LoWPAN/ws/ws_stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2018-2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef WS_STATS_H_
#define WS_STATS_H_

#ifdef HAVE_WS

typedef enum {
STATS_WS_ASYNCH_TX,
STATS_WS_ASYNCH_RX
} ws_stats_type_t;

void ws_stats_update(protocol_interface_info_entry_t *cur, ws_stats_type_t type, uint32_t update_val);

#endif // HAVE_WS

#endif // WS_STATS_H_
1 change: 1 addition & 0 deletions sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SRCS += \
source/6LoWPAN/ws/ws_eapol_auth_relay.c \
source/6LoWPAN/ws/ws_eapol_relay_lib.c \
source/6LoWPAN/ws/ws_eapol_pdu.c \
source/6LoWPAN/ws/ws_stats.c \
source/BorderRouter/border_router.c \
source/Common_Protocols/icmpv6.c \
source/Common_Protocols/icmpv6_prefix.c \
Expand Down

0 comments on commit 18dbac2

Please sign in to comment.