Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1 | /* -*- 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 | |
| 9 | namespace nfd { |
| 10 | |
| 11 | NFD_LOG_INIT("MulticastUdpFace"); |
| 12 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame^] | 13 | MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket, |
| 14 | const MulticastUdpFace::protocol::endpoint& localEndpoint) |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 15 | : DatagramFace<protocol>(FaceUri(socket->local_endpoint()), |
| 16 | FaceUri(localEndpoint), |
| 17 | socket, false) |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 18 | , m_multicastGroup(m_socket->local_endpoint()) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 19 | { |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 20 | NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 21 | } |
| 22 | |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 23 | const MulticastUdpFace::protocol::endpoint& |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 24 | MulticastUdpFace::getMulticastGroup() const |
| 25 | { |
| 26 | return m_multicastGroup; |
| 27 | } |
| 28 | |
| 29 | void |
| 30 | MulticastUdpFace::sendInterest(const Interest& interest) |
| 31 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 32 | onSendInterest(interest); |
| 33 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 34 | 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 DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 39 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 40 | // anything else should be done here? |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | MulticastUdpFace::sendData(const Data& data) |
| 45 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 46 | /// \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 Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 50 | NFD_LOG_DEBUG("Sending data"); |
| 51 | m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(), |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 52 | data.wireEncode().size()), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 53 | m_multicastGroup, |
| 54 | bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode())); |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 55 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 56 | // anything else should be done here? |
| 57 | } |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 58 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 59 | bool |
| 60 | MulticastUdpFace::isMultiAccess() const |
| 61 | { |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | } // namespace nfd |