Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 3 | * 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 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 25 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 26 | #include "face/ethernet-factory.hpp" |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 27 | #include "core/network-interface.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 28 | |
Davide Pesavento | 4c1a078 | 2014-08-14 16:13:20 +0200 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 30 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 31 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 32 | namespace tests { |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 33 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 35 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 36 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 37 | { |
| 38 | EthernetFactory factory; |
| 39 | |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 40 | auto channels = factory.getChannels(); |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 41 | BOOST_CHECK_EQUAL(channels.empty(), true); |
| 42 | } |
| 43 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 44 | class InterfacesFixture : protected BaseFixture |
| 45 | { |
| 46 | protected: |
| 47 | InterfacesFixture() |
| 48 | { |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 49 | EthernetFactory factory; |
| 50 | |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 51 | for (const auto& netif : listNetworkInterfaces()) { |
| 52 | if (!netif.isLoopback() && netif.isUp()) { |
| 53 | try { |
| 54 | factory.createMulticastFace(netif, ethernet::getBroadcastAddress()); |
| 55 | } |
| 56 | catch (Face::Error&) { |
| 57 | continue; |
| 58 | } |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 59 | |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 60 | m_interfaces.push_back(netif); |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 61 | } |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 62 | } |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | protected: |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 66 | std::vector<NetworkInterfaceInfo> m_interfaces; |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | |
| 70 | BOOST_FIXTURE_TEST_CASE(MulticastFacesMap, InterfacesFixture) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 71 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 72 | EthernetFactory factory; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 73 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 74 | if (m_interfaces.empty()) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 75 | { |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 76 | BOOST_WARN_MESSAGE(false, "No interfaces available, cannot perform MulticastFacesMap test"); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 77 | return; |
| 78 | } |
| 79 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 80 | shared_ptr<EthernetFace> face1 = factory.createMulticastFace(m_interfaces.front(), |
| 81 | ethernet::getBroadcastAddress()); |
| 82 | shared_ptr<EthernetFace> face1bis = factory.createMulticastFace(m_interfaces.front(), |
| 83 | ethernet::getBroadcastAddress()); |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(face1, face1bis); |
| 85 | |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 86 | if (m_interfaces.size() > 1) { |
| 87 | shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(), |
| 88 | ethernet::getBroadcastAddress()); |
| 89 | BOOST_CHECK_NE(face1, face2); |
| 90 | } |
| 91 | else { |
| 92 | BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, " |
| 93 | "only one interface available"); |
| 94 | } |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 95 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 96 | shared_ptr<EthernetFace> face3 = factory.createMulticastFace(m_interfaces.front(), |
| 97 | ethernet::getDefaultMulticastAddress()); |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 98 | BOOST_CHECK_NE(face1, face3); |
| 99 | } |
| 100 | |
| 101 | BOOST_FIXTURE_TEST_CASE(SendPacket, InterfacesFixture) |
| 102 | { |
| 103 | EthernetFactory factory; |
| 104 | |
| 105 | if (m_interfaces.empty()) |
| 106 | { |
| 107 | BOOST_WARN_MESSAGE(false, "No interfaces available for pcap, cannot perform SendPacket test"); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(), |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 112 | ethernet::getDefaultMulticastAddress()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 113 | BOOST_REQUIRE(static_cast<bool>(face)); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 114 | |
| 115 | BOOST_CHECK(!face->isOnDemand()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(face->isLocal(), false); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(face->getRemoteUri().toString(), |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 118 | "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 119 | BOOST_CHECK_EQUAL(face->getLocalUri().toString(), |
Davide Pesavento | b499a60 | 2014-11-18 22:36:56 +0100 | [diff] [blame^] | 120 | "dev://" + m_interfaces.front().name); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 121 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 122 | shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 123 | shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
| 124 | shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 125 | shared_ptr<Data> data2 = makeData("ndn:/XNBV796f"); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 126 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 127 | BOOST_CHECK_NO_THROW(face->sendInterest(*interest1)); |
| 128 | BOOST_CHECK_NO_THROW(face->sendData (*data1 )); |
| 129 | BOOST_CHECK_NO_THROW(face->sendInterest(*interest2)); |
| 130 | BOOST_CHECK_NO_THROW(face->sendData (*data2 )); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 131 | |
| 132 | // m_ioRemaining = 4; |
| 133 | // m_ioService.run(); |
| 134 | // m_ioService.reset(); |
| 135 | |
| 136 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 137 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 138 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 139 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 140 | |
| 141 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 142 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 143 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 144 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 145 | } |
| 146 | |
| 147 | BOOST_AUTO_TEST_SUITE_END() |
| 148 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 149 | } // namespace tests |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 150 | } // namespace nfd |