blob: b8e45112963d0c8af39153bd272cb6544256e16f [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- 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 Afanasyev0eb70652014-02-27 18:35:07 -08007#ifndef NFD_FACE_ETHERNET_FACTORY_HPP
8#define NFD_FACE_ETHERNET_FACTORY_HPP
Davide Pesavento44deacc2014-02-19 10:48:07 +01009
10#include "ethernet-face.hpp"
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080011#include "protocol-factory.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010012
13namespace nfd {
14
Davide Pesaventob60cc122014-03-19 19:26:02 +010015class NetworkInterfaceInfo;
16
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080017class EthernetFactory : public ProtocolFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010018{
19public:
20 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080021 * \brief Exception of EthernetFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010022 */
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080023 struct Error : public ProtocolFactory::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010024 {
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080025 Error(const std::string& what) : ProtocolFactory::Error(what) {}
Davide Pesavento44deacc2014-02-19 10:48:07 +010026 };
27
Davide Pesaventob60cc122014-03-19 19:26:02 +010028 // from ProtocolFactory
29 virtual void
30 createFace(const FaceUri& uri,
31 const FaceCreatedCallback& onCreated,
32 const FaceConnectFailedCallback& onConnectFailed);
33
Davide Pesavento44deacc2014-02-19 10:48:07 +010034 /**
35 * \brief Create an EthernetFace to communicate with the given multicast group
36 *
Davide Pesaventob60cc122014-03-19 19:26:02 +010037 * If this method is called twice with the same interface and group, only
Davide Pesavento44deacc2014-02-19 10:48:07 +010038 * one face will be created. Instead, the second call will just retrieve
39 * the existing face.
40 *
41 * \param interface Local network interface
42 * \param address Ethernet broadcast/multicast destination address
43 *
44 * \returns always a valid shared pointer to an EthernetFace object,
45 * an exception will be thrown if the creation fails
46 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080047 * \throws EthernetFactory::Error or EthernetFace::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010048 */
49 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +010050 createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface,
Alexander Afanasyevd6655302014-02-28 08:41:28 -080051 const ethernet::Address& address);
Davide Pesavento44deacc2014-02-19 10:48:07 +010052
Davide Pesavento44deacc2014-02-19 10:48:07 +010053private:
54 void
Davide Pesaventob60cc122014-03-19 19:26:02 +010055 afterFaceFailed(const std::string& interfaceName,
Davide Pesavento44deacc2014-02-19 10:48:07 +010056 const ethernet::Address& address);
57
58 /**
59 * \brief Look up EthernetFace using specified interface and address
60 *
61 * \returns shared pointer to the existing EthernetFace object or
62 * empty shared pointer when such face does not exist
63 *
64 * \throws never
65 */
66 shared_ptr<EthernetFace>
Davide Pesaventob60cc122014-03-19 19:26:02 +010067 findMulticastFace(const std::string& interfaceName,
Alexander Afanasyevd6655302014-02-28 08:41:28 -080068 const ethernet::Address& address) const;
Davide Pesavento44deacc2014-02-19 10:48:07 +010069
70private:
Davide Pesaventob60cc122014-03-19 19:26:02 +010071 typedef std::map< std::pair<std::string, ethernet::Address>,
Davide Pesavento44deacc2014-02-19 10:48:07 +010072 shared_ptr<EthernetFace> > MulticastFacesMap;
73 MulticastFacesMap m_multicastFaces;
74};
75
76} // namespace nfd
77
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080078#endif // NFD_FACE_ETHERNET_FACTORY_HPP