NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
internal-transport.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, 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 #include "internal-transport.hpp"
27 #include "common/global.hpp"
28 
29 namespace nfd {
30 namespace face {
31 
32 NFD_LOG_MEMBER_INIT(InternalForwarderTransport, InternalForwarderTransport);
33 NFD_LOG_MEMBER_INIT(InternalClientTransport, InternalClientTransport);
34 
37 {
38  this->setLocalUri(localUri);
39  this->setRemoteUri(remoteUri);
40  this->setScope(scope);
42  this->setLinkType(linkType);
43  this->setMtu(MTU_UNLIMITED);
44 
45  NFD_LOG_FACE_DEBUG("Creating transport");
46 }
47 
48 void
50 {
51  getGlobalIoService().post([this, packet] {
52  NFD_LOG_FACE_TRACE("Received: " << packet.size() << " bytes");
53  receive(packet);
54  });
55 }
56 
57 void
58 InternalForwarderTransport::doSend(const Block& packet)
59 {
60  NFD_LOG_FACE_TRACE("Sending to " << m_peer);
61 
62  if (m_peer)
63  m_peer->receivePacket(packet);
64 }
65 
66 void
68 {
69  NFD_LOG_FACE_TRACE(__func__);
70 
72 }
73 
75 {
76  if (m_forwarder != nullptr) {
77  m_forwarder->setPeer(nullptr);
78  }
79 }
80 
81 void
83 {
84  NFD_LOG_DEBUG(__func__ << " " << forwarder);
85 
86  if (m_forwarder != nullptr) {
87  // disconnect from the old forwarder transport
88  m_forwarder->setPeer(nullptr);
89  m_fwTransportStateConn.disconnect();
90  }
91 
92  m_forwarder = forwarder;
93 
94  if (m_forwarder != nullptr) {
95  // connect to the new forwarder transport
96  m_forwarder->setPeer(this);
97  m_fwTransportStateConn = m_forwarder->afterStateChange.connect(
98  [this] (TransportState oldState, TransportState newState) {
99  if (newState == TransportState::CLOSED) {
100  connectToForwarder(nullptr);
101  }
102  });
103  }
104 }
105 
106 void
108 {
109  getGlobalIoService().post([this, packet] {
110  NFD_LOG_TRACE("Received: " << packet.size() << " bytes");
111  if (m_receiveCallback) {
112  m_receiveCallback(packet);
113  }
114  });
115 }
116 
117 void
119 {
120  NFD_LOG_TRACE("Sending to " << m_forwarder);
121 
122  if (m_forwarder)
123  m_forwarder->receivePacket(wire);
124 }
125 
126 } // namespace face
127 } // namespace nfd
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:164
void connectToForwarder(InternalForwarderTransport *forwarder)
Connect to a forwarder-side transport.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:91
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:397
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
Definition: global.cpp:49
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:427
void setMtu(ssize_t mtu)
Definition: transport.cpp:126
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:409
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
void receive(const Block &packet, const EndpointId &endpoint=0)
Pass a received link-layer packet to the upper layer for further processing.
Definition: transport.cpp:113
size_t size() const
Return the size of the encoded wire, i.e., of the whole TLV.
Definition: block.cpp:294
Implements a forwarder-side transport that can be paired with another transport.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
#define NFD_LOG_DEBUG
Definition: logger.hpp:38
the transport is closed, and can be safely deallocated
void setPeer(InternalTransportBase *peer)
void post(const std::function< void()> &callback)
Definition: global.cpp:35
#define NFD_LOG_TRACE
Definition: logger.hpp:37
void doClose() final
performs Transport specific operations to close the transport
NFD_LOG_MEMBER_INIT(InternalForwarderTransport, InternalForwarderTransport)
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:385
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
void receivePacket(const Block &packet) final
void setState(TransportState newState)
set transport state
Definition: transport.cpp:187
InternalForwarderTransport(const FaceUri &localUri=FaceUri("internal://"), const FaceUri &remoteUri=FaceUri("internal://"), ndn::nfd::FaceScope scope=ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LinkType linkType=ndn::nfd::LINK_TYPE_POINT_TO_POINT)
void send(const Block &block) final
Send a TLV block through the transport.
virtual void receivePacket(const Block &packet)=0
void receivePacket(const Block &packet) final