net: move network-related files to src/net
Some namespaces are changed:
* ndn::util::FaceUri is now ndn::FaceUri
* ndn::util::ethernet is now ndn::ethernet
* ndn::util::NetworkMonitor and related classes are now in ndn::net
refs #3940
Change-Id: Ia4754caef9726efc73f5a303cec46fc95c744d70
diff --git a/tests/unit-tests/net/dns.t.cpp b/tests/unit-tests/net/dns.t.cpp
new file mode 100644
index 0000000..0e1aada
--- /dev/null
+++ b/tests/unit-tests/net/dns.t.cpp
@@ -0,0 +1,185 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "net/dns.hpp"
+
+#include "boost-test.hpp"
+#include "network-configuration-detector.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace dns {
+namespace tests {
+
+using boost::asio::ip::address_v4;
+using boost::asio::ip::address_v6;
+
+class DnsFixture
+{
+public:
+ DnsFixture()
+ : m_nFailures(0)
+ , m_nSuccesses(0)
+ {
+ }
+
+ void
+ onSuccess(const IpAddress& resolvedAddress,
+ const IpAddress& expectedAddress,
+ bool isValid,
+ bool shouldCheckAddress = false)
+ {
+ ++m_nSuccesses;
+
+ if (!isValid) {
+ BOOST_FAIL("Resolved to " + resolvedAddress.to_string() + ", but should have failed");
+ }
+
+ BOOST_CHECK_EQUAL(resolvedAddress.is_v4(), expectedAddress.is_v4());
+
+ // checking address is not deterministic and should be enabled only
+ // if only one IP address will be returned by resolution
+ if (shouldCheckAddress) {
+ BOOST_CHECK_EQUAL(resolvedAddress, expectedAddress);
+ }
+ }
+
+ void
+ onFailure(bool isValid)
+ {
+ ++m_nFailures;
+
+ if (!isValid) {
+ BOOST_FAIL("Resolution should not have failed");
+ }
+
+ BOOST_CHECK_MESSAGE(true, "Resolution failed as expected");
+ }
+
+protected:
+ uint32_t m_nFailures;
+ uint32_t m_nSuccesses;
+ boost::asio::io_service m_ioService;
+};
+
+BOOST_AUTO_TEST_SUITE(Net)
+BOOST_FIXTURE_TEST_SUITE(TestDns, DnsFixture)
+
+BOOST_AUTO_TEST_CASE(Asynchronous)
+{
+ SKIP_IF_IP_UNAVAILABLE();
+
+ asyncResolve("nothost.nothost.nothost.arpa",
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), false, false),
+ bind(&DnsFixture::onFailure, this, true),
+ m_ioService); // should fail
+
+ m_ioService.run();
+ BOOST_CHECK_EQUAL(m_nFailures, 1);
+ BOOST_CHECK_EQUAL(m_nSuccesses, 0);
+}
+
+BOOST_AUTO_TEST_CASE(AsynchronousV4)
+{
+ SKIP_IF_IPV4_UNAVAILABLE();
+
+ asyncResolve("192.0.2.1",
+ bind(&DnsFixture::onSuccess, this, _1,
+ IpAddress(address_v4::from_string("192.0.2.1")), true, true),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService);
+
+ m_ioService.run();
+ BOOST_CHECK_EQUAL(m_nFailures, 0);
+ BOOST_CHECK_EQUAL(m_nSuccesses, 1);
+}
+
+BOOST_AUTO_TEST_CASE(AsynchronousV6)
+{
+ SKIP_IF_IPV6_UNAVAILABLE();
+
+ asyncResolve("ipv6.google.com", // only IPv6 address should be available
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService);
+
+ asyncResolve("2001:db8:3f9:0:3025:ccc5:eeeb:86d3",
+ bind(&DnsFixture::onSuccess, this, _1,
+ IpAddress(address_v6::from_string("2001:db8:3f9:0:3025:ccc5:eeeb:86d3")),
+ true, true),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService);
+
+ m_ioService.run();
+ BOOST_CHECK_EQUAL(m_nFailures, 0);
+ BOOST_CHECK_EQUAL(m_nSuccesses, 2);
+}
+
+BOOST_AUTO_TEST_CASE(AsynchronousV4AndV6)
+{
+ SKIP_IF_IPV4_UNAVAILABLE();
+ SKIP_IF_IPV6_UNAVAILABLE();
+
+ asyncResolve("www.named-data.net",
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService, Ipv4Only());
+
+ asyncResolve("a.root-servers.net",
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v4()), true, false),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService, Ipv4Only()); // request IPv4 address
+
+ asyncResolve("a.root-servers.net",
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService, Ipv6Only()); // request IPv6 address
+
+ asyncResolve("ipv6.google.com", // only IPv6 address should be available
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), true, false),
+ bind(&DnsFixture::onFailure, this, false),
+ m_ioService, Ipv6Only());
+
+ asyncResolve("ipv6.google.com", // only IPv6 address should be available
+ bind(&DnsFixture::onSuccess, this, _1, IpAddress(address_v6()), false, false),
+ bind(&DnsFixture::onFailure, this, true),
+ m_ioService, Ipv4Only()); // should fail
+
+ m_ioService.run();
+ BOOST_CHECK_EQUAL(m_nFailures, 1);
+ BOOST_CHECK_EQUAL(m_nSuccesses, 4);
+}
+
+BOOST_AUTO_TEST_CASE(Synchronous)
+{
+ SKIP_IF_IP_UNAVAILABLE();
+
+ IpAddress address = syncResolve("www.named-data.net", m_ioService);
+ BOOST_CHECK(address.is_v4() || address.is_v6());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestDns
+BOOST_AUTO_TEST_SUITE_END() // Net
+
+} // namespace tests
+} // namespace dns
+} // namespace ndn
diff --git a/tests/unit-tests/util/ethernet.t.cpp b/tests/unit-tests/net/ethernet.t.cpp
similarity index 95%
rename from tests/unit-tests/util/ethernet.t.cpp
rename to tests/unit-tests/net/ethernet.t.cpp
index 38e05aa..cfcd6cb 100644
--- a/tests/unit-tests/util/ethernet.t.cpp
+++ b/tests/unit-tests/net/ethernet.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2016 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,15 +25,14 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-#include "util/ethernet.hpp"
+#include "net/ethernet.hpp"
#include "boost-test.hpp"
namespace ndn {
-namespace util {
namespace tests {
-BOOST_AUTO_TEST_SUITE(Util)
+BOOST_AUTO_TEST_SUITE(Net)
BOOST_AUTO_TEST_SUITE(TestEthernet)
BOOST_AUTO_TEST_CASE(Basic)
@@ -112,8 +111,7 @@
}
BOOST_AUTO_TEST_SUITE_END() // TestEthernet
-BOOST_AUTO_TEST_SUITE_END() // Util
+BOOST_AUTO_TEST_SUITE_END() // Net
} // namespace tests
-} // namespace util
} // namespace ndn
diff --git a/tests/unit-tests/util/face-uri.t.cpp b/tests/unit-tests/net/face-uri.t.cpp
similarity index 98%
rename from tests/unit-tests/util/face-uri.t.cpp
rename to tests/unit-tests/net/face-uri.t.cpp
index 559a5b0..27313f7 100644
--- a/tests/unit-tests/util/face-uri.t.cpp
+++ b/tests/unit-tests/net/face-uri.t.cpp
@@ -25,19 +25,15 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-#include "util/face-uri.hpp"
-#include "util/ethernet.hpp"
+#include "net/face-uri.hpp"
#include "boost-test.hpp"
-#include "../network-configuration-detector.hpp"
+#include "network-configuration-detector.hpp"
namespace ndn {
-namespace util {
namespace tests {
-using ndn::tests::NetworkConfigurationDetector;
-
-BOOST_AUTO_TEST_SUITE(Util)
+BOOST_AUTO_TEST_SUITE(Net)
BOOST_AUTO_TEST_SUITE(TestFaceUri)
class CanonizeFixture : noncopyable
@@ -566,8 +562,7 @@
}
BOOST_AUTO_TEST_SUITE_END() // TestFaceUri
-BOOST_AUTO_TEST_SUITE_END() // Util
+BOOST_AUTO_TEST_SUITE_END() // Net
} // namespace tests
-} // namespace util
} // namespace ndn
diff --git a/tests/unit-tests/network-configuration-detector.cpp b/tests/unit-tests/net/network-configuration-detector.cpp
similarity index 97%
rename from tests/unit-tests/network-configuration-detector.cpp
rename to tests/unit-tests/net/network-configuration-detector.cpp
index f00b3e8..9aa196b 100644
--- a/tests/unit-tests/network-configuration-detector.cpp
+++ b/tests/unit-tests/net/network-configuration-detector.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
diff --git a/tests/unit-tests/network-configuration-detector.hpp b/tests/unit-tests/net/network-configuration-detector.hpp
similarity index 70%
rename from tests/unit-tests/network-configuration-detector.hpp
rename to tests/unit-tests/net/network-configuration-detector.hpp
index 95d2aa8..c039c52 100644
--- a/tests/unit-tests/network-configuration-detector.hpp
+++ b/tests/unit-tests/net/network-configuration-detector.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -19,12 +19,12 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-#ifndef NDN_TESTS_NETWORK_CONFIGURATION_DETECTOR_HPP
-#define NDN_TESTS_NETWORK_CONFIGURATION_DETECTOR_HPP
+#ifndef NDN_TESTS_NET_NETWORK_CONFIGURATION_DETECTOR_HPP
+#define NDN_TESTS_NET_NETWORK_CONFIGURATION_DETECTOR_HPP
#define SKIP_IF_IPV4_UNAVAILABLE() \
do { \
- if (!NetworkConfigurationDetector::hasIpv4()) { \
+ if (!::ndn::tests::NetworkConfigurationDetector::hasIpv4()) { \
BOOST_WARN_MESSAGE(false, "skipping assertions that require IPv4 support"); \
return; \
} \
@@ -32,12 +32,21 @@
#define SKIP_IF_IPV6_UNAVAILABLE() \
do { \
- if (!NetworkConfigurationDetector::hasIpv6()) { \
+ if (!::ndn::tests::NetworkConfigurationDetector::hasIpv6()) { \
BOOST_WARN_MESSAGE(false, "skipping assertions that require IPv6 support"); \
return; \
} \
} while (false)
+#define SKIP_IF_IP_UNAVAILABLE() \
+ do { \
+ if (!::ndn::tests::NetworkConfigurationDetector::hasIpv4() && \
+ !::ndn::tests::NetworkConfigurationDetector::hasIpv6()) { \
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require either IPv4 or IPv6 support"); \
+ return; \
+ } \
+ } while (false)
+
namespace ndn {
namespace tests {
@@ -63,4 +72,4 @@
} // namespace tests
} // namespace ndn
-#endif // NDN_TESTS_NETWORK_CONFIGURATION_DETECTOR_HPP
+#endif // NDN_TESTS_NET_NETWORK_CONFIGURATION_DETECTOR_HPP
diff --git a/tests/unit-tests/util/network-monitor.t.cpp b/tests/unit-tests/net/network-monitor.t.cpp
similarity index 93%
rename from tests/unit-tests/util/network-monitor.t.cpp
rename to tests/unit-tests/net/network-monitor.t.cpp
index 8e82086..d23cb38 100644
--- a/tests/unit-tests/util/network-monitor.t.cpp
+++ b/tests/unit-tests/net/network-monitor.t.cpp
@@ -19,16 +19,16 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-#include "util/network-monitor.hpp"
+#include "net/network-monitor.hpp"
#include "boost-test.hpp"
#include <boost/asio/io_service.hpp>
namespace ndn {
-namespace util {
+namespace net {
namespace tests {
-BOOST_AUTO_TEST_SUITE(Util)
+BOOST_AUTO_TEST_SUITE(Net)
BOOST_AUTO_TEST_SUITE(TestNetworkMonitor)
#define NM_REQUIRE_CAP(capability) \
@@ -66,8 +66,8 @@
}
BOOST_AUTO_TEST_SUITE_END() // TestNetworkMonitor
-BOOST_AUTO_TEST_SUITE_END() // Util
+BOOST_AUTO_TEST_SUITE_END() // Net
} // namespace tests
-} // namespace util
+} // namespace net
} // namespace ndn
diff --git a/tests/unit-tests/util/dns.t.cpp b/tests/unit-tests/util/dns.t.cpp
deleted file mode 100644
index e76d593..0000000
--- a/tests/unit-tests/util/dns.t.cpp
+++ /dev/null
@@ -1,208 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "util/dns.hpp"
-
-#include "boost-test.hpp"
-#include "../network-configuration-detector.hpp"
-
-#include <boost/asio/io_service.hpp>
-
-namespace ndn {
-namespace util {
-namespace tests {
-
-using boost::asio::ip::address_v4;
-using boost::asio::ip::address_v6;
-
-using ndn::tests::NetworkConfigurationDetector;
-
-class DnsFixture
-{
-public:
- DnsFixture()
- : m_nFailures(0)
- , m_nSuccesses(0)
- {
- }
-
- void
- onSuccess(const dns::IpAddress& resolvedAddress,
- const dns::IpAddress& expectedAddress,
- bool isValid,
- bool shouldCheckAddress = false)
- {
- ++m_nSuccesses;
-
- if (!isValid) {
- BOOST_FAIL("Resolved to " + resolvedAddress.to_string() + ", but should have failed");
- }
-
- BOOST_CHECK_EQUAL(resolvedAddress.is_v4(), expectedAddress.is_v4());
-
- // checking address is not deterministic and should be enabled only
- // if only one IP address will be returned by resolution
- if (shouldCheckAddress) {
- BOOST_CHECK_EQUAL(resolvedAddress, expectedAddress);
- }
- }
-
- void
- onFailure(bool isValid)
- {
- ++m_nFailures;
-
- if (!isValid) {
- BOOST_FAIL("Resolution should not have failed");
- }
-
- BOOST_CHECK_MESSAGE(true, "Resolution failed as expected");
- }
-
-protected:
- uint32_t m_nFailures;
- uint32_t m_nSuccesses;
- boost::asio::io_service m_ioService;
-};
-
-BOOST_AUTO_TEST_SUITE(Util)
-BOOST_FIXTURE_TEST_SUITE(TestDns, DnsFixture)
-
-BOOST_AUTO_TEST_CASE(Asynchronous)
-{
- if (!NetworkConfigurationDetector::hasIpv4() && !NetworkConfigurationDetector::hasIpv6()) {
- BOOST_WARN_MESSAGE(false, "skipping assertions that require either IPv4 or IPv6 support");
- return;
- }
-
- dns::asyncResolve("nothost.nothost.nothost.arpa",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v4()), false, false),
- bind(&DnsFixture::onFailure, this, true),
- m_ioService); // should fail
- m_ioService.run();
-
- BOOST_CHECK_EQUAL(m_nFailures, 1);
- BOOST_CHECK_EQUAL(m_nSuccesses, 0);
-}
-
-BOOST_AUTO_TEST_CASE(AsynchronousV4)
-{
- SKIP_IF_IPV4_UNAVAILABLE();
-
- dns::asyncResolve("192.0.2.1",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v4::from_string("192.0.2.1")),
- true, true),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService);
- m_ioService.run();
-
- BOOST_CHECK_EQUAL(m_nFailures, 0);
- BOOST_CHECK_EQUAL(m_nSuccesses, 1);
-}
-
-BOOST_AUTO_TEST_CASE(AsynchronousV6)
-{
- SKIP_IF_IPV6_UNAVAILABLE();
-
- dns::asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService);
-
- dns::asyncResolve("2001:db8:3f9:0:3025:ccc5:eeeb:86d3",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v6::
- from_string("2001:db8:3f9:0:3025:ccc5:eeeb:86d3")),
- true, true),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService);
- m_ioService.run();
-
- BOOST_CHECK_EQUAL(m_nFailures, 0);
- BOOST_CHECK_EQUAL(m_nSuccesses, 2);
-}
-
-BOOST_AUTO_TEST_CASE(AsynchronousV4AndV6)
-{
- SKIP_IF_IPV4_UNAVAILABLE();
- SKIP_IF_IPV6_UNAVAILABLE();
-
- dns::asyncResolve("www.named-data.net",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v4()), true, false),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService,
- dns::Ipv4Only());
-
- dns::asyncResolve("a.root-servers.net",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v4()), true, false),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService,
- dns::Ipv4Only()); // request IPv4 address
-
- dns::asyncResolve("a.root-servers.net",
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService,
- dns::Ipv6Only()); // request IPv6 address
-
- dns::asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v6()), true, false),
- bind(&DnsFixture::onFailure, this, false),
- m_ioService,
- dns::Ipv6Only());
-
- dns::asyncResolve("ipv6.google.com", // only IPv6 address should be available
- bind(&DnsFixture::onSuccess, this, _1,
- dns::IpAddress(address_v6()), false, false),
- bind(&DnsFixture::onFailure, this, true), // should fail
- m_ioService,
- dns::Ipv4Only());
- m_ioService.run();
-
- BOOST_CHECK_EQUAL(m_nFailures, 1);
- BOOST_CHECK_EQUAL(m_nSuccesses, 4);
-}
-
-BOOST_AUTO_TEST_CASE(Synchronous)
-{
- if (!NetworkConfigurationDetector::hasIpv4() && !NetworkConfigurationDetector::hasIpv6()) {
- BOOST_WARN_MESSAGE(false, "skipping assertions that require either IPv4 or IPv6 support");
- return;
- }
- dns::IpAddress address;
- BOOST_CHECK_NO_THROW(address = dns::syncResolve("www.named-data.net", m_ioService));
-
- BOOST_CHECK(address.is_v4() || address.is_v6());
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestDns
-BOOST_AUTO_TEST_SUITE_END() // Util
-
-} // namespace tests
-} // namespace util
-} // namespace ndn