blob: bdaa3dfd2f9ab3a88ac118d4bec613878c62f07d [file] [log] [blame]
Davide Pesaventocb425e82019-07-14 21:48:22 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, 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>
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050034#include <ndn-cxx/net/face-uri.hpp>
Davide Pesaventocb425e82019-07-14 21:48:22 -040035
36#include <boost/logic/tribool.hpp>
Teng Liangd94b7b32022-07-10 21:29:37 +080037#include <variant>
Davide Pesaventocb425e82019-07-14 21:48:22 -040038
39namespace nfd {
40namespace face {
41
42class Face;
43class LinkService;
44
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040045/**
46 * \brief Identifies a face.
Davide Pesaventocb425e82019-07-14 21:48:22 -040047 */
48using FaceId = uint64_t;
49
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040050/// Indicates an invalid FaceId
Davide Pesavento20d94f62022-09-26 03:30:53 -040051inline constexpr FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040052/// Identifies the InternalFace used in management
Davide Pesavento20d94f62022-09-26 03:30:53 -040053inline constexpr FaceId FACEID_INTERNAL_FACE = 1;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040054/// Identifies a packet comes from the ContentStore
Davide Pesavento20d94f62022-09-26 03:30:53 -040055inline constexpr FaceId FACEID_CONTENT_STORE = 254;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040056/// Identifies the NullFace that drops every packet
Davide Pesavento20d94f62022-09-26 03:30:53 -040057inline constexpr FaceId FACEID_NULL = 255;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040058/// Upper bound of reserved FaceIds
Davide Pesavento20d94f62022-09-26 03:30:53 -040059inline constexpr FaceId FACEID_RESERVED_MAX = 255;
Davide Pesaventocb425e82019-07-14 21:48:22 -040060
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040061/**
62 * \brief Minimum MTU that may be set.
Eric Newberrycb6551e2020-03-02 14:12:16 -080063 *
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040064 * This is done to ensure the NDNLPv2 fragmentation feature functions properly.
Eric Newberrycb6551e2020-03-02 14:12:16 -080065 */
Davide Pesavento20d94f62022-09-26 03:30:53 -040066inline constexpr ssize_t MIN_MTU = 64;
Eric Newberrycb6551e2020-03-02 14:12:16 -080067
Teng Liangd94b7b32022-07-10 21:29:37 +080068/**
69 * \brief Identifies a remote endpoint on the link.
Davide Pesaventocb425e82019-07-14 21:48:22 -040070 *
Teng Liangd94b7b32022-07-10 21:29:37 +080071 * This ID is only meaningful in the context of the same Transport.
72 * Incoming packets from the same remote endpoint have the same EndpointId,
73 * and incoming packets from different remote endpoints have different EndpointIds.
Davide Pesaventocb425e82019-07-14 21:48:22 -040074 *
Teng Liangd94b7b32022-07-10 21:29:37 +080075 * Typically, a point-to-point Transport has only one meaningful EndpointId,
76 * represented by `std::monostate`.
Davide Pesaventocb425e82019-07-14 21:48:22 -040077 */
Teng Liangd94b7b32022-07-10 21:29:37 +080078using EndpointId = std::variant<std::monostate, ethernet::Address, udp::Endpoint>;
Davide Pesaventocb425e82019-07-14 21:48:22 -040079
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050080/**
81 * \brief Parameters used to set Transport properties or LinkService options on a newly created face.
Davide Pesaventocb425e82019-07-14 21:48:22 -040082 *
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050083 * Parameters are passed as a struct rather than individually, so that a future change in the list
84 * of parameters does not require an update to the method signature in all subclasses.
Davide Pesaventocb425e82019-07-14 21:48:22 -040085 */
86struct FaceParams
87{
88 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040089 std::optional<time::nanoseconds> baseCongestionMarkingInterval;
90 std::optional<uint64_t> defaultCongestionThreshold;
91 std::optional<ssize_t> mtu;
Davide Pesaventocb425e82019-07-14 21:48:22 -040092 bool wantLocalFields = false;
93 bool wantLpReliability = false;
94 boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
95};
96
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050097/**
98 * \brief For internal use by FaceLogging macros.
Davide Pesaventocb425e82019-07-14 21:48:22 -040099 *
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500100 * FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
Davide Pesaventocb425e82019-07-14 21:48:22 -0400101 *
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500102 * `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
103 * should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
104 * which will appear as part of the log message.
Davide Pesaventocb425e82019-07-14 21:48:22 -0400105 */
106template<typename T>
107class FaceLogHelper
108{
109public:
110 explicit
111 FaceLogHelper(const T& obj1) noexcept
112 : obj(obj1)
113 {
114 }
115
116public:
117 const T& obj;
118};
119
120} // namespace face
121
122using face::EndpointId;
123using face::FaceId;
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500124using ::ndn::FaceUri;
Davide Pesaventocb425e82019-07-14 21:48:22 -0400125
126} // namespace nfd
127
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500128/**
129 * \defgroup FaceLogging Face logging macros.
Davide Pesaventocb425e82019-07-14 21:48:22 -0400130 *
131 * These macros augment the log message with some face-specific information,
132 * such as the face ID, that are useful to distinguish which face produced the
133 * message. It is strongly recommended to use these macros instead of the
134 * generic ones for all logging inside Face, LinkService, Transport subclasses.
135 * @{
136 */
137
138/** \cond */
139// implementation detail
140#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
141 ::nfd::face::FaceLogHelper< \
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400142 std::remove_cv_t<std::remove_reference_t<decltype(*this)>> \
Davide Pesaventocb425e82019-07-14 21:48:22 -0400143 >(*this) \
144 << msg)
145/** \endcond */
146
147/** \brief Log a message at TRACE level */
148#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
149
150/** \brief Log a message at DEBUG level */
151#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
152
153/** \brief Log a message at INFO level */
154#define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
155
156/** \brief Log a message at WARN level */
157#define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
158
159/** \brief Log a message at ERROR level */
160#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
161
162/** @} */
163
164#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP