---
tests/unit/network_interface_test.cc | 81 ++++++++++++++++++++++++++++
tests/unit/CMakeLists.txt | 3 ++
2 files changed, 84 insertions(+)
create mode 100644 tests/unit/network_interface_test.cc
diff --git a/tests/unit/network_interface_test.cc b/tests/unit/network_interface_test.cc
new file mode 100644
index 00000000..b061e399
--- /dev/null
+++ b/tests/unit/network_interface_test.cc
@@ -0,0 +1,81 @@
+/*
+ * This file is open source software, licensed to you under the terms
+ * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
+ * distributed with this work for additional information regarding copyright
+ * ownership. You may not use this file except in compliance with the License.
+ *
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Copyright (C) 2019 Cloudius Systems, Ltd.
+ */
+
+#include <seastar/testing/test_case.hh>
+#include <seastar/net/api.hh>
+#include <seastar/net/inet_address.hh>
+#include <seastar/net/ethernet.hh>
+#include <seastar/net/ip.hh>
+#include <seastar/core/reactor.hh>
+#include <seastar/core/thread.hh>
+#include <seastar/util/log.hh>
+
+using namespace seastar;
+
+static logger niflog("network_interface_test");
+
+SEASTAR_TEST_CASE(list_interfaces) {
+ // just verifying we have something. And can access all the stuff.
+ auto interfaces = engine().net().network_interfaces();
+ BOOST_REQUIRE_GT(interfaces.size(), 0);
+
+ for (auto& nif : interfaces) {
+
niflog.info("Iface: {}, index = {}, mtu = {}, loopback = {}, virtual = {}, up = {}",
+
nif.name(), nif.index(), nif.mtu(), nif.is_loopback(), nif.is_virtual(), nif.is_up()
+ );
+ if (nif.hardware_address().size() >= 6) {
+
niflog.info(" HW: {}", net::ethernet_address(nif.hardware_address().data()));
+ }
+ for (auto& addr : nif.addresses()) {
+
niflog.info(" Addr: {}", addr);
+ }
+ }
+
+ return make_ready_future();
+}
+
+SEASTAR_TEST_CASE(match_ipv6_scope) {
+ auto interfaces = engine().net().network_interfaces();
+
+ for (auto& nif : interfaces) {
+ if (nif.is_loopback()) {
+ continue;
+ }
+ auto i = std::find_if(nif.addresses().begin(), nif.addresses().end(), std::mem_fn(&net::inet_address::is_ipv6));
+ if (i == nif.addresses().end()) {
+ continue;
+ }
+
+ std::ostringstream ss;
+ ss << net::inet_address(i->as_ipv6_address()) << "%" <<
nif.name();
+ auto text = ss.str();
+
+ net::inet_address na(text);
+
+ BOOST_REQUIRE_EQUAL(na.as_ipv6_address(), i->as_ipv6_address());
+ BOOST_REQUIRE_EQUAL(na.scope(), nif.index());
+
+
niflog.info("Org: {}, Parsed: {}, Text: {}", *i, na, text);
+
+ }
+
+ return make_ready_future();
+}
diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt
index 67be5eed..d2e9c0c4 100644
--- a/tests/unit/CMakeLists.txt
+++ b/tests/unit/CMakeLists.txt
@@ -306,6 +306,9 @@ seastar_add_test (httpd
seastar_add_test (ipv6
SOURCES ipv6_test.cc)
+seastar_add_test (network_interface
+ SOURCES network_interface_test.cc)
+
seastar_add_test (json_formatter
SOURCES json_formatter_test.cc)
--
2.21.0