blob: 905e2e79bb084b1f98077b5bc058cd4edc5ce628 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * 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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Davide Pesavento44deacc2014-02-19 10:48:07 +010025
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080026#include "face/ethernet-factory.hpp"
Davide Pesaventob60cc122014-03-19 19:26:02 +010027#include "core/network-interface.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010029
Alexander Afanasyev4a771362014-04-24 21:29:33 -070030#include <ndn-cxx/security/key-chain.hpp>
Davide Pesaventob60cc122014-03-19 19:26:02 +010031#include <pcap/pcap.h>
32
Davide Pesavento44deacc2014-02-19 10:48:07 +010033namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034namespace tests {
Davide Pesavento44deacc2014-02-19 10:48:07 +010035
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture)
Davide Pesavento44deacc2014-02-19 10:48:07 +010037
Steve DiBenedettoef04f272014-06-04 14:28:31 -060038BOOST_AUTO_TEST_CASE(GetChannels)
39{
40 EthernetFactory factory;
41
42 std::list<shared_ptr<const Channel> > channels = factory.getChannels();
43 BOOST_CHECK_EQUAL(channels.empty(), true);
44}
45
Davide Pesaventob60cc122014-03-19 19:26:02 +010046class InterfacesFixture : protected BaseFixture
47{
48protected:
49 InterfacesFixture()
50 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030051 EthernetFactory factory;
52
Davide Pesaventob60cc122014-03-19 19:26:02 +010053 std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
54 for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
55 i != ifs.end();
56 ++i)
57 {
58 if (!(*i)->isLoopback() && (*i)->isUp())
59 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030060 try {
61 factory.createMulticastFace(*i, ethernet::getBroadcastAddress());
62 }
63 catch (Face::Error&) {
Davide Pesaventob60cc122014-03-19 19:26:02 +010064 continue;
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030065 }
Davide Pesaventob60cc122014-03-19 19:26:02 +010066
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030067 m_interfaces.push_back(*i);
Davide Pesaventob60cc122014-03-19 19:26:02 +010068 }
69 }
70 }
71
72protected:
73 std::list< shared_ptr<NetworkInterfaceInfo> > m_interfaces;
74};
75
76
77BOOST_FIXTURE_TEST_CASE(MulticastFacesMap, InterfacesFixture)
Davide Pesavento44deacc2014-02-19 10:48:07 +010078{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080079 EthernetFactory factory;
Davide Pesavento44deacc2014-02-19 10:48:07 +010080
Davide Pesaventob60cc122014-03-19 19:26:02 +010081 if (m_interfaces.empty())
Davide Pesavento44deacc2014-02-19 10:48:07 +010082 {
Davide Pesaventob60cc122014-03-19 19:26:02 +010083 BOOST_WARN_MESSAGE(false, "No interfaces available, cannot perform MulticastFacesMap test");
Davide Pesavento44deacc2014-02-19 10:48:07 +010084 return;
85 }
86
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030087 shared_ptr<EthernetFace> face1 = factory.createMulticastFace(m_interfaces.front(),
88 ethernet::getBroadcastAddress());
89 shared_ptr<EthernetFace> face1bis = factory.createMulticastFace(m_interfaces.front(),
90 ethernet::getBroadcastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +010091 BOOST_CHECK_EQUAL(face1, face1bis);
92
93 if (m_interfaces.size() > 1)
94 {
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +030095 shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
96 ethernet::getBroadcastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +010097 BOOST_CHECK_NE(face1, face2);
98 }
99 else
100 {
101 BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
102 "only one interface available");
103 }
104
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300105 shared_ptr<EthernetFace> face3 = factory.createMulticastFace(m_interfaces.front(),
106 ethernet::getDefaultMulticastAddress());
Davide Pesaventob60cc122014-03-19 19:26:02 +0100107 BOOST_CHECK_NE(face1, face3);
108}
109
110BOOST_FIXTURE_TEST_CASE(SendPacket, InterfacesFixture)
111{
112 EthernetFactory factory;
113
114 if (m_interfaces.empty())
115 {
116 BOOST_WARN_MESSAGE(false, "No interfaces available for pcap, cannot perform SendPacket test");
117 return;
118 }
119
120 shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(),
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300121 ethernet::getDefaultMulticastAddress());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100122
123 BOOST_REQUIRE(static_cast<bool>(face));
Alexander Afanasyev355c0662014-03-20 18:08:17 -0700124
125 BOOST_CHECK(!face->isOnDemand());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100126 BOOST_CHECK_EQUAL(face->isLocal(), false);
Junxiao Shi79494162014-04-02 18:25:11 -0700127 BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600128 "ether://[" + ethernet::getDefaultMulticastAddress().toString()+"]");
Junxiao Shi79494162014-04-02 18:25:11 -0700129 BOOST_CHECK_EQUAL(face->getLocalUri().toString(),
130 "dev://" + m_interfaces.front()->name);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100131
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300132 shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
133 shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
134 shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
135 shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100136
Alexander Afanasyevb56c5b92014-06-05 08:05:24 +0300137 BOOST_CHECK_NO_THROW(face->sendInterest(*interest1));
138 BOOST_CHECK_NO_THROW(face->sendData (*data1 ));
139 BOOST_CHECK_NO_THROW(face->sendInterest(*interest2));
140 BOOST_CHECK_NO_THROW(face->sendData (*data2 ));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100141
142// m_ioRemaining = 4;
143// m_ioService.run();
144// m_ioService.reset();
145
146// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
147// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
148// BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
149// BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
150
151// BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
152// BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
153// BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
154// BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
155}
156
157BOOST_AUTO_TEST_SUITE_END()
158
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700159} // namespace tests
Davide Pesavento44deacc2014-02-19 10:48:07 +0100160} // namespace nfd