netstats.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Cenk Gündoğan <cenk.guendogan@haw-hamburg.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include "irq.h"
26 #include "net/rpl/rpl_netstats.h"
27 
28 #define GNRC_RPL_NETSTATS_MULTICAST (0)
29 #define GNRC_RPL_NETSTATS_UNICAST (1)
30 
38 static inline void gnrc_rpl_netstats_rx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
39 {
40  /* other threads (e.g. the shell thread via the rpl shell command) read
41  * out the data, so we have to sync accesses */
42  unsigned irq_state = irq_disable();
43  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
44  netstats->dio.rx_mcast_count++;
45  netstats->dio.rx_mcast_bytes += len;
46  }
47  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
48  netstats->dio.rx_ucast_count++;
49  netstats->dio.rx_ucast_bytes += len;
50  }
51  irq_restore(irq_state);
52 }
53 
61 static inline void gnrc_rpl_netstats_tx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
62 {
63  /* other threads (e.g. the shell thread via the rpl shell command) read
64  * out the data, so we have to sync accesses */
65  unsigned irq_state = irq_disable();
66  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
67  netstats->dio.tx_mcast_count++;
68  netstats->dio.tx_mcast_bytes += len;
69  }
70  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
71  netstats->dio.tx_ucast_count++;
72  netstats->dio.tx_ucast_bytes += len;
73  }
74  irq_restore(irq_state);
75 }
76 
84 static inline void gnrc_rpl_netstats_rx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
85 {
86  /* other threads (e.g. the shell thread via the rpl shell command) read
87  * out the data, so we have to sync accesses */
88  unsigned irq_state = irq_disable();
89  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
90  netstats->dis.rx_mcast_count++;
91  netstats->dis.rx_mcast_bytes += len;
92  }
93  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
94  netstats->dis.rx_ucast_count++;
95  netstats->dis.rx_ucast_bytes += len;
96  }
97  irq_restore(irq_state);
98 }
99 
107 static inline void gnrc_rpl_netstats_tx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
108 {
109  /* other threads (e.g. the shell thread via the rpl shell command) read
110  * out the data, so we have to sync accesses */
111  unsigned irq_state = irq_disable();
112  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
113  netstats->dis.tx_mcast_count++;
114  netstats->dis.tx_mcast_bytes += len;
115  }
116  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
117  netstats->dis.tx_ucast_count++;
118  netstats->dis.tx_ucast_bytes += len;
119  }
120  irq_restore(irq_state);
121 }
122 
130 static inline void gnrc_rpl_netstats_rx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
131 {
132  /* other threads (e.g. the shell thread via the rpl shell command) read
133  * out the data, so we have to sync accesses */
134  unsigned irq_state = irq_disable();
135  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
136  netstats->dao.rx_mcast_count++;
137  netstats->dao.rx_mcast_bytes += len;
138  }
139  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
140  netstats->dao.rx_ucast_count++;
141  netstats->dao.rx_ucast_bytes += len;
142  }
143  irq_restore(irq_state);
144 }
145 
153 static inline void gnrc_rpl_netstats_tx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
154 {
155  /* other threads (e.g. the shell thread via the rpl shell command) read
156  * out the data, so we have to sync accesses */
157  unsigned irq_state = irq_disable();
158  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
159  netstats->dao.tx_mcast_count++;
160  netstats->dao.tx_mcast_bytes += len;
161  }
162  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
163  netstats->dao.tx_ucast_count++;
164  netstats->dao.tx_ucast_bytes += len;
165  }
166  irq_restore(irq_state);
167 }
168 
176 static inline void gnrc_rpl_netstats_rx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
177 {
178  /* other threads (e.g. the shell thread via the rpl shell command) read
179  * out the data, so we have to sync accesses */
180  unsigned irq_state = irq_disable();
181  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
182  netstats->dao_ack.rx_mcast_count++;
183  netstats->dao_ack.rx_mcast_bytes += len;
184  }
185  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
186  netstats->dao_ack.rx_ucast_count++;
187  netstats->dao_ack.rx_ucast_bytes += len;
188  }
189  irq_restore(irq_state);
190 }
191 
199 static inline void gnrc_rpl_netstats_tx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
200 {
201  /* other threads (e.g. the shell thread via the rpl shell command) read
202  * out the data, so we have to sync accesses */
203  unsigned irq_state = irq_disable();
204  if (cast == GNRC_RPL_NETSTATS_MULTICAST) {
205  netstats->dao_ack.tx_mcast_count++;
206  netstats->dao_ack.tx_mcast_bytes += len;
207  }
208  else if (cast == GNRC_RPL_NETSTATS_UNICAST) {
209  netstats->dao_ack.tx_ucast_count++;
210  netstats->dao_ack.tx_ucast_bytes += len;
211  }
212  irq_restore(irq_state);
213 }
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
IRQ driver interface.
static void gnrc_rpl_netstats_tx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for sent DIO.
Definition: netstats.h:61
static void gnrc_rpl_netstats_tx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for sent DAO-ACK.
Definition: netstats.h:199
static void gnrc_rpl_netstats_rx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for received DAO.
Definition: netstats.h:130
static void gnrc_rpl_netstats_tx_DAO(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for sent DIO.
Definition: netstats.h:153
static void gnrc_rpl_netstats_rx_DIO(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for received DIO.
Definition: netstats.h:38
static void gnrc_rpl_netstats_rx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for received DIS.
Definition: netstats.h:84
static void gnrc_rpl_netstats_rx_DAO_ACK(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for received DAO-ACK.
Definition: netstats.h:176
static void gnrc_rpl_netstats_tx_DIS(netstats_rpl_t *netstats, size_t len, int cast)
Increase statistics for sent DIS.
Definition: netstats.h:107
Definition of RPL related packet statistics.
uint32_t rx_ucast_bytes
unicast bytes received
Definition: rpl_netstats.h:34
uint32_t rx_mcast_count
multicast packets received
Definition: rpl_netstats.h:35
uint32_t tx_mcast_count
multicast packets sent
Definition: rpl_netstats.h:39
uint32_t rx_ucast_count
unicast packets received
Definition: rpl_netstats.h:33
uint32_t rx_mcast_bytes
multicast bytes received
Definition: rpl_netstats.h:36
uint32_t tx_ucast_bytes
unicast bytes sent
Definition: rpl_netstats.h:38
uint32_t tx_mcast_bytes
multicast bytes sent
Definition: rpl_netstats.h:40
uint32_t tx_ucast_count
unicast packets sent
Definition: rpl_netstats.h:37
RPL statistics struct.
Definition: rpl_netstats.h:47
netstats_rpl_block_t dis
DIS statistics.
Definition: rpl_netstats.h:49
netstats_rpl_block_t dio
DIO statistics.
Definition: rpl_netstats.h:48
netstats_rpl_block_t dao_ack
DAO-ACK statistics.
Definition: rpl_netstats.h:51
netstats_rpl_block_t dao
DAO statistics.
Definition: rpl_netstats.h:50