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 | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * 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, |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 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/>. |
| 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 | |
| 29 | #include "ethernet-face.hpp" |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 30 | #include "protocol-factory.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 34 | class NetworkInterfaceInfo; |
| 35 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 36 | class EthernetFactory : public ProtocolFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | /** |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 40 | * \brief Exception of EthernetFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 41 | */ |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 42 | class Error : public ProtocolFactory::Error |
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 | public: |
| 45 | explicit |
| 46 | Error(const std::string& what) |
| 47 | : ProtocolFactory::Error(what) |
| 48 | { |
| 49 | } |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 52 | typedef std::map< std::pair<std::string, ethernet::Address>, |
| 53 | shared_ptr<EthernetFace> > MulticastFaceMap; |
| 54 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 55 | // from ProtocolFactory |
| 56 | virtual void |
| 57 | createFace(const FaceUri& uri, |
| 58 | const FaceCreatedCallback& onCreated, |
| 59 | const FaceConnectFailedCallback& onConnectFailed); |
| 60 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 61 | /** |
| 62 | * \brief Create an EthernetFace to communicate with the given multicast group |
| 63 | * |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 64 | * 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] | 65 | * one face will be created. Instead, the second call will just retrieve |
| 66 | * the existing face. |
| 67 | * |
| 68 | * \param interface Local network interface |
| 69 | * \param address Ethernet broadcast/multicast destination address |
| 70 | * |
| 71 | * \returns always a valid shared pointer to an EthernetFace object, |
| 72 | * an exception will be thrown if the creation fails |
| 73 | * |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 74 | * \throws EthernetFactory::Error or EthernetFace::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 75 | */ |
| 76 | shared_ptr<EthernetFace> |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 77 | createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 78 | const ethernet::Address& address); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 79 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 80 | /** |
| 81 | * \brief Get map of configured multicast faces |
| 82 | */ |
| 83 | const MulticastFaceMap& |
| 84 | getMulticastFaces() const; |
| 85 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 86 | virtual std::list<shared_ptr<const Channel> > |
| 87 | getChannels() const; |
| 88 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 89 | private: |
| 90 | void |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 91 | afterFaceFailed(const std::string& interfaceName, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 92 | const ethernet::Address& address); |
| 93 | |
| 94 | /** |
| 95 | * \brief Look up EthernetFace using specified interface and address |
| 96 | * |
| 97 | * \returns shared pointer to the existing EthernetFace object or |
| 98 | * empty shared pointer when such face does not exist |
| 99 | * |
| 100 | * \throws never |
| 101 | */ |
| 102 | shared_ptr<EthernetFace> |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 103 | findMulticastFace(const std::string& interfaceName, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 104 | const ethernet::Address& address) const; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 105 | |
| 106 | private: |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 107 | MulticastFaceMap m_multicastFaces; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 108 | }; |
| 109 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 110 | |
| 111 | inline const EthernetFactory::MulticastFaceMap& |
| 112 | EthernetFactory::getMulticastFaces() const |
| 113 | { |
| 114 | return m_multicastFaces; |
| 115 | } |
| 116 | |
| 117 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 118 | } // namespace nfd |
| 119 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 120 | #endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP |