blob: f2333096fa64c27531eeae90501803f00255aac6 [file] [log] [blame]
Davide Pesaventocb425e82019-07-14 21:48:22 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2019, 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.
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_COMMON_HPP
27#define NFD_DAEMON_FACE_FACE_COMMON_HPP
28
29#include "core/common.hpp"
30#include "common/logger.hpp"
31
32#include <ndn-cxx/encoding/nfd-constants.hpp>
33
34#include <boost/logic/tribool.hpp>
35
36namespace nfd {
37namespace face {
38
39class Face;
40class LinkService;
41
42/** \brief Identifies a face.
43 */
44using FaceId = uint64_t;
45
46/// indicates an invalid FaceId
47const FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
48/// identifies the InternalFace used in management
49const FaceId FACEID_INTERNAL_FACE = 1;
50/// identifies a packet comes from the ContentStore
51const FaceId FACEID_CONTENT_STORE = 254;
52/// identifies the NullFace that drops every packet
53const FaceId FACEID_NULL = 255;
54/// upper bound of reserved FaceIds
55const FaceId FACEID_RESERVED_MAX = 255;
56
57/** \brief Identifies a remote endpoint on the link.
58 *
59 * This ID is only meaningful in the context of the same Transport.
60 * Incoming packets from the same remote endpoint have the same EndpointId,
61 * and incoming packets from different remote endpoints have different EndpointIds.
62 *
63 * Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0).
64 */
65using EndpointId = uint64_t;
66
67/** \brief Parameters used to set Transport properties or LinkService options on a newly created face.
68 *
69 * Parameters are passed as a struct rather than individually, so that a future change in the list
70 * of parameters does not require an update to the method signature in all subclasses.
71 */
72struct FaceParams
73{
74 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
75 optional<time::nanoseconds> baseCongestionMarkingInterval;
76 optional<uint64_t> defaultCongestionThreshold;
77 optional<ssize_t> mtu;
78 bool wantLocalFields = false;
79 bool wantLpReliability = false;
80 boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
81};
82
83/** \brief For internal use by FaceLogging macros.
84 *
85 * FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
86 *
87 * `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
88 * should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
89 * which will appear as part of the log message.
90 */
91template<typename T>
92class FaceLogHelper
93{
94public:
95 explicit
96 FaceLogHelper(const T& obj1) noexcept
97 : obj(obj1)
98 {
99 }
100
101public:
102 const T& obj;
103};
104
105} // namespace face
106
107using face::EndpointId;
108using face::FaceId;
109
110} // namespace nfd
111
112/** \defgroup FaceLogging Face logging macros
113 *
114 * These macros augment the log message with some face-specific information,
115 * such as the face ID, that are useful to distinguish which face produced the
116 * message. It is strongly recommended to use these macros instead of the
117 * generic ones for all logging inside Face, LinkService, Transport subclasses.
118 * @{
119 */
120
121/** \cond */
122// implementation detail
123#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
124 ::nfd::face::FaceLogHelper< \
125 typename std::remove_cv< \
126 typename std::remove_reference<decltype(*this)>::type \
127 >::type \
128 >(*this) \
129 << msg)
130/** \endcond */
131
132/** \brief Log a message at TRACE level */
133#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
134
135/** \brief Log a message at DEBUG level */
136#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
137
138/** \brief Log a message at INFO level */
139#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
140
141/** \brief Log a message at WARN level */
142#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
143
144/** \brief Log a message at ERROR level */
145#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
146
147/** @} */
148
149#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP