blob: d676f470c2a77821a3495445dd7f319fa1c8c32a [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
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080015class EthernetFactory : public ProtocolFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010016{
17public:
18 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080019 * \brief Exception of EthernetFactory
Davide Pesavento44deacc2014-02-19 10:48:07 +010020 */
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080021 struct Error : public ProtocolFactory::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010022 {
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080023 Error(const std::string& what) : ProtocolFactory::Error(what) {}
Davide Pesavento44deacc2014-02-19 10:48:07 +010024 };
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 Afanasyev0eb70652014-02-27 18:35:07 -080039 * \throws EthernetFactory::Error or EthernetFace::Error
Davide Pesavento44deacc2014-02-19 10:48:07 +010040 */
41 shared_ptr<EthernetFace>
42 createMulticast(const ethernet::Endpoint& interface,
43 const ethernet::Address& address);
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
53private:
54 void
55 afterFaceFailed(const ethernet::Endpoint& endpoint,
56 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>
67 findMulticast(const ethernet::Endpoint& interface,
68 const ethernet::Address& address) const;
69
70private:
71 typedef std::map< std::pair<ethernet::Endpoint, ethernet::Address>,
72 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