From d39808227b8a8e794a7cb0b990f4fcb0f5daadf5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 28 Apr 2011 11:13:53 -0700 Subject: [PATCH] netdev-linux: New functions for converting netdev stats formats. An upcoming commit will introduce another function that needs to convert between rtnl_link_stats64 and netdev_stats, so it seemed best to just add functions to do the conversion. --- lib/automake.mk | 1 + lib/netdev-linux.c | 77 +++++++++++++++++++++++++++++++--------------- lib/netdev-linux.h | 34 ++++++++++++++++++++ lib/netdev-vport.c | 45 ++------------------------- 4 files changed, 91 insertions(+), 66 deletions(-) create mode 100644 lib/netdev-linux.h diff --git a/lib/automake.mk b/lib/automake.mk index 802cc9920..7c1977f80 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -196,6 +196,7 @@ lib_libopenvswitch_a_SOURCES += \ lib/dpif-linux.c \ lib/dpif-linux.h \ lib/netdev-linux.c \ + lib/netdev-linux.h \ lib/netdev-vport.c \ lib/netdev-vport.h \ lib/netlink-protocol.h \ diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index e2af6594f..384fdafee 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -15,6 +15,9 @@ */ #include + +#include "netdev-linux.h" + #include #include #include @@ -3925,7 +3928,55 @@ tc_calc_buffer(unsigned int Bps, int mtu, uint64_t burst_bytes) unsigned int min_burst = tc_buffer_per_jiffy(Bps) + mtu; return tc_bytes_to_ticks(Bps, MAX(burst_bytes, min_burst)); } - + +/* Public utility functions. */ + +#define COPY_NETDEV_STATS \ + dst->rx_packets = src->rx_packets; \ + dst->tx_packets = src->tx_packets; \ + dst->rx_bytes = src->rx_bytes; \ + dst->tx_bytes = src->tx_bytes; \ + dst->rx_errors = src->rx_errors; \ + dst->tx_errors = src->tx_errors; \ + dst->rx_dropped = src->rx_dropped; \ + dst->tx_dropped = src->tx_dropped; \ + dst->multicast = src->multicast; \ + dst->collisions = src->collisions; \ + dst->rx_length_errors = src->rx_length_errors; \ + dst->rx_over_errors = src->rx_over_errors; \ + dst->rx_crc_errors = src->rx_crc_errors; \ + dst->rx_frame_errors = src->rx_frame_errors; \ + dst->rx_fifo_errors = src->rx_fifo_errors; \ + dst->rx_missed_errors = src->rx_missed_errors; \ + dst->tx_aborted_errors = src->tx_aborted_errors; \ + dst->tx_carrier_errors = src->tx_carrier_errors; \ + dst->tx_fifo_errors = src->tx_fifo_errors; \ + dst->tx_heartbeat_errors = src->tx_heartbeat_errors; \ + dst->tx_window_errors = src->tx_window_errors + +/* Copies 'src' into 'dst', performing format conversion in the process. */ +void +netdev_stats_from_rtnl_link_stats(struct netdev_stats *dst, + const struct rtnl_link_stats *src) +{ + COPY_NETDEV_STATS; +} + +/* Copies 'src' into 'dst', performing format conversion in the process. */ +void +netdev_stats_from_rtnl_link_stats64(struct netdev_stats *dst, + const struct rtnl_link_stats64 *src) +{ + COPY_NETDEV_STATS; +} + +/* Copies 'src' into 'dst', performing format conversion in the process. */ +void +netdev_stats_to_rtnl_link_stats64(struct rtnl_link_stats64 *dst, + const struct netdev_stats *src) +{ + COPY_NETDEV_STATS; +} /* Utility functions. */ @@ -3945,7 +3996,6 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats) struct ofpbuf request; struct ofpbuf *reply; struct ifinfomsg *ifi; - const struct rtnl_link_stats *rtnl_stats; struct nlattr *attrs[ARRAY_SIZE(rtnlgrp_link_policy)]; int error; @@ -3973,28 +4023,7 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats) return EPROTO; } - rtnl_stats = nl_attr_get(attrs[IFLA_STATS]); - stats->rx_packets = rtnl_stats->rx_packets; - stats->tx_packets = rtnl_stats->tx_packets; - stats->rx_bytes = rtnl_stats->rx_bytes; - stats->tx_bytes = rtnl_stats->tx_bytes; - stats->rx_errors = rtnl_stats->rx_errors; - stats->tx_errors = rtnl_stats->tx_errors; - stats->rx_dropped = rtnl_stats->rx_dropped; - stats->tx_dropped = rtnl_stats->tx_dropped; - stats->multicast = rtnl_stats->multicast; - stats->collisions = rtnl_stats->collisions; - stats->rx_length_errors = rtnl_stats->rx_length_errors; - stats->rx_over_errors = rtnl_stats->rx_over_errors; - stats->rx_crc_errors = rtnl_stats->rx_crc_errors; - stats->rx_frame_errors = rtnl_stats->rx_frame_errors; - stats->rx_fifo_errors = rtnl_stats->rx_fifo_errors; - stats->rx_missed_errors = rtnl_stats->rx_missed_errors; - stats->tx_aborted_errors = rtnl_stats->tx_aborted_errors; - stats->tx_carrier_errors = rtnl_stats->tx_carrier_errors; - stats->tx_fifo_errors = rtnl_stats->tx_fifo_errors; - stats->tx_heartbeat_errors = rtnl_stats->tx_heartbeat_errors; - stats->tx_window_errors = rtnl_stats->tx_window_errors; + netdev_stats_from_rtnl_link_stats(stats, nl_attr_get(attrs[IFLA_STATS])); ofpbuf_delete(reply); diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h new file mode 100644 index 000000000..7a112049b --- /dev/null +++ b/lib/netdev-linux.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Nicira Networks. + * + * 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 NETDEV_LINUX_H +#define NETDEV_LINUX_H 1 + +/* These functions are Linux specific, so they should be used directly only by + * Linux-specific code. */ + +struct netdev_stats; +struct rtnl_link_stats; +struct rtnl_link_stats64; + +void netdev_stats_from_rtnl_link_stats(struct netdev_stats *dst, + const struct rtnl_link_stats *src); +void netdev_stats_from_rtnl_link_stats64(struct netdev_stats *dst, + const struct rtnl_link_stats64 *src); +void netdev_stats_to_rtnl_link_stats64(struct rtnl_link_stats64 *dst, + const struct netdev_stats *src); + +#endif /* netdev-linux.h */ diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index f31f85fd1..e11cb2a8d 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -32,6 +32,7 @@ #include "hash.h" #include "hmap.h" #include "list.h" +#include "netdev-linux.h" #include "netdev-provider.h" #include "netlink.h" #include "netlink-socket.h" @@ -416,27 +417,7 @@ netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats) return EOPNOTSUPP; } - stats->rx_packets = reply.stats->rx_packets; - stats->tx_packets = reply.stats->tx_packets; - stats->rx_bytes = reply.stats->rx_bytes; - stats->tx_bytes = reply.stats->tx_bytes; - stats->rx_errors = reply.stats->rx_errors; - stats->tx_errors = reply.stats->tx_errors; - stats->rx_dropped = reply.stats->rx_dropped; - stats->tx_dropped = reply.stats->tx_dropped; - stats->multicast = reply.stats->multicast; - stats->collisions = reply.stats->collisions; - stats->rx_length_errors = reply.stats->rx_length_errors; - stats->rx_over_errors = reply.stats->rx_over_errors; - stats->rx_crc_errors = reply.stats->rx_crc_errors; - stats->rx_frame_errors = reply.stats->rx_frame_errors; - stats->rx_fifo_errors = reply.stats->rx_fifo_errors; - stats->rx_missed_errors = reply.stats->rx_missed_errors; - stats->tx_aborted_errors = reply.stats->tx_aborted_errors; - stats->tx_carrier_errors = reply.stats->tx_carrier_errors; - stats->tx_fifo_errors = reply.stats->tx_fifo_errors; - stats->tx_heartbeat_errors = reply.stats->tx_heartbeat_errors; - stats->tx_window_errors = reply.stats->tx_window_errors; + netdev_stats_from_rtnl_link_stats64(stats, reply.stats); ofpbuf_delete(buf); @@ -450,27 +431,7 @@ netdev_vport_set_stats(struct netdev *netdev, const struct netdev_stats *stats) struct dpif_linux_vport vport; int err; - rtnl_stats.rx_packets = stats->rx_packets; - rtnl_stats.tx_packets = stats->tx_packets; - rtnl_stats.rx_bytes = stats->rx_bytes; - rtnl_stats.tx_bytes = stats->tx_bytes; - rtnl_stats.rx_errors = stats->rx_errors; - rtnl_stats.tx_errors = stats->tx_errors; - rtnl_stats.rx_dropped = stats->rx_dropped; - rtnl_stats.tx_dropped = stats->tx_dropped; - rtnl_stats.multicast = stats->multicast; - rtnl_stats.collisions = stats->collisions; - rtnl_stats.rx_length_errors = stats->rx_length_errors; - rtnl_stats.rx_over_errors = stats->rx_over_errors; - rtnl_stats.rx_crc_errors = stats->rx_crc_errors; - rtnl_stats.rx_frame_errors = stats->rx_frame_errors; - rtnl_stats.rx_fifo_errors = stats->rx_fifo_errors; - rtnl_stats.rx_missed_errors = stats->rx_missed_errors; - rtnl_stats.tx_aborted_errors = stats->tx_aborted_errors; - rtnl_stats.tx_carrier_errors = stats->tx_carrier_errors; - rtnl_stats.tx_fifo_errors = stats->tx_fifo_errors; - rtnl_stats.tx_heartbeat_errors = stats->tx_heartbeat_errors; - rtnl_stats.tx_window_errors = stats->tx_window_errors; + netdev_stats_to_rtnl_link_stats64(&rtnl_stats, stats); dpif_linux_vport_init(&vport); vport.cmd = ODP_VPORT_CMD_SET; -- 2.43.0