blob: 43436bbfb75b5ec0c00309acde225a92e0ec16b2 [file] [log] [blame]
Davide Pesavento248d6bd2014-03-09 10:24:08 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080024 */
Davide Pesavento248d6bd2014-03-09 10:24:08 +010025
26#include "core/network-interface.hpp"
27#include "tests/test-common.hpp"
28
Davide Pesavento248d6bd2014-03-09 10:24:08 +010029namespace nfd {
30namespace tests {
31
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080032BOOST_FIXTURE_TEST_SUITE(TestNetworkInterface, BaseFixture)
Davide Pesavento248d6bd2014-03-09 10:24:08 +010033
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080034BOOST_AUTO_TEST_CASE(ListRealNetworkInterfaces)
Davide Pesavento248d6bd2014-03-09 10:24:08 +010035{
Davide Pesaventob499a602014-11-18 22:36:56 +010036 std::vector<NetworkInterfaceInfo> netifs;
Davide Pesavento248d6bd2014-03-09 10:24:08 +010037 BOOST_CHECK_NO_THROW(netifs = listNetworkInterfaces());
38
Davide Pesaventob499a602014-11-18 22:36:56 +010039 for (const auto& netif : netifs) {
40 BOOST_TEST_MESSAGE(netif.index << ": " << netif.name);
41 BOOST_TEST_MESSAGE("\tether " << netif.etherAddress);
42 for (const auto& address : netif.ipv4Addresses)
Davide Pesavento248d6bd2014-03-09 10:24:08 +010043 BOOST_TEST_MESSAGE("\tinet " << address);
Davide Pesaventob499a602014-11-18 22:36:56 +010044 for (const auto& address : netif.ipv6Addresses)
Davide Pesavento248d6bd2014-03-09 10:24:08 +010045 BOOST_TEST_MESSAGE("\tinet6 " << address);
Davide Pesaventob499a602014-11-18 22:36:56 +010046 BOOST_TEST_MESSAGE("\tloopback : " << netif.isLoopback());
47 BOOST_TEST_MESSAGE("\tmulticast : " << netif.isMulticastCapable());
48 BOOST_TEST_MESSAGE("\tup : " << netif.isUp());
Davide Pesavento248d6bd2014-03-09 10:24:08 +010049 }
50}
51
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080052class FakeNetworkInterfaceFixture : public BaseFixture
53{
54public:
55 FakeNetworkInterfaceFixture()
56 {
57 using namespace boost::asio::ip;
58
59 auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
60
61 fakeInterfaces->push_back(
62 NetworkInterfaceInfo {0, "lo0",
63 ethernet::Address(),
64 {address_v4::from_string("127.0.0.1")},
65 {address_v6::from_string("fe80::1")},
66 address_v4::from_string("127.255.255.255"),
67 IFF_LOOPBACK | IFF_UP});
68 fakeInterfaces->push_back(
69 NetworkInterfaceInfo {1, "eth0",
70 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
71 {address_v4::from_string("192.168.2.1")},
72 {},
73 address_v4::from_string("192.168.2.255"),
74 0});
75 fakeInterfaces->push_back(
76 NetworkInterfaceInfo {2, "eth1",
77 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
78 {address_v4::from_string("198.51.100.1")},
79 {address_v6::from_string("2001:db8::1")},
80 address_v4::from_string("198.51.100.255"),
81 IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
82
83 setDebugNetworkInterfaces(fakeInterfaces);
84 }
85
86 ~FakeNetworkInterfaceFixture()
87 {
88 setDebugNetworkInterfaces(nullptr);
89 }
90};
91
92BOOST_FIXTURE_TEST_CASE(ListFakeNetworkInterfaces, FakeNetworkInterfaceFixture)
93{
94 std::vector<NetworkInterfaceInfo> netifs;
95 BOOST_CHECK_NO_THROW(netifs = listNetworkInterfaces());
96
97 BOOST_REQUIRE_EQUAL(netifs.size(), 3);
98
99 BOOST_CHECK_EQUAL(netifs[0].index, 0);
100 BOOST_CHECK_EQUAL(netifs[1].index, 1);
101 BOOST_CHECK_EQUAL(netifs[2].index, 2);
102
103 BOOST_CHECK_EQUAL(netifs[0].name, "lo0");
104 BOOST_CHECK_EQUAL(netifs[1].name, "eth0");
105 BOOST_CHECK_EQUAL(netifs[2].name, "eth1");
106
107 // no real value of testing other parameters
108}
109
Davide Pesavento248d6bd2014-03-09 10:24:08 +0100110BOOST_AUTO_TEST_SUITE_END()
111
112} // namespace tests
113} // namespace nfd