blob: 08facf847f85f31c8fda991ea9a3a6a424f7b076 [file] [log] [blame]
Junxiao Shi33152f12014-07-16 19:54:32 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi57df2882015-11-11 06:12:35 -07003 * 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 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;
73 const PacketCounter& nInData;
74 const PacketCounter& nOutData;
75 const PacketCounter& nInNacks;
76 const PacketCounter& nOutNacks;
77
78 const PacketCounter& nInPackets;
79 const PacketCounter& nOutPackets;
80 const ByteCounter& nInBytes;
81 const ByteCounter& nOutBytes;
82
Junxiao Shi33152f12014-07-16 19:54:32 -070083private:
Junxiao Shida93f1f2015-11-11 06:13:16 -070084 const LinkService::Counters& m_linkServiceCounters;
85 const Transport::Counters& m_transportCounters;
Junxiao Shi33152f12014-07-16 19:54:32 -070086};
87
Junxiao Shida93f1f2015-11-11 06:13:16 -070088} // namespace face
Junxiao Shi33152f12014-07-16 19:54:32 -070089} // namespace nfd
90
91#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP