blob: b5632e225cc12074657a0b51570de0ca3adeaa36 [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
Giulio Grassi624f6c62014-02-18 19:42:14 +010013MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket)
Alexander Afanasyev355c0662014-03-20 18:08:17 -070014 : DatagramFace<protocol>(FaceUri(socket->local_endpoint()), socket, false)
Davide Pesaventod8d4d982014-03-21 18:47:58 +010015 , m_multicastGroup(m_socket->local_endpoint())
Giulio Grassi624f6c62014-02-18 19:42:14 +010016{
Davide Pesaventod8d4d982014-03-21 18:47:58 +010017 NFD_LOG_INFO("Creating multicast UDP face for group " << m_multicastGroup);
Giulio Grassi624f6c62014-02-18 19:42:14 +010018}
19
Davide Pesaventod8d4d982014-03-21 18:47:58 +010020const MulticastUdpFace::protocol::endpoint&
Giulio Grassi624f6c62014-02-18 19:42:14 +010021MulticastUdpFace::getMulticastGroup() const
22{
23 return m_multicastGroup;
24}
25
26void
27MulticastUdpFace::sendInterest(const Interest& interest)
28{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000029 onSendInterest(interest);
30
Giulio Grassi624f6c62014-02-18 19:42:14 +010031 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()));
36
37 // anything else should be done here?
38}
39
40void
41MulticastUdpFace::sendData(const Data& data)
42{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000043 /// \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 Grassi624f6c62014-02-18 19:42:14 +010047 NFD_LOG_DEBUG("Sending data");
48 m_socket->async_send_to(boost::asio::buffer(data.wireEncode().wire(),
Davide Pesaventod8d4d982014-03-21 18:47:58 +010049 data.wireEncode().size()),
Giulio Grassi624f6c62014-02-18 19:42:14 +010050 m_multicastGroup,
51 bind(&DatagramFace<protocol>::handleSend, this, _1, data.wireEncode()));
Davide Pesaventod8d4d982014-03-21 18:47:58 +010052
Giulio Grassi624f6c62014-02-18 19:42:14 +010053 // anything else should be done here?
54}
Davide Pesaventod8d4d982014-03-21 18:47:58 +010055
Giulio Grassi624f6c62014-02-18 19:42:14 +010056bool
57MulticastUdpFace::isMultiAccess() const
58{
59 return true;
60}
61
62} // namespace nfd