multicast-udp-transport.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
27 #include "udp-protocol.hpp"
28 
29 namespace nfd {
30 namespace face {
31 
33  Multicast, "MulticastUdpTransport");
34 
35 MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& localEndpoint,
36  const protocol::endpoint& multicastGroup,
37  protocol::socket&& recvSocket,
38  protocol::socket&& sendSocket,
39  ndn::nfd::LinkType linkType)
40  : DatagramTransport(std::move(recvSocket))
41  , m_multicastGroup(multicastGroup)
42  , m_sendSocket(std::move(sendSocket))
43 {
44  this->setLocalUri(FaceUri(localEndpoint));
45  this->setRemoteUri(FaceUri(multicastGroup));
46  this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
47  this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
48  this->setLinkType(linkType);
49  this->setMtu(udp::computeMtu(localEndpoint));
50 
51  NFD_LOG_FACE_INFO("Creating transport");
52 }
53 
54 void
55 MulticastUdpTransport::doSend(Transport::Packet&& packet)
56 {
57  NFD_LOG_FACE_TRACE(__func__);
58 
59  m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
61  boost::asio::placeholders::error,
62  boost::asio::placeholders::bytes_transferred,
63  packet.packet));
64 }
65 
66 void
67 MulticastUdpTransport::doClose()
68 {
69  if (m_sendSocket.is_open()) {
70  NFD_LOG_FACE_TRACE("Closing sending socket");
71 
72  // Cancel all outstanding operations and close the socket.
73  // Use the non-throwing variants and ignore errors, if any.
74  boost::system::error_code error;
75  m_sendSocket.cancel(error);
76  m_sendSocket.close(error);
77  }
78 
80 }
81 
82 template<>
85 {
86  // IPv6 multicast is not supported
87  BOOST_ASSERT(ep.address().is_v4());
88 
89  return (static_cast<uint64_t>(ep.port()) << 32) |
90  static_cast<uint64_t>(ep.address().to_v4().to_ulong());
91 }
92 
93 } // namespace face
94 } // namespace nfd
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
void doClose() override
performs Transport specific operations to close the transport
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-log.hpp:79
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:408
void setMtu(ssize_t mtu)
Definition: transport.hpp:438
STL namespace.
ssize_t computeMtu(const Endpoint &localEndpoint)
computes maximum payload size in a UDP packet
stores a packet along with the remote endpoint
Definition: transport.hpp:113
void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Definition: face-log.hpp:85
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:109
#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name)
Definition: logger.hpp:139
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:426
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:151
Implements Transport for datagram-based protocols.
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:396
MulticastUdpTransport(const protocol::endpoint &localEndpoint, const protocol::endpoint &multicastGroup, protocol::socket &&recvSocket, protocol::socket &&sendSocket, ndn::nfd::LinkType linkType)
Creates a UDP-based transport for multicast communication.