blob: 6dc1d6a2011555f6b1c1facd856166e0a2b3c763 [file] [log] [blame]
Junxiao Shi33152f12014-07-16 19:54:32 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_DAEMON_FACE_FACE_COUNTERS_HPP
27#define NFD_DAEMON_FACE_FACE_COUNTERS_HPP
28
29#include "common.hpp"
30
31namespace nfd {
32
33/** \brief represents a counter of number of packets
34 */
35// PacketCounter is noncopyable, because increment should be called on the counter,
36// not a copy of it; it's implicitly convertible to uint64_t to be observed
37class PacketCounter : noncopyable
38{
39public:
40 typedef uint64_t rep;
41
42 PacketCounter()
43 : m_value(0)
44 {
45 }
46
47 operator rep() const
48 {
49 return m_value;
50 }
51
52 PacketCounter&
53 operator++()
54 {
55 ++m_value;
56 return *this;
57 }
58 // postfix ++ operator is not provided because it's not needed
59
60 void
61 set(rep value)
62 {
63 m_value = value;
64 }
65
66private:
67 rep m_value;
68};
69
Junxiao Shi33152f12014-07-16 19:54:32 -070070/** \brief represents a counter of number of bytes
71 */
72// ByteCounter is noncopyable, because increment should be called on the counter,
73// not a copy of it; it's implicitly convertible to uint64_t to be observed
74class ByteCounter : noncopyable
75{
76public:
77 typedef uint64_t rep;
78
79 ByteCounter()
80 : m_value(0)
81 {
82 }
83
84 operator rep() const
85 {
86 return m_value;
87 }
88
89 ByteCounter&
90 operator+=(rep n)
91 {
92 m_value += n;
93 return *this;
94 }
95
96 void
97 set(rep value)
98 {
99 m_value = value;
100 }
101
102private:
103 rep m_value;
104};
105
Junxiao Shi33152f12014-07-16 19:54:32 -0700106/** \brief contains network layer packet counters
107 */
108class NetworkLayerCounters : noncopyable
109{
110public:
111 /// incoming Interest
112 const PacketCounter&
113 getNInInterests() const
114 {
115 return m_nInInterests;
116 }
117
118 PacketCounter&
119 getNInInterests()
120 {
121 return m_nInInterests;
122 }
123
124 /// incoming Data
125 const PacketCounter&
126 getNInDatas() const
127 {
128 return m_nInDatas;
129 }
130
131 PacketCounter&
132 getNInDatas()
133 {
134 return m_nInDatas;
135 }
136
137 /// outgoing Interest
138 const PacketCounter&
139 getNOutInterests() const
140 {
141 return m_nOutInterests;
142 }
143
144 PacketCounter&
145 getNOutInterests()
146 {
147 return m_nOutInterests;
148 }
149
150 /// outgoing Data
151 const PacketCounter&
152 getNOutDatas() const
153 {
154 return m_nOutDatas;
155 }
156
157 PacketCounter&
158 getNOutDatas()
159 {
160 return m_nOutDatas;
161 }
162
Junxiao Shi632a6202014-07-20 01:14:30 -0700163protected:
164 /** \brief copy current obseverations to a struct
165 * \param recipient an object with set methods for counters
166 */
167 template<typename R>
168 void
169 copyTo(R& recipient) const
170 {
171 recipient.setNInInterests(this->getNInInterests());
172 recipient.setNInDatas(this->getNInDatas());
173 recipient.setNOutInterests(this->getNOutInterests());
174 recipient.setNOutDatas(this->getNOutDatas());
175 }
176
Junxiao Shi33152f12014-07-16 19:54:32 -0700177private:
178 PacketCounter m_nInInterests;
179 PacketCounter m_nInDatas;
180 PacketCounter m_nOutInterests;
181 PacketCounter m_nOutDatas;
182};
183
Junxiao Shi33152f12014-07-16 19:54:32 -0700184/** \brief contains link layer byte counters
185 */
186class LinkLayerCounters : noncopyable
187{
188public:
189 /// received bytes
190 const ByteCounter&
191 getNInBytes() const
192 {
193 return m_nInBytes;
194 }
195
196 ByteCounter&
197 getNInBytes()
198 {
199 return m_nInBytes;
200 }
201
202 /// sent bytes
203 const ByteCounter&
204 getNOutBytes() const
205 {
206 return m_nOutBytes;
207 }
208
209 ByteCounter&
210 getNOutBytes()
211 {
212 return m_nOutBytes;
213 }
214
Junxiao Shi632a6202014-07-20 01:14:30 -0700215protected:
216 /** \brief copy current obseverations to a struct
217 * \param recipient an object with set methods for counters
218 */
219 template<typename R>
220 void
221 copyTo(R& recipient) const
222 {
223 recipient.setNInBytes(this->getNInBytes());
224 recipient.setNOutBytes(this->getNOutBytes());
225 }
226
Junxiao Shi33152f12014-07-16 19:54:32 -0700227private:
228 ByteCounter m_nInBytes;
229 ByteCounter m_nOutBytes;
230};
231
Junxiao Shi33152f12014-07-16 19:54:32 -0700232/** \brief contains counters on face
233 */
234class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
235{
Junxiao Shi632a6202014-07-20 01:14:30 -0700236public:
237 /** \brief copy current obseverations to a struct
238 * \param recipient an object with set methods for counters
239 */
240 template<typename R>
241 void
242 copyTo(R& recipient) const
243 {
244 this->NetworkLayerCounters::copyTo(recipient);
245 this->LinkLayerCounters::copyTo(recipient);
246 }
Junxiao Shi33152f12014-07-16 19:54:32 -0700247};
248
249} // namespace nfd
250
251#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP