blob: 7df879c7ddf4cd85d093d1c46b68d75cef149614 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 Pesavento44deacc2014-02-19 10:48:07 +010024
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080025#include "face/ethernet-factory.hpp"
Davide Pesaventob60cc122014-03-19 19:26:02 +010026#include "core/network-interface.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070027#include "tests/test-common.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010028
Alexander Afanasyev4a771362014-04-24 21:29:33 -070029#include <ndn-cxx/security/key-chain.hpp>
Davide Pesaventob60cc122014-03-19 19:26:02 +010030#include <pcap/pcap.h>
31
Davide Pesavento44deacc2014-02-19 10:48:07 +010032namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Davide Pesavento44deacc2014-02-19 10:48:07 +010034
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture)
Davide Pesavento44deacc2014-02-19 10:48:07 +010036
Davide Pesaventob60cc122014-03-19 19:26:02 +010037class InterfacesFixture : protected BaseFixture
38{
39protected:
40 InterfacesFixture()
41 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030042 EthernetFactory factory;
43
Davide Pesaventob60cc122014-03-19 19:26:02 +010044 std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
45 for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
46 i != ifs.end();
47 ++i)
48 {
49 if (!(*i)->isLoopback() && (*i)->isUp())
50 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030051 try {
52 factory.createMulticastFace(*i, ethernet::getBroadcastAddress());
53 }
54 catch (Face::Error&) {
Davide Pesaventob60cc122014-03-19 19:26:02 +010055 continue;
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030056 }
Davide Pesaventob60cc122014-03-19 19:26:02 +010057
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030058 m_interfaces.push_back(*i);
Davide Pesaventob60cc122014-03-19 19:26:02 +010059 }
60 }
61 }
62
63protected:
64 std::list< shared_ptr<NetworkInterfaceInfo> > m_interfaces;
65};
66
67
68BOOST_FIXTURE_TEST_CASE(MulticastFacesMap, InterfacesFixture)
Davide Pesavento44deacc2014-02-19 10:48:07 +010069{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080070 EthernetFactory factory;
Davide Pesavento44deacc2014-02-19 10:48:07 +010071
Davide Pesaventob60cc122014-03-19 19:26:02 +010072 if (m_interfaces.empty())
Davide Pesavento44deacc2014-02-19 10:48:07 +010073 {
Davide Pesaventob60cc122014-03-19 19:26:02 +010074 BOOST_WARN_MESSAGE(false, "No interfaces available, cannot perform MulticastFacesMap test");
Davide Pesavento44deacc2014-02-19 10:48:07 +010075 return;
76 }
77
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030078 shared_ptr<EthernetFace> face1 = factory.createMulticastFace(m_interfaces.front(),
79 ethernet::getBroadcastAddress());
80 shared_ptr<EthernetFace> face1bis = factory.createMulticastFace(m_interfaces.front(),
81 ethernet::getBroadcastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +010082 BOOST_CHECK_EQUAL(face1, face1bis);
83
84 if (m_interfaces.size() > 1)
85 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030086 shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
87 ethernet::getBroadcastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +010088 BOOST_CHECK_NE(face1, face2);
89 }
90 else
91 {
92 BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
93 "only one interface available");
94 }
95
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030096 shared_ptr<EthernetFace> face3 = factory.createMulticastFace(m_interfaces.front(),
97 ethernet::getDefaultMulticastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +010098 BOOST_CHECK_NE(face1, face3);
99}
100
101BOOST_FIXTURE_TEST_CASE(SendPacket, InterfacesFixture)
102{
103 EthernetFactory factory;
104
105 if (m_interfaces.empty())
106 {
107 BOOST_WARN_MESSAGE(false, "No interfaces available for pcap, cannot perform SendPacket test");
108 return;
109 }
110
111 shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(),
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300112 ethernet::getDefaultMulticastAddress());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100113
114 BOOST_REQUIRE(static_cast<bool>(face));
Alexander Afanasyev355c0662014-03-20 18:08:17 -0700115
116 BOOST_CHECK(!face->isOnDemand());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100117 BOOST_CHECK_EQUAL(face->isLocal(), false);
Junxiao Shi79494162014-04-02 18:25:11 -0700118 BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600119 "ether://[" + ethernet::getDefaultMulticastAddress().toString()+"]");
Junxiao Shi79494162014-04-02 18:25:11 -0700120 BOOST_CHECK_EQUAL(face->getLocalUri().toString(),
121 "dev://" + m_interfaces.front()->name);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100122
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300123 shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
124 shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
125 shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
126 shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100127
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300128 BOOST_CHECK_NO_THROW(face->sendInterest(*interest1));
129 BOOST_CHECK_NO_THROW(face->sendData (*data1 ));
130 BOOST_CHECK_NO_THROW(face->sendInterest(*interest2));
131 BOOST_CHECK_NO_THROW(face->sendData (*data2 ));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100132
133// m_ioRemaining = 4;
134// m_ioService.run();
135// m_ioService.reset();
136
137// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
138// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
139// BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
140// BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
141
142// BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
143// BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
144// BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
145// BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
146}
147
148BOOST_AUTO_TEST_SUITE_END()
149
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700150} // namespace tests
Davide Pesavento44deacc2014-02-19 10:48:07 +0100151} // namespace nfd