blob: f7cea1cbfa81d22462ae86f2d00a680f6b55b6b6 [file] [log] [blame]
Junxiao Shi8c8d2182014-01-30 22:33:00 -07001/* -*- 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 **/
Junxiao Shi8c8d2182014-01-30 22:33:00 -070024
25#include "fw/forwarder.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shif3c07812014-03-11 21:48:49 -070027#include "dummy-strategy.hpp"
Junxiao Shi8c8d2182014-01-30 22:33:00 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070030#include "tests/limited-io.hpp"
Junxiao Shi8c8d2182014-01-30 22:33:00 -070031
32namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shi8c8d2182014-01-30 22:33:00 -070034
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035BOOST_FIXTURE_TEST_SUITE(FwForwarder, BaseFixture)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070036
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037BOOST_AUTO_TEST_CASE(SimpleExchange)
38{
Junxiao Shic041ca32014-02-25 20:01:15 -070039 Forwarder forwarder;
40
Junxiao Shi8c8d2182014-01-30 22:33:00 -070041 Name nameA ("ndn:/A");
42 Name nameAB ("ndn:/A/B");
43 Name nameABC("ndn:/A/B/C");
Junxiao Shif3c07812014-03-11 21:48:49 -070044 shared_ptr<Interest> interestAB = makeInterest(nameAB);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070045 interestAB->setInterestLifetime(time::seconds(4));
Junxiao Shif3c07812014-03-11 21:48:49 -070046 shared_ptr<Data> dataABC = makeData(nameABC);
Junxiao Shi8c8d2182014-01-30 22:33:00 -070047
Junxiao Shid9ee45c2014-02-27 15:38:11 -070048 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
49 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
50 face1->afterSend += bind(&boost::asio::io_service::stop, &g_io);
51 face2->afterSend += bind(&boost::asio::io_service::stop, &g_io);
Junxiao Shi8c8d2182014-01-30 22:33:00 -070052 forwarder.addFace(face1);
53 forwarder.addFace(face2);
Junxiao Shic041ca32014-02-25 20:01:15 -070054
Junxiao Shi8c8d2182014-01-30 22:33:00 -070055 Fib& fib = forwarder.getFib();
Junxiao Shi6e694322014-04-03 10:27:13 -070056 shared_ptr<fib::Entry> fibEntry = fib.insert(Name("ndn:/A")).first;
Junxiao Shi8c8d2182014-01-30 22:33:00 -070057 fibEntry->addNextHop(face2, 0);
Junxiao Shic041ca32014-02-25 20:01:15 -070058
Junxiao Shi6e694322014-04-03 10:27:13 -070059 BOOST_CHECK_EQUAL(forwarder.getCounters().getNInInterests (), 0);
60 BOOST_CHECK_EQUAL(forwarder.getCounters().getNOutInterests(), 0);
Junxiao Shif3c07812014-03-11 21:48:49 -070061 face1->receiveInterest(*interestAB);
Junxiao Shid9ee45c2014-02-27 15:38:11 -070062 g_io.run();
63 g_io.reset();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070064 BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 1);
65 BOOST_CHECK(face2->m_sentInterests[0].getName().equals(nameAB));
Junxiao Shi06887ac2014-02-13 20:15:42 -070066 BOOST_CHECK_EQUAL(face2->m_sentInterests[0].getIncomingFaceId(), face1->getId());
Junxiao Shi6e694322014-04-03 10:27:13 -070067 BOOST_CHECK_EQUAL(forwarder.getCounters().getNInInterests (), 1);
68 BOOST_CHECK_EQUAL(forwarder.getCounters().getNOutInterests(), 1);
Junxiao Shic041ca32014-02-25 20:01:15 -070069
Junxiao Shi6e694322014-04-03 10:27:13 -070070 BOOST_CHECK_EQUAL(forwarder.getCounters().getNInDatas (), 0);
71 BOOST_CHECK_EQUAL(forwarder.getCounters().getNOutDatas(), 0);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080072 face2->receiveData(*dataABC);
Junxiao Shid9ee45c2014-02-27 15:38:11 -070073 g_io.run();
74 g_io.reset();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070075 BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
76 BOOST_CHECK(face1->m_sentDatas[0].getName().equals(nameABC));
Junxiao Shi06887ac2014-02-13 20:15:42 -070077 BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getIncomingFaceId(), face2->getId());
Junxiao Shi6e694322014-04-03 10:27:13 -070078 BOOST_CHECK_EQUAL(forwarder.getCounters().getNInDatas (), 1);
79 BOOST_CHECK_EQUAL(forwarder.getCounters().getNOutDatas(), 1);
Junxiao Shi8c8d2182014-01-30 22:33:00 -070080}
81
Junxiao Shiad3f1cb2014-08-18 11:12:30 -070082BOOST_AUTO_TEST_CASE(CsMatched)
83{
84 LimitedIo limitedIo;
85 Forwarder forwarder;
86
87 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
88 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
89 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
90 forwarder.addFace(face1);
91 forwarder.addFace(face2);
92 forwarder.addFace(face3);
93
94 shared_ptr<Interest> interestA = makeInterest("ndn:/A");
95 interestA->setInterestLifetime(time::seconds(4));
96 shared_ptr<Data> dataA = makeData("ndn:/A");
97 dataA->setIncomingFaceId(face3->getId());
98
99 Fib& fib = forwarder.getFib();
100 shared_ptr<fib::Entry> fibEntry = fib.insert(Name("ndn:/A")).first;
101 fibEntry->addNextHop(face2, 0);
102
103 Pit& pit = forwarder.getPit();
104 BOOST_CHECK_EQUAL(pit.size(), 0);
105
106 Cs& cs = forwarder.getCs();
107 BOOST_REQUIRE(cs.insert(*dataA));
108
109 face1->receiveInterest(*interestA);
110 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
111 // Interest matching ContentStore should not be forwarded
112 BOOST_REQUIRE_EQUAL(face2->m_sentInterests.size(), 0);
113
114 BOOST_REQUIRE_EQUAL(face1->m_sentDatas.size(), 1);
115 // IncomingFaceId field should be reset to represent CS
116 BOOST_CHECK_EQUAL(face1->m_sentDatas[0].getIncomingFaceId(), FACEID_CONTENT_STORE);
117
118 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(500));
119 // PIT entry should not be left behind
120 BOOST_CHECK_EQUAL(pit.size(), 0);
121}
122
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700123class ScopeLocalhostIncomingTestForwarder : public Forwarder
Junxiao Shi88884492014-02-15 15:57:43 -0700124{
125public:
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700126 ScopeLocalhostIncomingTestForwarder()
Junxiao Shi88884492014-02-15 15:57:43 -0700127 {
128 }
129
130 virtual void
131 onDataUnsolicited(Face& inFace, const Data& data)
132 {
133 ++m_onDataUnsolicited_count;
134 }
135
136protected:
137 virtual void
Junxiao Shif3c07812014-03-11 21:48:49 -0700138 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> f)
Junxiao Shi88884492014-02-15 15:57:43 -0700139 {
140 ++m_dispatchToStrategy_count;
141 }
142
143public:
144 int m_dispatchToStrategy_count;
145 int m_onDataUnsolicited_count;
146};
147
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700148BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
Junxiao Shi88884492014-02-15 15:57:43 -0700149{
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700150 ScopeLocalhostIncomingTestForwarder forwarder;
151 shared_ptr<Face> face1 = make_shared<DummyLocalFace>();
152 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shi88884492014-02-15 15:57:43 -0700153 forwarder.addFace(face1);
154 forwarder.addFace(face2);
Junxiao Shic041ca32014-02-25 20:01:15 -0700155
Junxiao Shi88884492014-02-15 15:57:43 -0700156 // local face, /localhost: OK
157 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700158 shared_ptr<Interest> i1 = makeInterest("/localhost/A1");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800159 forwarder.onIncomingInterest(*face1, *i1);
Junxiao Shi88884492014-02-15 15:57:43 -0700160 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700161
Junxiao Shi88884492014-02-15 15:57:43 -0700162 // non-local face, /localhost: violate
163 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700164 shared_ptr<Interest> i2 = makeInterest("/localhost/A2");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800165 forwarder.onIncomingInterest(*face2, *i2);
Junxiao Shi88884492014-02-15 15:57:43 -0700166 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 0);
Junxiao Shic041ca32014-02-25 20:01:15 -0700167
Junxiao Shi88884492014-02-15 15:57:43 -0700168 // local face, non-/localhost: OK
169 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700170 shared_ptr<Interest> i3 = makeInterest("/A3");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800171 forwarder.onIncomingInterest(*face1, *i3);
Junxiao Shi88884492014-02-15 15:57:43 -0700172 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700173
Junxiao Shi88884492014-02-15 15:57:43 -0700174 // non-local face, non-/localhost: OK
175 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700176 shared_ptr<Interest> i4 = makeInterest("/A4");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800177 forwarder.onIncomingInterest(*face2, *i4);
Junxiao Shi88884492014-02-15 15:57:43 -0700178 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700179
Junxiao Shi88884492014-02-15 15:57:43 -0700180 // local face, /localhost: OK
181 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700182 shared_ptr<Data> d1 = makeData("/localhost/B1");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800183 forwarder.onIncomingData(*face1, *d1);
Junxiao Shi88884492014-02-15 15:57:43 -0700184 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
185
186 // non-local face, /localhost: OK
187 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700188 shared_ptr<Data> d2 = makeData("/localhost/B2");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800189 forwarder.onIncomingData(*face2, *d2);
Junxiao Shi88884492014-02-15 15:57:43 -0700190 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 0);
Junxiao Shic041ca32014-02-25 20:01:15 -0700191
Junxiao Shi88884492014-02-15 15:57:43 -0700192 // local face, non-/localhost: OK
193 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700194 shared_ptr<Data> d3 = makeData("/B3");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800195 forwarder.onIncomingData(*face1, *d3);
Junxiao Shi88884492014-02-15 15:57:43 -0700196 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
197
198 // non-local face, non-/localhost: OK
199 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700200 shared_ptr<Data> d4 = makeData("/B4");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800201 forwarder.onIncomingData(*face2, *d4);
Junxiao Shi88884492014-02-15 15:57:43 -0700202 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
203}
204
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700205BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing)
206{
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700207 Forwarder forwarder;
208 shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
209 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
210 shared_ptr<Face> face3 = make_shared<DummyLocalFace>();
211 forwarder.addFace(face1);
212 forwarder.addFace(face2);
213 forwarder.addFace(face3);
214 Pit& pit = forwarder.getPit();
215
216 // local face, /localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700217 shared_ptr<Interest> interestA1 = makeInterest("/localhost/A1");
218 shared_ptr<pit::Entry> pitA1 = pit.insert(*interestA1).first;
219 pitA1->insertOrUpdateInRecord(face3, *interestA1);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700220 face1->m_sentInterests.clear();
221 forwarder.onOutgoingInterest(pitA1, *face1);
222 BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
223
224 // non-local face, /localhost: violate
Junxiao Shif3c07812014-03-11 21:48:49 -0700225 shared_ptr<Interest> interestA2 = makeInterest("/localhost/A2");
226 shared_ptr<pit::Entry> pitA2 = pit.insert(*interestA2).first;
227 pitA2->insertOrUpdateInRecord(face3, *interestA2);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700228 face2->m_sentInterests.clear();
229 forwarder.onOutgoingInterest(pitA2, *face2);
230 BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 0);
231
232 // local face, non-/localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700233 shared_ptr<Interest> interestA3 = makeInterest("/A3");
234 shared_ptr<pit::Entry> pitA3 = pit.insert(*interestA3).first;
235 pitA3->insertOrUpdateInRecord(face3, *interestA3);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700236 face1->m_sentInterests.clear();
237 forwarder.onOutgoingInterest(pitA3, *face1);
238 BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
239
240 // non-local face, non-/localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700241 shared_ptr<Interest> interestA4 = makeInterest("/A4");
242 shared_ptr<pit::Entry> pitA4 = pit.insert(*interestA4).first;
243 pitA4->insertOrUpdateInRecord(face3, *interestA4);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700244 face2->m_sentInterests.clear();
245 forwarder.onOutgoingInterest(pitA4, *face2);
246 BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1);
247
248 // local face, /localhost: OK
249 face1->m_sentDatas.clear();
250 forwarder.onOutgoingData(Data("/localhost/B1"), *face1);
251 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
252
253 // non-local face, /localhost: OK
254 face2->m_sentDatas.clear();
255 forwarder.onOutgoingData(Data("/localhost/B2"), *face2);
256 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 0);
257
258 // local face, non-/localhost: OK
259 face1->m_sentDatas.clear();
260 forwarder.onOutgoingData(Data("/B3"), *face1);
261 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
262
263 // non-local face, non-/localhost: OK
264 face2->m_sentDatas.clear();
265 forwarder.onOutgoingData(Data("/B4"), *face2);
266 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
267}
268
Junxiao Shi11bd9c22014-03-13 20:44:13 -0700269BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing)
270{
271 Forwarder forwarder;
272 shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
273 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
274 shared_ptr<DummyLocalFace> face3 = make_shared<DummyLocalFace>();
275 shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
276 forwarder.addFace(face1);
277 forwarder.addFace(face2);
278 forwarder.addFace(face3);
279 forwarder.addFace(face4);
280 Pit& pit = forwarder.getPit();
281
282 // from local face, to local face: OK
283 shared_ptr<Interest> interest1 = makeInterest("/localhop/1");
284 shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
285 pit1->insertOrUpdateInRecord(face1, *interest1);
286 face3->m_sentInterests.clear();
287 forwarder.onOutgoingInterest(pit1, *face3);
288 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
289
290 // from non-local face, to local face: OK
291 shared_ptr<Interest> interest2 = makeInterest("/localhop/2");
292 shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
293 pit2->insertOrUpdateInRecord(face2, *interest2);
294 face3->m_sentInterests.clear();
295 forwarder.onOutgoingInterest(pit2, *face3);
296 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
297
298 // from local face, to non-local face: OK
299 shared_ptr<Interest> interest3 = makeInterest("/localhop/3");
300 shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first;
301 pit3->insertOrUpdateInRecord(face1, *interest3);
302 face4->m_sentInterests.clear();
303 forwarder.onOutgoingInterest(pit3, *face4);
304 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
305
306 // from non-local face, to non-local face: violate
307 shared_ptr<Interest> interest4 = makeInterest("/localhop/4");
308 shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
309 pit4->insertOrUpdateInRecord(face2, *interest4);
310 face4->m_sentInterests.clear();
311 forwarder.onOutgoingInterest(pit4, *face4);
312 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 0);
313
314 // from local face and non-local face, to local face: OK
315 shared_ptr<Interest> interest5 = makeInterest("/localhop/5");
316 shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first;
317 pit5->insertOrUpdateInRecord(face1, *interest5);
318 pit5->insertOrUpdateInRecord(face2, *interest5);
319 face3->m_sentInterests.clear();
320 forwarder.onOutgoingInterest(pit5, *face3);
321 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
322
323 // from local face and non-local face, to non-local face: OK
324 shared_ptr<Interest> interest6 = makeInterest("/localhop/6");
325 shared_ptr<pit::Entry> pit6 = pit.insert(*interest6).first;
326 pit6->insertOrUpdateInRecord(face1, *interest6);
327 pit6->insertOrUpdateInRecord(face2, *interest6);
328 face4->m_sentInterests.clear();
329 forwarder.onOutgoingInterest(pit6, *face4);
330 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
331}
332
Junxiao Shif3c07812014-03-11 21:48:49 -0700333BOOST_AUTO_TEST_CASE(StrategyDispatch)
334{
335 LimitedIo limitedIo;
336 Forwarder forwarder;
337 shared_ptr<Face> face1 = make_shared<DummyFace>();
338 shared_ptr<Face> face2 = make_shared<DummyFace>();
339 forwarder.addFace(face1);
340 forwarder.addFace(face2);
341
342 StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
343 shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700344 ref(forwarder), "ndn:/strategyP");
Junxiao Shif3c07812014-03-11 21:48:49 -0700345 shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700346 ref(forwarder), "ndn:/strategyQ");
Junxiao Shif3c07812014-03-11 21:48:49 -0700347 strategyChoice.install(strategyP);
348 strategyChoice.install(strategyQ);
349 strategyChoice.insert("ndn:/" , strategyP->getName());
350 strategyChoice.insert("ndn:/B", strategyQ->getName());
351
352 shared_ptr<Interest> interest1 = makeInterest("ndn:/A/1");
353 strategyP->m_afterReceiveInterest_count = 0;
354 strategyP->m_interestOutFace = face2;
355 forwarder.onInterest(*face1, *interest1);
356 BOOST_CHECK_EQUAL(strategyP->m_afterReceiveInterest_count, 1);
357
358 shared_ptr<Interest> interest2 = makeInterest("ndn:/B/2");
359 strategyQ->m_afterReceiveInterest_count = 0;
360 strategyQ->m_interestOutFace = face2;
361 forwarder.onInterest(*face1, *interest2);
362 BOOST_CHECK_EQUAL(strategyQ->m_afterReceiveInterest_count, 1);
363
364 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
365
366 shared_ptr<Data> data1 = makeData("ndn:/A/1/a");
367 strategyP->m_beforeSatisfyPendingInterest_count = 0;
368 forwarder.onData(*face2, *data1);
369 BOOST_CHECK_EQUAL(strategyP->m_beforeSatisfyPendingInterest_count, 1);
370
371 shared_ptr<Data> data2 = makeData("ndn:/B/2/b");
372 strategyQ->m_beforeSatisfyPendingInterest_count = 0;
373 forwarder.onData(*face2, *data2);
374 BOOST_CHECK_EQUAL(strategyQ->m_beforeSatisfyPendingInterest_count, 1);
375
376 shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700377 interest3->setInterestLifetime(time::milliseconds(30));
Junxiao Shif3c07812014-03-11 21:48:49 -0700378 forwarder.onInterest(*face1, *interest3);
379 shared_ptr<Interest> interest4 = makeInterest("ndn:/B/4");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700380 interest4->setInterestLifetime(time::milliseconds(5000));
Junxiao Shif3c07812014-03-11 21:48:49 -0700381 forwarder.onInterest(*face1, *interest4);
382
383 strategyP->m_beforeExpirePendingInterest_count = 0;
384 strategyQ->m_beforeExpirePendingInterest_count = 0;
385 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(100));
386 BOOST_CHECK_EQUAL(strategyP->m_beforeExpirePendingInterest_count, 1);
387 BOOST_CHECK_EQUAL(strategyQ->m_beforeExpirePendingInterest_count, 0);
388}
389
Junxiao Shida006f52014-05-16 11:18:00 -0700390BOOST_AUTO_TEST_CASE(IncomingData)
391{
392 LimitedIo limitedIo;
393 Forwarder forwarder;
394 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
395 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
396 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
397 shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
398 forwarder.addFace(face1);
399 forwarder.addFace(face2);
Junxiao Shi223271b2014-07-03 22:06:13 -0700400 forwarder.addFace(face3);
401 forwarder.addFace(face4);
Junxiao Shida006f52014-05-16 11:18:00 -0700402
403 Pit& pit = forwarder.getPit();
404 shared_ptr<Interest> interest0 = makeInterest("ndn:/");
405 shared_ptr<pit::Entry> pit0 = pit.insert(*interest0).first;
406 pit0->insertOrUpdateInRecord(face1, *interest0);
407 shared_ptr<Interest> interestA = makeInterest("ndn:/A");
408 shared_ptr<pit::Entry> pitA = pit.insert(*interestA).first;
409 pitA->insertOrUpdateInRecord(face1, *interestA);
410 pitA->insertOrUpdateInRecord(face2, *interestA);
411 shared_ptr<Interest> interestC = makeInterest("ndn:/A/B/C");
412 shared_ptr<pit::Entry> pitC = pit.insert(*interestC).first;
413 pitC->insertOrUpdateInRecord(face3, *interestC);
414 pitC->insertOrUpdateInRecord(face4, *interestC);
415
416 shared_ptr<Data> dataD = makeData("ndn:/A/B/C/D");
417 forwarder.onIncomingData(*face3, *dataD);
418 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
419
420 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
421 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
422 BOOST_CHECK_EQUAL(face3->m_sentDatas.size(), 0);
423 BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1);
424}
425
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700426BOOST_AUTO_TEST_SUITE_END()
427
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700428} // namespace tests
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700429} // namespace nfd