Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #include "face/ethernet-factory.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 8 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 9 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 10 | #include "tests/test-common.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 13 | namespace tests { |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 14 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 15 | BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 16 | |
| 17 | BOOST_AUTO_TEST_CASE(MulticastFacesMap) |
| 18 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 19 | EthernetFactory factory; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 20 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 21 | std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces(); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 22 | if (interfaces.size() > 0) |
| 23 | { |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 24 | shared_ptr<EthernetFace> face1; |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 25 | BOOST_REQUIRE_NO_THROW(face1 = |
| 26 | factory.createMulticastFace(interfaces[0], |
| 27 | ethernet::getBroadcastAddress())); |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 28 | shared_ptr<EthernetFace> face1bis; |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 29 | BOOST_REQUIRE_NO_THROW(face1bis = |
| 30 | factory.createMulticastFace(interfaces[0], |
| 31 | ethernet::getBroadcastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 32 | BOOST_CHECK_EQUAL(face1, face1bis); |
| 33 | |
| 34 | if (interfaces.size() > 1) |
| 35 | { |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 36 | shared_ptr<EthernetFace> face2; |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 37 | BOOST_REQUIRE_NO_THROW(face2 = |
| 38 | factory.createMulticastFace(interfaces[1], |
| 39 | ethernet::getBroadcastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 40 | BOOST_CHECK_NE(face1, face2); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | BOOST_WARN_MESSAGE(interfaces.size() < 2, "Cannot test second EthernetFace creation, " |
| 45 | "only one interface available for pcap"); |
| 46 | } |
| 47 | |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 48 | shared_ptr<EthernetFace> face3; |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 49 | BOOST_REQUIRE_NO_THROW(face3 = |
| 50 | factory.createMulticastFace(interfaces[0], |
| 51 | ethernet::getDefaultMulticastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 52 | BOOST_CHECK_NE(face1, face3); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | BOOST_WARN_MESSAGE(interfaces.empty(), "Cannot perform MulticastFacesMap tests, " |
| 57 | "no interfaces are available for pcap"); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | BOOST_AUTO_TEST_CASE(SendPacket) |
| 62 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 63 | EthernetFactory factory; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 64 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 65 | std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces(); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 66 | if (interfaces.empty()) |
| 67 | { |
| 68 | BOOST_WARN_MESSAGE(interfaces.empty(), |
| 69 | "No interfaces are available for pcap, cannot perform SendPacket test"); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | shared_ptr<EthernetFace> face = |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 74 | factory.createMulticastFace(interfaces[0], ethernet::getDefaultMulticastAddress()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 75 | |
| 76 | BOOST_REQUIRE(static_cast<bool>(face)); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame^] | 77 | |
| 78 | BOOST_CHECK(!face->isOnDemand()); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(face->isLocal(), false); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(face->getUri().toString(), |
| 81 | "ether://" + interfaces[0] + "/" + |
| 82 | ethernet::getDefaultMulticastAddress().toString(':')); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 83 | |
| 84 | Interest interest1("ndn:/TpnzGvW9R"); |
| 85 | Data data1 ("ndn:/KfczhUqVix"); |
| 86 | data1.setContent(0, 0); |
| 87 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 88 | Data data2 ("ndn:/XNBV796f"); |
| 89 | data2.setContent(0, 0); |
| 90 | |
| 91 | ndn::SignatureSha256WithRsa fakeSignature; |
| 92 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 93 | |
| 94 | // set fake signature on data1 and data2 |
| 95 | data1.setSignature(fakeSignature); |
| 96 | data2.setSignature(fakeSignature); |
| 97 | |
| 98 | BOOST_CHECK_NO_THROW(face->sendInterest(interest1)); |
| 99 | BOOST_CHECK_NO_THROW(face->sendData (data1 )); |
| 100 | BOOST_CHECK_NO_THROW(face->sendInterest(interest2)); |
| 101 | BOOST_CHECK_NO_THROW(face->sendData (data2 )); |
| 102 | |
| 103 | // m_ioRemaining = 4; |
| 104 | // m_ioService.run(); |
| 105 | // m_ioService.reset(); |
| 106 | |
| 107 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 108 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 109 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 110 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 111 | |
| 112 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 113 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 114 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 115 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 116 | } |
| 117 | |
| 118 | BOOST_AUTO_TEST_SUITE_END() |
| 119 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 120 | } // namespace tests |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 121 | } // namespace nfd |