blob: 996d7b6defb921cce675f517ce631274e2e3c0b3 [file] [log] [blame]
Davide Pesaventocb425e82019-07-14 21:48:22 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesaventocb425e82019-07-14 21:48:22 -04004 * 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
Teng Liangd94b7b32022-07-10 21:29:37 +080029#include "ethernet-protocol.hpp"
30#include "udp-protocol.hpp"
Davide Pesaventocb425e82019-07-14 21:48:22 -040031#include "common/logger.hpp"
32
33#include <ndn-cxx/encoding/nfd-constants.hpp>
34
35#include <boost/logic/tribool.hpp>
Teng Liangd94b7b32022-07-10 21:29:37 +080036#include <variant>
Davide Pesaventocb425e82019-07-14 21:48:22 -040037
38namespace nfd {
39namespace face {
40
41class Face;
42class LinkService;
43
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040044/**
45 * \brief Identifies a face.
Davide Pesaventocb425e82019-07-14 21:48:22 -040046 */
47using FaceId = uint64_t;
48
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040049/// Indicates an invalid FaceId
50constexpr FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
51/// Identifies the InternalFace used in management
52constexpr FaceId FACEID_INTERNAL_FACE = 1;
53/// Identifies a packet comes from the ContentStore
54constexpr FaceId FACEID_CONTENT_STORE = 254;
55/// Identifies the NullFace that drops every packet
56constexpr FaceId FACEID_NULL = 255;
57/// Upper bound of reserved FaceIds
58constexpr FaceId FACEID_RESERVED_MAX = 255;
Davide Pesaventocb425e82019-07-14 21:48:22 -040059
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040060/**
61 * \brief Minimum MTU that may be set.
Eric Newberrycb6551e2020-03-02 14:12:16 -080062 *
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040063 * This is done to ensure the NDNLPv2 fragmentation feature functions properly.
Eric Newberrycb6551e2020-03-02 14:12:16 -080064 */
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040065constexpr ssize_t MIN_MTU = 64;
Eric Newberrycb6551e2020-03-02 14:12:16 -080066
Teng Liangd94b7b32022-07-10 21:29:37 +080067/**
68 * \brief Identifies a remote endpoint on the link.
Davide Pesaventocb425e82019-07-14 21:48:22 -040069 *
Teng Liangd94b7b32022-07-10 21:29:37 +080070 * This ID is only meaningful in the context of the same Transport.
71 * Incoming packets from the same remote endpoint have the same EndpointId,
72 * and incoming packets from different remote endpoints have different EndpointIds.
Davide Pesaventocb425e82019-07-14 21:48:22 -040073 *
Teng Liangd94b7b32022-07-10 21:29:37 +080074 * Typically, a point-to-point Transport has only one meaningful EndpointId,
75 * represented by `std::monostate`.
Davide Pesaventocb425e82019-07-14 21:48:22 -040076 */
Teng Liangd94b7b32022-07-10 21:29:37 +080077using EndpointId = std::variant<std::monostate, ethernet::Address, udp::Endpoint>;
Davide Pesaventocb425e82019-07-14 21:48:22 -040078
79/** \brief Parameters used to set Transport properties or LinkService options on a newly created face.
80 *
81 * Parameters are passed as a struct rather than individually, so that a future change in the list
82 * of parameters does not require an update to the method signature in all subclasses.
83 */
84struct FaceParams
85{
86 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040087 std::optional<time::nanoseconds> baseCongestionMarkingInterval;
88 std::optional<uint64_t> defaultCongestionThreshold;
89 std::optional<ssize_t> mtu;
Davide Pesaventocb425e82019-07-14 21:48:22 -040090 bool wantLocalFields = false;
91 bool wantLpReliability = false;
92 boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
93};
94
95/** \brief For internal use by FaceLogging macros.
96 *
97 * FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
98 *
99 * `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
100 * should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
101 * which will appear as part of the log message.
102 */
103template<typename T>
104class FaceLogHelper
105{
106public:
107 explicit
108 FaceLogHelper(const T& obj1) noexcept
109 : obj(obj1)
110 {
111 }
112
113public:
114 const T& obj;
115};
116
117} // namespace face
118
119using face::EndpointId;
120using face::FaceId;
121
122} // namespace nfd
123
124/** \defgroup FaceLogging Face logging macros
125 *
126 * These macros augment the log message with some face-specific information,
127 * such as the face ID, that are useful to distinguish which face produced the
128 * message. It is strongly recommended to use these macros instead of the
129 * generic ones for all logging inside Face, LinkService, Transport subclasses.
130 * @{
131 */
132
133/** \cond */
134// implementation detail
135#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
136 ::nfd::face::FaceLogHelper< \
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400137 std::remove_cv_t<std::remove_reference_t<decltype(*this)>> \
Davide Pesaventocb425e82019-07-14 21:48:22 -0400138 >(*this) \
139 << msg)
140/** \endcond */
141
142/** \brief Log a message at TRACE level */
143#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
144
145/** \brief Log a message at DEBUG level */
146#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
147
148/** \brief Log a message at INFO level */
149#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
150
151/** \brief Log a message at WARN level */
152#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
153
154/** \brief Log a message at ERROR level */
155#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
156
157/** @} */
158
159#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP