Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #ifndef NFD_FACE_ETHERNET_FACTORY_HPP |
| 8 | #define NFD_FACE_ETHERNET_FACTORY_HPP |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 9 | |
| 10 | #include "ethernet-face.hpp" |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 11 | #include "protocol-factory.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
| 14 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 15 | class EthernetFactory : public ProtocolFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 16 | { |
| 17 | public: |
| 18 | /** |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 19 | * \brief Exception of EthernetFactory |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 21 | struct Error : public ProtocolFactory::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 22 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 23 | Error(const std::string& what) : ProtocolFactory::Error(what) {} |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * \brief Create an EthernetFace to communicate with the given multicast group |
| 28 | * |
| 29 | * If this method is called twice with the same endpoint and group, only |
| 30 | * one face will be created. Instead, the second call will just retrieve |
| 31 | * the existing face. |
| 32 | * |
| 33 | * \param interface Local network interface |
| 34 | * \param address Ethernet broadcast/multicast destination address |
| 35 | * |
| 36 | * \returns always a valid shared pointer to an EthernetFace object, |
| 37 | * an exception will be thrown if the creation fails |
| 38 | * |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 39 | * \throws EthernetFactory::Error or EthernetFace::Error |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 40 | */ |
| 41 | shared_ptr<EthernetFace> |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 42 | createMulticastFace(const ethernet::Endpoint& interface, |
| 43 | const ethernet::Address& address); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * \brief Get a list of devices that can be opened for a live capture |
| 47 | * |
| 48 | * This function is a wrapper for pcap_findalldevs()/pcap_freealldevs() |
| 49 | */ |
| 50 | static std::vector<ethernet::Endpoint> |
| 51 | findAllInterfaces(); |
| 52 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 53 | // from Factory |
| 54 | |
| 55 | virtual void |
| 56 | createFace(const FaceUri& uri, |
| 57 | const FaceCreatedCallback& onCreated, |
| 58 | const FaceConnectFailedCallback& onConnectFailed); |
| 59 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 60 | private: |
| 61 | void |
| 62 | afterFaceFailed(const ethernet::Endpoint& endpoint, |
| 63 | const ethernet::Address& address); |
| 64 | |
| 65 | /** |
| 66 | * \brief Look up EthernetFace using specified interface and address |
| 67 | * |
| 68 | * \returns shared pointer to the existing EthernetFace object or |
| 69 | * empty shared pointer when such face does not exist |
| 70 | * |
| 71 | * \throws never |
| 72 | */ |
| 73 | shared_ptr<EthernetFace> |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 74 | findMulticastFace(const ethernet::Endpoint& interface, |
| 75 | const ethernet::Address& address) const; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | typedef std::map< std::pair<ethernet::Endpoint, ethernet::Address>, |
| 79 | shared_ptr<EthernetFace> > MulticastFacesMap; |
| 80 | MulticastFacesMap m_multicastFaces; |
| 81 | }; |
| 82 | |
| 83 | } // namespace nfd |
| 84 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 85 | #endif // NFD_FACE_ETHERNET_FACTORY_HPP |