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: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 43 | using tlv::Error::Error; |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | CsInfo(); |
| 47 | |
| 48 | explicit |
| 49 | CsInfo(const Block& block); |
| 50 | |
| 51 | template<encoding::Tag TAG> |
| 52 | size_t |
| 53 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 54 | |
| 55 | const Block& |
| 56 | wireEncode() const; |
| 57 | |
| 58 | void |
| 59 | wireDecode(const Block& wire); |
| 60 | |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 61 | /** \brief get CS capacity (in number of packets) |
| 62 | */ |
| 63 | uint64_t |
| 64 | getCapacity() const |
| 65 | { |
| 66 | return m_capacity; |
| 67 | } |
| 68 | |
| 69 | CsInfo& |
| 70 | setCapacity(uint64_t capacity); |
| 71 | |
| 72 | /** \brief get CS_ENABLE_ADMIT flag |
| 73 | */ |
| 74 | bool |
| 75 | getEnableAdmit() const |
| 76 | { |
| 77 | return m_flags.test(BIT_CS_ENABLE_ADMIT); |
| 78 | } |
| 79 | |
| 80 | CsInfo& |
| 81 | setEnableAdmit(bool enableAdmit); |
| 82 | |
| 83 | /** \brief get CS_ENABLE_SERVE flag |
| 84 | */ |
| 85 | bool |
| 86 | getEnableServe() const |
| 87 | { |
| 88 | return m_flags.test(BIT_CS_ENABLE_SERVE); |
| 89 | } |
| 90 | |
| 91 | CsInfo& |
| 92 | setEnableServe(bool enableServe); |
| 93 | |
| 94 | /** \brief get number of stored CS entries |
| 95 | */ |
| 96 | uint64_t |
| 97 | getNEntries() const |
| 98 | { |
| 99 | return m_nEntries; |
| 100 | } |
| 101 | |
| 102 | CsInfo& |
| 103 | setNEntries(uint64_t nEntries); |
| 104 | |
| 105 | /** \brief get number of CS lookup hits since NFD starts |
| 106 | */ |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 107 | uint64_t |
| 108 | getNHits() const |
| 109 | { |
| 110 | return m_nHits; |
| 111 | } |
| 112 | |
| 113 | CsInfo& |
| 114 | setNHits(uint64_t nHits); |
| 115 | |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 116 | /** \brief get number of CS lookup misses since NFD starts |
| 117 | */ |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 118 | uint64_t |
| 119 | getNMisses() const |
| 120 | { |
| 121 | return m_nMisses; |
| 122 | } |
| 123 | |
| 124 | CsInfo& |
| 125 | setNMisses(uint64_t nMisses); |
| 126 | |
| 127 | private: |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 128 | using FlagsBitSet = std::bitset<2>; |
| 129 | |
| 130 | uint64_t m_capacity; |
| 131 | FlagsBitSet m_flags; |
| 132 | uint64_t m_nEntries; |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 133 | uint64_t m_nHits; |
| 134 | uint64_t m_nMisses; |
| 135 | mutable Block m_wire; |
| 136 | }; |
| 137 | |
| 138 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CsInfo); |
| 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& |
Junxiao Shi | a7ab06d | 2018-01-29 22:28:47 +0000 | [diff] [blame] | 150 | operator<<(std::ostream& os, const CsInfo& csi); |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 151 | |
| 152 | } // namespace nfd |
| 153 | } // namespace ndn |
| 154 | |
| 155 | #endif // NDN_MGMT_NFD_CS_INFO_HPP |