Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 24 | */ |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP |
| 27 | #define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 28 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 29 | #include "protocol-factory.hpp" |
Alexander Afanasyev | eae4f80 | 2015-01-05 17:28:15 -0800 | [diff] [blame] | 30 | #include "core/network-interface.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame^] | 34 | namespace face { |
| 35 | class LpFaceWrapper; |
| 36 | } // namespace face |
Alexander Afanasyev | eae4f80 | 2015-01-05 17:28:15 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 38 | class EthernetFactory : public ProtocolFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | /** |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 42 | * \brief Exception of EthernetFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 43 | */ |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 44 | class Error : public ProtocolFactory::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 45 | { |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 46 | public: |
| 47 | explicit |
| 48 | Error(const std::string& what) |
| 49 | : ProtocolFactory::Error(what) |
| 50 | { |
| 51 | } |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
Davide Pesavento | 7726ae5 | 2014-11-23 21:01:05 +0100 | [diff] [blame] | 54 | typedef std::map<std::pair<std::string, ethernet::Address>, |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame^] | 55 | shared_ptr<face::LpFaceWrapper>> MulticastFaceMap; |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 56 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 57 | /** |
| 58 | * \brief Create an EthernetFace to communicate with the given multicast group |
| 59 | * |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 60 | * If this method is called twice with the same interface and group, only |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 61 | * one face will be created. Instead, the second call will just retrieve |
| 62 | * the existing face. |
| 63 | * |
| 64 | * \param interface Local network interface |
| 65 | * \param address Ethernet broadcast/multicast destination address |
| 66 | * |
| 67 | * \returns always a valid shared pointer to an EthernetFace object, |
| 68 | * an exception will be thrown if the creation fails |
| 69 | * |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame^] | 70 | * \throws EthernetFactory::Error or EthernetTransport::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 71 | */ |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame^] | 72 | shared_ptr<face::LpFaceWrapper> |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame] | 73 | createMulticastFace(const NetworkInterfaceInfo& interface, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 74 | const ethernet::Address& address); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 75 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 76 | /** |
| 77 | * \brief Get map of configured multicast faces |
| 78 | */ |
| 79 | const MulticastFaceMap& |
| 80 | getMulticastFaces() const; |
| 81 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 82 | public: // from ProtocolFactory |
| 83 | virtual void |
| 84 | createFace(const FaceUri& uri, |
| 85 | ndn::nfd::FacePersistency persistency, |
| 86 | const FaceCreatedCallback& onCreated, |
| 87 | const FaceCreationFailedCallback& onConnectFailed) DECL_OVERRIDE; |
| 88 | |
| 89 | virtual std::vector<shared_ptr<const Channel>> |
Alexander Afanasyev | 435d705 | 2015-09-17 15:10:25 -0700 | [diff] [blame] | 90 | getChannels() const DECL_OVERRIDE; |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 91 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 92 | private: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 93 | /** |
| 94 | * \brief Look up EthernetFace using specified interface and address |
| 95 | * |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 96 | * \returns shared pointer to the existing EthernetFace object |
| 97 | * or nullptr when such face does not exist |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 98 | */ |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame^] | 99 | shared_ptr<face::LpFaceWrapper> |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 100 | findMulticastFace(const std::string& interfaceName, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 101 | const ethernet::Address& address) const; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 102 | |
| 103 | private: |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 104 | MulticastFaceMap m_multicastFaces; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 107 | inline const EthernetFactory::MulticastFaceMap& |
| 108 | EthernetFactory::getMulticastFaces() const |
| 109 | { |
| 110 | return m_multicastFaces; |
| 111 | } |
| 112 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 113 | } // namespace nfd |
| 114 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 115 | #endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP |