blob: 5630141d7cd8d4e73d882a81ec6081644adc507c [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +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 **/
Davide Pesavento44deacc2014-02-19 10:48:07 +010024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
26#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
Davide Pesavento44deacc2014-02-19 10:48:07 +010027
28#include "ethernet-face.hpp"
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080029#include "protocol-factory.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010030
31namespace nfd {
32
Davide Pesaventob60cc122014-03-19 19:26:02 +010033class NetworkInterfaceInfo;
34
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080035class EthernetFactory : public ProtocolFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010036{
37public:
38 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080039 * \brief Exception of EthernetFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010040 */
Alexander Afanasyev5959b012014-06-02 19:18:12 +030041 class Error : public ProtocolFactory::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010042 {
Alexander Afanasyev5959b012014-06-02 19:18:12 +030043 public:
44 explicit
45 Error(const std::string& what)
46 : ProtocolFactory::Error(what)
47 {
48 }
Davide Pesavento44deacc2014-02-19 10:48:07 +010049 };
50
Alexander Afanasyev5959b012014-06-02 19:18:12 +030051 typedef std::map< std::pair<std::string, ethernet::Address>,
52 shared_ptr<EthernetFace> > MulticastFaceMap;
53
Davide Pesaventob60cc122014-03-19 19:26:02 +010054 // from ProtocolFactory
55 virtual void
56 createFace(const FaceUri& uri,
57 const FaceCreatedCallback& onCreated,
58 const FaceConnectFailedCallback& onConnectFailed);
59
Davide Pesavento44deacc2014-02-19 10:48:07 +010060 /**
61 * \brief Create an EthernetFace to communicate with the given multicast group
62 *
Davide Pesaventob60cc122014-03-19 19:26:02 +010063 * If this method is called twice with the same interface and group, only
Davide Pesavento44deacc2014-02-19 10:48:07 +010064 * one face will be created. Instead, the second call will just retrieve
65 * the existing face.
66 *
67 * \param interface Local network interface
68 * \param address Ethernet broadcast/multicast destination address
69 *
70 * \returns always a valid shared pointer to an EthernetFace object,
71 * an exception will be thrown if the creation fails
72 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080073 * \throws EthernetFactory::Error or EthernetFace::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010074 */
75 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +010076 createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface,
Alexander Afanasyevd6655302014-02-28 08:41:28 -080077 const ethernet::Address& address);
Davide Pesavento44deacc2014-02-19 10:48:07 +010078
Alexander Afanasyev5959b012014-06-02 19:18:12 +030079 /**
80 * \brief Get map of configured multicast faces
81 */
82 const MulticastFaceMap&
83 getMulticastFaces() const;
84
Davide Pesavento44deacc2014-02-19 10:48:07 +010085private:
86 void
Davide Pesaventob60cc122014-03-19 19:26:02 +010087 afterFaceFailed(const std::string& interfaceName,
Davide Pesavento44deacc2014-02-19 10:48:07 +010088 const ethernet::Address& address);
89
90 /**
91 * \brief Look up EthernetFace using specified interface and address
92 *
93 * \returns shared pointer to the existing EthernetFace object or
94 * empty shared pointer when such face does not exist
95 *
96 * \throws never
97 */
98 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +010099 findMulticastFace(const std::string& interfaceName,
Alexander Afanasyevd6655302014-02-28 08:41:28 -0800100 const ethernet::Address& address) const;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100101
102private:
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300103 MulticastFaceMap m_multicastFaces;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100104};
105
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300106
107inline const EthernetFactory::MulticastFaceMap&
108EthernetFactory::getMulticastFaces() const
109{
110 return m_multicastFaces;
111}
112
113
Davide Pesavento44deacc2014-02-19 10:48:07 +0100114} // namespace nfd
115
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700116#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP