blob: d96c1831dd7e9f99a1290cc4e4e6ec0562e18b3e [file] [log] [blame]
Giulio Grassi624f6c62014-02-18 19:42:14 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "multicast-udp-face.hpp"
8
9namespace nfd {
10
11NFD_LOG_INIT("MulticastUdpFace");
12
Junxiao Shi6e694322014-04-03 10:27:13 -070013MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket,
14 const MulticastUdpFace::protocol::endpoint& localEndpoint)
Junxiao Shi79494162014-04-02 18:25:11 -070015 : DatagramFace<protocol>(FaceUri(socket->local_endpoint()),
16 FaceUri(localEndpoint),
17 socket, false)
Davide Pesaventod8d4d982014-03-21 18:47:58 +010018 , m_multicastGroup(m_socket->local_endpoint())
Giulio Grassi624f6c62014-02-18 19:42:14 +010019{
Davide Pesaventod8d4d982014-03-21 18:47:58 +010020 NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup);
Giulio Grassi624f6c62014-02-18 19:42:14 +010021}
22
Davide Pesaventod8d4d982014-03-21 18:47:58 +010023const MulticastUdpFace::protocol::endpoint&
Giulio Grassi624f6c62014-02-18 19:42:14 +010024MulticastUdpFace::getMulticastGroup() const
25{
26 return m_multicastGroup;
27}
28
29void
30MulticastUdpFace::sendInterest(const Interest& interest)
31{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000032 onSendInterest(interest);
33
Giulio Grassi624f6c62014-02-18 19:42:14 +010034 NFD_LOG_DEBUG("Sending interest");
35 m_socket->async_send_to(boost::asio::buffer(interest.wireEncode().wire(),
36 interest.wireEncode().size()),
37 m_multicastGroup,
38 bind(&DatagramFace<protocol>::handleSend, this, _1, interest.wireEncode()));
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060039
Giulio Grassi624f6c62014-02-18 19:42:14 +010040 // anything else should be done here?
41}
42
43void
44MulticastUdpFace::sendData(const Data& data)
45{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000046 /// \todo After this method implements duplicate suppression, onSendData event should
47 /// be triggered only when data is actually sent out
48 onSendData(data);
49
Giulio Grassi624f6c62014-02-18 19:42:14 +010050 NFD_LOG_DEBUG("Sending data");
51 m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(),
Davide Pesaventod8d4d982014-03-21 18:47:58 +010052 data.wireEncode().size()),
Giulio Grassi624f6c62014-02-18 19:42:14 +010053 m_multicastGroup,
54 bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode()));
Davide Pesaventod8d4d982014-03-21 18:47:58 +010055
Giulio Grassi624f6c62014-02-18 19:42:14 +010056 // anything else should be done here?
57}
Davide Pesaventod8d4d982014-03-21 18:47:58 +010058
Giulio Grassi624f6c62014-02-18 19:42:14 +010059bool
60MulticastUdpFace::isMultiAccess() const
61{
62 return true;
63}
64
65} // namespace nfd