-
Notifications
You must be signed in to change notification settings - Fork 2.1k
net: introduce IPv6 netstats #5178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| #include "mutex.h" | ||
| #include "net/ipv6.h" | ||
| #include "net/ipv6/addr.h" | ||
| #include "net/netstats.h" | ||
| #include "xtimer.h" | ||
|
|
||
| #ifdef __cplusplus | ||
|
|
@@ -344,6 +345,9 @@ typedef struct { | |
| xtimer_t rtr_adv_timer; /**< Timer for periodic router advertisements */ | ||
| msg_t rtr_adv_msg; /**< msg_t for gnrc_ipv6_netif_t::rtr_adv_timer */ | ||
| #endif | ||
| #ifdef MODULE_NETSTATS_IPV6 | ||
| netstats_t stats; /**< transceiver's statistics */ | ||
| #endif | ||
| } gnrc_ipv6_netif_t; | ||
|
|
||
| /** | ||
|
|
@@ -587,6 +591,18 @@ static inline bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr) | |
| */ | ||
| void gnrc_ipv6_netif_init_by_dev(void); | ||
|
|
||
| /** | ||
| * @brief Get sent and received statistics about IPv6 traffic on this interface. | ||
| * | ||
| * @note This function is only available if compiled with module `netstats_ipv6`. | ||
| * | ||
| * @param[in] pid The PID to the interface. | ||
| * | ||
| * @return A @ref netstats_t pointer to the statistics. | ||
| * @return NULL if no statistics are available. | ||
| */ | ||
| netstats_t *gnrc_ipv6_netif_get_stats(kernel_pid_t pid); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be more suitable to put this into some unit file of the netstats module itself? Then you can also drop the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO that would be conceptionally unclean. Actually, I think the better idea would be drop the netstats module completely and move its "functionality" into the shell.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about the new solution?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It depends: Can I still use netstats then if I do not compile the shell, but send the stats over e.g. UDP to a server?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. The only thing in the |
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,6 +373,11 @@ static void _send_to_iface(kernel_pid_t iface, gnrc_pktsnip_t *pkt) | |
| gnrc_pktbuf_release(pkt); | ||
| return; | ||
| } | ||
| #ifdef MODULE_NETSTATS_IPV6 | ||
| if_entry->stats.tx_success++; | ||
| if_entry->stats.tx_bytes += gnrc_pkt_len(pkt->next); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if it's available here, but why not use the length field of the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IPv6 header length + ipv6->len; that would be.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, looking at the code again, I wonder if the current solution is not more reasonable: we add the amount of data that is actually passed to the lower layer here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this amount of data can also include padding, if I am not mistaken? AFAIK, the pkts in the pktbuf need to be size aligned(?)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, who does actually remove the padding before sending?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, no idea. In gnrc_pktbuf_static.c:423 the size for a |
||
| #endif | ||
|
|
||
| #ifdef MODULE_GNRC_SIXLOWPAN | ||
| if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { | ||
| DEBUG("ipv6: send to 6LoWPAN instead\n"); | ||
|
|
@@ -419,6 +424,9 @@ static void _send_unicast(kernel_pid_t iface, uint8_t *dst_l2addr, | |
|
|
||
| DEBUG("ipv6: send unicast over interface %" PRIkernel_pid "\n", iface); | ||
| /* and send to interface */ | ||
| #ifdef MODULE_NETSTATS_IPV6 | ||
| gnrc_ipv6_netif_get_stats(iface)->tx_unicast_count++; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about keeping the netstats struct cached in a (static) global (to this unit file only) variable, assigned only once in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And in this case the call should just de-reference a pointer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assuming the call gets inlined.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we have to trust the compiler here a little bit. I'm not objecting "caching" this value, I just don't know how without sacrificing RAM. |
||
| #endif | ||
| _send_to_iface(iface, pkt); | ||
| } | ||
|
|
||
|
|
@@ -486,6 +494,9 @@ static inline void _send_multicast_over_iface(kernel_pid_t iface, gnrc_pktsnip_t | |
| DEBUG("ipv6: send multicast over interface %" PRIkernel_pid "\n", iface); | ||
| /* mark as multicast */ | ||
| ((gnrc_netif_hdr_t *)pkt->data)->flags |= GNRC_NETIF_HDR_FLAGS_MULTICAST; | ||
| #ifdef MODULE_NETSTATS_IPV6 | ||
| gnrc_ipv6_netif_get_stats(iface)->tx_mcast_count++; | ||
| #endif | ||
| /* and send to interface */ | ||
| _send_to_iface(iface, pkt); | ||
| } | ||
|
|
@@ -788,6 +799,13 @@ static void _receive(gnrc_pktsnip_t *pkt) | |
|
|
||
| if (netif != NULL) { | ||
| iface = ((gnrc_netif_hdr_t *)netif->data)->if_pid; | ||
|
|
||
| #ifdef MODULE_NETSTATS_IPV6 | ||
| assert(iface); | ||
| netstats_t *stats = gnrc_ipv6_netif_get_stats(iface); | ||
| stats->rx_count++; | ||
| stats->rx_bytes += (gnrc_pkt_len(pkt) - netif->size); | ||
| #endif | ||
| } | ||
|
|
||
| first_ext = pkt; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so sure if we really want this - should go into a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you elaborate? I lost the context (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant if we really want to have netstats per default in the gnrc_networking example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I wouldn't object, because
gnrc_networkingis IMO for showcasing our features, whilegnrc_minimalis for showcasing our minamility.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about compiling in
netstats_ipv6automatically ifnetstatsandipv6are compiled?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what if I'm only interested in L2 stats?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DISABLE_MODULE=netstats_ipv6. But it was just food for thought. I am fine with both variants.