BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
protocol_stats.c
00001 /* 00002 * Copyright (c) 2014-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "nsconfig.h" 00018 #include <string.h> 00019 #include "ns_types.h" 00020 #include "nwk_stats_api.h" 00021 #include "NWK_INTERFACE/Include/protocol_stats.h" 00022 00023 nwk_stats_t *NS_LARGE nwk_stats_ptr = 0; 00024 00025 void protocol_stats_init(void) 00026 { 00027 nwk_stats_ptr = 0; 00028 //Init timers 00029 } 00030 void protocol_stats_start(nwk_stats_t *stats_ptr) //Enable stats collection 00031 { 00032 nwk_stats_ptr = stats_ptr; 00033 } 00034 void protocol_stats_stop(void)//Clean structure pointer 00035 { 00036 nwk_stats_ptr = 0; 00037 } 00038 void protocol_stats_reset(void) //Clean all entrys to zero 00039 { 00040 if (nwk_stats_ptr) { 00041 memset(nwk_stats_ptr, 0, sizeof(nwk_stats_t)); 00042 } 00043 } 00044 00045 void protocol_stats_update(nwk_stats_type_t type, uint16_t update_val) 00046 { 00047 if (nwk_stats_ptr) { 00048 switch (type) { 00049 case STATS_IP_RX_COUNT: //RX Payload 00050 nwk_stats_ptr->ip_rx_count++; 00051 nwk_stats_ptr->ip_rx_bytes += update_val; 00052 break; 00053 00054 case STATS_IP_ROUTE_UP: 00055 nwk_stats_ptr->ip_routed_up += update_val; 00056 /* fall through */ 00057 case STATS_IP_TX_COUNT: 00058 nwk_stats_ptr->ip_tx_count++; 00059 nwk_stats_ptr->ip_tx_bytes += update_val; 00060 break; 00061 00062 case STATS_IP_RX_DROP: 00063 nwk_stats_ptr->ip_rx_drop++; 00064 break; 00065 00066 case STATS_IP_CKSUM_ERROR: 00067 nwk_stats_ptr->ip_cksum_error++; 00068 break; 00069 00070 case STATS_FRAG_RX_ERROR: 00071 nwk_stats_ptr->frag_rx_errors++; 00072 break; 00073 00074 case STATS_FRAG_TX_ERROR: 00075 nwk_stats_ptr->frag_tx_errors++; 00076 break; 00077 00078 case STATS_RPL_PARENT_CHANGE: 00079 nwk_stats_ptr->rpl_route_routecost_better_change++; 00080 break; 00081 00082 case STATS_RPL_ROUTELOOP: 00083 nwk_stats_ptr->ip_routeloop_detect++; 00084 break; 00085 00086 case STATS_IP_NO_ROUTE: 00087 nwk_stats_ptr->ip_no_route++; 00088 break; 00089 00090 case STATS_RPL_MEMORY_OVERFLOW: 00091 nwk_stats_ptr->rpl_memory_overflow += update_val; 00092 break; 00093 00094 case STATS_RPL_PARENT_TX_FAIL: 00095 nwk_stats_ptr->rpl_parent_tx_fail += update_val; 00096 break; 00097 00098 case STATS_RPL_UNKNOWN_INSTANCE: 00099 nwk_stats_ptr->rpl_unknown_instance += update_val; 00100 break; 00101 00102 case STATS_RPL_LOCAL_REPAIR: 00103 nwk_stats_ptr->rpl_local_repair += update_val; 00104 break; 00105 00106 case STATS_RPL_GLOBAL_REPAIR: 00107 nwk_stats_ptr->rpl_global_repair += update_val; 00108 break; 00109 00110 case STATS_RPL_MALFORMED_MESSAGE: 00111 nwk_stats_ptr->rpl_malformed_message += update_val; 00112 break; 00113 00114 case STATS_RPL_TIME_NO_NEXT_HOP: 00115 nwk_stats_ptr->rpl_time_no_next_hop += update_val; 00116 break; 00117 00118 case STATS_RPL_MEMORY_ALLOC: 00119 nwk_stats_ptr->rpl_total_memory += update_val; 00120 break; 00121 00122 case STATS_RPL_MEMORY_FREE: 00123 nwk_stats_ptr->rpl_total_memory -= update_val; 00124 break; 00125 00126 case STATS_BUFFER_ALLOC: 00127 nwk_stats_ptr->buf_alloc++; 00128 break; 00129 00130 case STATS_BUFFER_HEADROOM_REALLOC: 00131 nwk_stats_ptr->buf_headroom_realloc++; 00132 break; 00133 00134 case STATS_BUFFER_HEADROOM_SHUFFLE: 00135 nwk_stats_ptr->buf_headroom_shuffle++; 00136 break; 00137 00138 case STATS_BUFFER_HEADROOM_FAIL: 00139 nwk_stats_ptr->buf_headroom_fail++; 00140 break; 00141 00142 case STATS_ETX_1ST_PARENT: 00143 nwk_stats_ptr->etx_1st_parent = update_val; 00144 break; 00145 00146 case STATS_ETX_2ND_PARENT: 00147 nwk_stats_ptr->etx_2nd_parent = update_val; 00148 break; 00149 } 00150 } 00151 } 00152 00153
Generated on Tue Jul 12 2022 12:22:18 by
