Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 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 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 29 | #include "ethernet-protocol.hpp" |
| 30 | #include "udp-protocol.hpp" |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 31 | #include "common/logger.hpp" |
| 32 | |
| 33 | #include <ndn-cxx/encoding/nfd-constants.hpp> |
| 34 | |
| 35 | #include <boost/logic/tribool.hpp> |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 36 | #include <variant> |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 37 | |
| 38 | namespace nfd { |
| 39 | namespace face { |
| 40 | |
| 41 | class Face; |
| 42 | class LinkService; |
| 43 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 44 | /** |
| 45 | * \brief Identifies a face. |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 46 | */ |
| 47 | using FaceId = uint64_t; |
| 48 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 49 | /// Indicates an invalid FaceId |
| 50 | constexpr FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID; |
| 51 | /// Identifies the InternalFace used in management |
| 52 | constexpr FaceId FACEID_INTERNAL_FACE = 1; |
| 53 | /// Identifies a packet comes from the ContentStore |
| 54 | constexpr FaceId FACEID_CONTENT_STORE = 254; |
| 55 | /// Identifies the NullFace that drops every packet |
| 56 | constexpr FaceId FACEID_NULL = 255; |
| 57 | /// Upper bound of reserved FaceIds |
| 58 | constexpr FaceId FACEID_RESERVED_MAX = 255; |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 59 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 60 | /** |
| 61 | * \brief Minimum MTU that may be set. |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 62 | * |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 63 | * This is done to ensure the NDNLPv2 fragmentation feature functions properly. |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 64 | */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 65 | constexpr ssize_t MIN_MTU = 64; |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 66 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 67 | /** |
| 68 | * \brief Identifies a remote endpoint on the link. |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 69 | * |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 70 | * 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 Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 73 | * |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 74 | * Typically, a point-to-point Transport has only one meaningful EndpointId, |
| 75 | * represented by `std::monostate`. |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 76 | */ |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 77 | using EndpointId = std::variant<std::monostate, ethernet::Address, udp::Endpoint>; |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 78 | |
| 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 | */ |
| 84 | struct FaceParams |
| 85 | { |
| 86 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 87 | std::optional<time::nanoseconds> baseCongestionMarkingInterval; |
| 88 | std::optional<uint64_t> defaultCongestionThreshold; |
| 89 | std::optional<ssize_t> mtu; |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 90 | 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 | */ |
| 103 | template<typename T> |
| 104 | class FaceLogHelper |
| 105 | { |
| 106 | public: |
| 107 | explicit |
| 108 | FaceLogHelper(const T& obj1) noexcept |
| 109 | : obj(obj1) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | public: |
| 114 | const T& obj; |
| 115 | }; |
| 116 | |
| 117 | } // namespace face |
| 118 | |
| 119 | using face::EndpointId; |
| 120 | using 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 Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 137 | std::remove_cv_t<std::remove_reference_t<decltype(*this)>> \ |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 138 | >(*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 |