blob: 5b1666c4b2371a32990fb242be5da9db3c17deb8 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * Copyright (c) 2014-2015, 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 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shia1937bf2014-11-06 11:43:40 -070024 */
Davide Pesavento44deacc2014-02-19 10:48:07 +010025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
27#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
Davide Pesavento44deacc2014-02-19 10:48:07 +010028
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080029#include "protocol-factory.hpp"
Alexander Afanasyeveae4f802015-01-05 17:28:15 -080030#include "core/network-interface.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010031
32namespace nfd {
33
Alexander Afanasyeveae4f802015-01-05 17:28:15 -080034class EthernetFace;
35
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080036class EthernetFactory : public ProtocolFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010037{
38public:
39 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080040 * \brief Exception of EthernetFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010041 */
Alexander Afanasyev5959b012014-06-02 19:18:12 +030042 class Error : public ProtocolFactory::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010043 {
Alexander Afanasyev5959b012014-06-02 19:18:12 +030044 public:
45 explicit
46 Error(const std::string& what)
47 : ProtocolFactory::Error(what)
48 {
49 }
Davide Pesavento44deacc2014-02-19 10:48:07 +010050 };
51
Davide Pesavento7726ae52014-11-23 21:01:05 +010052 typedef std::map<std::pair<std::string, ethernet::Address>,
53 shared_ptr<EthernetFace>> MulticastFaceMap;
Alexander Afanasyev5959b012014-06-02 19:18:12 +030054
Davide Pesaventob60cc122014-03-19 19:26:02 +010055 // from ProtocolFactory
56 virtual void
57 createFace(const FaceUri& uri,
Yukai Tu7c90e6d2015-07-11 12:21:46 +080058 ndn::nfd::FacePersistency persistency,
Davide Pesaventob60cc122014-03-19 19:26:02 +010059 const FaceCreatedCallback& onCreated,
Yukai Tu7c90e6d2015-07-11 12:21:46 +080060 const FaceConnectFailedCallback& onConnectFailed) DECL_OVERRIDE;
Davide Pesaventob60cc122014-03-19 19:26:02 +010061
Davide Pesavento44deacc2014-02-19 10:48:07 +010062 /**
63 * \brief Create an EthernetFace to communicate with the given multicast group
64 *
Davide Pesaventob60cc122014-03-19 19:26:02 +010065 * If this method is called twice with the same interface and group, only
Davide Pesavento44deacc2014-02-19 10:48:07 +010066 * one face will be created. Instead, the second call will just retrieve
67 * the existing face.
68 *
69 * \param interface Local network interface
70 * \param address Ethernet broadcast/multicast destination address
71 *
72 * \returns always a valid shared pointer to an EthernetFace object,
73 * an exception will be thrown if the creation fails
74 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080075 * \throws EthernetFactory::Error or EthernetFace::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010076 */
77 shared_ptr<EthernetFace>
Davide Pesaventob499a602014-11-18 22:36:56 +010078 createMulticastFace(const NetworkInterfaceInfo& interface,
Alexander Afanasyevd6655302014-02-28 08:41:28 -080079 const ethernet::Address& address);
Davide Pesavento44deacc2014-02-19 10:48:07 +010080
Alexander Afanasyev5959b012014-06-02 19:18:12 +030081 /**
82 * \brief Get map of configured multicast faces
83 */
84 const MulticastFaceMap&
85 getMulticastFaces() const;
86
Davide Pesavento7726ae52014-11-23 21:01:05 +010087 virtual std::list<shared_ptr<const Channel>>
Alexander Afanasyev435d7052015-09-17 15:10:25 -070088 getChannels() const DECL_OVERRIDE;
Steve DiBenedettoef04f272014-06-04 14:28:31 -060089
Davide Pesavento44deacc2014-02-19 10:48:07 +010090private:
Davide Pesavento44deacc2014-02-19 10:48:07 +010091 /**
92 * \brief Look up EthernetFace using specified interface and address
93 *
94 * \returns shared pointer to the existing EthernetFace object or
95 * empty shared pointer when such face does not exist
96 *
97 * \throws never
98 */
99 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +0100100 findMulticastFace(const std::string& interfaceName,
Alexander Afanasyevd6655302014-02-28 08:41:28 -0800101 const ethernet::Address& address) const;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100102
103private:
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300104 MulticastFaceMap m_multicastFaces;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100105};
106
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300107inline const EthernetFactory::MulticastFaceMap&
108EthernetFactory::getMulticastFaces() const
109{
110 return m_multicastFaces;
111}
112
Davide Pesavento44deacc2014-02-19 10:48:07 +0100113} // namespace nfd
114
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700115#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP