Loading...
Searching...
No Matches
face.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, 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_HPP
27#define NFD_DAEMON_FACE_FACE_HPP
28
29#include "face-common.hpp"
30#include "link-service.hpp"
31#include "transport.hpp"
32
33namespace nfd {
34namespace face {
35
36class Channel;
37
42
52{
53public:
54 FaceCounters(const LinkService::Counters& linkServiceCounters,
55 const Transport::Counters& transportCounters);
56
62 template<typename T>
63 std::enable_if_t<std::is_base_of_v<LinkService::Counters, T>, const T&>
64 get() const
65 {
66 return dynamic_cast<const T&>(m_linkServiceCounters);
67 }
68
74 template<typename T>
75 std::enable_if_t<std::is_base_of_v<Transport::Counters, T>, const T&>
76 get() const
77 {
78 return dynamic_cast<const T&>(m_transportCounters);
79 }
80
81public:
89
94
99
100private:
101 const LinkService::Counters& m_linkServiceCounters;
102 const Transport::Counters& m_transportCounters;
103};
104
117class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
118{
119public:
120 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
121
123 getLinkService() const noexcept
124 {
125 return m_service.get();
126 }
127
128 Transport*
129 getTransport() const noexcept
130 {
131 return m_transport.get();
132 }
133
144 void
146 {
147 m_transport->close();
148 }
149
150public: // upper interface connected to forwarding
154 void
155 sendInterest(const Interest& interest)
156 {
157 m_service->sendInterest(interest);
158 }
159
163 void
164 sendData(const Data& data)
165 {
166 m_service->sendData(data);
167 }
168
172 void
173 sendNack(const lp::Nack& nack)
174 {
175 m_service->sendNack(nack);
176 }
177
179 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
180
182 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
183
185 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
186
188 signal::Signal<LinkService, Interest>& onDroppedInterest;
189
190public: // properties
194 FaceId
195 getId() const noexcept
196 {
197 return m_id;
198 }
199
204 void
205 setId(FaceId id) noexcept
206 {
207 m_id = id;
208 }
209
213 FaceUri
214 getLocalUri() const noexcept
215 {
216 return m_transport->getLocalUri();
217 }
218
222 FaceUri
223 getRemoteUri() const noexcept
224 {
225 return m_transport->getRemoteUri();
226 }
227
231 ndn::nfd::FaceScope
232 getScope() const noexcept
233 {
234 return m_transport->getScope();
235 }
236
240 ndn::nfd::FacePersistency
241 getPersistency() const noexcept
242 {
243 return m_transport->getPersistency();
244 }
245
249 void
250 setPersistency(ndn::nfd::FacePersistency persistency)
251 {
252 return m_transport->setPersistency(persistency);
253 }
254
258 ndn::nfd::LinkType
259 getLinkType() const noexcept
260 {
261 return m_transport->getLinkType();
262 }
263
269 ssize_t
270 getMtu() const
271 {
272 return m_service->getEffectiveMtu();
273 }
274
279 getState() const noexcept
280 {
281 return m_transport->getState();
282 }
283
285 signal::Signal<Transport, FaceState /*old*/, FaceState /*new*/>& afterStateChange;
286
291 time::steady_clock::time_point
292 getExpirationTime() const noexcept
293 {
294 return m_transport->getExpirationTime();
295 }
296
297 const FaceCounters&
298 getCounters() const noexcept
299 {
300 return m_counters;
301 }
302
304 getCounters() noexcept
305 {
306 return m_counters;
307 }
308
312 weak_ptr<Channel>
313 getChannel() const noexcept
314 {
315 return m_channel;
316 }
317
321 void
322 setChannel(weak_ptr<Channel> channel) noexcept
323 {
324 m_channel = std::move(channel);
325 }
326
327private:
328 FaceId m_id = INVALID_FACEID;
329 unique_ptr<LinkService> m_service;
330 unique_ptr<Transport> m_transport;
331 FaceCounters m_counters;
332 weak_ptr<Channel> m_channel;
333};
334
335std::ostream&
336operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
337
338} // namespace face
339
340using face::Face;
341
342} // namespace nfd
343
344#endif // NFD_DAEMON_FACE_FACE_HPP
Represents a counter of number of bytes.
Definition counter.hpp:90
Represents a counter of number of packets.
Definition counter.hpp:71
Gives access to the counters provided by Face.
Definition face.hpp:52
PacketCounter nInHopLimitZero
Count of incoming Interests dropped due to HopLimit == 0.
Definition face.hpp:96
const PacketCounter & nInPackets
Count of incoming packets.
Definition face.hpp:90
std::enable_if_t< std::is_base_of_v< Transport::Counters, T >, const T & > get() const
Returns the counters provided by (a subclass of) Transport.
Definition face.hpp:76
PacketCounter nOutHopLimitZero
Count of outgoing Interests dropped due to HopLimit == 0 on non-local faces.
Definition face.hpp:98
const ByteCounter & nInBytes
Total bytes received.
Definition face.hpp:92
const PacketCounter & nOutPackets
Count of outgoing packets.
Definition face.hpp:91
std::enable_if_t< std::is_base_of_v< LinkService::Counters, T >, const T & > get() const
Returns the counters provided by (a subclass of) LinkService.
Definition face.hpp:64
const PacketCounter & nInInterests
Count of incoming Interest packets.
Definition face.hpp:82
const PacketCounter & nInNacks
Count of incoming Nack packets.
Definition face.hpp:87
const PacketCounter & nInData
Count of incoming Data packets.
Definition face.hpp:85
const PacketCounter & nOutNacks
Count of outgoing Nack packets.
Definition face.hpp:88
const ByteCounter & nOutBytes
Total bytes sent.
Definition face.hpp:93
const PacketCounter & nInterestsExceededRetx
Count of Interests dropped by reliability system for exceeding allowed number of retx.
Definition face.hpp:84
const PacketCounter & nOutInterests
Count of outgoing Interest packets.
Definition face.hpp:83
const PacketCounter & nOutData
Count of outgoing Data packets.
Definition face.hpp:86
Generalization of a network interface.
Definition face.hpp:118
FaceState getState() const noexcept
Returns the face state.
Definition face.hpp:279
const FaceCounters & getCounters() const noexcept
Definition face.hpp:298
signal::Signal< LinkService, Data, EndpointId > & afterReceiveData
Called when a Data packet is received.
Definition face.hpp:182
ndn::nfd::FaceScope getScope() const noexcept
Returns whether the face is local or non-local for scope control purposes.
Definition face.hpp:232
void setPersistency(ndn::nfd::FacePersistency persistency)
Changes the face persistency setting.
Definition face.hpp:250
signal::Signal< LinkService, Interest > & onDroppedInterest
Called when an Interest is dropped by the reliability system for exceeding the allowed number of retr...
Definition face.hpp:188
FaceCounters & getCounters() noexcept
Definition face.hpp:304
Transport * getTransport() const noexcept
Definition face.hpp:129
void sendInterest(const Interest &interest)
Send Interest.
Definition face.hpp:155
void setChannel(weak_ptr< Channel > channel) noexcept
Set channel on which face was created (unicast) or the associated channel (multicast).
Definition face.hpp:322
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
Called when the transport state changes.
Definition face.hpp:285
signal::Signal< LinkService, lp::Nack, EndpointId > & afterReceiveNack
Called when a Nack packet is received.
Definition face.hpp:185
FaceUri getLocalUri() const noexcept
Returns a FaceUri representing the local endpoint.
Definition face.hpp:214
ndn::nfd::LinkType getLinkType() const noexcept
Returns the link type of the face (point-to-point, multi-access, ...).
Definition face.hpp:259
FaceUri getRemoteUri() const noexcept
Returns a FaceUri representing the remote endpoint.
Definition face.hpp:223
void setId(FaceId id) noexcept
Sets the face ID.
Definition face.hpp:205
ssize_t getMtu() const
Returns the effective MTU of the face.
Definition face.hpp:270
FaceId getId() const noexcept
Returns the face ID.
Definition face.hpp:195
void sendNack(const lp::Nack &nack)
Send Nack.
Definition face.hpp:173
signal::Signal< LinkService, Interest, EndpointId > & afterReceiveInterest
Called when an Interest packet is received.
Definition face.hpp:179
void close()
Request that the face be closed.
Definition face.hpp:145
weak_ptr< Channel > getChannel() const noexcept
Get channel on which face was created (unicast) or the associated channel (multicast).
Definition face.hpp:313
void sendData(const Data &data)
Send Data.
Definition face.hpp:164
ndn::nfd::FacePersistency getPersistency() const noexcept
Returns the current persistency setting of the face.
Definition face.hpp:241
LinkService * getLinkService() const noexcept
Definition face.hpp:123
time::steady_clock::time_point getExpirationTime() const noexcept
Returns the expiration time of the face.
Definition face.hpp:292
Counters provided by a transport.
Definition transport.hpp:55
The lower half of a Face.
#define NFD_FINAL_UNLESS_WITH_TESTS
Definition common.hpp:44
std::ostream & operator<<(std::ostream &os, const FaceLogHelper< Face > &flh)
Definition face.cpp:63
TransportState
Indicates the state of a transport.
Definition transport.hpp:37
constexpr FaceId INVALID_FACEID
Indicates an invalid FaceId.
uint64_t FaceId
Identifies a face.
-status-http-server
Definition common.hpp:71