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  : DatagramTransport(std::move(recvSocket))
40  , m_multicastGroup(multicastGroup)
41  , m_sendSocket(std::move(sendSocket))
42 {
43  this->setLocalUri(FaceUri(localEndpoint));
44  this->setRemoteUri(FaceUri(multicastGroup));
45  this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
46  this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
47  this->setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
48  this->setMtu(udp::computeMtu(localEndpoint));
49 
50  NFD_LOG_FACE_INFO("Creating transport");
51 }
52 
53 void
54 MulticastUdpTransport::doSend(Transport::Packet&& packet)
55 {
56  NFD_LOG_FACE_TRACE(__func__);
57 
58  m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
60  boost::asio::placeholders::error,
61  boost::asio::placeholders::bytes_transferred,
62  packet.packet));
63 }
64 
65 void
66 MulticastUdpTransport::doClose()
67 {
68  if (m_sendSocket.is_open()) {
69  NFD_LOG_FACE_TRACE("Closing sending socket");
70 
71  // Cancel all outstanding operations and close the socket.
72  // Use the non-throwing variants and ignore errors, if any.
73  boost::system::error_code error;
74  m_sendSocket.cancel(error);
75  m_sendSocket.close(error);
76  }
77 
79 }
80 
81 template<>
84 {
85  // IPv6 multicast is not supported
86  BOOST_ASSERT(ep.address().is_v4());
87 
88  return (static_cast<uint64_t>(ep.port()) << 32) |
89  static_cast<uint64_t>(ep.address().to_v4().to_ulong());
90 }
91 
92 } // namespace face
93 } // namespace nfd
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
virtual 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:74
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
MulticastUdpTransport(const protocol::endpoint &localEndpoint, const protocol::endpoint &multicastGroup, protocol::socket &&recvSocket, protocol::socket &&sendSocket)
Creates a UDP-based transport for multicast communication.
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...
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Definition: face-log.hpp:80
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