Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 25 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 26 | #include "ethernet-factory.hpp" |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 27 | #include "generic-link-service.hpp" |
Davide Pesavento | 6bd6d0b | 2017-03-25 15:16:40 -0400 | [diff] [blame] | 28 | #include "multicast-ethernet-transport.hpp" |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 29 | #include <boost/range/adaptors.hpp> |
| 30 | #include <boost/range/algorithm/copy.hpp> |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 31 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 33 | namespace face { |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 34 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 35 | NFD_LOG_INIT("EthernetFactory"); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 36 | NFD_REGISTER_PROTOCOL_FACTORY(EthernetFactory); |
| 37 | |
| 38 | const std::string& |
| 39 | EthernetFactory::getId() |
| 40 | { |
| 41 | static std::string id("ether"); |
| 42 | return id; |
| 43 | } |
| 44 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 45 | EthernetFactory::EthernetFactory(const CtorParams& params) |
| 46 | : ProtocolFactory(params) |
| 47 | { |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 48 | m_netifAddConn = netmon->onInterfaceAdded.connect( |
| 49 | [this] (const shared_ptr<const ndn::net::NetworkInterface>& netif) { |
| 50 | this->applyUnicastConfigToNetif(netif); |
| 51 | this->applyMcastConfigToNetif(*netif); |
| 52 | }); |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 53 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 54 | |
| 55 | void |
| 56 | EthernetFactory::processConfig(OptionalConfigSection configSection, |
| 57 | FaceSystem::ConfigContext& context) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 58 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 59 | // ether |
| 60 | // { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 61 | // listen yes |
| 62 | // idle_timeout 600 |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 63 | // mcast yes |
| 64 | // mcast_group 01:00:5E:00:17:AA |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 65 | // mcast_ad_hoc no |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 66 | // whitelist |
| 67 | // { |
| 68 | // * |
| 69 | // } |
| 70 | // blacklist |
| 71 | // { |
| 72 | // } |
| 73 | // } |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 74 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 75 | UnicastConfig unicastConfig; |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 76 | MulticastConfig mcastConfig; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 77 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 78 | if (configSection) { |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 79 | // listen and mcast default to 'yes' but only if face_system.ether section is present |
| 80 | unicastConfig.isEnabled = unicastConfig.wantListen = mcastConfig.isEnabled = true; |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 81 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 82 | for (const auto& pair : *configSection) { |
| 83 | const std::string& key = pair.first; |
| 84 | const ConfigSection& value = pair.second; |
Davide Pesavento | 7726ae5 | 2014-11-23 21:01:05 +0100 | [diff] [blame] | 85 | |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 86 | if (key == "listen") { |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 87 | unicastConfig.wantListen = ConfigFile::parseYesNo(pair, "face_system.ether"); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 88 | } |
| 89 | else if (key == "idle_timeout") { |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 90 | unicastConfig.idleTimeout = time::seconds(ConfigFile::parseNumber<uint32_t>(pair, "face_system.ether")); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 91 | } |
| 92 | else if (key == "mcast") { |
| 93 | mcastConfig.isEnabled = ConfigFile::parseYesNo(pair, "face_system.ether"); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 94 | } |
| 95 | else if (key == "mcast_group") { |
| 96 | const std::string& valueStr = value.get_value<std::string>(); |
| 97 | mcastConfig.group = ethernet::Address::fromString(valueStr); |
| 98 | if (mcastConfig.group.isNull()) { |
| 99 | BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.ether.mcast_group: '" + |
| 100 | valueStr + "' cannot be parsed as an Ethernet address")); |
| 101 | } |
| 102 | else if (!mcastConfig.group.isMulticast()) { |
| 103 | BOOST_THROW_EXCEPTION(ConfigFile::Error("face_system.ether.mcast_group: '" + |
| 104 | valueStr + "' is not a multicast address")); |
| 105 | } |
| 106 | } |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 107 | else if (key == "mcast_ad_hoc") { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 108 | bool wantAdHoc = ConfigFile::parseYesNo(pair, "face_system.ether"); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 109 | mcastConfig.linkType = wantAdHoc ? ndn::nfd::LINK_TYPE_AD_HOC : ndn::nfd::LINK_TYPE_MULTI_ACCESS; |
| 110 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 111 | else if (key == "whitelist") { |
| 112 | mcastConfig.netifPredicate.parseWhitelist(value); |
| 113 | } |
| 114 | else if (key == "blacklist") { |
| 115 | mcastConfig.netifPredicate.parseBlacklist(value); |
| 116 | } |
| 117 | else { |
| 118 | BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option face_system.ether." + key)); |
| 119 | } |
| 120 | } |
| 121 | } |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 122 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 123 | if (context.isDryRun) { |
| 124 | return; |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 125 | } |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 126 | |
| 127 | if (unicastConfig.isEnabled) { |
| 128 | if (m_unicastConfig.wantListen && !unicastConfig.wantListen && !m_channels.empty()) { |
| 129 | NFD_LOG_WARN("Cannot stop listening on Ethernet channels"); |
| 130 | } |
| 131 | if (m_unicastConfig.idleTimeout != unicastConfig.idleTimeout && !m_channels.empty()) { |
| 132 | NFD_LOG_WARN("Idle timeout setting applies to new Ethernet channels only"); |
| 133 | } |
| 134 | } |
| 135 | else if (m_unicastConfig.isEnabled && !m_channels.empty()) { |
| 136 | NFD_LOG_WARN("Cannot disable Ethernet channels after initialization"); |
| 137 | } |
| 138 | |
| 139 | if (m_mcastConfig.isEnabled != mcastConfig.isEnabled) { |
| 140 | if (mcastConfig.isEnabled) { |
| 141 | NFD_LOG_INFO("enabling multicast on " << mcastConfig.group); |
| 142 | } |
| 143 | else { |
| 144 | NFD_LOG_INFO("disabling multicast"); |
| 145 | } |
| 146 | } |
| 147 | else if (mcastConfig.isEnabled) { |
| 148 | if (m_mcastConfig.linkType != mcastConfig.linkType && !m_mcastFaces.empty()) { |
| 149 | NFD_LOG_WARN("Cannot change ad hoc setting on existing faces"); |
| 150 | } |
| 151 | if (m_mcastConfig.group != mcastConfig.group) { |
| 152 | NFD_LOG_INFO("changing multicast group from " << m_mcastConfig.group << |
| 153 | " to " << mcastConfig.group); |
| 154 | } |
| 155 | if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) { |
| 156 | NFD_LOG_INFO("changing whitelist/blacklist"); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // Even if there's no configuration change, we still need to re-apply configuration because |
| 161 | // netifs may have changed. |
| 162 | m_unicastConfig = unicastConfig; |
| 163 | m_mcastConfig = mcastConfig; |
| 164 | this->applyConfig(context); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 167 | void |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 168 | EthernetFactory::createFace(const CreateFaceParams& params, |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 169 | const FaceCreatedCallback& onCreated, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 170 | const FaceCreationFailedCallback& onFailure) |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 171 | { |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 172 | BOOST_ASSERT(params.remoteUri.isCanonical()); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 173 | |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 174 | if (!params.localUri || params.localUri->getScheme() != "dev") { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 175 | NFD_LOG_TRACE("Cannot create unicast Ethernet face without dev:// LocalUri"); |
| 176 | onFailure(406, "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"); |
| 177 | return; |
| 178 | } |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 179 | BOOST_ASSERT(params.localUri->isCanonical()); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 180 | |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 181 | if (params.persistency == ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 182 | NFD_LOG_TRACE("createFace does not support FACE_PERSISTENCY_ON_DEMAND"); |
| 183 | onFailure(406, "Outgoing Ethernet faces do not support on-demand persistency"); |
| 184 | return; |
| 185 | } |
| 186 | |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 187 | ethernet::Address remoteEndpoint(ethernet::Address::fromString(params.remoteUri.getHost())); |
| 188 | std::string localEndpoint(params.localUri->getHost()); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 189 | |
| 190 | if (remoteEndpoint.isMulticast()) { |
| 191 | NFD_LOG_TRACE("createFace does not support multicast faces"); |
| 192 | onFailure(406, "Cannot create multicast Ethernet faces"); |
| 193 | return; |
| 194 | } |
| 195 | |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 196 | if (params.wantLocalFieldsEnabled) { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 197 | // Ethernet faces are never local |
| 198 | NFD_LOG_TRACE("createFace cannot create non-local face with local fields enabled"); |
| 199 | onFailure(406, "Local fields can only be enabled on faces with local scope"); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | for (const auto& i : m_channels) { |
| 204 | if (i.first == localEndpoint) { |
Eric Newberry | 944f38b | 2017-07-20 20:54:22 -0400 | [diff] [blame] | 205 | i.second->connect(remoteEndpoint, params.persistency, onCreated, onFailure); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 206 | return; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | NFD_LOG_TRACE("No channels available to connect to " << remoteEndpoint); |
| 211 | onFailure(504, "No channels available to connect"); |
| 212 | } |
| 213 | |
| 214 | shared_ptr<EthernetChannel> |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 215 | EthernetFactory::createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 216 | time::nanoseconds idleTimeout) |
| 217 | { |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 218 | auto it = m_channels.find(localEndpoint->getName()); |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 219 | if (it != m_channels.end()) |
| 220 | return it->second; |
| 221 | |
| 222 | auto channel = std::make_shared<EthernetChannel>(localEndpoint, idleTimeout); |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 223 | m_channels[localEndpoint->getName()] = channel; |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 224 | |
| 225 | return channel; |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 228 | std::vector<shared_ptr<const Channel>> |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 229 | EthernetFactory::getChannels() const |
| 230 | { |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 231 | return getChannelsFromMap(m_channels); |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 232 | } |
| 233 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 234 | shared_ptr<Face> |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 235 | EthernetFactory::createMulticastFace(const ndn::net::NetworkInterface& netif, |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 236 | const ethernet::Address& address) |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 237 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 238 | BOOST_ASSERT(address.isMulticast()); |
| 239 | |
Junxiao Shi | 0d82d04 | 2017-07-07 06:15:27 +0000 | [diff] [blame] | 240 | auto key = std::make_pair(netif.getName(), address); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 241 | auto found = m_mcastFaces.find(key); |
| 242 | if (found != m_mcastFaces.end()) { |
| 243 | return found->second; |
| 244 | } |
| 245 | |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 246 | GenericLinkService::Options opts; |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 247 | opts.allowFragmentation = true; |
| 248 | opts.allowReassembly = true; |
| 249 | |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 250 | auto linkService = make_unique<GenericLinkService>(opts); |
| 251 | auto transport = make_unique<MulticastEthernetTransport>(netif, address, m_mcastConfig.linkType); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 252 | auto face = make_shared<Face>(std::move(linkService), std::move(transport)); |
| 253 | |
| 254 | m_mcastFaces[key] = face; |
| 255 | connectFaceClosedSignal(*face, [this, key] { m_mcastFaces.erase(key); }); |
| 256 | |
| 257 | return face; |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 260 | shared_ptr<EthernetChannel> |
| 261 | EthernetFactory::applyUnicastConfigToNetif(const shared_ptr<const ndn::net::NetworkInterface>& netif) |
| 262 | { |
| 263 | if (!m_unicastConfig.isEnabled) { |
| 264 | return nullptr; |
| 265 | } |
| 266 | |
| 267 | if (!netif->isUp()) { |
| 268 | NFD_LOG_DEBUG("Not creating channel on " << netif->getName() << ": netif is down"); |
| 269 | return nullptr; |
| 270 | } |
| 271 | |
| 272 | if (netif->isLoopback()) { |
| 273 | NFD_LOG_DEBUG("Not creating channel on " << netif->getName() << ": netif is loopback"); |
| 274 | return nullptr; |
| 275 | } |
| 276 | |
| 277 | auto channel = this->createChannel(netif, m_unicastConfig.idleTimeout); |
| 278 | if (m_unicastConfig.wantListen && !channel->isListening()) { |
| 279 | try { |
| 280 | channel->listen(this->addFace, nullptr); |
| 281 | } |
| 282 | catch (const EthernetChannel::Error& e) { |
| 283 | NFD_LOG_WARN("Cannot listen on " << netif->getName() << ": " << e.what()); |
| 284 | } |
| 285 | } |
| 286 | return channel; |
| 287 | } |
| 288 | |
| 289 | shared_ptr<Face> |
| 290 | EthernetFactory::applyMcastConfigToNetif(const ndn::net::NetworkInterface& netif) |
| 291 | { |
| 292 | if (!m_mcastConfig.isEnabled) { |
| 293 | return nullptr; |
| 294 | } |
| 295 | |
| 296 | if (!netif.isUp()) { |
| 297 | NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": netif is down"); |
| 298 | return nullptr; |
| 299 | } |
| 300 | |
| 301 | if (!netif.canMulticast()) { |
| 302 | NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": netif cannot multicast"); |
| 303 | return nullptr; |
| 304 | } |
| 305 | |
| 306 | if (!m_mcastConfig.netifPredicate(netif)) { |
| 307 | NFD_LOG_DEBUG("Not creating multicast face on " << netif.getName() << ": rejected by whitelist/blacklist"); |
| 308 | return nullptr; |
| 309 | } |
| 310 | |
| 311 | NFD_LOG_DEBUG("Creating multicast face on " << netif.getName()); |
| 312 | shared_ptr<Face> face; |
| 313 | try { |
| 314 | face = this->createMulticastFace(netif, m_mcastConfig.group); |
| 315 | } |
| 316 | catch (const EthernetTransport::Error& e) { |
| 317 | NFD_LOG_WARN("Cannot create multicast face on " << netif.getName() << ": " << e.what()); |
| 318 | return nullptr; |
| 319 | } |
| 320 | |
| 321 | if (face->getId() == face::INVALID_FACEID) { |
| 322 | // new face: register with forwarding |
| 323 | this->addFace(face); |
| 324 | } |
| 325 | return face; |
| 326 | } |
| 327 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 328 | void |
| 329 | EthernetFactory::applyConfig(const FaceSystem::ConfigContext& context) |
| 330 | { |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 331 | if (m_unicastConfig.isEnabled) { |
| 332 | providedSchemes.insert("ether"); |
| 333 | } |
| 334 | else { |
| 335 | providedSchemes.erase("ether"); |
| 336 | } |
| 337 | |
| 338 | // collect old multicast faces |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 339 | std::set<shared_ptr<Face>> oldFaces; |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 340 | boost::copy(m_mcastFaces | boost::adaptors::map_values, std::inserter(oldFaces, oldFaces.end())); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 341 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 342 | // create channels and multicast faces if requested by config |
| 343 | for (const auto& netif : netmon->listNetworkInterfaces()) { |
| 344 | this->applyUnicastConfigToNetif(netif); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 345 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 346 | auto face = this->applyMcastConfigToNetif(*netif); |
| 347 | if (face != nullptr) { |
| 348 | // don't destroy face |
| 349 | oldFaces.erase(face); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame^] | 353 | // destroy old multicast faces that are not needed in new configuration |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 354 | for (const auto& face : oldFaces) { |
| 355 | face->close(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | } // namespace face |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 360 | } // namespace nfd |