]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/tests/unit/network_interface_test.cc
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2019 Cloudius Systems, Ltd.
22 #include <seastar/testing/test_case.hh>
23 #include <seastar/net/api.hh>
24 #include <seastar/net/inet_address.hh>
25 #include <seastar/net/ethernet.hh>
26 #include <seastar/net/ip.hh>
27 #include <seastar/core/reactor.hh>
28 #include <seastar/core/thread.hh>
29 #include <seastar/util/log.hh>
31 using namespace seastar
;
33 static logger
niflog("network_interface_test");
35 SEASTAR_TEST_CASE(list_interfaces
) {
36 // just verifying we have something. And can access all the stuff.
37 auto interfaces
= engine().net().network_interfaces();
38 BOOST_REQUIRE_GT(interfaces
.size(), 0);
40 for (auto& nif
: interfaces
) {
41 niflog
.info("Iface: {}, index = {}, mtu = {}, loopback = {}, virtual = {}, up = {}",
42 nif
.name(), nif
.index(), nif
.mtu(), nif
.is_loopback(), nif
.is_virtual(), nif
.is_up()
44 if (nif
.hardware_address().size() >= 6) {
45 niflog
.info(" HW: {}", net::ethernet_address(nif
.hardware_address().data()));
47 for (auto& addr
: nif
.addresses()) {
48 niflog
.info(" Addr: {}", addr
);
52 return make_ready_future();
55 SEASTAR_TEST_CASE(match_ipv6_scope
) {
56 auto interfaces
= engine().net().network_interfaces();
58 for (auto& nif
: interfaces
) {
59 if (nif
.is_loopback()) {
62 auto i
= std::find_if(nif
.addresses().begin(), nif
.addresses().end(), std::mem_fn(&net::inet_address::is_ipv6
));
63 if (i
== nif
.addresses().end()) {
67 std::ostringstream ss
;
68 ss
<< net::inet_address(i
->as_ipv6_address()) << "%" << nif
.name();
71 net::inet_address
na(text
);
73 BOOST_REQUIRE_EQUAL(na
.as_ipv6_address(), i
->as_ipv6_address());
74 // also verify that the inet_address itself matches
75 BOOST_REQUIRE_EQUAL(na
, *i
);
76 // and that inet_address _without_ scope matches.
77 BOOST_REQUIRE_EQUAL(net::inet_address(na
.as_ipv6_address()), *i
);
78 BOOST_REQUIRE_EQUAL(na
.scope(), nif
.index());
79 // and that they are not ipv4 addresses
80 BOOST_REQUIRE_THROW(i
->as_ipv4_address(), std::invalid_argument
);
81 BOOST_REQUIRE_THROW(na
.as_ipv4_address(), std::invalid_argument
);
83 niflog
.info("Org: {}, Parsed: {}, Text: {}", *i
, na
, text
);
87 return make_ready_future();