blob: 93aebf4ef8be1220fc9053335d35eb3d86abd56f [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 {
33
Junxiao Shida93f1f2015-11-11 06:13:16 -070034class OldFaceCounters;
35
36namespace 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 Shi33152f12014-07-16 19:54:32 -070044 */
Junxiao Shida93f1f2015-11-11 06:13:16 -070045class FaceCounters
Junxiao Shi33152f12014-07-16 19:54:32 -070046{
47public:
Junxiao Shida93f1f2015-11-11 06:13:16 -070048 FaceCounters(const LinkService::Counters& linkServiceCounters,
49 const Transport::Counters& transportCounters);
Junxiao Shi33152f12014-07-16 19:54:32 -070050
Junxiao Shida93f1f2015-11-11 06:13:16 -070051 /** \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 Shi632a6202014-07-20 01:14:30 -070055 */
Junxiao Shida93f1f2015-11-11 06:13:16 -070056 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 Shi632a6202014-07-20 01:14:30 -070066 {
Junxiao Shida93f1f2015-11-11 06:13:16 -070067 return dynamic_cast<const T&>(m_linkServiceCounters);
Junxiao Shi632a6202014-07-20 01:14:30 -070068 }
69
Junxiao Shida93f1f2015-11-11 06:13:16 -070070 /** \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
81public:
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 Shi33152f12014-07-16 19:54:32 -070094private:
Junxiao Shida93f1f2015-11-11 06:13:16 -070095 const LinkService::Counters& m_linkServiceCounters;
96 const Transport::Counters& m_transportCounters;
Junxiao Shi33152f12014-07-16 19:54:32 -070097};
98
Junxiao Shida93f1f2015-11-11 06:13:16 -070099} // namespace face
Junxiao Shi33152f12014-07-16 19:54:32 -0700100} // namespace nfd
101
102#endif // NFD_DAEMON_FACE_FACE_COUNTERS_HPP