mirror of
https://github.com/apache/nuttx.git
synced 2025-12-11 21:20:26 +08:00
net/can/: add statistics for recv, sent and drop
Add support for network statistics for CAN. It includes counters for receive, sent and drop frames. Signed-off-by: Javier Casas <javiercasas@geotab.com>
This commit is contained in:
committed by
Alan C. Assis
parent
48b93b8dc8
commit
d52ff33e78
@@ -2,7 +2,8 @@
|
||||
* include/nuttx/net/can.h
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
* SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All
|
||||
* rights reserved.
|
||||
* SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved.
|
||||
* SPDX-FileContributor: Gregory Nutt <gnutt@nuttx.org>
|
||||
* SPDX-FileContributor: Adam Dunkels <adam@dunkels.com>
|
||||
@@ -43,6 +44,7 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/can.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -59,6 +61,19 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The structure holding the CAN statistics that are gathered if
|
||||
* CONFIG_NET_STATISTICS is defined.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
struct can_stats_s
|
||||
{
|
||||
net_stats_t drop; /* Number of dropped CAN frames */
|
||||
net_stats_t recv; /* Number of received CAN frames */
|
||||
net_stats_t sent; /* Number of sent CAN frames */
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
#ifdef CONFIG_NET_MLD
|
||||
# include <nuttx/net/mld.h>
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
# include <nuttx/net/can.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
|
||||
@@ -114,6 +117,10 @@ struct net_stats_s
|
||||
#ifdef CONFIG_NET_UDP
|
||||
struct udp_stats_s udp; /* UDP statistics */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_CAN
|
||||
struct can_stats_s can; /* CAN statistics */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/mm/iob.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "can/can.h"
|
||||
@@ -83,10 +84,7 @@ can_data_event(FAR struct net_driver_s *dev, FAR struct can_conn_s *conn,
|
||||
ninfo("Dropped %d bytes\n", dev->d_len);
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
/* No support CAN net statistics yet */
|
||||
|
||||
/* g_netstats.tcp.drop++; */
|
||||
|
||||
g_netstats.can.drop++;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/can.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "can/can.h"
|
||||
@@ -270,6 +271,10 @@ int can_input(FAR struct net_driver_s *dev)
|
||||
FAR uint8_t *buf;
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
g_netstats.can.recv++;
|
||||
#endif
|
||||
|
||||
if (dev->d_iob != NULL)
|
||||
{
|
||||
buf = dev->d_buf;
|
||||
@@ -284,7 +289,15 @@ int can_input(FAR struct net_driver_s *dev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return netdev_input(dev, can_in, false);
|
||||
ret = netdev_input(dev, can_in, false);
|
||||
if (ret < 0)
|
||||
{
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
g_netstats.can.drop++;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_CAN */
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
@@ -199,7 +200,13 @@ static inline void can_newdata(FAR struct net_driver_s *dev,
|
||||
|
||||
if (recvlen < dev->d_len)
|
||||
{
|
||||
can_datahandler(dev, pstate->pr_conn);
|
||||
if (can_datahandler(dev, pstate->pr_conn) < dev->d_len)
|
||||
{
|
||||
ninfo("Dropped %d bytes\n", dev->d_len);
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
g_netstats.can.drop++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Indicate no data in the buffer */
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
@@ -301,6 +302,10 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
g_netstats.can.sent++;
|
||||
#endif
|
||||
|
||||
/* Return the number of bytes actually sent */
|
||||
|
||||
return state.snd_sent;
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* IP/TCP/UDP/ICMP statistics for all network interfaces */
|
||||
/* IP/TCP/UDP/ICMP/CAN statistics for all network interfaces */
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
struct net_stats_s g_netstats;
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
|
||||
#if defined(CONFIG_NET_IPv4) || defined(CONFIG_NET_IPv6) || \
|
||||
defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) || \
|
||||
defined(CONFIG_NET_ICMP) || defined(CONFIG_NET_ICMPv6)
|
||||
defined(CONFIG_NET_ICMP) || defined(CONFIG_NET_ICMPv6) || \
|
||||
defined(CONFIG_NET_CAN)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
@@ -135,7 +136,10 @@ static int netprocfs_header(FAR struct netprocfs_file_s *netfile)
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ICMP");
|
||||
#endif
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ICMPv6");
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ICMPv6");
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " CAN");
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
@@ -178,6 +182,11 @@ static int netprocfs_received(FAR struct netprocfs_file_s *netfile)
|
||||
g_netstats.icmpv6.recv);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.can.recv);
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
}
|
||||
@@ -217,6 +226,10 @@ static int netprocfs_dropped(FAR struct netprocfs_file_s *netfile)
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.icmpv6.drop);
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.can.drop);
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
@@ -280,6 +293,9 @@ static int netprocfs_checksum(FAR struct netprocfs_file_s *netfile)
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----");
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----");
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
@@ -344,6 +360,9 @@ static int netprocfs_prototype(FAR struct netprocfs_file_s *netfile)
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.icmpv6.typeerr);
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----");
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
@@ -384,6 +403,10 @@ static int netprocfs_sent(FAR struct netprocfs_file_s *netfile)
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.icmpv6.sent);
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " %04x",
|
||||
g_netstats.can.sent);
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
@@ -417,6 +440,9 @@ static int netprocfs_retransmissions(FAR struct netprocfs_file_s *netfile)
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----");
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CAN
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, " ----");
|
||||
#endif
|
||||
|
||||
len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");
|
||||
return len;
|
||||
|
||||
Reference in New Issue
Block a user