Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [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 | * |
| 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 Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 24 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 25 | #include "face/ethernet-factory.hpp" |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 26 | #include "core/network-interface.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 27 | #include "tests/test-common.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 28 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 29 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 30 | #include <pcap/pcap.h> |
| 31 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 34 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 36 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 37 | class InterfacesFixture : protected BaseFixture |
| 38 | { |
| 39 | protected: |
| 40 | InterfacesFixture() |
| 41 | { |
| 42 | std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces(); |
| 43 | for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin(); |
| 44 | i != ifs.end(); |
| 45 | ++i) |
| 46 | { |
| 47 | if (!(*i)->isLoopback() && (*i)->isUp()) |
| 48 | { |
| 49 | pcap_t* p = pcap_create((*i)->name.c_str(), 0); |
| 50 | if (!p) |
| 51 | continue; |
| 52 | |
| 53 | if (pcap_activate(p) == 0) |
| 54 | m_interfaces.push_back(*i); |
| 55 | |
| 56 | pcap_close(p); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | protected: |
| 62 | std::list< shared_ptr<NetworkInterfaceInfo> > m_interfaces; |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | BOOST_FIXTURE_TEST_CASE(MulticastFacesMap, InterfacesFixture) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 67 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 68 | EthernetFactory factory; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 69 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 70 | if (m_interfaces.empty()) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 71 | { |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 72 | BOOST_WARN_MESSAGE(false, "No interfaces available, cannot perform MulticastFacesMap test"); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 76 | shared_ptr<EthernetFace> face1; |
| 77 | BOOST_REQUIRE_NO_THROW(face1 = factory.createMulticastFace(m_interfaces.front(), |
| 78 | ethernet::getBroadcastAddress())); |
| 79 | shared_ptr<EthernetFace> face1bis; |
| 80 | BOOST_REQUIRE_NO_THROW(face1bis = factory.createMulticastFace(m_interfaces.front(), |
| 81 | ethernet::getBroadcastAddress())); |
| 82 | BOOST_CHECK_EQUAL(face1, face1bis); |
| 83 | |
| 84 | if (m_interfaces.size() > 1) |
| 85 | { |
| 86 | shared_ptr<EthernetFace> face2; |
| 87 | BOOST_REQUIRE_NO_THROW(face2 = factory.createMulticastFace(m_interfaces.back(), |
| 88 | ethernet::getBroadcastAddress())); |
| 89 | BOOST_CHECK_NE(face1, face2); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, " |
| 94 | "only one interface available"); |
| 95 | } |
| 96 | |
| 97 | shared_ptr<EthernetFace> face3; |
| 98 | BOOST_REQUIRE_NO_THROW(face3 = factory.createMulticastFace(m_interfaces.front(), |
| 99 | ethernet::getDefaultMulticastAddress())); |
| 100 | BOOST_CHECK_NE(face1, face3); |
| 101 | } |
| 102 | |
| 103 | BOOST_FIXTURE_TEST_CASE(SendPacket, InterfacesFixture) |
| 104 | { |
| 105 | EthernetFactory factory; |
| 106 | |
| 107 | if (m_interfaces.empty()) |
| 108 | { |
| 109 | BOOST_WARN_MESSAGE(false, "No interfaces available for pcap, cannot perform SendPacket test"); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(), |
| 114 | ethernet::getDefaultMulticastAddress()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 115 | |
| 116 | BOOST_REQUIRE(static_cast<bool>(face)); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 117 | |
| 118 | BOOST_CHECK(!face->isOnDemand()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 119 | BOOST_CHECK_EQUAL(face->isLocal(), false); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL(face->getRemoteUri().toString(), |
Davide Pesavento | edae353 | 2014-04-09 03:07:11 +0200 | [diff] [blame] | 121 | "ether://" + ethernet::getDefaultMulticastAddress().toString()); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(face->getLocalUri().toString(), |
| 123 | "dev://" + m_interfaces.front()->name); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 124 | |
| 125 | Interest interest1("ndn:/TpnzGvW9R"); |
| 126 | Data data1 ("ndn:/KfczhUqVix"); |
| 127 | data1.setContent(0, 0); |
| 128 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 129 | Data data2 ("ndn:/XNBV796f"); |
| 130 | data2.setContent(0, 0); |
| 131 | |
| 132 | ndn::SignatureSha256WithRsa fakeSignature; |
| 133 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 134 | |
| 135 | // set fake signature on data1 and data2 |
| 136 | data1.setSignature(fakeSignature); |
| 137 | data2.setSignature(fakeSignature); |
| 138 | |
| 139 | BOOST_CHECK_NO_THROW(face->sendInterest(interest1)); |
| 140 | BOOST_CHECK_NO_THROW(face->sendData (data1 )); |
| 141 | BOOST_CHECK_NO_THROW(face->sendInterest(interest2)); |
| 142 | BOOST_CHECK_NO_THROW(face->sendData (data2 )); |
| 143 | |
| 144 | // m_ioRemaining = 4; |
| 145 | // m_ioService.run(); |
| 146 | // m_ioService.reset(); |
| 147 | |
| 148 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 149 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 150 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 151 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 152 | |
| 153 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 154 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 155 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 156 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 157 | } |
| 158 | |
| 159 | BOOST_AUTO_TEST_SUITE_END() |
| 160 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 161 | } // namespace tests |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 162 | } // namespace nfd |