core: use FaceUri from ndn-cxx

refs #2143

Change-Id: Ida06daf406f941a699c9f1013450951db3cd28e9
diff --git a/common.hpp b/common.hpp
index ac20f92..17edcc5 100644
--- a/common.hpp
+++ b/common.hpp
@@ -50,7 +50,6 @@
 #include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/data.hpp>
 #include <ndn-cxx/util/event-emitter.hpp>
-#include <ndn-cxx/util/ethernet.hpp>
 
 #include <boost/algorithm/string.hpp>
 #include <boost/asio.hpp>
@@ -95,7 +94,6 @@
 
 namespace name = ndn::name;
 namespace time = ndn::time;
-namespace ethernet = ndn::util::ethernet;
 
 } // namespace nfd
 
diff --git a/core/face-uri.cpp b/core/face-uri.cpp
deleted file mode 100644
index 635d8d3..0000000
--- a/core/face-uri.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "face-uri.hpp"
-#include "core/logger.hpp"
-
-#include <boost/regex.hpp>
-
-NFD_LOG_INIT("FaceUri");
-
-namespace nfd {
-
-FaceUri::FaceUri(const std::string& uri)
-{
-  if (!parse(uri)) {
-    throw Error("Malformed URI: " + uri);
-  }
-}
-
-FaceUri::FaceUri(const char* uri)
-{
-  if (!parse(uri)) {
-    throw Error("Malformed URI: " + std::string(uri));
-  }
-}
-
-bool
-FaceUri::parse(const std::string& uri)
-{
-  m_scheme.clear();
-  m_host.clear();
-  m_isV6 = false;
-  m_port.clear();
-  m_path.clear();
-
-  static const boost::regex protocolExp("(\\w+\\d?)://([^/]*)(\\/[^?]*)?");
-  boost::smatch protocolMatch;
-  if (!boost::regex_match(uri, protocolMatch, protocolExp)) {
-    return false;
-  }
-  m_scheme = protocolMatch[1];
-  const std::string& authority = protocolMatch[2];
-  m_path = protocolMatch[3];
-
-  // pattern for IPv6 address enclosed in [ ], with optional port number
-  static const boost::regex v6Exp("^\\[([a-fA-F0-9:]+)\\](?:\\:(\\d+))?$");
-  // pattern for Ethernet address in standard hex-digits-and-colons notation
-  static const boost::regex etherExp("^\\[((?:[a-fA-F0-9]{1,2}\\:){5}(?:[a-fA-F0-9]{1,2}))\\]$");
-  // pattern for IPv4-mapped IPv6 address, with optional port number
-  static const boost::regex v4MappedV6Exp("^\\[::ffff:(\\d+(?:\\.\\d+){3})\\](?:\\:(\\d+))?$");
-  // pattern for IPv4/hostname/fd/ifname, with optional port number
-  static const boost::regex v4HostExp("^([^:]+)(?:\\:(\\d+))?$");
-
-  if (authority.empty()) {
-    // UNIX, internal
-  }
-  else {
-    boost::smatch match;
-    m_isV6 = boost::regex_match(authority, match, v6Exp);
-    if (m_isV6 ||
-        boost::regex_match(authority, match, etherExp) ||
-        boost::regex_match(authority, match, v4MappedV6Exp) ||
-        boost::regex_match(authority, match, v4HostExp)) {
-      m_host = match[1];
-      m_port = match[2];
-    }
-    else {
-      return false;
-    }
-  }
-
-  NFD_LOG_DEBUG("URI [" << uri << "] parsed into: " <<
-                m_scheme << ", " << m_host << ", " << m_port << ", " << m_path);
-  return true;
-}
-
-FaceUri::FaceUri(const boost::asio::ip::tcp::endpoint& endpoint)
-{
-  m_isV6 = endpoint.address().is_v6();
-  m_scheme = m_isV6 ? "tcp6" : "tcp4";
-  m_host = endpoint.address().to_string();
-  m_port = boost::lexical_cast<std::string>(endpoint.port());
-}
-
-FaceUri::FaceUri(const boost::asio::ip::udp::endpoint& endpoint)
-{
-  m_isV6 = endpoint.address().is_v6();
-  m_scheme = m_isV6 ? "udp6" : "udp4";
-  m_host = endpoint.address().to_string();
-  m_port = boost::lexical_cast<std::string>(endpoint.port());
-}
-
-FaceUri::FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme)
-  : m_scheme(scheme)
-{
-  m_isV6 = endpoint.address().is_v6();
-  m_host = endpoint.address().to_string();
-  m_port = boost::lexical_cast<std::string>(endpoint.port());
-}
-
-#ifdef HAVE_UNIX_SOCKETS
-FaceUri::FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint)
-  : m_isV6(false)
-{
-  m_scheme = "unix";
-  m_path = endpoint.path();
-}
-#endif // HAVE_UNIX_SOCKETS
-
-FaceUri
-FaceUri::fromFd(int fd)
-{
-  FaceUri uri;
-  uri.m_scheme = "fd";
-  uri.m_host = boost::lexical_cast<std::string>(fd);
-  return uri;
-}
-
-#ifdef HAVE_LIBPCAP
-FaceUri::FaceUri(const ethernet::Address& address)
-  : m_isV6(true)
-{
-  m_scheme = "ether";
-  m_host = address.toString();
-}
-#endif // HAVE_LIBPCAP
-
-FaceUri
-FaceUri::fromDev(const std::string& ifname)
-{
-  FaceUri uri;
-  uri.m_scheme = "dev";
-  uri.m_host = ifname;
-  return uri;
-}
-
-} // namespace nfd
diff --git a/core/face-uri.hpp b/core/face-uri.hpp
deleted file mode 100644
index 17cda71..0000000
--- a/core/face-uri.hpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_CORE_FACE_URI_H
-#define NFD_CORE_FACE_URI_H
-
-#include "common.hpp"
-
-namespace nfd {
-
-/** \brief represents the underlying protocol and address used by a Face
- *  \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#FaceUri
- */
-class FaceUri
-{
-public:
-  class Error : public std::invalid_argument
-  {
-  public:
-    explicit
-    Error(const std::string& what)
-      : std::invalid_argument(what)
-    {
-    }
-  };
-
-  FaceUri();
-
-  /** \brief construct by parsing
-   *
-   *  \param uri scheme://host[:port]/path
-   *  \throw FaceUri::Error if URI cannot be parsed
-   */
-  explicit
-  FaceUri(const std::string& uri);
-
-  // This overload is needed so that calls with string literal won't be
-  // resolved to boost::asio::local::stream_protocol::endpoint overload.
-  explicit
-  FaceUri(const char* uri);
-
-  /// exception-safe parsing
-  bool
-  parse(const std::string& uri);
-
-public: // scheme-specific construction
-  /// construct tcp4 or tcp6 canonical FaceUri
-  explicit
-  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint);
-
-  /// construct udp4 or udp6 canonical FaceUri
-  explicit
-  FaceUri(const boost::asio::ip::udp::endpoint& endpoint);
-
-  /// construct tcp canonical FaceUri with customized scheme
-  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme);
-
-#ifdef HAVE_UNIX_SOCKETS
-  /// construct unix canonical FaceUri
-  explicit
-  FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint);
-#endif // HAVE_UNIX_SOCKETS
-
-  /// create fd FaceUri from file descriptor
-  static FaceUri
-  fromFd(int fd);
-
-#ifdef HAVE_LIBPCAP
-  /// construct ether canonical FaceUri
-  explicit
-  FaceUri(const ethernet::Address& address);
-#endif // HAVE_LIBPCAP
-
-  /// create dev FaceUri from network device name
-  static FaceUri
-  fromDev(const std::string& ifname);
-
-public: // getters
-  /// get scheme (protocol)
-  const std::string&
-  getScheme() const;
-
-  /// get host (domain)
-  const std::string&
-  getHost() const;
-
-  /// get port
-  const std::string&
-  getPort() const;
-
-  /// get path
-  const std::string&
-  getPath() const;
-
-  /// write as a string
-  std::string
-  toString() const;
-
-public: // EqualityComparable concept
-  /// equality operator
-  bool
-  operator==(const FaceUri& rhs) const;
-
-  /// inequality operator
-  bool
-  operator!=(const FaceUri& rhs) const;
-
-private:
-  std::string m_scheme;
-  std::string m_host;
-  /// whether to add [] around host when writing string
-  bool m_isV6;
-  std::string m_port;
-  std::string m_path;
-
-  friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
-};
-
-inline
-FaceUri::FaceUri()
-  : m_isV6(false)
-{
-}
-
-inline const std::string&
-FaceUri::getScheme() const
-{
-  return m_scheme;
-}
-
-inline const std::string&
-FaceUri::getHost() const
-{
-  return m_host;
-}
-
-inline const std::string&
-FaceUri::getPort() const
-{
-  return m_port;
-}
-
-inline const std::string&
-FaceUri::getPath() const
-{
-  return m_path;
-}
-
-inline std::string
-FaceUri::toString() const
-{
-  std::ostringstream os;
-  os << *this;
-  return os.str();
-}
-
-inline bool
-FaceUri::operator==(const FaceUri& rhs) const
-{
-  return (m_scheme == rhs.m_scheme &&
-          m_host == rhs.m_host &&
-          m_isV6 == rhs.m_isV6 &&
-          m_port == rhs.m_port &&
-          m_path == rhs.m_path);
-}
-
-inline bool
-FaceUri::operator!=(const FaceUri& rhs) const
-{
-  return !(*this == rhs);
-}
-
-inline std::ostream&
-operator<<(std::ostream& os, const FaceUri& uri)
-{
-  os << uri.m_scheme << "://";
-  if (uri.m_isV6) {
-    os << "[" << uri.m_host << "]";
-  }
-  else {
-    os << uri.m_host;
-  }
-  if (!uri.m_port.empty()) {
-    os << ":" << uri.m_port;
-  }
-  os << uri.m_path;
-  return os;
-}
-
-} // namespace nfd
-
-#endif // NFD_CORE_FACE_URI_H
diff --git a/core/network-interface.hpp b/core/network-interface.hpp
index baaa85b..c5296a1 100644
--- a/core/network-interface.hpp
+++ b/core/network-interface.hpp
@@ -30,8 +30,14 @@
 
 #include <net/if.h>
 
+#include <ndn-cxx/util/ethernet.hpp>
+
 namespace nfd {
 
+namespace ethernet = ndn::util::ethernet;
+
+/** \brief contains information about a network interface
+ */
 class NetworkInterfaceInfo
 {
 public:
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index fe110ad..2fc24ab 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -25,7 +25,6 @@
 
 #include "ethernet-face.hpp"
 #include "core/logger.hpp"
-#include "core/network-interface.hpp"
 
 #include <pcap/pcap.h>
 
diff --git a/daemon/face/ethernet-face.hpp b/daemon/face/ethernet-face.hpp
index 7530648..8f44eab 100644
--- a/daemon/face/ethernet-face.hpp
+++ b/daemon/face/ethernet-face.hpp
@@ -28,6 +28,7 @@
 
 #include "config.hpp"
 #include "face.hpp"
+#include "core/network-interface.hpp"
 
 #ifndef HAVE_LIBPCAP
 #error "Cannot include this file when libpcap is not available"
@@ -39,8 +40,6 @@
 
 namespace nfd {
 
-class NetworkInterfaceInfo;
-
 /**
  * \brief Implementation of Face abstraction that uses raw
  *        Ethernet frames as underlying transport mechanism
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index e95b2be..b96a0b4 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -26,7 +26,6 @@
 #include "ethernet-factory.hpp"
 #include "core/logger.hpp"
 #include "core/global-io.hpp"
-#include "core/network-interface.hpp"
 
 #include <boost/algorithm/string/predicate.hpp>
 #include <pcap/pcap.h>
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index 4571a9e..f7f6588 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology,
- *                     The University of Memphis
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -21,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #ifndef NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
 #define NFD_DAEMON_FACE_ETHERNET_FACTORY_HPP
@@ -31,8 +31,6 @@
 
 namespace nfd {
 
-class NetworkInterfaceInfo;
-
 class EthernetFactory : public ProtocolFactory
 {
 public:
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index a79c405..40a77a1 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -27,9 +27,9 @@
 #define NFD_DAEMON_FACE_FACE_HPP
 
 #include "common.hpp"
-#include "core/face-uri.hpp"
 #include "face-counters.hpp"
 
+#include <ndn-cxx/util/face-uri.hpp>
 #include <ndn-cxx/management/nfd-face-status.hpp>
 #include <ndn-cxx/management/nfd-face-event-notification.hpp>
 
@@ -52,6 +52,7 @@
 /// upper bound of reserved FaceIds
 const FaceId FACEID_RESERVED_MAX = 255;
 
+using ndn::util::FaceUri;
 
 /** \brief represents a face
  */
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index 5a4a2f5..0542017 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -26,12 +26,10 @@
 #ifndef NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP
 #define NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP
 
-#include "common.hpp"
-#include "core/face-uri.hpp"
+#include "face.hpp"
 
 namespace nfd {
 
-class Face;
 class Channel;
 
 /**
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index 1d61709..cd2744d 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,11 +21,10 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "tcp-channel.hpp"
 #include "core/global-io.hpp"
-#include "core/face-uri.hpp"
 
 namespace nfd {
 
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index d1c82b1..c4bb0e8 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -25,7 +25,6 @@
 
 #include "udp-channel.hpp"
 #include "core/global-io.hpp"
-#include "core/face-uri.hpp"
 
 namespace nfd {
 
diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp
index a16ee64..8abdbac 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology,
- *                     The University of Memphis
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -21,10 +21,9 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "websocket-channel.hpp"
-#include "core/face-uri.hpp"
 
 #include <boost/date_time/posix_time/posix_time.hpp>
 
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 64d7af4..e4286e8 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -26,7 +26,6 @@
 #include "face-manager.hpp"
 
 #include "core/logger.hpp"
-#include "core/face-uri.hpp"
 #include "core/network-interface.hpp"
 #include "fw/face-table.hpp"
 #include "face/tcp-factory.hpp"
diff --git a/tests/core/face-uri.cpp b/tests/core/face-uri.cpp
deleted file mode 100644
index 11d7083..0000000
--- a/tests/core/face-uri.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "core/face-uri.hpp"
-
-#include "tests/test-common.hpp"
-
-namespace nfd {
-namespace tests {
-
-BOOST_FIXTURE_TEST_SUITE(CoreFaceUri, BaseFixture)
-
-BOOST_AUTO_TEST_CASE(Internal)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("internal://"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "internal");
-  BOOST_CHECK_EQUAL(uri.getHost(), "");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK_EQUAL(uri.parse("internal:"), false);
-  BOOST_CHECK_EQUAL(uri.parse("internal:/"), false);
-}
-
-BOOST_AUTO_TEST_CASE(Udp)
-{
-  BOOST_CHECK_NO_THROW(FaceUri("udp://hostname:6363"));
-  BOOST_CHECK_THROW(FaceUri("udp//hostname:6363"), FaceUri::Error);
-  BOOST_CHECK_THROW(FaceUri("udp://hostname:port"), FaceUri::Error);
-
-  FaceUri uri;
-  BOOST_CHECK_EQUAL(uri.parse("udp//hostname:6363"), false);
-
-  BOOST_CHECK(uri.parse("udp://hostname:80"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "udp");
-  BOOST_CHECK_EQUAL(uri.getHost(), "hostname");
-  BOOST_CHECK_EQUAL(uri.getPort(), "80");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK(uri.parse("udp4://192.0.2.1:20"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "udp4");
-  BOOST_CHECK_EQUAL(uri.getHost(), "192.0.2.1");
-  BOOST_CHECK_EQUAL(uri.getPort(), "20");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0::1]:6363"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
-  BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0::1");
-  BOOST_CHECK_EQUAL(uri.getPort(), "6363");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86d3]:6363"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
-  BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3");
-  BOOST_CHECK_EQUAL(uri.getPort(), "6363");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK_EQUAL(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86dg]:6363"), false);
-
-  using namespace boost::asio;
-  ip::udp::endpoint endpoint4(ip::address_v4::from_string("192.0.2.1"), 7777);
-  BOOST_REQUIRE_NO_THROW(FaceUri(endpoint4));
-  BOOST_CHECK_EQUAL(FaceUri(endpoint4).toString(), "udp4://192.0.2.1:7777");
-
-  ip::udp::endpoint endpoint6(ip::address_v6::from_string("2001:DB8::1"), 7777);
-  BOOST_REQUIRE_NO_THROW(FaceUri(endpoint6));
-  BOOST_CHECK_EQUAL(FaceUri(endpoint6).toString(), "udp6://[2001:db8::1]:7777");
-}
-
-BOOST_AUTO_TEST_CASE(Tcp)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("tcp://random.host.name"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "tcp");
-  BOOST_CHECK_EQUAL(uri.getHost(), "random.host.name");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK_EQUAL(uri.parse("tcp://192.0.2.1:"), false);
-  BOOST_CHECK_EQUAL(uri.parse("tcp://[::zzzz]"), false);
-
-  using namespace boost::asio;
-  ip::tcp::endpoint endpoint4(ip::address_v4::from_string("192.0.2.1"), 7777);
-  BOOST_REQUIRE_NO_THROW(FaceUri(endpoint4));
-  BOOST_CHECK_EQUAL(FaceUri(endpoint4).toString(), "tcp4://192.0.2.1:7777");
-
-  ip::tcp::endpoint endpoint6(ip::address_v6::from_string("2001:DB8::1"), 7777);
-  BOOST_REQUIRE_NO_THROW(FaceUri(endpoint6));
-  BOOST_CHECK_EQUAL(FaceUri(endpoint6).toString(), "tcp6://[2001:db8::1]:7777");
-}
-
-BOOST_AUTO_TEST_CASE(Unix)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("unix:///var/run/example.sock"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "unix");
-  BOOST_CHECK_EQUAL(uri.getHost(), "");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "/var/run/example.sock");
-
-  //BOOST_CHECK_EQUAL(uri.parse("unix://var/run/example.sock"), false);
-  // This is not a valid unix:/ URI, but the parse would treat "var" as host
-
-#ifdef HAVE_UNIX_SOCKETS
-  using namespace boost::asio;
-  local::stream_protocol::endpoint endpoint("/var/run/example.sock");
-  BOOST_REQUIRE_NO_THROW(FaceUri(endpoint));
-  BOOST_CHECK_EQUAL(FaceUri(endpoint).toString(), "unix:///var/run/example.sock");
-#endif // HAVE_UNIX_SOCKETS
-}
-
-BOOST_AUTO_TEST_CASE(Fd)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("fd://6"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "fd");
-  BOOST_CHECK_EQUAL(uri.getHost(), "6");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  int fd = 21;
-  BOOST_REQUIRE_NO_THROW(FaceUri::fromFd(fd));
-  BOOST_CHECK_EQUAL(FaceUri::fromFd(fd).toString(), "fd://21");
-}
-
-BOOST_AUTO_TEST_CASE(Ether)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("ether://[08:00:27:01:dd:01]"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "ether");
-  BOOST_CHECK_EQUAL(uri.getHost(), "08:00:27:01:dd:01");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  BOOST_CHECK_EQUAL(uri.parse("ether://08:00:27:zz:dd:01"), false);
-
-#ifdef HAVE_LIBPCAP
-  ethernet::Address address = ethernet::Address::fromString("33:33:01:01:01:01");
-  BOOST_REQUIRE_NO_THROW(FaceUri(address));
-  BOOST_CHECK_EQUAL(FaceUri(address).toString(), "ether://[33:33:01:01:01:01]");
-#endif // HAVE_LIBPCAP
-}
-
-BOOST_AUTO_TEST_CASE(Dev)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("dev://eth0"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "dev");
-  BOOST_CHECK_EQUAL(uri.getHost(), "eth0");
-  BOOST_CHECK_EQUAL(uri.getPort(), "");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-
-  std::string ifname = "en1";
-  BOOST_REQUIRE_NO_THROW(FaceUri::fromDev(ifname));
-  BOOST_CHECK_EQUAL(FaceUri::fromDev(ifname).toString(), "dev://en1");
-}
-
-BOOST_AUTO_TEST_CASE(Bug1635)
-{
-  FaceUri uri;
-
-  BOOST_CHECK(uri.parse("wsclient://[::ffff:76.90.11.239]:56366"));
-  BOOST_CHECK_EQUAL(uri.getScheme(), "wsclient");
-  BOOST_CHECK_EQUAL(uri.getHost(), "76.90.11.239");
-  BOOST_CHECK_EQUAL(uri.getPort(), "56366");
-  BOOST_CHECK_EQUAL(uri.getPath(), "");
-  BOOST_CHECK_EQUAL(uri.toString(), "wsclient://76.90.11.239:56366");
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace nfd
diff --git a/tools/ndn-autoconfig.cpp b/tools/ndn-autoconfig.cpp
index 77470c5..fdd8ba9 100644
--- a/tools/ndn-autoconfig.cpp
+++ b/tools/ndn-autoconfig.cpp
@@ -25,16 +25,16 @@
 
 #include "version.hpp"
 
-#include "core/face-uri.hpp"
-
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/management/nfd-controller.hpp>
 #include <ndn-cxx/management/nfd-face-status.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/util/face-uri.hpp>
 
 #include <boost/lexical_cast.hpp>
+#include <boost/noncopyable.hpp>
 
 #include <sys/types.h>
 #include <netinet/in.h>
@@ -59,7 +59,7 @@
             << std::endl;
 }
 
-class NdnAutoconfig
+class NdnAutoconfig : boost::noncopyable
 {
 public:
   union QueryAnswer
@@ -149,7 +149,7 @@
 
         nfd::FaceStatus faceStatus(block);
 
-        ::nfd::FaceUri uri(faceStatus.getRemoteUri());
+        ndn::util::FaceUri uri(faceStatus.getRemoteUri());
         if (uri.getScheme() == "udp4") {
           namespace ip = boost::asio::ip;
           boost::system::error_code ec;
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index 43862a6..0ad6841 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -27,6 +27,7 @@
 #include <ndn-cxx/name.hpp>
 
 #include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/util/face-uri.hpp>
 #include <ndn-cxx/management/nfd-controller.hpp>
 #include <ndn-cxx/management/nfd-face-monitor.hpp>
 #include <ndn-cxx/management/nfd-face-status.hpp>
@@ -37,17 +38,19 @@
 #include <boost/program_options/parsers.hpp>
 
 #include "version.hpp"
-#include "core/face-uri.hpp"
 #include "core/network.hpp"
 
-namespace po = boost::program_options;
-
-namespace nfd {
-
 using namespace ndn::nfd;
 using ndn::Face;
 using ndn::KeyChain;
 using ndn::nfd::FaceEventNotification;
+using ndn::util::FaceUri;
+using ::nfd::Network;
+
+namespace ndn {
+namespace nfd_autoreg {
+
+namespace po = boost::program_options;
 
 class AutoregServer : boost::noncopyable
 {
@@ -250,17 +253,14 @@
     uint64_t currentSegment = data.getName().get(-1).toSegment();
 
     const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
-    if (finalBlockId.empty() ||
-        finalBlockId.toSegment() > currentSegment)
-      {
-        m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1),
-                               bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer),
-                               ndn::OnTimeout());
-      }
-    else
-      {
-        return processFaceStatusDataset(buffer);
-      }
+    if (finalBlockId.empty() || finalBlockId.toSegment() > currentSegment) {
+      m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment + 1),
+                             bind(&AutoregServer::fetchFaceStatusSegments, this, _2, buffer),
+                             ndn::OnTimeout());
+    }
+    else {
+      return processFaceStatusDataset(buffer);
+    }
   }
 
   void
@@ -389,11 +389,12 @@
   std::vector<Network> m_blackList;
 };
 
-} // namespace nfd
+} // namespace nfd_autoreg
+} // namespace ndn
 
 int
 main(int argc, char* argv[])
 {
-  nfd::AutoregServer server;
+  ndn::nfd_autoreg::AutoregServer server;
   return server.main(argc, argv);
 }