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