NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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));
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::beforeChangePersistency(ndn::nfd::FacePersistency newPersistency)
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,
68  bind(&MulticastUdpTransport::handleSend, this,
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
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-log.hpp:74
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
stores a packet along with the remote endpoint
Definition: transport.hpp:113
STL namespace.
Implements Transport for datagram-based protocols.
virtual void doClose() 1
performs Transport specific operations to close the transport
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
#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name)
Definition: logger.hpp:50
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