Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 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 { |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 33 | namespace face { |
| 34 | |
| 35 | /** \brief gives access to counters provided by Face |
| 36 | * |
| 37 | * This type is a facade that exposes common counters of a Face. |
| 38 | * |
| 39 | * get<T>() can be used to access extended counters provided by |
| 40 | * LinkService or Transport of the Face. |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 41 | */ |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 42 | class FaceCounters |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 45 | FaceCounters(const LinkService::Counters& linkServiceCounters, |
| 46 | const Transport::Counters& transportCounters); |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 47 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 48 | /** \return counters provided by LinkService |
| 49 | * \tparam T LinkService counters type |
| 50 | * \throw std::bad_cast counters type mismatch |
| 51 | */ |
| 52 | template<typename T> |
| 53 | typename std::enable_if<std::is_base_of<LinkService::Counters, T>::value, const T&>::type |
| 54 | get() const |
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 | return dynamic_cast<const T&>(m_linkServiceCounters); |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 59 | /** \return counters provided by Transport |
| 60 | * \tparam T Transport counters type |
| 61 | * \throw std::bad_cast counters type mismatch |
| 62 | */ |
| 63 | template<typename T> |
| 64 | typename std::enable_if<std::is_base_of<Transport::Counters, T>::value, const T&>::type |
| 65 | get() const |
| 66 | { |
| 67 | return dynamic_cast<const T&>(m_transportCounters); |
| 68 | } |
| 69 | |
| 70 | public: |
| 71 | const PacketCounter& nInInterests; |
| 72 | const PacketCounter& nOutInterests; |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 73 | const PacketCounter& nDroppedInterests; |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 74 | const PacketCounter& nInData; |
| 75 | const PacketCounter& nOutData; |
| 76 | const PacketCounter& nInNacks; |
| 77 | const PacketCounter& nOutNacks; |
| 78 | |
| 79 | const PacketCounter& nInPackets; |
| 80 | const PacketCounter& nOutPackets; |
| 81 | const ByteCounter& nInBytes; |
| 82 | const ByteCounter& nOutBytes; |
| 83 | |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 84 | private: |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 85 | const LinkService::Counters& m_linkServiceCounters; |
| 86 | const Transport::Counters& m_transportCounters; |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 89 | } // namespace face |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 90 | } // namespace nfd |
| 91 | |
| 92 | #endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP |