blob: 51af2d9b2f37168793ce0567bdb823a5984d7861 [file] [log] [blame]
Junxiao Shi33152f12014-07-16 19:54:32 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry41aba102017-11-01 16:42:13 -07002/*
Ju Pan6c8c2a02019-09-04 08:01:13 +00003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi57df2882015-11-11 06:12:35 -07004 * 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 Shi33152f12014-07-16 19:54:32 -070010 *
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 Shida93f1f2015-11-11 06:13:16 -070029#include "link-service.hpp"
30#include "transport.hpp"
Junxiao Shi33152f12014-07-16 19:54:32 -070031
32namespace nfd {
Junxiao Shida93f1f2015-11-11 06:13:16 -070033namespace 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 Shi33152f12014-07-16 19:54:32 -070041 */
Junxiao Shida93f1f2015-11-11 06:13:16 -070042class FaceCounters
Junxiao Shi33152f12014-07-16 19:54:32 -070043{
44public:
Junxiao Shida93f1f2015-11-11 06:13:16 -070045 FaceCounters(const LinkService::Counters& linkServiceCounters,
46 const Transport::Counters& transportCounters);
Junxiao Shi33152f12014-07-16 19:54:32 -070047
Junxiao Shida93f1f2015-11-11 06:13:16 -070048 /** \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 Shi632a6202014-07-20 01:14:30 -070055 {
Junxiao Shida93f1f2015-11-11 06:13:16 -070056 return dynamic_cast<const T&>(m_linkServiceCounters);
Junxiao Shi632a6202014-07-20 01:14:30 -070057 }
58
Junxiao Shida93f1f2015-11-11 06:13:16 -070059 /** \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
70public:
71 const PacketCounter& nInInterests;
72 const PacketCounter& nOutInterests;
Eric Newberry41aba102017-11-01 16:42:13 -070073 const PacketCounter& nDroppedInterests;
Junxiao Shida93f1f2015-11-11 06:13:16 -070074 const PacketCounter& nInData;
75 const PacketCounter& nOutData;
76 const PacketCounter& nInNacks;
77 const PacketCounter& nOutNacks;
Ju Pan6c8c2a02019-09-04 08:01:13 +000078 PacketCounter nKeptInterests;
Junxiao Shida93f1f2015-11-11 06:13:16 -070079
80 const PacketCounter& nInPackets;
81 const PacketCounter& nOutPackets;
82 const ByteCounter& nInBytes;
83 const ByteCounter& nOutBytes;
84
Junxiao Shi33152f12014-07-16 19:54:32 -070085private:
Junxiao Shida93f1f2015-11-11 06:13:16 -070086 const LinkService::Counters& m_linkServiceCounters;
87 const Transport::Counters& m_transportCounters;
Junxiao Shi33152f12014-07-16 19:54:32 -070088};
89
Junxiao Shida93f1f2015-11-11 06:13:16 -070090} // namespace face
Junxiao Shi33152f12014-07-16 19:54:32 -070091} // namespace nfd
92
93#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP