blob: b7d5ec0c48f572e5480f11eb255bca6382cfbcba [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shia1937bf2014-11-06 11:43:40 -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 * 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
29#include "ethernet-face.hpp"
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080030#include "protocol-factory.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010031
32namespace nfd {
33
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080034class EthernetFactory : public ProtocolFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010035{
36public:
37 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080038 * \brief Exception of EthernetFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010039 */
Alexander Afanasyev5959b012014-06-02 19:18:12 +030040 class Error : public ProtocolFactory::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010041 {
Alexander Afanasyev5959b012014-06-02 19:18:12 +030042 public:
43 explicit
44 Error(const std::string& what)
45 : ProtocolFactory::Error(what)
46 {
47 }
Davide Pesavento44deacc2014-02-19 10:48:07 +010048 };
49
Alexander Afanasyev5959b012014-06-02 19:18:12 +030050 typedef std::map< std::pair<std::string, ethernet::Address>,
51 shared_ptr<EthernetFace> > MulticastFaceMap;
52
Davide Pesaventob60cc122014-03-19 19:26:02 +010053 // from ProtocolFactory
54 virtual void
55 createFace(const FaceUri& uri,
56 const FaceCreatedCallback& onCreated,
57 const FaceConnectFailedCallback& onConnectFailed);
58
Davide Pesavento44deacc2014-02-19 10:48:07 +010059 /**
60 * \brief Create an EthernetFace to communicate with the given multicast group
61 *
Davide Pesaventob60cc122014-03-19 19:26:02 +010062 * If this method is called twice with the same interface and group, only
Davide Pesavento44deacc2014-02-19 10:48:07 +010063 * one face will be created. Instead, the second call will just retrieve
64 * the existing face.
65 *
66 * \param interface Local network interface
67 * \param address Ethernet broadcast/multicast destination address
68 *
69 * \returns always a valid shared pointer to an EthernetFace object,
70 * an exception will be thrown if the creation fails
71 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080072 * \throws EthernetFactory::Error or EthernetFace::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010073 */
74 shared_ptr<EthernetFace>
Davide Pesaventob499a602014-11-18 22:36:56 +010075 createMulticastFace(const NetworkInterfaceInfo& interface,
Alexander Afanasyevd6655302014-02-28 08:41:28 -080076 const ethernet::Address& address);
Davide Pesavento44deacc2014-02-19 10:48:07 +010077
Alexander Afanasyev5959b012014-06-02 19:18:12 +030078 /**
79 * \brief Get map of configured multicast faces
80 */
81 const MulticastFaceMap&
82 getMulticastFaces() const;
83
Steve DiBenedettoef04f272014-06-04 14:28:31 -060084 virtual std::list<shared_ptr<const Channel> >
85 getChannels() const;
86
Davide Pesavento44deacc2014-02-19 10:48:07 +010087private:
88 void
Davide Pesaventob60cc122014-03-19 19:26:02 +010089 afterFaceFailed(const std::string& interfaceName,
Davide Pesavento44deacc2014-02-19 10:48:07 +010090 const ethernet::Address& address);
91
92 /**
93 * \brief Look up EthernetFace using specified interface and address
94 *
95 * \returns shared pointer to the existing EthernetFace object or
96 * empty shared pointer when such face does not exist
97 *
98 * \throws never
99 */
100 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +0100101 findMulticastFace(const std::string& interfaceName,
Alexander Afanasyevd6655302014-02-28 08:41:28 -0800102 const ethernet::Address& address) const;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100103
104private:
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300105 MulticastFaceMap m_multicastFaces;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100106};
107
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300108
109inline const EthernetFactory::MulticastFaceMap&
110EthernetFactory::getMulticastFaces() const
111{
112 return m_multicastFaces;
113}
114
115
Davide Pesavento44deacc2014-02-19 10:48:07 +0100116} // namespace nfd
117
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700118#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP