30 #include <boost/range/adaptors.hpp>
31 #include <boost/range/algorithm/copy.hpp>
42 static std::string id(
"ether");
64 MulticastConfig mcastConfig;
68 mcastConfig.isEnabled =
true;
70 for (
const auto& pair : *configSection) {
71 const std::string& key = pair.first;
77 else if (key ==
"mcast_group") {
78 const std::string& valueStr = value.get_value<std::string>();
79 mcastConfig.group = ethernet::Address::fromString(valueStr);
80 if (mcastConfig.group.isNull()) {
82 valueStr +
"' cannot be parsed as an Ethernet address"));
84 else if (!mcastConfig.group.isMulticast()) {
86 valueStr +
"' is not a multicast address"));
89 else if (key ==
"whitelist") {
90 mcastConfig.netifPredicate.parseWhitelist(value);
92 else if (key ==
"blacklist") {
93 mcastConfig.netifPredicate.parseBlacklist(value);
96 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option face_system.ether." + key));
102 if (m_mcastConfig.isEnabled != mcastConfig.isEnabled) {
103 if (mcastConfig.isEnabled) {
104 NFD_LOG_INFO(
"enabling multicast on " << mcastConfig.group);
110 else if (m_mcastConfig.group != mcastConfig.group) {
111 NFD_LOG_INFO(
"changing multicast group from " << m_mcastConfig.group <<
112 " to " << mcastConfig.group);
114 else if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
122 m_mcastConfig = mcastConfig;
123 this->applyConfig(context);
129 ndn::nfd::FacePersistency persistency,
130 bool wantLocalFieldsEnabled,
134 onFailure(406,
"Unsupported protocol");
137 std::vector<shared_ptr<const Channel>>
145 const ethernet::Address& address)
147 BOOST_ASSERT(address.isMulticast());
149 auto key = std::make_pair(netif.
name, address);
150 auto found = m_mcastFaces.find(key);
151 if (found != m_mcastFaces.end()) {
152 return found->second;
159 auto linkService = make_unique<face::GenericLinkService>(opts);
160 auto transport = make_unique<face::EthernetTransport>(netif, address);
161 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
163 m_mcastFaces[key] = face;
170 EthernetFactory::applyConfig(
const FaceSystem::ConfigContext& context)
173 std::set<shared_ptr<Face>> oldFaces;
174 boost::copy(m_mcastFaces | boost::adaptors::map_values,
175 std::inserter(oldFaces, oldFaces.end()));
177 if (m_mcastConfig.isEnabled) {
179 auto capableNetifs = context.listNetifs() |
180 boost::adaptors::filtered([
this] (
const NetworkInterfaceInfo& netif) {
181 return netif.isUp() && netif.isMulticastCapable() &&
182 m_mcastConfig.netifPredicate(netif);
186 for (
const auto& netif : capableNetifs) {
187 shared_ptr<Face> face;
189 face = this->createMulticastFace(netif, m_mcastConfig.group);
191 catch (
const EthernetTransport::Error& e) {
192 NFD_LOG_ERROR(
"Cannot create Ethernet multicast face on " << netif.name <<
": " <<
193 e.what() <<
", continuing");
199 context.addFace(face);
203 oldFaces.erase(face);
209 for (
const auto& face : oldFaces) {
contains information about a network interface
bool allowFragmentation
enables fragmentation
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
std::vector< shared_ptr< const Channel > > getChannels() const override
#define NFD_LOG_ERROR(expression)
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
#define NFD_REGISTER_PROTOCOL_FACTORY(PF)
registers a protocol factory
context for processing a config section in ProtocolFactory
#define NFD_LOG_INFO(expression)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
static const std::string & getId()
boost::property_tree::ptree ConfigSection
a config file section
void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
unicast face creation is not supported and will always fail
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Options that control the behavior of GenericLinkService.
#define NFD_LOG_INIT(name)
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context) override
process face_system.ether config section
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
const FaceId INVALID_FACEID
indicates an invalid FaceId
bool allowReassembly
enables reassembly