blob: 05303b5fdb9360e5d07c564955d68f9212d3b578 [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
70
71/** \brief represents a counter of number of bytes
72 */
73// ByteCounter is noncopyable, because increment should be called on the counter,
74// not a copy of it; it's implicitly convertible to uint64_t to be observed
75class ByteCounter : noncopyable
76{
77public:
78 typedef uint64_t rep;
79
80 ByteCounter()
81 : m_value(0)
82 {
83 }
84
85 operator rep() const
86 {
87 return m_value;
88 }
89
90 ByteCounter&
91 operator+=(rep n)
92 {
93 m_value += n;
94 return *this;
95 }
96
97 void
98 set(rep value)
99 {
100 m_value = value;
101 }
102
103private:
104 rep m_value;
105};
106
107
108/** \brief contains network layer packet counters
109 */
110class NetworkLayerCounters : noncopyable
111{
112public:
113 /// incoming Interest
114 const PacketCounter&
115 getNInInterests() const
116 {
117 return m_nInInterests;
118 }
119
120 PacketCounter&
121 getNInInterests()
122 {
123 return m_nInInterests;
124 }
125
126 /// incoming Data
127 const PacketCounter&
128 getNInDatas() const
129 {
130 return m_nInDatas;
131 }
132
133 PacketCounter&
134 getNInDatas()
135 {
136 return m_nInDatas;
137 }
138
139 /// outgoing Interest
140 const PacketCounter&
141 getNOutInterests() const
142 {
143 return m_nOutInterests;
144 }
145
146 PacketCounter&
147 getNOutInterests()
148 {
149 return m_nOutInterests;
150 }
151
152 /// outgoing Data
153 const PacketCounter&
154 getNOutDatas() const
155 {
156 return m_nOutDatas;
157 }
158
159 PacketCounter&
160 getNOutDatas()
161 {
162 return m_nOutDatas;
163 }
164
165private:
166 PacketCounter m_nInInterests;
167 PacketCounter m_nInDatas;
168 PacketCounter m_nOutInterests;
169 PacketCounter m_nOutDatas;
170};
171
172
173/** \brief contains link layer byte counters
174 */
175class LinkLayerCounters : noncopyable
176{
177public:
178 /// received bytes
179 const ByteCounter&
180 getNInBytes() const
181 {
182 return m_nInBytes;
183 }
184
185 ByteCounter&
186 getNInBytes()
187 {
188 return m_nInBytes;
189 }
190
191 /// sent bytes
192 const ByteCounter&
193 getNOutBytes() const
194 {
195 return m_nOutBytes;
196 }
197
198 ByteCounter&
199 getNOutBytes()
200 {
201 return m_nOutBytes;
202 }
203
204private:
205 ByteCounter m_nInBytes;
206 ByteCounter m_nOutBytes;
207};
208
209
210/** \brief contains counters on face
211 */
212class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
213{
214};
215
216} // namespace nfd
217
218#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP