|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
26 #ifndef NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
27 #define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
45 template<
class Protocol,
class Addressing = Unicast>
65 const boost::system::error_code& error);
75 handleSend(
const boost::system::error_code& error,
size_t nBytesSent);
78 handleReceive(
const boost::system::error_code& error,
size_t nBytesReceived);
99 std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
100 bool m_hasRecentlyReceived;
104 template<
class T,
class U>
106 : m_socket(std::
move(socket))
107 , m_hasRecentlyReceived(false)
109 boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
110 boost::system::error_code error;
111 m_socket.get_option(sendBufferSizeOption, error);
113 NFD_LOG_FACE_WARN(
"Failed to obtain send queue capacity from socket: " << error.message());
121 [
this] (
auto&&... args) {
126 template<
class T,
class U>
132 NFD_LOG_FACE_WARN(
"Failed to obtain send queue length from socket: " << std::strerror(errno));
137 template<
class T,
class U>
143 if (m_socket.is_open()) {
146 boost::system::error_code error;
147 m_socket.cancel(error);
148 m_socket.close(error);
158 template<
class T,
class U>
164 m_socket.async_send(boost::asio::buffer(packet),
166 [
this, packet] (
auto&&... args) {
167 this->handleSend(std::forward<decltype(args)>(args)...);
171 template<
class T,
class U>
174 const boost::system::error_code& error)
177 return processErrorCode(error);
189 if (element.
size() != nBytesReceived) {
190 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
194 m_hasRecentlyReceived =
true;
196 this->receive(element, makeEndpointId(m_sender));
199 template<
class T,
class U>
203 receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
205 if (m_socket.is_open())
206 m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
207 [
this] (
auto&&... args) {
208 this->handleReceive(std::forward<decltype(args)>(args)...);
212 template<
class T,
class U>
217 return processErrorCode(error);
222 template<
class T,
class U>
231 error == boost::asio::error::operation_aborted) {
246 template<
class T,
class U>
250 return m_hasRecentlyReceived;
253 template<
class T,
class U>
257 m_hasRecentlyReceived =
false;
260 template<
class T,
class U>
270 #endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP
void setSendQueueCapacity(ssize_t sendQueueCapacity)
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
@ CLOSED
the transport is closed, and can be safely deallocated
void post(const std::function< void()> &callback)
@ FACE_PERSISTENCY_PERMANENT
face is permanent
void doSend(const Block &packet, const EndpointId &endpoint) override
performs Transport specific operations to send a packet
protocol::endpoint m_sender
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
ssize_t getSendQueueLength() override
void processErrorCode(const boost::system::error_code &error)
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
void handleSend(const boost::system::error_code &error, size_t nBytesSent)
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
void resetRecentlyReceived()
@ CLOSING
the transport is being closed gracefully, either by the peer or by a call to close()
void doClose() override
performs Transport specific operations to close the transport
Copyright (c) 2011-2015 Regents of the University of California.
static NDN_CXX_NODISCARD std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to parse Block from a wire buffer.
protocol::socket m_socket
DatagramTransport(typename protocol::socket &&socket)
Construct datagram transport.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
const ssize_t QUEUE_ERROR
indicates that the transport was unable to retrieve the queue capacity/length
Implements Transport for datagram-based protocols.
void receiveDatagram(const uint8_t *buffer, size_t nBytesReceived, const boost::system::error_code &error)
Receive datagram, translate buffer into packet, deliver to parent class.
Represents a TLV element of NDN packet format.
size_t size() const
Return the size of the encoded wire, i.e.
@ FAILED
the transport is being closed due to a failure
bool hasRecentlyReceived() const
uint64_t EndpointId
Identifies a remote endpoint on the link.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
The lower half of a Face.
ssize_t getTxQueueLength(int fd)
obtain send queue length from a specified system socket