face: construct EthernetTransport with NetworkInterface

EthernetTransport and EthernetChannel constructors now accept
ndn::net::NetworkInterface instead of NetworkInterfaceInfo,
in preparation for the transition to NetworkMonitor.

refs #4021

Change-Id: I1687a13dfaafde4ab3795a6f8c76c728c12929b9
diff --git a/core/network-interface.cpp b/core/network-interface.cpp
index 02761a9..ad9485e 100644
--- a/core/network-interface.cpp
+++ b/core/network-interface.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,6 +25,7 @@
 
 #include "network-interface.hpp"
 #include "core/logger.hpp"
+#include <ndn-cxx/net/network-monitor-stub.hpp>
 
 #include <cerrno>
 #include <cstring>
@@ -59,6 +60,29 @@
               "NetworkInterfaceInfo must provide a default constructor");
 #endif
 
+shared_ptr<ndn::net::NetworkInterface>
+NetworkInterfaceInfo::asNetworkInterface() const
+{
+  using namespace ndn::net;
+
+  shared_ptr<NetworkInterface> netif = NetworkMonitorStub::makeNetworkInterface();
+  netif->setIndex(this->index);
+  netif->setName(this->name);
+  netif->setEthernetAddress(this->etherAddress);
+  netif->setFlags(this->flags);
+
+  for (const auto& a4 : this->ipv4Addresses) {
+    netif->addNetworkAddress(NetworkAddress(AddressFamily::V4, a4, this->broadcastAddress,
+                                            32, AddressScope::GLOBAL, 0));
+  }
+  for (const auto& a6 : this->ipv6Addresses) {
+    netif->addNetworkAddress(NetworkAddress(AddressFamily::V6, a6, {},
+                                            128, AddressScope::GLOBAL, 0));
+  }
+
+  return netif;
+}
+
 #ifdef WITH_TESTS
 static shared_ptr<std::vector<NetworkInterfaceInfo>> s_debugNetworkInterfaces = nullptr;
 
@@ -100,59 +124,59 @@
 
     switch (ifa->ifa_addr->sa_family) {
 
-    case AF_INET: {
-      const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
-      char address[INET_ADDRSTRLEN];
-      if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address))) {
-        netif.ipv4Addresses.push_back(address_v4::from_string(address));
-        NFD_LOG_TRACE(ifname << ": added IPv4 address " << address);
+      case AF_INET: {
+        const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
+        char address[INET_ADDRSTRLEN];
+        if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address))) {
+          netif.ipv4Addresses.push_back(address_v4::from_string(address));
+          NFD_LOG_TRACE(ifname << ": added IPv4 address " << address);
+        }
+        else
+          NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) failed: " << strerror(errno));
+        break;
       }
-      else
-        NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) failed: " << strerror(errno));
-      break;
-    }
 
-    case AF_INET6: {
-      const sockaddr_in6* sin6 = reinterpret_cast<sockaddr_in6*>(ifa->ifa_addr);
-      char address[INET6_ADDRSTRLEN];
-      if (::inet_ntop(AF_INET6, &sin6->sin6_addr, address, sizeof(address))) {
-        netif.ipv6Addresses.push_back(address_v6::from_string(address));
-        NFD_LOG_TRACE(ifname << ": added IPv6 address " << address);
+      case AF_INET6: {
+        const sockaddr_in6* sin6 = reinterpret_cast<sockaddr_in6*>(ifa->ifa_addr);
+        char address[INET6_ADDRSTRLEN];
+        if (::inet_ntop(AF_INET6, &sin6->sin6_addr, address, sizeof(address))) {
+          netif.ipv6Addresses.push_back(address_v6::from_string(address));
+          NFD_LOG_TRACE(ifname << ": added IPv6 address " << address);
+        }
+        else
+          NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET6) failed: " << strerror(errno));
+        break;
       }
-      else
-        NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET6) failed: " << strerror(errno));
-      break;
-    }
 
 #if defined(__linux__)
-    case AF_PACKET: {
-      const sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ifa->ifa_addr);
-      netif.index = sll->sll_ifindex;
-      if (sll->sll_hatype == ARPHRD_ETHER && sll->sll_halen == ethernet::ADDR_LEN) {
-        netif.etherAddress = ethernet::Address(sll->sll_addr);
-        NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+      case AF_PACKET: {
+        const sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ifa->ifa_addr);
+        netif.index = sll->sll_ifindex;
+        if (sll->sll_hatype == ARPHRD_ETHER && sll->sll_halen == ethernet::ADDR_LEN) {
+          netif.etherAddress = ethernet::Address(sll->sll_addr);
+          NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+        }
+        else if (sll->sll_hatype != ARPHRD_LOOPBACK) {
+          NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled hardware type "
+                        << sll->sll_hatype);
+        }
+        break;
       }
-      else if (sll->sll_hatype != ARPHRD_LOOPBACK) {
-        NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled hardware type "
-                      << sll->sll_hatype);
-      }
-      break;
-    }
 
 #elif defined(__APPLE__) || defined(__FreeBSD__)
-    case AF_LINK: {
-      const sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(ifa->ifa_addr);
-      netif.index = sdl->sdl_index;
-      if (sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == ethernet::ADDR_LEN) {
-        netif.etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
-        NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+      case AF_LINK: {
+        const sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(ifa->ifa_addr);
+        netif.index = sdl->sdl_index;
+        if (sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == ethernet::ADDR_LEN) {
+          netif.etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
+          NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+        }
+        else if (sdl->sdl_type != IFT_LOOP) {
+          NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled interface type "
+                        << sdl->sdl_type);
+        }
+        break;
       }
-      else if (sdl->sdl_type != IFT_LOOP) {
-        NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled interface type "
-                      << sdl->sdl_type);
-      }
-      break;
-    }
 #endif
     }
 
diff --git a/core/network-interface.hpp b/core/network-interface.hpp
index 4fb76d1..b94fabd 100644
--- a/core/network-interface.hpp
+++ b/core/network-interface.hpp
@@ -1,5 +1,5 @@
 /* -*- 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,
@@ -27,8 +27,8 @@
 #define NFD_CORE_NETWORK_INTERFACE_HPP
 
 #include "common.hpp"
-
 #include <ndn-cxx/net/ethernet.hpp>
+#include <ndn-cxx/net/network-interface.hpp>
 
 #include <net/if.h>
 
@@ -43,15 +43,6 @@
 class NetworkInterfaceInfo
 {
 public:
-
-  int index;
-  std::string name;
-  ethernet::Address etherAddress;
-  std::vector<boost::asio::ip::address_v4> ipv4Addresses;
-  std::vector<boost::asio::ip::address_v6> ipv6Addresses;
-  boost::asio::ip::address_v4 broadcastAddress;
-  unsigned int flags;
-
   bool
   isLoopback() const;
 
@@ -64,6 +55,22 @@
   bool
   isUp() const;
 
+  /** \brief Export to ndn::net::NetworkInterface
+   *  \warning This is a temporary adaptation during the transition from NetworkInterfaceInfo to
+   *           ndn::net::NetworkInterface. The return value carries the information in this instance
+   *           and will not track changes in the actual network interface or emit signals.
+   */
+  shared_ptr<ndn::net::NetworkInterface>
+  asNetworkInterface() const;
+
+public:
+  int index;
+  std::string name;
+  ethernet::Address etherAddress;
+  std::vector<boost::asio::ip::address_v4> ipv4Addresses;
+  std::vector<boost::asio::ip::address_v6> ipv6Addresses;
+  boost::asio::ip::address_v4 broadcastAddress;
+  unsigned int flags;
 };
 
 inline bool