cs-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_MGMT_NFD_CS_INFO_HPP
23 #define NDN_CXX_MGMT_NFD_CS_INFO_HPP
24 
27 
28 #include <bitset>
29 
30 namespace ndn::nfd {
31 
36 class CsInfo
37 {
38 public:
39  class Error : public tlv::Error
40  {
41  public:
42  using tlv::Error::Error;
43  };
44 
45  CsInfo();
46 
47  explicit
48  CsInfo(const Block& block);
49 
50  template<encoding::Tag TAG>
51  size_t
52  wireEncode(EncodingImpl<TAG>& encoder) const;
53 
54  const Block&
55  wireEncode() const;
56 
57  void
58  wireDecode(const Block& wire);
59 
62  uint64_t
63  getCapacity() const
64  {
65  return m_capacity;
66  }
67 
68  CsInfo&
69  setCapacity(uint64_t capacity);
70 
73  bool
75  {
76  return m_flags.test(BIT_CS_ENABLE_ADMIT);
77  }
78 
79  CsInfo&
80  setEnableAdmit(bool enableAdmit);
81 
84  bool
86  {
87  return m_flags.test(BIT_CS_ENABLE_SERVE);
88  }
89 
90  CsInfo&
91  setEnableServe(bool enableServe);
92 
95  uint64_t
96  getNEntries() const
97  {
98  return m_nEntries;
99  }
100 
101  CsInfo&
102  setNEntries(uint64_t nEntries);
103 
106  uint64_t
107  getNHits() const
108  {
109  return m_nHits;
110  }
111 
112  CsInfo&
113  setNHits(uint64_t nHits);
114 
117  uint64_t
118  getNMisses() const
119  {
120  return m_nMisses;
121  }
122 
123  CsInfo&
124  setNMisses(uint64_t nMisses);
125 
126 private:
127  using FlagsBitSet = std::bitset<2>;
128 
129  uint64_t m_capacity = 0;
130  FlagsBitSet m_flags;
131  uint64_t m_nEntries = 0;
132  uint64_t m_nHits = 0;
133  uint64_t m_nMisses = 0;
134 
135  mutable Block m_wire;
136 };
137 
139 
140 bool
141 operator==(const CsInfo& a, const CsInfo& b);
142 
143 inline bool
144 operator!=(const CsInfo& a, const CsInfo& b)
145 {
146  return !(a == b);
147 }
148 
149 std::ostream&
150 operator<<(std::ostream& os, const CsInfo& csi);
151 
152 } // namespace ndn::nfd
153 
154 #endif // NDN_CXX_MGMT_NFD_CS_INFO_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
Represents the CS Information dataset.
Definition: cs-info.hpp:37
CsInfo & setEnableServe(bool enableServe)
Definition: cs-info.cpp:139
CsInfo & setNEntries(uint64_t nEntries)
Definition: cs-info.cpp:147
CsInfo & setEnableAdmit(bool enableAdmit)
Definition: cs-info.cpp:131
uint64_t getCapacity() const
Get CS capacity (in number of packets).
Definition: cs-info.hpp:63
CsInfo & setNMisses(uint64_t nMisses)
Definition: cs-info.cpp:163
void wireDecode(const Block &wire)
Definition: cs-info.cpp:72
const Block & wireEncode() const
Definition: cs-info.cpp:56
bool getEnableAdmit() const
Get CS_ENABLE_ADMIT flag.
Definition: cs-info.hpp:74
uint64_t getNEntries() const
Get number of stored CS entries.
Definition: cs-info.hpp:96
CsInfo & setCapacity(uint64_t capacity)
Definition: cs-info.cpp:123
uint64_t getNHits() const
Get number of CS lookup hits since NFD started.
Definition: cs-info.hpp:107
CsInfo & setNHits(uint64_t nHits)
Definition: cs-info.cpp:155
bool getEnableServe() const
Get CS_ENABLE_SERVE flag.
Definition: cs-info.hpp:85
uint64_t getNMisses() const
Get number of CS lookup misses since NFD started.
Definition: cs-info.hpp:118
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:28
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
@ BIT_CS_ENABLE_ADMIT
enables the CS to admit new Data
@ BIT_CS_ENABLE_SERVE
enables the CS to satisfy Interests using cached Data
Contains classes and functions related to the NFD Management protocol.
bool operator!=(const ChannelStatus &a, const ChannelStatus &b)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
bool operator==(const ChannelStatus &a, const ChannelStatus &b)