blob: 7f53cff6a2ad866ac082de02724eb157b6439a6b [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
#define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
#include "protocol-factory.hpp"
#include "ethernet-channel.hpp"
namespace nfd {
namespace face {
/** \brief protocol factory for Ethernet
*/
class EthernetFactory : public ProtocolFactory
{
public:
static const std::string&
getId();
explicit
EthernetFactory(const CtorParams& params);
/** \brief process face_system.ether config section
*/
void
processConfig(OptionalConfigSection configSection,
FaceSystem::ConfigContext& context) override;
void
createFace(const CreateFaceParams& params,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onFailure) override;
/**
* \brief Create Ethernet-based channel on the specified network interface
*
* If this method is called twice with the same endpoint, only one channel
* will be created. The second call will just return the existing channel.
*
* \return always a valid pointer to a EthernetChannel object, an exception
* is thrown if it cannot be created.
* \throw PcapHelper::Error channel creation failed
*/
shared_ptr<EthernetChannel>
createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
time::nanoseconds idleTimeout);
std::vector<shared_ptr<const Channel>>
getChannels() const override;
/**
* \brief Create a face to communicate on the given Ethernet multicast group
*
* If this method is called twice with the same arguments, only one face
* will be created. The second call will just return the existing face.
*
* \param localEndpoint local network interface
* \param group multicast group address
*
* \throw EthernetTransport::Error transport creation fails
*/
shared_ptr<Face>
createMulticastFace(const ndn::net::NetworkInterface& localEndpoint,
const ethernet::Address& group);
private:
/** \brief Create EthernetChannel on \p netif if requested by \p m_unicastConfig.
* \return new or existing channel, or nullptr if no channel should be created
*/
shared_ptr<EthernetChannel>
applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif);
/** \brief Create Ethernet multicast face on \p netif if requested by \p m_mcastConfig.
* \return new or existing face, or nullptr if no face should be created
*/
shared_ptr<Face>
applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif);
void
applyConfig(const FaceSystem::ConfigContext& context);
private:
std::map<std::string, shared_ptr<EthernetChannel>> m_channels; ///< ifname => channel
struct UnicastConfig
{
bool isEnabled = false;
bool wantListen = false;
time::nanoseconds idleTimeout = time::seconds(600);
};
UnicastConfig m_unicastConfig;
struct MulticastConfig
{
bool isEnabled = false;
ethernet::Address group = ethernet::getDefaultMulticastAddress();
ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS;
NetworkInterfacePredicate netifPredicate;
};
MulticastConfig m_mcastConfig;
/// (ifname, group) => face
std::map<std::pair<std::string, ethernet::Address>, shared_ptr<Face>> m_mcastFaces;
signal::ScopedConnection m_netifAddConn;
};
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP