blob: 2e731bf1f657b0f468d6790534dfc7412c6225c9 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- 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 Afanasyev0eb70652014-02-27 18:35:07 -08007#include "face/ethernet-factory.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +01008#include <ndn-cpp-dev/security/key-chain.hpp>
9
Junxiao Shid9ee45c2014-02-27 15:38:11 -070010#include "tests/test-common.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010011
12namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070013namespace tests {
Davide Pesavento44deacc2014-02-19 10:48:07 +010014
Junxiao Shid9ee45c2014-02-27 15:38:11 -070015BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture)
Davide Pesavento44deacc2014-02-19 10:48:07 +010016
17BOOST_AUTO_TEST_CASE(MulticastFacesMap)
18{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080019 EthernetFactory factory;
Davide Pesavento44deacc2014-02-19 10:48:07 +010020
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080021 std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces();
Davide Pesavento44deacc2014-02-19 10:48:07 +010022 if (interfaces.size() > 0)
23 {
Alexander Afanasyevef968e12014-02-27 15:17:50 -080024 shared_ptr<EthernetFace> face1;
Alexander Afanasyevd6655302014-02-28 08:41:28 -080025 BOOST_REQUIRE_NO_THROW(face1 =
26 factory.createMulticastFace(interfaces[0],
27 ethernet::getBroadcastAddress()));
Alexander Afanasyevef968e12014-02-27 15:17:50 -080028 shared_ptr<EthernetFace> face1bis;
Alexander Afanasyevd6655302014-02-28 08:41:28 -080029 BOOST_REQUIRE_NO_THROW(face1bis =
30 factory.createMulticastFace(interfaces[0],
31 ethernet::getBroadcastAddress()));
Davide Pesavento44deacc2014-02-19 10:48:07 +010032 BOOST_CHECK_EQUAL(face1, face1bis);
33
34 if (interfaces.size() > 1)
35 {
Alexander Afanasyevef968e12014-02-27 15:17:50 -080036 shared_ptr<EthernetFace> face2;
Alexander Afanasyevd6655302014-02-28 08:41:28 -080037 BOOST_REQUIRE_NO_THROW(face2 =
38 factory.createMulticastFace(interfaces[1],
39 ethernet::getBroadcastAddress()));
Davide Pesavento44deacc2014-02-19 10:48:07 +010040 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 Afanasyevef968e12014-02-27 15:17:50 -080048 shared_ptr<EthernetFace> face3;
Alexander Afanasyevd6655302014-02-28 08:41:28 -080049 BOOST_REQUIRE_NO_THROW(face3 =
50 factory.createMulticastFace(interfaces[0],
51 ethernet::getDefaultMulticastAddress()));
Davide Pesavento44deacc2014-02-19 10:48:07 +010052 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
61BOOST_AUTO_TEST_CASE(SendPacket)
62{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080063 EthernetFactory factory;
Davide Pesavento44deacc2014-02-19 10:48:07 +010064
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080065 std::vector<ethernet::Endpoint> interfaces = EthernetFactory::findAllInterfaces();
Davide Pesavento44deacc2014-02-19 10:48:07 +010066 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 Afanasyevd6655302014-02-28 08:41:28 -080074 factory.createMulticastFace(interfaces[0], ethernet::getDefaultMulticastAddress());
Davide Pesavento44deacc2014-02-19 10:48:07 +010075
76 BOOST_REQUIRE(static_cast<bool>(face));
77 BOOST_CHECK_EQUAL(face->isLocal(), false);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000078 BOOST_CHECK_EQUAL(face->getUri().toString(),
79 "ether://" + interfaces[0] + "/" +
80 ethernet::getDefaultMulticastAddress().toString(':'));
Davide Pesavento44deacc2014-02-19 10:48:07 +010081
82 Interest interest1("ndn:/TpnzGvW9R");
83 Data data1 ("ndn:/KfczhUqVix");
84 data1.setContent(0, 0);
85 Interest interest2("ndn:/QWiIMfj5sL");
86 Data data2 ("ndn:/XNBV796f");
87 data2.setContent(0, 0);
88
89 ndn::SignatureSha256WithRsa fakeSignature;
90 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
91
92 // set fake signature on data1 and data2
93 data1.setSignature(fakeSignature);
94 data2.setSignature(fakeSignature);
95
96 BOOST_CHECK_NO_THROW(face->sendInterest(interest1));
97 BOOST_CHECK_NO_THROW(face->sendData (data1 ));
98 BOOST_CHECK_NO_THROW(face->sendInterest(interest2));
99 BOOST_CHECK_NO_THROW(face->sendData (data2 ));
100
101// m_ioRemaining = 4;
102// m_ioService.run();
103// m_ioService.reset();
104
105// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
106// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
107// BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
108// BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
109
110// BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
111// BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
112// BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
113// BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
114}
115
116BOOST_AUTO_TEST_SUITE_END()
117
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700118} // namespace tests
Davide Pesavento44deacc2014-02-19 10:48:07 +0100119} // namespace nfd