face: configuration option to make Ethernet face "ad hoc"

Change-Id: I55aeb2ca38ec34365b2d5d951b9ca2d7b05f46b2
Refs: #4018, #3967
diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp
index 62748cd..56373d0 100644
--- a/tests/daemon/face/ethernet-factory.t.cpp
+++ b/tests/daemon/face/ethernet-factory.t.cpp
@@ -48,15 +48,15 @@
 {
 public:
   std::vector<const Face*>
-  listEtherMcastFaces() const
+  listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listFacesByScheme("ether", ndn::nfd::LINK_TYPE_MULTI_ACCESS);
+    return this->listFacesByScheme("ether", linkType);
   }
 
   size_t
-  countEtherMcastFaces() const
+  countEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
   {
-    return this->listEtherMcastFaces().size();
+    return this->listEtherMcastFaces(linkType).size();
   }
 };
 
@@ -73,6 +73,7 @@
       {
         mcast yes
         mcast_group 01:00:5E:00:17:AA
+        mcast_ad_hoc no
         whitelist
         {
           *
@@ -90,18 +91,94 @@
   BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
 }
 
-BOOST_AUTO_TEST_CASE(Omitted)
+BOOST_AUTO_TEST_CASE(EnableDisableMcast)
 {
-  const std::string CONFIG = R"CONFIG(
+  const std::string CONFIG_WITH_MCAST = R"CONFIG(
     face_system
     {
+      ether
+      {
+        mcast yes
+      }
+    }
+  )CONFIG";
+  const std::string CONFIG_WITHOUT_MCAST = R"CONFIG(
+    face_system
+    {
+      ether
+      {
+        mcast no
+      }
     }
   )CONFIG";
 
-  parseConfig(CONFIG, true);
-  parseConfig(CONFIG, false);
-
+  parseConfig(CONFIG_WITHOUT_MCAST, false);
   BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
+
+  SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
+
+  parseConfig(CONFIG_WITH_MCAST, false);
+  g_io.poll();
+  BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
+
+  parseConfig(CONFIG_WITHOUT_MCAST, false);
+  g_io.poll();
+  BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(McastAdHoc)
+{
+  SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
+
+  const std::string CONFIG = R"CONFIG(
+    face_system
+    {
+      ether
+      {
+        mcast_ad_hoc yes
+      }
+    }
+  )CONFIG";
+
+  parseConfig(CONFIG, false);
+  BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_AD_HOC), netifs.size());
+}
+
+BOOST_AUTO_TEST_CASE(ChangeMcastGroup)
+{
+  SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
+
+  const std::string CONFIG1 = R"CONFIG(
+    face_system
+    {
+      ether
+      {
+        mcast_group 01:00:00:00:00:01
+      }
+    }
+  )CONFIG";
+  const std::string CONFIG2 = R"CONFIG(
+    face_system
+    {
+      ether
+      {
+        mcast_group 01:00:00:00:00:02
+      }
+    }
+  )CONFIG";
+
+  parseConfig(CONFIG1, false);
+  auto etherMcastFaces = this->listEtherMcastFaces();
+  BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
+  BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
+                    FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x01)));
+
+  parseConfig(CONFIG2, false);
+  g_io.poll();
+  etherMcastFaces = this->listEtherMcastFaces();
+  BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
+  BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
+                    FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x02)));
 }
 
 BOOST_AUTO_TEST_CASE(Whitelist)
@@ -154,76 +231,18 @@
   }), 0);
 }
 
-BOOST_AUTO_TEST_CASE(EnableDisableMcast)
+BOOST_AUTO_TEST_CASE(Omitted)
 {
-  const std::string CONFIG_WITH_MCAST = R"CONFIG(
+  const std::string CONFIG = R"CONFIG(
     face_system
     {
-      ether
-      {
-        mcast yes
-      }
-    }
-  )CONFIG";
-  const std::string CONFIG_WITHOUT_MCAST = R"CONFIG(
-    face_system
-    {
-      ether
-      {
-        mcast no
-      }
     }
   )CONFIG";
 
-  parseConfig(CONFIG_WITHOUT_MCAST, false);
+  parseConfig(CONFIG, true);
+  parseConfig(CONFIG, false);
+
   BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
-
-  SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
-
-  parseConfig(CONFIG_WITH_MCAST, false);
-  g_io.poll();
-  BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
-
-  parseConfig(CONFIG_WITHOUT_MCAST, false);
-  g_io.poll();
-  BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
-}
-
-BOOST_AUTO_TEST_CASE(ChangeMcastGroup)
-{
-  SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
-
-  const std::string CONFIG1 = R"CONFIG(
-    face_system
-    {
-      ether
-      {
-        mcast_group 01:00:00:00:00:01
-      }
-    }
-  )CONFIG";
-  const std::string CONFIG2 = R"CONFIG(
-    face_system
-    {
-      ether
-      {
-        mcast_group 01:00:00:00:00:02
-      }
-    }
-  )CONFIG";
-
-  parseConfig(CONFIG1, false);
-  auto etherMcastFaces = this->listEtherMcastFaces();
-  BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
-  BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
-                    FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x01)));
-
-  parseConfig(CONFIG2, false);
-  g_io.poll();
-  etherMcastFaces = this->listEtherMcastFaces();
-  BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
-  BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
-                    FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x02)));
 }
 
 BOOST_AUTO_TEST_CASE(BadMcast)
diff --git a/tests/daemon/face/ethernet-fixture.hpp b/tests/daemon/face/ethernet-fixture.hpp
index 4228f79..5769637 100644
--- a/tests/daemon/face/ethernet-fixture.hpp
+++ b/tests/daemon/face/ethernet-fixture.hpp
@@ -43,7 +43,7 @@
     for (const auto& netif : listNetworkInterfaces()) {
       if (!netif.isLoopback() && netif.isUp()) {
         try {
-          EthernetTransport transport(netif, ethernet::getBroadcastAddress());
+          EthernetTransport transport(netif, ethernet::getBroadcastAddress(), ndn::nfd::LINK_TYPE_MULTI_ACCESS);
           netifs.push_back(netif);
         }
         catch (const EthernetTransport::Error&) {
diff --git a/tests/daemon/face/ethernet-transport.t.cpp b/tests/daemon/face/ethernet-transport.t.cpp
index cd46a04..c0d5138 100644
--- a/tests/daemon/face/ethernet-transport.t.cpp
+++ b/tests/daemon/face/ethernet-transport.t.cpp
@@ -42,7 +42,9 @@
   SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
 
   auto netif = netifs.front();
-  EthernetTransport transport(netif, ethernet::getDefaultMulticastAddress());
+  EthernetTransport transport(netif,
+                              ethernet::getDefaultMulticastAddress(),
+                              ndn::nfd::LINK_TYPE_MULTI_ACCESS);
   checkStaticPropertiesInitialized(transport);
 
   BOOST_CHECK_EQUAL(transport.getLocalUri(), FaceUri::fromDev(netif.name));
@@ -55,7 +57,9 @@
 BOOST_AUTO_TEST_CASE(PersistencyChange)
 {
   SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
-  EthernetTransport transport(netifs.front(), ethernet::getDefaultMulticastAddress());
+  EthernetTransport transport(netifs.front(),
+                              ethernet::getDefaultMulticastAddress(),
+                              ndn::nfd::LINK_TYPE_MULTI_ACCESS);
 
   BOOST_CHECK_EQUAL(transport.canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND), false);
   BOOST_CHECK_EQUAL(transport.canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERSISTENT), false);