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 | |
| 7 | #include "face/ethernet-channel-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 | { |
| 19 | EthernetChannelFactory factory; |
| 20 | |
| 21 | std::vector<ethernet::Endpoint> interfaces = EthernetChannelFactory::findAllInterfaces(); |
| 22 | if (interfaces.size() > 0) |
| 23 | { |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 24 | shared_ptr<EthernetFace> face1; |
| 25 | BOOST_REQUIRE_NO_THROW(face1 = factory.createMulticast(interfaces[0], |
| 26 | ethernet::getBroadcastAddress())); |
| 27 | shared_ptr<EthernetFace> face1bis; |
| 28 | BOOST_REQUIRE_NO_THROW(face1bis = factory.createMulticast(interfaces[0], |
| 29 | ethernet::getBroadcastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 30 | BOOST_CHECK_EQUAL(face1, face1bis); |
| 31 | |
| 32 | if (interfaces.size() > 1) |
| 33 | { |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 34 | shared_ptr<EthernetFace> face2; |
| 35 | BOOST_REQUIRE_NO_THROW(face2 = factory.createMulticast(interfaces[1], |
| 36 | ethernet::getBroadcastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 37 | BOOST_CHECK_NE(face1, face2); |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | BOOST_WARN_MESSAGE(interfaces.size() < 2, "Cannot test second EthernetFace creation, " |
| 42 | "only one interface available for pcap"); |
| 43 | } |
| 44 | |
Alexander Afanasyev | ef968e1 | 2014-02-27 15:17:50 -0800 | [diff] [blame] | 45 | shared_ptr<EthernetFace> face3; |
| 46 | BOOST_REQUIRE_NO_THROW(face3 = factory.createMulticast(interfaces[0], |
| 47 | ethernet::getDefaultMulticastAddress())); |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 48 | BOOST_CHECK_NE(face1, face3); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | BOOST_WARN_MESSAGE(interfaces.empty(), "Cannot perform MulticastFacesMap tests, " |
| 53 | "no interfaces are available for pcap"); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(SendPacket) |
| 58 | { |
| 59 | EthernetChannelFactory factory; |
| 60 | |
| 61 | std::vector<ethernet::Endpoint> interfaces = EthernetChannelFactory::findAllInterfaces(); |
| 62 | if (interfaces.empty()) |
| 63 | { |
| 64 | BOOST_WARN_MESSAGE(interfaces.empty(), |
| 65 | "No interfaces are available for pcap, cannot perform SendPacket test"); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | shared_ptr<EthernetFace> face = |
| 70 | factory.createMulticast(interfaces[0], ethernet::getDefaultMulticastAddress()); |
| 71 | |
| 72 | BOOST_REQUIRE(static_cast<bool>(face)); |
| 73 | BOOST_CHECK_EQUAL(face->isLocal(), false); |
| 74 | |
| 75 | Interest interest1("ndn:/TpnzGvW9R"); |
| 76 | Data data1 ("ndn:/KfczhUqVix"); |
| 77 | data1.setContent(0, 0); |
| 78 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 79 | Data data2 ("ndn:/XNBV796f"); |
| 80 | data2.setContent(0, 0); |
| 81 | |
| 82 | ndn::SignatureSha256WithRsa fakeSignature; |
| 83 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 84 | |
| 85 | // set fake signature on data1 and data2 |
| 86 | data1.setSignature(fakeSignature); |
| 87 | data2.setSignature(fakeSignature); |
| 88 | |
| 89 | BOOST_CHECK_NO_THROW(face->sendInterest(interest1)); |
| 90 | BOOST_CHECK_NO_THROW(face->sendData (data1 )); |
| 91 | BOOST_CHECK_NO_THROW(face->sendInterest(interest2)); |
| 92 | BOOST_CHECK_NO_THROW(face->sendData (data2 )); |
| 93 | |
| 94 | // m_ioRemaining = 4; |
| 95 | // m_ioService.run(); |
| 96 | // m_ioService.reset(); |
| 97 | |
| 98 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 99 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 100 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 101 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 102 | |
| 103 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 104 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 105 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 106 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 107 | } |
| 108 | |
| 109 | BOOST_AUTO_TEST_SUITE_END() |
| 110 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 111 | } // namespace tests |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 112 | } // namespace nfd |