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  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));
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 handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:151
#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:79
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:396
void doClose() override
performs Transport specific operations to close the transport
stores a packet along with the remote endpoint
Definition: transport.hpp:113
STL namespace.
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:426
Implements Transport for datagram-based protocols.
void setMtu(ssize_t mtu)
Definition: transport.hpp:438
ssize_t computeMtu(const Endpoint &localEndpoint)
computes maximum payload size in a UDP packet
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:408
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
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
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.
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:43
Catch-all error for socket component errors that don&#39;t fit in other categories.
Definition: base.hpp:83
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:109