blob: 4f655bd2eca25b4d04a0035a76eb565bbeac7547 [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
7#ifndef NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
8#define NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP
9
10#include "ethernet-face.hpp"
11
12namespace nfd {
13
14class EthernetChannelFactory
15{
16public:
17 /**
18 * \brief Exception of EthernetChannelFactory
19 */
20 struct Error : public std::runtime_error
21 {
22 Error(const std::string& what) : std::runtime_error(what) {}
23 };
24
25 /**
26 * \brief Create an EthernetFace to communicate with the given multicast group
27 *
28 * If this method is called twice with the same endpoint and group, only
29 * one face will be created. Instead, the second call will just retrieve
30 * the existing face.
31 *
32 * \param interface Local network interface
33 * \param address Ethernet broadcast/multicast destination address
34 *
35 * \returns always a valid shared pointer to an EthernetFace object,
36 * an exception will be thrown if the creation fails
37 *
38 * \throws EthernetChannelFactory::Error or EthernetFace::Error
39 */
40 shared_ptr<EthernetFace>
41 createMulticast(const ethernet::Endpoint& interface,
42 const ethernet::Address& address);
43
44 /**
45 * \brief Get a list of devices that can be opened for a live capture
46 *
47 * This function is a wrapper for pcap_findalldevs()/pcap_freealldevs()
48 */
49 static std::vector<ethernet::Endpoint>
50 findAllInterfaces();
51
52private:
53 void
54 afterFaceFailed(const ethernet::Endpoint& endpoint,
55 const ethernet::Address& address);
56
57 /**
58 * \brief Look up EthernetFace using specified interface and address
59 *
60 * \returns shared pointer to the existing EthernetFace object or
61 * empty shared pointer when such face does not exist
62 *
63 * \throws never
64 */
65 shared_ptr<EthernetFace>
66 findMulticast(const ethernet::Endpoint& interface,
67 const ethernet::Address& address) const;
68
69private:
70 typedef std::map< std::pair<ethernet::Endpoint, ethernet::Address>,
71 shared_ptr<EthernetFace> > MulticastFacesMap;
72 MulticastFacesMap m_multicastFaces;
73};
74
75} // namespace nfd
76
77#endif // NFD_FACE_ETHERNET_CHANNEL_FACTORY_HPP