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