/src/ntopng/include/EthStats.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2013-26 - ntop.org |
4 | | * |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef _ETH_STATS_H_ |
23 | | #define _ETH_STATS_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | class EthStats { |
28 | | private: |
29 | | ProtoStats rawIngress, rawEgress, eth_IPv4, eth_IPv6, eth_ARP, eth_MPLS, |
30 | | eth_other; |
31 | | ThroughputStats ingress_bytes_thpt, ingress_pkts_thpt, egress_bytes_thpt, |
32 | | egress_pkts_thpt; |
33 | | |
34 | | public: |
35 | | EthStats(); |
36 | | |
37 | 0 | inline ProtoStats* getIPv4Stats() { return (ð_IPv4); }; |
38 | 0 | inline ProtoStats* getIPv6Stats() { return (ð_IPv6); }; |
39 | 0 | inline ProtoStats* getARPStats() { return (ð_ARP); }; |
40 | 0 | inline ProtoStats* getMPLSStats() { return (ð_MPLS); }; |
41 | 0 | inline ProtoStats* getEthOtherStats() { return (ð_other); }; |
42 | | |
43 | | void lua(lua_State* vm); |
44 | | void updateStats(const struct timeval* tv); |
45 | | void incStats(bool ingressPacket, u_int32_t num_pkts, u_int32_t num_bytes, |
46 | | u_int pkt_overhead); |
47 | | void incProtoStats(u_int16_t proto, u_int32_t num_pkts, u_int32_t num_bytes); |
48 | | |
49 | 0 | inline void incNumPackets(bool ingressPacket, u_int64_t v) { |
50 | 0 | if (ingressPacket) |
51 | 0 | rawIngress.incPkts(v); |
52 | 0 | else |
53 | 0 | rawEgress.incPkts(v); |
54 | 0 | } |
55 | | |
56 | 0 | inline void incNumBytes(bool ingressPacket, u_int64_t v) { |
57 | 0 | if (ingressPacket) |
58 | 0 | rawIngress.incBytes(v); |
59 | 0 | else |
60 | 0 | rawEgress.incBytes(v); |
61 | 0 | } |
62 | | |
63 | 0 | inline u_int64_t getNumIngressPackets() { return (rawIngress.getPkts()); }; |
64 | 0 | inline u_int64_t getNumEgressPackets() { return (rawEgress.getPkts()); }; |
65 | 0 | inline u_int64_t getNumIngressBytes() { return (rawIngress.getBytes()); }; |
66 | 0 | inline u_int64_t getNumEgressBytes() { return (rawEgress.getBytes()); }; |
67 | 0 | inline float getIngressBytesThpt() { return (ingress_bytes_thpt.getThpt()); }; |
68 | 0 | inline float getEgressBytesThpt() { return (egress_bytes_thpt.getThpt()); }; |
69 | | |
70 | 0 | inline u_int64_t getNumPackets() { |
71 | 0 | return (rawIngress.getPkts() + rawEgress.getPkts()); |
72 | 0 | }; |
73 | 0 | inline u_int64_t getNumBytes() { |
74 | 0 | return (rawIngress.getBytes() + rawEgress.getBytes()); |
75 | 0 | }; |
76 | | |
77 | 0 | inline void sum(EthStats* e) const { |
78 | 0 | rawIngress.sum(&e->rawIngress), rawEgress.sum(&e->rawEgress), |
79 | 0 | ingress_bytes_thpt.sum(&e->ingress_bytes_thpt), |
80 | 0 | ingress_pkts_thpt.sum(&e->ingress_pkts_thpt), |
81 | 0 | egress_bytes_thpt.sum(&e->egress_bytes_thpt), |
82 | 0 | egress_pkts_thpt.sum(&e->egress_pkts_thpt), eth_IPv4.sum(&e->eth_IPv4), |
83 | 0 | eth_IPv6.sum(&e->eth_IPv6), eth_ARP.sum(&e->eth_ARP), |
84 | 0 | eth_MPLS.sum(&e->eth_MPLS), eth_other.sum(&e->eth_other); |
85 | 0 | }; |
86 | | |
87 | | /** |
88 | | * @brief Cleanup the proto stats. |
89 | | * @details Reset all proto stats information. |
90 | | */ |
91 | | void cleanup(); |
92 | | void print(); |
93 | | }; |
94 | | |
95 | | #endif /* _ETH_STATS_H_ */ |