Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 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_MGMT_NFD_CS_INFO_HPP |
| 23 | #define NDN_MGMT_NFD_CS_INFO_HPP |
| 24 | |
| 25 | #include "../../encoding/block.hpp" |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 26 | #include "../../encoding/nfd-constants.hpp" |
| 27 | |
| 28 | #include <bitset> |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace nfd { |
| 32 | |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 33 | /** \ingroup management |
| 34 | * \brief represents the CS Information dataset |
| 35 | * \sa https://redmine.named-data.net/projects/nfd/wiki/CsMgmt#CS-Information-Dataset |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 36 | */ |
| 37 | class CsInfo |
| 38 | { |
| 39 | public: |
| 40 | class Error : public tlv::Error |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
| 45 | : tlv::Error(what) |
| 46 | { |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | CsInfo(); |
| 51 | |
| 52 | explicit |
| 53 | CsInfo(const Block& block); |
| 54 | |
| 55 | template<encoding::Tag TAG> |
| 56 | size_t |
| 57 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 58 | |
| 59 | const Block& |
| 60 | wireEncode() const; |
| 61 | |
| 62 | void |
| 63 | wireDecode(const Block& wire); |
| 64 | |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 65 | /** \brief get CS capacity (in number of packets) |
| 66 | */ |
| 67 | uint64_t |
| 68 | getCapacity() const |
| 69 | { |
| 70 | return m_capacity; |
| 71 | } |
| 72 | |
| 73 | CsInfo& |
| 74 | setCapacity(uint64_t capacity); |
| 75 | |
| 76 | /** \brief get CS_ENABLE_ADMIT flag |
| 77 | */ |
| 78 | bool |
| 79 | getEnableAdmit() const |
| 80 | { |
| 81 | return m_flags.test(BIT_CS_ENABLE_ADMIT); |
| 82 | } |
| 83 | |
| 84 | CsInfo& |
| 85 | setEnableAdmit(bool enableAdmit); |
| 86 | |
| 87 | /** \brief get CS_ENABLE_SERVE flag |
| 88 | */ |
| 89 | bool |
| 90 | getEnableServe() const |
| 91 | { |
| 92 | return m_flags.test(BIT_CS_ENABLE_SERVE); |
| 93 | } |
| 94 | |
| 95 | CsInfo& |
| 96 | setEnableServe(bool enableServe); |
| 97 | |
| 98 | /** \brief get number of stored CS entries |
| 99 | */ |
| 100 | uint64_t |
| 101 | getNEntries() const |
| 102 | { |
| 103 | return m_nEntries; |
| 104 | } |
| 105 | |
| 106 | CsInfo& |
| 107 | setNEntries(uint64_t nEntries); |
| 108 | |
| 109 | /** \brief get number of CS lookup hits since NFD starts |
| 110 | */ |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 111 | uint64_t |
| 112 | getNHits() const |
| 113 | { |
| 114 | return m_nHits; |
| 115 | } |
| 116 | |
| 117 | CsInfo& |
| 118 | setNHits(uint64_t nHits); |
| 119 | |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 120 | /** \brief get number of CS lookup misses since NFD starts |
| 121 | */ |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 122 | uint64_t |
| 123 | getNMisses() const |
| 124 | { |
| 125 | return m_nMisses; |
| 126 | } |
| 127 | |
| 128 | CsInfo& |
| 129 | setNMisses(uint64_t nMisses); |
| 130 | |
| 131 | private: |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 132 | using FlagsBitSet = std::bitset<2>; |
| 133 | |
| 134 | uint64_t m_capacity; |
| 135 | FlagsBitSet m_flags; |
| 136 | uint64_t m_nEntries; |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 137 | uint64_t m_nHits; |
| 138 | uint64_t m_nMisses; |
| 139 | mutable Block m_wire; |
| 140 | }; |
| 141 | |
| 142 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CsInfo); |
| 143 | |
| 144 | bool |
| 145 | operator==(const CsInfo& a, const CsInfo& b); |
| 146 | |
| 147 | inline bool |
| 148 | operator!=(const CsInfo& a, const CsInfo& b) |
| 149 | { |
| 150 | return !(a == b); |
| 151 | } |
| 152 | |
| 153 | std::ostream& |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 154 | operator<<(std::ostream& os, const CsInfo& csi); |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 155 | |
| 156 | } // namespace nfd |
| 157 | } // namespace ndn |
| 158 | |
| 159 | #endif // NDN_MGMT_NFD_CS_INFO_HPP |