blob: 75c691ec3b13f7d33be5a15ea7413742b94764e5 [file] [log] [blame]
Giulio Grassi624f6c62014-02-18 19:42:14 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Giulio Grassi624f6c62014-02-18 19:42:14 +010024
25#include "multicast-udp-face.hpp"
26
27namespace nfd {
28
29NFD_LOG_INIT("MulticastUdpFace");
30
Junxiao Shi6e694322014-04-03 10:27:13 -070031MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket,
32 const MulticastUdpFace::protocol::endpoint& localEndpoint)
Junxiao Shi79494162014-04-02 18:25:11 -070033 : DatagramFace<protocol>(FaceUri(socket->local_endpoint()),
34 FaceUri(localEndpoint),
35 socket, false)
Davide Pesaventod8d4d982014-03-21 18:47:58 +010036 , m_multicastGroup(m_socket->local_endpoint())
Giulio Grassi624f6c62014-02-18 19:42:14 +010037{
Davide Pesaventod8d4d982014-03-21 18:47:58 +010038 NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup);
Giulio Grassi624f6c62014-02-18 19:42:14 +010039}
40
Davide Pesaventod8d4d982014-03-21 18:47:58 +010041const MulticastUdpFace::protocol::endpoint&
Giulio Grassi624f6c62014-02-18 19:42:14 +010042MulticastUdpFace::getMulticastGroup() const
43{
44 return m_multicastGroup;
45}
46
47void
48MulticastUdpFace::sendInterest(const Interest& interest)
49{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000050 onSendInterest(interest);
51
Giulio Grassi624f6c62014-02-18 19:42:14 +010052 NFD_LOG_DEBUG("Sending interest");
53 m_socket->async_send_to(boost::asio::buffer(interest.wireEncode().wire(),
54 interest.wireEncode().size()),
55 m_multicastGroup,
56 bind(&DatagramFace<protocol>::handleSend, this, _1, interest.wireEncode()));
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060057
Giulio Grassi624f6c62014-02-18 19:42:14 +010058 // anything else should be done here?
59}
60
61void
62MulticastUdpFace::sendData(const Data& data)
63{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000064 /// \todo After this method implements duplicate suppression, onSendData event should
65 /// be triggered only when data is actually sent out
66 onSendData(data);
67
Giulio Grassi624f6c62014-02-18 19:42:14 +010068 NFD_LOG_DEBUG("Sending data");
69 m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(),
Davide Pesaventod8d4d982014-03-21 18:47:58 +010070 data.wireEncode().size()),
Giulio Grassi624f6c62014-02-18 19:42:14 +010071 m_multicastGroup,
72 bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode()));
Davide Pesaventod8d4d982014-03-21 18:47:58 +010073
Giulio Grassi624f6c62014-02-18 19:42:14 +010074 // anything else should be done here?
75}
Davide Pesaventod8d4d982014-03-21 18:47:58 +010076
Giulio Grassi624f6c62014-02-18 19:42:14 +010077bool
78MulticastUdpFace::isMultiAccess() const
79{
80 return true;
81}
82
83} // namespace nfd