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