face: configuration option to make Ethernet face "ad hoc"
Change-Id: I55aeb2ca38ec34365b2d5d951b9ca2d7b05f46b2
Refs: #4018, #3967
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 8d3e737..7263118 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -52,6 +52,7 @@
// {
// mcast yes
// mcast_group 01:00:5E:00:17:AA
+ // mcast_ad_hoc no
// whitelist
// {
// *
@@ -86,6 +87,10 @@
valueStr + "' is not a multicast address"));
}
}
+ else if (key == "mcast_ad_hoc") {
+ bool wantAdHoc = ConfigFile::parseYesNo(pair, "ether");
+ mcastConfig.linkType = wantAdHoc ? ndn::nfd::LINK_TYPE_AD_HOC : ndn::nfd::LINK_TYPE_MULTI_ACCESS;
+ }
else if (key == "whitelist") {
mcastConfig.netifPredicate.parseWhitelist(value);
}
@@ -107,18 +112,21 @@
NFD_LOG_INFO("disabling multicast");
}
}
- else if (m_mcastConfig.group != mcastConfig.group) {
- NFD_LOG_INFO("changing multicast group from " << m_mcastConfig.group <<
- " to " << mcastConfig.group);
- }
- else if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
- NFD_LOG_INFO("changing whitelist/blacklist");
- }
- else {
- // There's no configuration change, but we still need to re-apply configuration because
- // netifs may have changed.
+ else if (mcastConfig.isEnabled) {
+ if (m_mcastConfig.linkType != mcastConfig.linkType && !m_mcastFaces.empty()) {
+ NFD_LOG_WARN("Cannot change ad hoc setting on existing faces");
+ }
+ if (m_mcastConfig.group != mcastConfig.group) {
+ NFD_LOG_INFO("changing multicast group from " << m_mcastConfig.group <<
+ " to " << mcastConfig.group);
+ }
+ if (m_mcastConfig.netifPredicate != mcastConfig.netifPredicate) {
+ NFD_LOG_INFO("changing whitelist/blacklist");
+ }
}
+ // Even if there's no configuration change, we still need to re-apply configuration because
+ // netifs may have changed.
m_mcastConfig = mcastConfig;
this->applyConfig(context);
}
@@ -157,7 +165,7 @@
opts.allowReassembly = true;
auto linkService = make_unique<face::GenericLinkService>(opts);
- auto transport = make_unique<face::EthernetTransport>(netif, address);
+ auto transport = make_unique<face::EthernetTransport>(netif, address, m_mcastConfig.linkType);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
m_mcastFaces[key] = face;
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index d1b9ee2..9facd71 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -80,6 +80,7 @@
{
bool isEnabled = false;
ethernet::Address group = ethernet::getDefaultMulticastAddress();
+ ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS;
NetworkInterfacePredicate netifPredicate;
};
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index f47f1b1..4b039c6 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -62,7 +62,8 @@
NFD_LOG_INIT("EthernetTransport");
EthernetTransport::EthernetTransport(const NetworkInterfaceInfo& interface,
- const ethernet::Address& mcastAddress)
+ const ethernet::Address& mcastAddress,
+ ndn::nfd::LinkType linkType)
: m_pcap(nullptr, pcap_close)
, m_socket(getGlobalIoService())
, m_srcAddress(interface.etherAddress)
@@ -79,7 +80,7 @@
this->setRemoteUri(FaceUri(mcastAddress));
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
- this->setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+ this->setLinkType(linkType);
NFD_LOG_FACE_INFO("Creating transport");
diff --git a/daemon/face/ethernet-transport.hpp b/daemon/face/ethernet-transport.hpp
index d89e280..0777d74 100644
--- a/daemon/face/ethernet-transport.hpp
+++ b/daemon/face/ethernet-transport.hpp
@@ -62,7 +62,8 @@
* @brief Creates an Ethernet-based transport for multicast communication
*/
EthernetTransport(const NetworkInterfaceInfo& interface,
- const ethernet::Address& mcastAddress);
+ const ethernet::Address& mcastAddress,
+ ndn::nfd::LinkType linkType);
protected:
void