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 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 13 | MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 14 | : DatagramFace<protocol>(FaceUri(socket->local_endpoint()), socket, false) |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 15 | , m_multicastGroup(m_socket->local_endpoint()) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 16 | { |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 17 | NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 18 | } |
| 19 | |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 20 | const MulticastUdpFace::protocol::endpoint& |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 21 | MulticastUdpFace::getMulticastGroup() const |
| 22 | { |
| 23 | return m_multicastGroup; |
| 24 | } |
| 25 | |
| 26 | void |
| 27 | MulticastUdpFace::sendInterest(const Interest& interest) |
| 28 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 29 | onSendInterest(interest); |
| 30 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 31 | NFD_LOG_DEBUG("Sending interest"); |
| 32 | m_socket->async_send_to(boost::asio::buffer(interest.wireEncode().wire(), |
| 33 | interest.wireEncode().size()), |
| 34 | m_multicastGroup, |
| 35 | bind(&DatagramFace<protocol>::handleSend, this, _1, interest.wireEncode())); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 36 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 37 | // anything else should be done here? |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | MulticastUdpFace::sendData(const Data& data) |
| 42 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 43 | /// \todo After this method implements duplicate suppression, onSendData event should |
| 44 | /// be triggered only when data is actually sent out |
| 45 | onSendData(data); |
| 46 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 47 | NFD_LOG_DEBUG("Sending data"); |
| 48 | m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(), |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 49 | data.wireEncode().size()), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 50 | m_multicastGroup, |
| 51 | bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode())); |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 52 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 53 | // anything else should be done here? |
| 54 | } |
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 | bool |
| 57 | MulticastUdpFace::isMultiAccess() const |
| 58 | { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | } // namespace nfd |