NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
face-counters.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_FACE_COUNTERS_HPP
27 #define NFD_DAEMON_FACE_FACE_COUNTERS_HPP
28 
29 #include "common.hpp"
30 
31 namespace nfd {
32 
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
37 class PacketCounter : noncopyable
38 {
39 public:
40  typedef uint64_t rep;
41 
43  : m_value(0)
44  {
45  }
46 
47  operator rep() const
48  {
49  return m_value;
50  }
51 
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 
66 private:
67  rep m_value;
68 };
69 
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
74 class ByteCounter : noncopyable
75 {
76 public:
77  typedef uint64_t rep;
78 
80  : m_value(0)
81  {
82  }
83 
84  operator rep() const
85  {
86  return m_value;
87  }
88 
91  {
92  m_value += n;
93  return *this;
94  }
95 
96  void
97  set(rep value)
98  {
99  m_value = value;
100  }
101 
102 private:
103  rep m_value;
104 };
105 
108 class NetworkLayerCounters : noncopyable
109 {
110 public:
112  const PacketCounter&
114  {
115  return m_nInInterests;
116  }
117 
120  {
121  return m_nInInterests;
122  }
123 
125  const PacketCounter&
126  getNInDatas() const
127  {
128  return m_nInDatas;
129  }
130 
133  {
134  return m_nInDatas;
135  }
136 
138  const PacketCounter&
140  {
141  return m_nOutInterests;
142  }
143 
146  {
147  return m_nOutInterests;
148  }
149 
151  const PacketCounter&
152  getNOutDatas() const
153  {
154  return m_nOutDatas;
155  }
156 
159  {
160  return m_nOutDatas;
161  }
162 
163 protected:
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 
177 private:
178  PacketCounter m_nInInterests;
179  PacketCounter m_nInDatas;
180  PacketCounter m_nOutInterests;
181  PacketCounter m_nOutDatas;
182 };
183 
186 class LinkLayerCounters : noncopyable
187 {
188 public:
190  const ByteCounter&
191  getNInBytes() const
192  {
193  return m_nInBytes;
194  }
195 
196  ByteCounter&
198  {
199  return m_nInBytes;
200  }
201 
203  const ByteCounter&
204  getNOutBytes() const
205  {
206  return m_nOutBytes;
207  }
208 
209  ByteCounter&
211  {
212  return m_nOutBytes;
213  }
214 
215 protected:
219  template<typename R>
220  void
221  copyTo(R& recipient) const
222  {
223  recipient.setNInBytes(this->getNInBytes());
224  recipient.setNOutBytes(this->getNOutBytes());
225  }
226 
227 private:
228  ByteCounter m_nInBytes;
229  ByteCounter m_nOutBytes;
230 };
231 
235 {
236 public:
240  template<typename R>
241  void
242  copyTo(R& recipient) const
243  {
244  this->NetworkLayerCounters::copyTo(recipient);
245  this->LinkLayerCounters::copyTo(recipient);
246  }
247 };
248 
249 } // namespace nfd
250 
251 #endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP
ByteCounter & getNOutBytes()
contains counters on face
void set(rep value)
represents a counter of number of packets
const PacketCounter & getNOutDatas() const
outgoing Data
const PacketCounter & getNOutInterests() const
outgoing Interest
PacketCounter & getNInDatas()
PacketCounter & getNOutInterests()
represents a counter of number of bytes
void copyTo(R &recipient) const
copy current obseverations to a struct
void copyTo(R &recipient) const
copy current obseverations to a struct
ByteCounter & getNInBytes()
PacketCounter & operator++()
const ByteCounter & getNInBytes() const
received bytes
contains link layer byte counters
const PacketCounter & getNInDatas() const
incoming Data
void copyTo(R &recipient) const
copy current obseverations to a struct
contains network layer packet counters
const PacketCounter & getNInInterests() const
incoming Interest
void set(rep value)
PacketCounter & getNOutDatas()
PacketCounter & getNInInterests()
const ByteCounter & getNOutBytes() const
sent bytes
ByteCounter & operator+=(rep n)