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; -*- */
26 #include "internal-transport.hpp"
27 #include "core/global-io.hpp"
28 
29 namespace nfd {
30 namespace face {
31 
32 NFD_LOG_INCLASS_DEFINE(InternalForwarderTransport, "InternalForwarderTransport");
33 
35  const FaceUri& localUri, const FaceUri& remoteUri,
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_INFO("Creating transport");
46 }
47 
48 void
50 {
51  NFD_LOG_FACE_TRACE(__func__);
52 
53  Packet p;
54  p.packet = packet;
55  this->receive(std::move(p));
56 }
57 
58 void
59 InternalForwarderTransport::doSend(Packet&& packet)
60 {
61  NFD_LOG_FACE_TRACE(__func__);
62 
63  this->emitSignal(afterSend, packet.packet);
64 }
65 
66 void
68 {
69  NFD_LOG_FACE_TRACE(__func__);
70 
72 }
73 
74 NFD_LOG_INCLASS_DEFINE(InternalClientTransport, "InternalClientTransport");
75 
76 static void
77 asyncReceive(InternalTransportBase* recipient, const Block& packet)
78 {
79  getGlobalIoService().post([packet, recipient] {
80  recipient->receiveFromLink(packet);
81  });
82 }
83 
84 void
86 {
87  NFD_LOG_DEBUG(__func__ << " " << forwarderTransport);
88 
89  m_fwToClientTransmitConn.disconnect();
90  m_clientToFwTransmitConn.disconnect();
91  m_fwTransportStateConn.disconnect();
92 
93  if (forwarderTransport != nullptr) {
94  m_fwToClientTransmitConn = forwarderTransport->afterSend.connect(bind(&asyncReceive, this, _1));
95  m_clientToFwTransmitConn = this->afterSend.connect(bind(&asyncReceive, forwarderTransport, _1));
96  m_fwTransportStateConn = forwarderTransport->afterStateChange.connect(
97  [this] (TransportState oldState, TransportState newState) {
98  if (newState == TransportState::CLOSED) {
99  this->connectToForwarder(nullptr);
100  }
101  });
102  }
103 }
104 
105 void
107 {
108  if (m_receiveCallback) {
109  m_receiveCallback(packet);
110  }
111 }
112 
113 void
115 {
116  this->emitSignal(afterSend, wire);
117 }
118 
119 void
120 InternalClientTransport::send(const Block& header, const Block& payload)
121 {
122  ndn::EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
123  encoder.appendByteArray(header.wire(), header.size());
124  encoder.appendByteArray(payload.wire(), payload.size());
125 
126  this->send(encoder.block());
127 }
128 
129 } // namespace face
130 } // namespace nfd
implements a client-side transport that can be paired with another
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:158
static void asyncReceive(InternalTransportBase *recipient, const Block &packet)
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-log.hpp:79
void connectToForwarder(InternalForwarderTransport *forwarderTransport)
connect to a forwarder-side transport
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:96
TransportState
indicates the state of a transport
Definition: transport.hpp:42
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:423
signal::Signal< InternalTransportBase, Block > afterSend
stores a packet along with the remote endpoint
Definition: transport.hpp:122
#define emitSignal(...)
(implementation detail)
Definition: emit.hpp:76
const uint8_t * wire() const
Get pointer to encoded wire.
Definition: block.cpp:291
detail::SimulatorIo & getGlobalIoService()
Definition: global-io.cpp:48
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:55
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:453
virtual void receiveFromLink(const Block &packet)=0
causes the transport to receive a link-layer packet
ReceiveCallback m_receiveCallback
Definition: transport.hpp:119
abstracts a transport that can be paired with another
void setMtu(ssize_t mtu)
Definition: transport.hpp:465
void receiveFromLink(const Block &packet) override
causes the transport to receive a link-layer packet
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:435
size_t size() const
Get size of encoded wire, including Type-Length-Value.
Definition: block.cpp:300
implements a forwarder-side transport that can be paired with another
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Definition: face-log.hpp:85
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:281
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
Definition: global-io.cpp:34
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:411
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
size_t appendByteArray(const uint8_t *array, size_t length)
Append a byte array array of length length.
Definition: encoder.cpp:135
void receiveFromLink(const Block &packet) override
causes the transport to receive a link-layer packet
void disconnect()
disconnects the connection manually
void doClose() override
performs Transport specific operations to close the transport
void setState(TransportState newState)
set transport state
Definition: transport.cpp:181
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 receive(Packet &&packet)
receive a link-layer packet
Definition: transport.cpp:118
void send(const Block &wire) override
send a TLV block through the transport
EncodingImpl< EncoderTag > EncodingBuffer
Block packet
the packet as a TLV block
Definition: transport.hpp:133
#define NFD_LOG_INCLASS_DEFINE(cls, name)
Definition: logger.hpp:39