blob: 263967bf37cd546661ded54815642bee730a5f47 [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 Shi9b27bd22014-02-26 20:29:58 -070082class ScopeLocalhostIncomingTestForwarder : public Forwarder
Junxiao Shi88884492014-02-15 15:57:43 -070083{
84public:
Junxiao Shi9b27bd22014-02-26 20:29:58 -070085 ScopeLocalhostIncomingTestForwarder()
Junxiao Shi88884492014-02-15 15:57:43 -070086 {
87 }
88
89 virtual void
90 onDataUnsolicited(Face& inFace, const Data& data)
91 {
92 ++m_onDataUnsolicited_count;
93 }
94
95protected:
96 virtual void
Junxiao Shif3c07812014-03-11 21:48:49 -070097 dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> f)
Junxiao Shi88884492014-02-15 15:57:43 -070098 {
99 ++m_dispatchToStrategy_count;
100 }
101
102public:
103 int m_dispatchToStrategy_count;
104 int m_onDataUnsolicited_count;
105};
106
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700107BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
Junxiao Shi88884492014-02-15 15:57:43 -0700108{
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700109 ScopeLocalhostIncomingTestForwarder forwarder;
110 shared_ptr<Face> face1 = make_shared<DummyLocalFace>();
111 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shi88884492014-02-15 15:57:43 -0700112 forwarder.addFace(face1);
113 forwarder.addFace(face2);
Junxiao Shic041ca32014-02-25 20:01:15 -0700114
Junxiao Shi88884492014-02-15 15:57:43 -0700115 // local face, /localhost: OK
116 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700117 shared_ptr<Interest> i1 = makeInterest("/localhost/A1");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800118 forwarder.onIncomingInterest(*face1, *i1);
Junxiao Shi88884492014-02-15 15:57:43 -0700119 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700120
Junxiao Shi88884492014-02-15 15:57:43 -0700121 // non-local face, /localhost: violate
122 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700123 shared_ptr<Interest> i2 = makeInterest("/localhost/A2");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800124 forwarder.onIncomingInterest(*face2, *i2);
Junxiao Shi88884492014-02-15 15:57:43 -0700125 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 0);
Junxiao Shic041ca32014-02-25 20:01:15 -0700126
Junxiao Shi88884492014-02-15 15:57:43 -0700127 // local face, non-/localhost: OK
128 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700129 shared_ptr<Interest> i3 = makeInterest("/A3");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800130 forwarder.onIncomingInterest(*face1, *i3);
Junxiao Shi88884492014-02-15 15:57:43 -0700131 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700132
Junxiao Shi88884492014-02-15 15:57:43 -0700133 // non-local face, non-/localhost: OK
134 forwarder.m_dispatchToStrategy_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700135 shared_ptr<Interest> i4 = makeInterest("/A4");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800136 forwarder.onIncomingInterest(*face2, *i4);
Junxiao Shi88884492014-02-15 15:57:43 -0700137 BOOST_CHECK_EQUAL(forwarder.m_dispatchToStrategy_count, 1);
Junxiao Shic041ca32014-02-25 20:01:15 -0700138
Junxiao Shi88884492014-02-15 15:57:43 -0700139 // local face, /localhost: OK
140 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700141 shared_ptr<Data> d1 = makeData("/localhost/B1");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800142 forwarder.onIncomingData(*face1, *d1);
Junxiao Shi88884492014-02-15 15:57:43 -0700143 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
144
145 // non-local face, /localhost: OK
146 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700147 shared_ptr<Data> d2 = makeData("/localhost/B2");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800148 forwarder.onIncomingData(*face2, *d2);
Junxiao Shi88884492014-02-15 15:57:43 -0700149 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 0);
Junxiao Shic041ca32014-02-25 20:01:15 -0700150
Junxiao Shi88884492014-02-15 15:57:43 -0700151 // local face, non-/localhost: OK
152 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700153 shared_ptr<Data> d3 = makeData("/B3");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800154 forwarder.onIncomingData(*face1, *d3);
Junxiao Shi88884492014-02-15 15:57:43 -0700155 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
156
157 // non-local face, non-/localhost: OK
158 forwarder.m_onDataUnsolicited_count = 0;
Junxiao Shif3c07812014-03-11 21:48:49 -0700159 shared_ptr<Data> d4 = makeData("/B4");
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800160 forwarder.onIncomingData(*face2, *d4);
Junxiao Shi88884492014-02-15 15:57:43 -0700161 BOOST_CHECK_EQUAL(forwarder.m_onDataUnsolicited_count, 1);
162}
163
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700164BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing)
165{
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700166 Forwarder forwarder;
167 shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
168 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
169 shared_ptr<Face> face3 = make_shared<DummyLocalFace>();
170 forwarder.addFace(face1);
171 forwarder.addFace(face2);
172 forwarder.addFace(face3);
173 Pit& pit = forwarder.getPit();
174
175 // local face, /localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700176 shared_ptr<Interest> interestA1 = makeInterest("/localhost/A1");
177 shared_ptr<pit::Entry> pitA1 = pit.insert(*interestA1).first;
178 pitA1->insertOrUpdateInRecord(face3, *interestA1);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700179 face1->m_sentInterests.clear();
180 forwarder.onOutgoingInterest(pitA1, *face1);
181 BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
182
183 // non-local face, /localhost: violate
Junxiao Shif3c07812014-03-11 21:48:49 -0700184 shared_ptr<Interest> interestA2 = makeInterest("/localhost/A2");
185 shared_ptr<pit::Entry> pitA2 = pit.insert(*interestA2).first;
186 pitA2->insertOrUpdateInRecord(face3, *interestA2);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700187 face2->m_sentInterests.clear();
188 forwarder.onOutgoingInterest(pitA2, *face2);
189 BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 0);
190
191 // local face, non-/localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700192 shared_ptr<Interest> interestA3 = makeInterest("/A3");
193 shared_ptr<pit::Entry> pitA3 = pit.insert(*interestA3).first;
194 pitA3->insertOrUpdateInRecord(face3, *interestA3);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700195 face1->m_sentInterests.clear();
196 forwarder.onOutgoingInterest(pitA3, *face1);
197 BOOST_CHECK_EQUAL(face1->m_sentInterests.size(), 1);
198
199 // non-local face, non-/localhost: OK
Junxiao Shif3c07812014-03-11 21:48:49 -0700200 shared_ptr<Interest> interestA4 = makeInterest("/A4");
201 shared_ptr<pit::Entry> pitA4 = pit.insert(*interestA4).first;
202 pitA4->insertOrUpdateInRecord(face3, *interestA4);
Junxiao Shi9b27bd22014-02-26 20:29:58 -0700203 face2->m_sentInterests.clear();
204 forwarder.onOutgoingInterest(pitA4, *face2);
205 BOOST_CHECK_EQUAL(face2->m_sentInterests.size(), 1);
206
207 // local face, /localhost: OK
208 face1->m_sentDatas.clear();
209 forwarder.onOutgoingData(Data("/localhost/B1"), *face1);
210 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
211
212 // non-local face, /localhost: OK
213 face2->m_sentDatas.clear();
214 forwarder.onOutgoingData(Data("/localhost/B2"), *face2);
215 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 0);
216
217 // local face, non-/localhost: OK
218 face1->m_sentDatas.clear();
219 forwarder.onOutgoingData(Data("/B3"), *face1);
220 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
221
222 // non-local face, non-/localhost: OK
223 face2->m_sentDatas.clear();
224 forwarder.onOutgoingData(Data("/B4"), *face2);
225 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
226}
227
Junxiao Shi11bd9c22014-03-13 20:44:13 -0700228BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing)
229{
230 Forwarder forwarder;
231 shared_ptr<DummyLocalFace> face1 = make_shared<DummyLocalFace>();
232 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
233 shared_ptr<DummyLocalFace> face3 = make_shared<DummyLocalFace>();
234 shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
235 forwarder.addFace(face1);
236 forwarder.addFace(face2);
237 forwarder.addFace(face3);
238 forwarder.addFace(face4);
239 Pit& pit = forwarder.getPit();
240
241 // from local face, to local face: OK
242 shared_ptr<Interest> interest1 = makeInterest("/localhop/1");
243 shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
244 pit1->insertOrUpdateInRecord(face1, *interest1);
245 face3->m_sentInterests.clear();
246 forwarder.onOutgoingInterest(pit1, *face3);
247 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
248
249 // from non-local face, to local face: OK
250 shared_ptr<Interest> interest2 = makeInterest("/localhop/2");
251 shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
252 pit2->insertOrUpdateInRecord(face2, *interest2);
253 face3->m_sentInterests.clear();
254 forwarder.onOutgoingInterest(pit2, *face3);
255 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
256
257 // from local face, to non-local face: OK
258 shared_ptr<Interest> interest3 = makeInterest("/localhop/3");
259 shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first;
260 pit3->insertOrUpdateInRecord(face1, *interest3);
261 face4->m_sentInterests.clear();
262 forwarder.onOutgoingInterest(pit3, *face4);
263 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
264
265 // from non-local face, to non-local face: violate
266 shared_ptr<Interest> interest4 = makeInterest("/localhop/4");
267 shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
268 pit4->insertOrUpdateInRecord(face2, *interest4);
269 face4->m_sentInterests.clear();
270 forwarder.onOutgoingInterest(pit4, *face4);
271 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 0);
272
273 // from local face and non-local face, to local face: OK
274 shared_ptr<Interest> interest5 = makeInterest("/localhop/5");
275 shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first;
276 pit5->insertOrUpdateInRecord(face1, *interest5);
277 pit5->insertOrUpdateInRecord(face2, *interest5);
278 face3->m_sentInterests.clear();
279 forwarder.onOutgoingInterest(pit5, *face3);
280 BOOST_CHECK_EQUAL(face3->m_sentInterests.size(), 1);
281
282 // from local face and non-local face, to non-local face: OK
283 shared_ptr<Interest> interest6 = makeInterest("/localhop/6");
284 shared_ptr<pit::Entry> pit6 = pit.insert(*interest6).first;
285 pit6->insertOrUpdateInRecord(face1, *interest6);
286 pit6->insertOrUpdateInRecord(face2, *interest6);
287 face4->m_sentInterests.clear();
288 forwarder.onOutgoingInterest(pit6, *face4);
289 BOOST_CHECK_EQUAL(face4->m_sentInterests.size(), 1);
290}
291
Junxiao Shif3c07812014-03-11 21:48:49 -0700292BOOST_AUTO_TEST_CASE(StrategyDispatch)
293{
294 LimitedIo limitedIo;
295 Forwarder forwarder;
296 shared_ptr<Face> face1 = make_shared<DummyFace>();
297 shared_ptr<Face> face2 = make_shared<DummyFace>();
298 forwarder.addFace(face1);
299 forwarder.addFace(face2);
300
301 StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
302 shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700303 ref(forwarder), "ndn:/strategyP");
Junxiao Shif3c07812014-03-11 21:48:49 -0700304 shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700305 ref(forwarder), "ndn:/strategyQ");
Junxiao Shif3c07812014-03-11 21:48:49 -0700306 strategyChoice.install(strategyP);
307 strategyChoice.install(strategyQ);
308 strategyChoice.insert("ndn:/" , strategyP->getName());
309 strategyChoice.insert("ndn:/B", strategyQ->getName());
310
311 shared_ptr<Interest> interest1 = makeInterest("ndn:/A/1");
312 strategyP->m_afterReceiveInterest_count = 0;
313 strategyP->m_interestOutFace = face2;
314 forwarder.onInterest(*face1, *interest1);
315 BOOST_CHECK_EQUAL(strategyP->m_afterReceiveInterest_count, 1);
316
317 shared_ptr<Interest> interest2 = makeInterest("ndn:/B/2");
318 strategyQ->m_afterReceiveInterest_count = 0;
319 strategyQ->m_interestOutFace = face2;
320 forwarder.onInterest(*face1, *interest2);
321 BOOST_CHECK_EQUAL(strategyQ->m_afterReceiveInterest_count, 1);
322
323 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
324
325 shared_ptr<Data> data1 = makeData("ndn:/A/1/a");
326 strategyP->m_beforeSatisfyPendingInterest_count = 0;
327 forwarder.onData(*face2, *data1);
328 BOOST_CHECK_EQUAL(strategyP->m_beforeSatisfyPendingInterest_count, 1);
329
330 shared_ptr<Data> data2 = makeData("ndn:/B/2/b");
331 strategyQ->m_beforeSatisfyPendingInterest_count = 0;
332 forwarder.onData(*face2, *data2);
333 BOOST_CHECK_EQUAL(strategyQ->m_beforeSatisfyPendingInterest_count, 1);
334
335 shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700336 interest3->setInterestLifetime(time::milliseconds(30));
Junxiao Shif3c07812014-03-11 21:48:49 -0700337 forwarder.onInterest(*face1, *interest3);
338 shared_ptr<Interest> interest4 = makeInterest("ndn:/B/4");
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700339 interest4->setInterestLifetime(time::milliseconds(5000));
Junxiao Shif3c07812014-03-11 21:48:49 -0700340 forwarder.onInterest(*face1, *interest4);
341
342 strategyP->m_beforeExpirePendingInterest_count = 0;
343 strategyQ->m_beforeExpirePendingInterest_count = 0;
344 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(100));
345 BOOST_CHECK_EQUAL(strategyP->m_beforeExpirePendingInterest_count, 1);
346 BOOST_CHECK_EQUAL(strategyQ->m_beforeExpirePendingInterest_count, 0);
347}
348
Junxiao Shida006f52014-05-16 11:18:00 -0700349BOOST_AUTO_TEST_CASE(IncomingData)
350{
351 LimitedIo limitedIo;
352 Forwarder forwarder;
353 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
354 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
355 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
356 shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
357 forwarder.addFace(face1);
358 forwarder.addFace(face2);
Junxiao Shi223271b2014-07-03 22:06:13 -0700359 forwarder.addFace(face3);
360 forwarder.addFace(face4);
Junxiao Shida006f52014-05-16 11:18:00 -0700361
362 Pit& pit = forwarder.getPit();
363 shared_ptr<Interest> interest0 = makeInterest("ndn:/");
364 shared_ptr<pit::Entry> pit0 = pit.insert(*interest0).first;
365 pit0->insertOrUpdateInRecord(face1, *interest0);
366 shared_ptr<Interest> interestA = makeInterest("ndn:/A");
367 shared_ptr<pit::Entry> pitA = pit.insert(*interestA).first;
368 pitA->insertOrUpdateInRecord(face1, *interestA);
369 pitA->insertOrUpdateInRecord(face2, *interestA);
370 shared_ptr<Interest> interestC = makeInterest("ndn:/A/B/C");
371 shared_ptr<pit::Entry> pitC = pit.insert(*interestC).first;
372 pitC->insertOrUpdateInRecord(face3, *interestC);
373 pitC->insertOrUpdateInRecord(face4, *interestC);
374
375 shared_ptr<Data> dataD = makeData("ndn:/A/B/C/D");
376 forwarder.onIncomingData(*face3, *dataD);
377 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
378
379 BOOST_CHECK_EQUAL(face1->m_sentDatas.size(), 1);
380 BOOST_CHECK_EQUAL(face2->m_sentDatas.size(), 1);
381 BOOST_CHECK_EQUAL(face3->m_sentDatas.size(), 0);
382 BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1);
383}
384
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700385BOOST_AUTO_TEST_SUITE_END()
386
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700387} // namespace tests
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700388} // namespace nfd