Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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. |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 29 | #include "link-service.hpp" |
| 30 | #include "transport.hpp" |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 34 | class OldFaceCounters; |
| 35 | |
| 36 | namespace face { |
| 37 | |
| 38 | /** \brief gives access to counters provided by Face |
| 39 | * |
| 40 | * This type is a facade that exposes common counters of a Face. |
| 41 | * |
| 42 | * get<T>() can be used to access extended counters provided by |
| 43 | * LinkService or Transport of the Face. |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 44 | */ |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 45 | class FaceCounters |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 48 | FaceCounters(const LinkService::Counters& linkServiceCounters, |
| 49 | const Transport::Counters& transportCounters); |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 51 | /** \brief wraps old counters |
| 52 | * |
| 53 | * FaceCounters instance created from this constructor only provides Interest/Data counters |
| 54 | * and Nack counters. Other counters are always zero. get<T>() should not be used. |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 55 | */ |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 56 | explicit |
| 57 | FaceCounters(const OldFaceCounters& oldCounters); |
| 58 | |
| 59 | /** \return counters provided by LinkService |
| 60 | * \tparam T LinkService counters type |
| 61 | * \throw std::bad_cast counters type mismatch |
| 62 | */ |
| 63 | template<typename T> |
| 64 | typename std::enable_if<std::is_base_of<LinkService::Counters, T>::value, const T&>::type |
| 65 | get() const |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 66 | { |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 67 | return dynamic_cast<const T&>(m_linkServiceCounters); |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 70 | /** \return counters provided by Transport |
| 71 | * \tparam T Transport counters type |
| 72 | * \throw std::bad_cast counters type mismatch |
| 73 | */ |
| 74 | template<typename T> |
| 75 | typename std::enable_if<std::is_base_of<Transport::Counters, T>::value, const T&>::type |
| 76 | get() const |
| 77 | { |
| 78 | return dynamic_cast<const T&>(m_transportCounters); |
| 79 | } |
| 80 | |
| 81 | public: |
| 82 | const PacketCounter& nInInterests; |
| 83 | const PacketCounter& nOutInterests; |
| 84 | const PacketCounter& nInData; |
| 85 | const PacketCounter& nOutData; |
| 86 | const PacketCounter& nInNacks; |
| 87 | const PacketCounter& nOutNacks; |
| 88 | |
| 89 | const PacketCounter& nInPackets; |
| 90 | const PacketCounter& nOutPackets; |
| 91 | const ByteCounter& nInBytes; |
| 92 | const ByteCounter& nOutBytes; |
| 93 | |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 94 | private: |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 95 | const LinkService::Counters& m_linkServiceCounters; |
| 96 | const Transport::Counters& m_transportCounters; |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 99 | } // namespace face |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 100 | } // namespace nfd |
| 101 | |
| 102 | #endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP |