Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * 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 Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 24 | |
| 25 | #include "multicast-udp-face.hpp" |
| 26 | |
| 27 | namespace nfd { |
| 28 | |
| 29 | NFD_LOG_INIT("MulticastUdpFace"); |
| 30 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 31 | MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket, |
| 32 | const MulticastUdpFace::protocol::endpoint& localEndpoint) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 33 | : DatagramFace<protocol>(FaceUri(socket->local_endpoint()), |
| 34 | FaceUri(localEndpoint), |
| 35 | socket, false) |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 36 | , m_multicastGroup(m_socket->local_endpoint()) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 37 | { |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 38 | NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 41 | const MulticastUdpFace::protocol::endpoint& |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 42 | MulticastUdpFace::getMulticastGroup() const |
| 43 | { |
| 44 | return m_multicastGroup; |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | MulticastUdpFace::sendInterest(const Interest& interest) |
| 49 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 50 | onSendInterest(interest); |
| 51 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 52 | 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 DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 57 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 58 | // anything else should be done here? |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | MulticastUdpFace::sendData(const Data& data) |
| 63 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 64 | /// \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 Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 68 | NFD_LOG_DEBUG("Sending data"); |
| 69 | m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(), |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 70 | data.wireEncode().size()), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 71 | m_multicastGroup, |
| 72 | bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode())); |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 73 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 74 | // anything else should be done here? |
| 75 | } |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 76 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 77 | bool |
| 78 | MulticastUdpFace::isMultiAccess() const |
| 79 | { |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | } // namespace nfd |