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