blob: a918b2603ebfc8b80ce6518922a193c26dc73fb5 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, 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.
10 *
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/>.
24 */
25
26#include "face/generic-link-service.hpp"
27#include "face/lp-face.hpp"
28#include "dummy-transport.hpp"
29
30#include "tests/test-common.hpp"
31
32namespace nfd {
33namespace face {
34namespace tests {
35
36using namespace nfd::tests;
37
38BOOST_AUTO_TEST_SUITE(Face)
39
40class GenericLinkServiceFixture : public BaseFixture
41{
42protected:
43 GenericLinkServiceFixture()
44 : service(nullptr)
45 , transport(nullptr)
46 {
47 this->initialize();
48 // By default, GenericLinkService is created with default options.
49 // Test cases may invoke .initialize with alternate options.
50 }
51
52 void
53 initialize()
54 {
55 // TODO#3104 add GenericLinkService::Options parameter,
56 // and create GenericLinkService with options
57 face.reset(new LpFace(make_unique<GenericLinkService>(),
58 make_unique<DummyTransport>()));
59 service = static_cast<GenericLinkService*>(face->getLinkService());
60 transport = static_cast<DummyTransport*>(face->getTransport());
61
62 face->afterReceiveInterest.connect(
63 [this] (const Interest& interest) { receivedInterests.push_back(interest); });
64 face->afterReceiveData.connect(
65 [this] (const Data& data) { receivedData.push_back(data); });
66 face->afterReceiveNack.connect(
67 [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); });
68 }
69
70protected:
71 unique_ptr<LpFace> face;
72 GenericLinkService* service;
73 DummyTransport* transport;
74 std::vector<Interest> receivedInterests;
75 std::vector<Data> receivedData;
76 std::vector<lp::Nack> receivedNacks;
77};
78
79BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
80
81
82BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
83
84BOOST_AUTO_TEST_CASE(SendInterest)
85{
86 // TODO#3104 initialize with Options that disables all services
87
88 shared_ptr<Interest> interest1 = makeInterest("/localhost/test");
89
90 face->sendInterest(*interest1);
91
92 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
93 BOOST_CHECK(transport->sentPackets.back().packet == interest1->wireEncode());
94}
95
96BOOST_AUTO_TEST_CASE(SendData)
97{
98 // TODO#3104 initialize with Options that disables all services
99
100 shared_ptr<Data> data1 = makeData("/localhost/test");
101
102 face->sendData(*data1);
103
104 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
105 BOOST_CHECK(transport->sentPackets.back().packet == data1->wireEncode());
106}
107
108BOOST_AUTO_TEST_CASE(SendNack)
109{
110 // TODO#3104 initialize with Options that disables all services
111
112 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
113
114 face->sendNack(nack1);
115
116 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
117 lp::Packet nack1pkt;
118 BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet));
119 BOOST_CHECK_EQUAL(nack1pkt.has<lp::NackField>(), true);
120 BOOST_CHECK_EQUAL(nack1pkt.has<lp::FragmentField>(), true);
121}
122
123BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
124{
125 // TODO#3104 initialize with Options that disables all services
126
127 shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
128
129 transport->receivePacket(interest1->wireEncode());
130
131 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
132 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
133}
134
135BOOST_AUTO_TEST_CASE(ReceiveInterest)
136{
137 // TODO#3104 initialize with Options that disables all services
138
139 shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
140 lp::Packet lpPacket;
141 lpPacket.set<lp::FragmentField>(std::make_pair(
142 interest1->wireEncode().begin(), interest1->wireEncode().end()));
143 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
144
145 transport->receivePacket(lpPacket.wireEncode());
146
147 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
148 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
149}
150
151BOOST_AUTO_TEST_CASE(ReceiveBareData)
152{
153 // TODO#3104 initialize with Options that disables all services
154
155 shared_ptr<Data> data1 = makeData("/12345678");
156
157 transport->receivePacket(data1->wireEncode());
158
159 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
160 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
161}
162
163BOOST_AUTO_TEST_CASE(ReceiveData)
164{
165 // TODO#3104 initialize with Options that disables all services
166
167 shared_ptr<Data> data1 = makeData("/12345689");
168 lp::Packet lpPacket;
169 lpPacket.set<lp::FragmentField>(std::make_pair(
170 data1->wireEncode().begin(), data1->wireEncode().end()));
171 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
172
173 transport->receivePacket(lpPacket.wireEncode());
174
175 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
176 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
177}
178
179BOOST_AUTO_TEST_CASE(ReceiveNack)
180{
181 // TODO#3104 initialize with Options that disables all services
182
183 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
184 lp::Packet lpPacket;
185 lpPacket.set<lp::FragmentField>(std::make_pair(
186 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
187 lpPacket.set<lp::NackField>(nack1.getHeader());
188
189 transport->receivePacket(lpPacket.wireEncode());
190
191 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
192}
193
194BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
195
196
197BOOST_AUTO_TEST_SUITE(LocalFields)
198
199BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
200{
201 // TODO#3104 initialize with Options that enables local fields
202 // TODO#3104 send Interest with IncomingFaceId
203 // expect transport->sentPackets.back() has IncomingFaceId field
204}
205
206BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
207{
208 // TODO#3104 initialize with Options that disables local fields
209 // TODO#3104 send Interest with IncomingFaceId
210 // expect transport->sentPackets.back() has no IncomingFaceId field
211}
212
213BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnore)
214{
215 // TODO#3104 initialize with Options that enables local fields
216 // TODO#3104 receive Interest with IncomingFaceId
217 // expect receivedInterests.back() has no IncomingFaceId tag
218}
219
220BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
221{
222 // TODO#3104 initialize with Options that enables local fields
223 // TODO#3104 receive Interest with NextHopFaceId
224 // expect receivedInterests.back() has NextHopFaceId tag
225}
226
227BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
228{
229 // TODO#3104 initialize with Options that disables local fields
230 // TODO#3104 receive Interest with NextHopFaceId
231 // expect receivedInterests.empty()
232 // or, expect receivedInterests.back() has no NextHopFaceId tag
233}
234
235BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
236{
237 // TODO#3104 initialize with Options that enables local fields
238 // TODO#3104 receive Data with NextHopFaceId
239 // expect receivedData.empty()
240}
241
242BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
243{
244 // TODO#3104 initialize with Options that enables local fields
245 // TODO#3104 receive Nack with NextHopFaceId
246 // expect receivedNacks.empty()
247}
248
249BOOST_AUTO_TEST_CASE(ReceiveCacheControl)
250{
251 // TODO#3104 initialize with Options that enables local fields
252 // TODO#3104 receive Data with CacheControl
253 // expect receivedData.back() has CacheControl tag
254}
255
256BOOST_AUTO_TEST_CASE(ReceiveCacheControlDisabled)
257{
258 // TODO#3104 initialize with Options that disables local fields
259 // TODO#3104 receive Data with CacheControl
260 // expect receivedData.back() has no CacheControl tag
261}
262
263BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropInterest)
264{
265 // TODO#3104 initialize with Options that enables local fields
266 // TODO#3104 receive Interest with CacheControl
267 // expect receivedInterests.empty()
268}
269
270BOOST_AUTO_TEST_CASE(ReceiveCacheControlDropNack)
271{
272 // TODO#3104 initialize with Options that enables local fields
273 // TODO#3104 receive Nack with CacheControl
274 // expect receivedNacks.empty()
275}
276
277BOOST_AUTO_TEST_SUITE_END() // LocalFields
278
279
280BOOST_AUTO_TEST_SUITE_END()
281BOOST_AUTO_TEST_SUITE_END()
282
283} // namespace tests
284} // namespace face
285} // namespace nfd