NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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));
48  this->setMtu(udp::computeMtu(localEndpoint));
49 
50  NFD_LOG_FACE_INFO("Creating transport");
51 }
52 
53 void
55 {
56  if (newPersistency != ndn::nfd::FACE_PERSISTENCY_PERMANENT) {
57  BOOST_THROW_EXCEPTION(
58  std::invalid_argument("MulticastUdpTransport supports only FACE_PERSISTENCY_PERMANENT"));
59  }
60 }
61 
62 void
63 MulticastUdpTransport::doSend(Transport::Packet&& packet)
64 {
65  NFD_LOG_FACE_TRACE(__func__);
66 
67  m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
69  boost::asio::placeholders::error,
70  boost::asio::placeholders::bytes_transferred,
71  packet.packet));
72 }
73 
74 void
75 MulticastUdpTransport::doClose()
76 {
77  if (m_sendSocket.is_open()) {
78  NFD_LOG_FACE_TRACE("Closing sending socket");
79 
80  // Cancel all outstanding operations and close the socket.
81  // Use the non-throwing variants and ignore errors, if any.
82  boost::system::error_code error;
83  m_sendSocket.cancel(error);
84  m_sendSocket.close(error);
85  }
86 
88 }
89 
90 template<>
93 {
94  // IPv6 multicast is not supported
95  BOOST_ASSERT(ep.address().is_v4());
96 
97  return (static_cast<uint64_t>(ep.port()) << 32) |
98  static_cast<uint64_t>(ep.address().to_v4().to_ulong());
99 }
100 
101 } // namespace face
102 } // namespace nfd
void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
MulticastUdpTransport(const protocol::endpoint &localEndpoint, const protocol::endpoint &multicastGroup, protocol::socket &&recvSocket, protocol::socket &&sendSocket)
Creates a UDP-based transport for multicast communication.
#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name)
Definition: logger.hpp:50
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-log.hpp:74
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: transport.cpp:131
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:374
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
virtual void doClose() override
performs Transport specific operations to close the transport
stores a packet along with the remote endpoint
Definition: transport.hpp:113
virtual void beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) final
invoked before persistency is changed
STL namespace.
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:404
Implements Transport for datagram-based protocols.
void setMtu(ssize_t mtu)
Definition: transport.hpp:416
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:386
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
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:362
ssize_t computeMtu(const boost::asio::ip::udp::endpoint &localEndpoint)
computes maximum payload size in a UDP packet
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:109