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/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index d0676cc..44fb03c 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -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,
@@ -37,18 +37,18 @@
 
 NFD_LOG_INIT("EthernetChannel");
 
-EthernetChannel::EthernetChannel(const NetworkInterfaceInfo& localEndpoint,
+EthernetChannel::EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
                                  time::nanoseconds idleTimeout)
-  : m_localEndpoint(localEndpoint)
+  : m_localEndpoint(std::move(localEndpoint))
   , m_isListening(false)
   , m_socket(getGlobalIoService())
-  , m_pcap(m_localEndpoint.name)
+  , m_pcap(m_localEndpoint->getName())
   , m_idleFaceTimeout(idleTimeout)
 #ifdef _DEBUG
   , m_nDropped(0)
 #endif
 {
-  setUri(FaceUri::fromDev(m_localEndpoint.name));
+  setUri(FaceUri::fromDev(m_localEndpoint->getName()));
   NFD_LOG_CHAN_INFO("Creating channel");
 }
 
@@ -131,8 +131,8 @@
   }
   else {
     const ether_header* eh;
-    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_localEndpoint.etherAddress,
-                                                   m_localEndpoint.etherAddress);
+    std::tie(eh, err) = ethernet::checkFrameHeader(pkt, len, m_localEndpoint->getEthernetAddress(),
+                                                   m_localEndpoint->getEthernetAddress());
     if (eh == nullptr) {
       NFD_LOG_CHAN_DEBUG(err);
     }
@@ -197,7 +197,7 @@
 
   // else, create a new face
   auto linkService = make_unique<GenericLinkService>();
-  auto transport = make_unique<UnicastEthernetTransport>(m_localEndpoint, remoteEndpoint,
+  auto transport = make_unique<UnicastEthernetTransport>(*m_localEndpoint, remoteEndpoint,
                                                          persistency, m_idleFaceTimeout);
   auto face = make_shared<Face>(std::move(linkService), std::move(transport));
 
@@ -218,7 +218,7 @@
     return;
 
   std::string filter = "(ether proto " + to_string(ethernet::ETHERTYPE_NDN) +
-                       ") && (ether dst " + m_localEndpoint.etherAddress.toString() + ")";
+                       ") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() + ")";
   for (const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
     filter += " && (not ether src " + addr.toString() + ")";
   }
diff --git a/daemon/face/ethernet-channel.hpp b/daemon/face/ethernet-channel.hpp
index cb4fbe9..8ad2432 100644
--- a/daemon/face/ethernet-channel.hpp
+++ b/daemon/face/ethernet-channel.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,9 @@
 #define NFD_DAEMON_FACE_ETHERNET_CHANNEL_HPP
 
 #include "channel.hpp"
+#include "ethernet-protocol.hpp"
 #include "pcap-helper.hpp"
-#include "core/network-interface.hpp"
+#include <ndn-cxx/net/network-interface.hpp>
 
 namespace nfd {
 namespace face {
@@ -58,7 +59,7 @@
    * To enable creation of faces upon incoming connections,
    * one needs to explicitly call EthernetChannel::listen method.
    */
-  EthernetChannel(const NetworkInterfaceInfo& localEndpoint,
+  EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
                   time::nanoseconds idleTimeout);
 
   bool
@@ -127,7 +128,7 @@
   updateFilter();
 
 private:
-  const NetworkInterfaceInfo m_localEndpoint;
+  shared_ptr<const ndn::net::NetworkInterface> m_localEndpoint;
   bool m_isListening;
   boost::asio::posix::stream_descriptor m_socket;
   PcapHelper m_pcap;
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 20fda6d..8fc9822 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -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,
@@ -118,9 +118,10 @@
 
       // determine the interfaces on which channels should be created
       auto netifs = context.listNetifs() |
-                    boost::adaptors::filtered([this] (const NetworkInterfaceInfo& netif) {
-                      return netif.isUp() && !netif.isLoopback();
-                    });
+        boost::adaptors::transformed([] (const NetworkInterfaceInfo& nii) { return nii.asNetworkInterface(); }) |
+        boost::adaptors::filtered([] (const shared_ptr<const ndn::net::NetworkInterface>& netif) {
+          return netif->isUp() && !netif->isLoopback();
+        });
 
       // create channels
       for (const auto& netif : netifs) {
@@ -130,7 +131,7 @@
             channel->listen(context.addFace, nullptr);
           }
           catch (const EthernetChannel::Error& e) {
-            NFD_LOG_WARN("Cannot listen on " << netif.name << ": " << e.what());
+            NFD_LOG_WARN("Cannot listen on " << netif->getName() << ": " << e.what());
           }
         }
       }
@@ -218,15 +219,15 @@
 }
 
 shared_ptr<EthernetChannel>
-EthernetFactory::createChannel(const NetworkInterfaceInfo& localEndpoint,
+EthernetFactory::createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
                                time::nanoseconds idleTimeout)
 {
-  auto it = m_channels.find(localEndpoint.name);
+  auto it = m_channels.find(localEndpoint->getName());
   if (it != m_channels.end())
     return it->second;
 
   auto channel = std::make_shared<EthernetChannel>(localEndpoint, idleTimeout);
-  m_channels[localEndpoint.name] = channel;
+  m_channels[localEndpoint->getName()] = channel;
 
   return channel;
 }
@@ -238,12 +239,12 @@
 }
 
 shared_ptr<Face>
-EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& netif,
+EthernetFactory::createMulticastFace(const ndn::net::NetworkInterface& netif,
                                      const ethernet::Address& address)
 {
   BOOST_ASSERT(address.isMulticast());
 
-  auto key = std::make_pair(netif.name, address);
+  auto key = std::make_pair(netif.getName(), address);
   auto found = m_mcastFaces.find(key);
   if (found != m_mcastFaces.end()) {
     return found->second;
@@ -274,19 +275,19 @@
   if (m_mcastConfig.isEnabled) {
     // determine interfaces on which faces should be created or retained
     auto capableNetifs = context.listNetifs() |
-                         boost::adaptors::filtered([this] (const NetworkInterfaceInfo& netif) {
-                           return netif.isUp() && netif.isMulticastCapable() &&
-                                  m_mcastConfig.netifPredicate(netif);
-                         });
+      boost::adaptors::transformed([] (const NetworkInterfaceInfo& nii) { return nii.asNetworkInterface(); }) |
+      boost::adaptors::filtered([this] (const shared_ptr<const ndn::net::NetworkInterface>& netif) {
+        return netif->isUp() && netif->canMulticast() && m_mcastConfig.netifPredicate(*netif);
+      });
 
     // create faces
     for (const auto& netif : capableNetifs) {
       shared_ptr<Face> face;
       try {
-        face = this->createMulticastFace(netif, m_mcastConfig.group);
+        face = this->createMulticastFace(*netif, m_mcastConfig.group);
       }
       catch (const EthernetTransport::Error& e) {
-        NFD_LOG_WARN("Cannot create Ethernet multicast face on " << netif.name << ": " << e.what());
+        NFD_LOG_WARN("Cannot create Ethernet multicast face on " << netif->getName() << ": " << e.what());
         continue;
       }
 
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index 1cbe4e9..7480728 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.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,
@@ -62,10 +62,10 @@
    *
    * \return always a valid pointer to a EthernetChannel object, an exception
    *         is thrown if it cannot be created.
-   * \throw PcapHelper::Error
+   * \throw PcapHelper::Error channel creation failed
    */
   shared_ptr<EthernetChannel>
-  createChannel(const NetworkInterfaceInfo& localEndpoint,
+  createChannel(const shared_ptr<const ndn::net::NetworkInterface>& localEndpoint,
                 time::nanoseconds idleTimeout);
 
   std::vector<shared_ptr<const Channel>>
@@ -77,13 +77,13 @@
    * If this method is called twice with the same arguments, only one face
    * will be created. The second call will just return the existing face.
    *
-   * \param netif local network interface
+   * \param localEndpoint local network interface
    * \param group multicast group address
    *
    * \throw EthernetTransport::Error transport creation fails
    */
   shared_ptr<Face>
-  createMulticastFace(const NetworkInterfaceInfo& netif,
+  createMulticastFace(const ndn::net::NetworkInterface& localEndpoint,
                       const ethernet::Address& group);
 
 private:
diff --git a/daemon/face/ethernet-protocol.hpp b/daemon/face/ethernet-protocol.hpp
index 4eca7cf..639c678 100644
--- a/daemon/face/ethernet-protocol.hpp
+++ b/daemon/face/ethernet-protocol.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,
@@ -26,13 +26,15 @@
 #ifndef NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
 #define NFD_DAEMON_FACE_ETHERNET_PROTOCOL_HPP
 
-#include "core/network-interface.hpp"
-
+#include "core/common.hpp"
+#include <ndn-cxx/net/ethernet.hpp>
 #include <net/ethernet.h>
 
 namespace nfd {
 namespace ethernet {
 
+using namespace ndn::ethernet;
+
 std::pair<const ether_header*, std::string>
 checkFrameHeader(const uint8_t* packet, size_t length,
                  const Address& localAddr, const Address& destAddr);
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index 026b540..5ea05c5 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -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,
@@ -40,13 +40,13 @@
 
 NFD_LOG_INIT("EthernetTransport");
 
-EthernetTransport::EthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+EthernetTransport::EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                                      const ethernet::Address& remoteEndpoint)
   : m_socket(getGlobalIoService())
-  , m_pcap(localEndpoint.name)
-  , m_srcAddress(localEndpoint.etherAddress)
+  , m_pcap(localEndpoint.getName())
+  , m_srcAddress(localEndpoint.getEthernetAddress())
   , m_destAddress(remoteEndpoint)
-  , m_interfaceName(localEndpoint.name)
+  , m_interfaceName(localEndpoint.getName())
   , m_hasRecentlyReceived(false)
 #ifdef _DEBUG
   , m_nDropped(0)
diff --git a/daemon/face/ethernet-transport.hpp b/daemon/face/ethernet-transport.hpp
index 69f4061..2412924 100644
--- a/daemon/face/ethernet-transport.hpp
+++ b/daemon/face/ethernet-transport.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,
@@ -26,9 +26,10 @@
 #ifndef NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
 #define NFD_DAEMON_FACE_ETHERNET_TRANSPORT_HPP
 
+#include "ethernet-protocol.hpp"
 #include "pcap-helper.hpp"
 #include "transport.hpp"
-#include "core/network-interface.hpp"
+#include <ndn-cxx/net/network-interface.hpp>
 
 namespace nfd {
 namespace face {
@@ -60,7 +61,7 @@
                  const ethernet::Address& sender);
 
 protected:
-  EthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+  EthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                     const ethernet::Address& remoteEndpoint);
 
   void
diff --git a/daemon/face/multicast-ethernet-transport.cpp b/daemon/face/multicast-ethernet-transport.cpp
index c8c9b2c..b4adea0 100644
--- a/daemon/face/multicast-ethernet-transport.cpp
+++ b/daemon/face/multicast-ethernet-transport.cpp
@@ -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,
@@ -48,12 +48,12 @@
 
 NFD_LOG_INIT("MulticastEthernetTransport");
 
-MulticastEthernetTransport::MulticastEthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+MulticastEthernetTransport::MulticastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                                                        const ethernet::Address& mcastAddress,
                                                        ndn::nfd::LinkType linkType)
   : EthernetTransport(localEndpoint, mcastAddress)
 #if defined(__linux__)
-  , m_interfaceIndex(localEndpoint.index)
+  , m_interfaceIndex(localEndpoint.getIndex())
 #endif
 {
   this->setLocalUri(FaceUri::fromDev(m_interfaceName));
diff --git a/daemon/face/multicast-ethernet-transport.hpp b/daemon/face/multicast-ethernet-transport.hpp
index b89e88b..8c2ce91 100644
--- a/daemon/face/multicast-ethernet-transport.hpp
+++ b/daemon/face/multicast-ethernet-transport.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,
@@ -40,7 +40,7 @@
   /**
    * @brief Creates an Ethernet-based transport for multicast communication
    */
-  MulticastEthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+  MulticastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                              const ethernet::Address& mcastAddress,
                              ndn::nfd::LinkType linkType);
 
diff --git a/daemon/face/unicast-ethernet-transport.cpp b/daemon/face/unicast-ethernet-transport.cpp
index 2ec15f0..316c91d 100644
--- a/daemon/face/unicast-ethernet-transport.cpp
+++ b/daemon/face/unicast-ethernet-transport.cpp
@@ -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,
@@ -32,7 +32,7 @@
 
 NFD_LOG_INIT("UnicastEthernetTransport");
 
-UnicastEthernetTransport::UnicastEthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+UnicastEthernetTransport::UnicastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                                                    const ethernet::Address& remoteEndpoint,
                                                    ndn::nfd::FacePersistency persistency,
                                                    time::nanoseconds idleTimeout)
diff --git a/daemon/face/unicast-ethernet-transport.hpp b/daemon/face/unicast-ethernet-transport.hpp
index d85dfc7..19617e3 100644
--- a/daemon/face/unicast-ethernet-transport.hpp
+++ b/daemon/face/unicast-ethernet-transport.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,
@@ -41,7 +41,7 @@
   /**
    * @brief Creates an Ethernet-based transport for unicast communication
    */
-  UnicastEthernetTransport(const NetworkInterfaceInfo& localEndpoint,
+  UnicastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
                            const ethernet::Address& remoteEndpoint,
                            ndn::nfd::FacePersistency persistency,
                            time::nanoseconds idleTimeout);