blob: 29de094a3ff19d209da19089e21a62febd77d5fa [file] [log] [blame]
Junxiao Shi986b8492014-08-20 12:07:14 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi4846f372016-04-05 13:39:30 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shi192af1f2015-01-13 23:19:39 -07004 * 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.
Junxiao Shi986b8492014-08-20 12:07:14 -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/>.
24 */
25
26#include "fw/best-route-strategy2.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070027
28#include "tests/test-common.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070029#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi5e5e4452015-09-24 16:56:52 -070030#include "strategy-tester.hpp"
31#include "topology-tester.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070032
33namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace fw {
Junxiao Shi986b8492014-08-20 12:07:14 -070035namespace tests {
36
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037using namespace nfd::tests;
38
Junxiao Shi890afe92016-12-15 14:34:34 +000039typedef StrategyTester<BestRouteStrategy2> BestRouteStrategy2Tester;
40NFD_REGISTER_STRATEGY(BestRouteStrategy2Tester);
41
Junxiao Shi5e5e4452015-09-24 16:56:52 -070042BOOST_AUTO_TEST_SUITE(Fw)
43
44class BestRouteStrategy2Fixture : public UnitTestTimeFixture
45{
46protected:
47 BestRouteStrategy2Fixture()
48 : strategy(forwarder)
49 , fib(forwarder.getFib())
50 , pit(forwarder.getPit())
51 , face1(make_shared<DummyFace>())
52 , face2(make_shared<DummyFace>())
53 , face3(make_shared<DummyFace>())
54 , face4(make_shared<DummyFace>())
55 , face5(make_shared<DummyFace>())
56 {
57 forwarder.addFace(face1);
58 forwarder.addFace(face2);
59 forwarder.addFace(face3);
60 forwarder.addFace(face4);
61 forwarder.addFace(face5);
62 }
63
64public:
65 Forwarder forwarder;
Junxiao Shi890afe92016-12-15 14:34:34 +000066 BestRouteStrategy2Tester strategy;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070067 Fib& fib;
68 Pit& pit;
69
70 shared_ptr<DummyFace> face1;
71 shared_ptr<DummyFace> face2;
72 shared_ptr<DummyFace> face3;
73 shared_ptr<DummyFace> face4;
74 shared_ptr<DummyFace> face5;
75};
76
77BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture)
Junxiao Shi986b8492014-08-20 12:07:14 -070078
Junxiao Shic34d1672016-12-09 15:57:59 +000079BOOST_AUTO_TEST_CASE(Registration)
80{
Junxiao Shi037f4ab2016-12-13 04:27:06 +000081 BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy2::getStrategyName()), 1);
Junxiao Shic34d1672016-12-09 15:57:59 +000082}
83
Junxiao Shi986b8492014-08-20 12:07:14 -070084BOOST_AUTO_TEST_CASE(Forward)
85{
Junxiao Shia6de4292016-07-12 02:08:10 +000086 fib::Entry& fibEntry = *fib.insert(Name()).first;
87 fibEntry.addNextHop(*face1, 10);
88 fibEntry.addNextHop(*face2, 20);
89 fibEntry.addNextHop(*face3, 30);
Junxiao Shi986b8492014-08-20 12:07:14 -070090
91 shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
Junxiao Shi986b8492014-08-20 12:07:14 -070092 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
93
Junxiao Shi584a5692014-12-13 21:55:28 -070094 const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>(
Junxiao Shi52e85402015-11-11 06:06:58 -070095 BestRouteStrategy2::RETX_SUPPRESSION_INITIAL * 0.1);
Junxiao Shi986b8492014-08-20 12:07:14 -070096
Junxiao Shi1f30aac2014-11-04 18:45:56 -070097 // first Interest goes to nexthop with lowest FIB cost,
98 // however face1 is downstream so it cannot be used
Junxiao Shi9cff7792016-08-01 21:45:11 +000099 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +0000100 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700101 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
102 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700103
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700104 // downstream retransmits frequently, but the strategy should not send Interests
Junxiao Shia788e252015-01-28 17:06:25 -0700105 // more often than DEFAULT_MIN_RETX_INTERVAL
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700106 scheduler::EventId retxFrom4Evt;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700107 size_t nSentLast = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700108 time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
Junxiao Shi913806d2014-11-14 11:43:52 -0700109 function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
110 periodicalRetxFrom4 = [&] {
Junxiao Shi9cff7792016-08-01 21:45:11 +0000111 pitEntry->insertOrUpdateInRecord(*face4, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +0000112 strategy.afterReceiveInterest(*face4, *interest, pitEntry);
Junxiao Shi986b8492014-08-20 12:07:14 -0700113
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700114 size_t nSent = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700115 if (nSent > nSentLast) {
116 BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
117 time::steady_clock::TimePoint timeSent = time::steady_clock::now();
Junxiao Shi684fa0f2015-02-23 21:39:57 -0700118 BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700119 nSentLast = nSent;
120 timeSentLast = timeSent;
121 }
Junxiao Shi986b8492014-08-20 12:07:14 -0700122
Junxiao Shi684fa0f2015-02-23 21:39:57 -0700123 retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700124 };
125 periodicalRetxFrom4();
Junxiao Shi52e85402015-11-11 06:06:58 -0700126 this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 16);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700127 scheduler::cancel(retxFrom4Evt);
Junxiao Shi986b8492014-08-20 12:07:14 -0700128
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700129 // nexthops for accepted retransmissions: follow FIB cost,
Junxiao Shi4846f372016-04-05 13:39:30 -0700130 // later forward to an eligible upstream with earliest out-record
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700131 BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6);
132 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId());
133 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId());
134 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId());
135 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
136 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700137
Junxiao Shia6de4292016-07-12 02:08:10 +0000138 fibEntry.removeNextHop(*face1);
Junxiao Shi986b8492014-08-20 12:07:14 -0700139
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700140 strategy.sendInterestHistory.clear();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700141 for (int i = 0; i < 3; ++i) {
Junxiao Shi52e85402015-11-11 06:06:58 -0700142 this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 2);
Junxiao Shi9cff7792016-08-01 21:45:11 +0000143 pitEntry->insertOrUpdateInRecord(*face5, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +0000144 strategy.afterReceiveInterest(*face5, *interest, pitEntry);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700145 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700146 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3);
147 BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId());
148 BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId());
149 BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700150 // face1 cannot be used because it's gone from FIB entry
151}
152
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700153BOOST_AUTO_TEST_SUITE(NoRouteNack) // send Nack-NoRoute if there's no usable FIB nexthop
154
155class EmptyNextHopList
156{
157public:
158 Name
159 getInterestName()
160 {
161 return "/P";
162 }
163
Junxiao Shia6de4292016-07-12 02:08:10 +0000164 void
165 insertFibEntry(BestRouteStrategy2Fixture* fixture)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700166 {
Junxiao Shia6de4292016-07-12 02:08:10 +0000167 fixture->fib.insert(Name());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700168 }
169};
170
171class NextHopIsDownstream
172{
173public:
174 Name
175 getInterestName()
176 {
177 return "/P";
178 }
179
Junxiao Shia6de4292016-07-12 02:08:10 +0000180 void
181 insertFibEntry(BestRouteStrategy2Fixture* fixture)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700182 {
Junxiao Shia6de4292016-07-12 02:08:10 +0000183 fixture->fib.insert(Name()).first->addNextHop(*fixture->face1, 10);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700184 }
185};
186
187class NextHopViolatesScope
188{
189public:
190 Name
191 getInterestName()
192 {
193 return "/localhop/P";
194 }
195
Junxiao Shia6de4292016-07-12 02:08:10 +0000196 void
197 insertFibEntry(BestRouteStrategy2Fixture* fixture)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700198 {
Junxiao Shia6de4292016-07-12 02:08:10 +0000199 fixture->fib.insert("/localhop").first->addNextHop(*fixture->face2, 10);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700200 // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700201 }
202};
203
204typedef boost::mpl::vector<EmptyNextHopList, NextHopIsDownstream, NextHopViolatesScope> NoRouteScenarios;
205
206BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios)
207{
208 Scenario scenario;
Junxiao Shia6de4292016-07-12 02:08:10 +0000209 scenario.insertFibEntry(this);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700210
211 shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
212 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000213 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700214
Junxiao Shi8d843142016-07-11 22:42:42 +0000215 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700216
217 BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000218 BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700219
220 BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000221 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700222 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
223 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
224}
225
226BOOST_AUTO_TEST_SUITE_END() // NoRouteNack
227
228BOOST_AUTO_TEST_SUITE(IncomingNack)
229
230BOOST_AUTO_TEST_CASE(OneUpstream) // one upstream, send Nack when Nack arrives
231{
Junxiao Shia6de4292016-07-12 02:08:10 +0000232 fib::Entry& fibEntry = *fib.insert(Name()).first;
233 fibEntry.addNextHop(*face3, 10);
234 fibEntry.addNextHop(*face4, 20);
235 fibEntry.addNextHop(*face5, 30);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700236
237 shared_ptr<Interest> interest1 = makeInterest("/McQYjMbm", 992);
238 shared_ptr<Interest> interest2 = makeInterest("/McQYjMbm", 114);
239 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000240 pitEntry->insertOrUpdateInRecord(*face1, *interest1);
241 pitEntry->insertOrUpdateInRecord(*face2, *interest2);
242 pitEntry->insertOrUpdateOutRecord(*face3, *interest1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700243
244 lp::Nack nack3 = makeNack("/McQYjMbm", 992, lp::NackReason::CONGESTION);
245 pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
Junxiao Shi8d843142016-07-11 22:42:42 +0000246 strategy.afterReceiveNack(*face3, nack3, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700247
248 BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 2);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000249 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700250 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000251 BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700252 BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].header.getReason(), lp::NackReason::CONGESTION);
253 std::unordered_set<FaceId> nackFaceIds{strategy.sendNackHistory[0].outFaceId,
254 strategy.sendNackHistory[1].outFaceId};
255 std::unordered_set<FaceId> expectedNackFaceIds{face1->getId(), face2->getId()};
256 BOOST_CHECK_EQUAL_COLLECTIONS(nackFaceIds.begin(), nackFaceIds.end(),
257 expectedNackFaceIds.begin(), expectedNackFaceIds.end());
258}
259
260BOOST_AUTO_TEST_CASE(TwoUpstreams) // two upstreams, send Nack when both Nacks arrive
261{
Junxiao Shia6de4292016-07-12 02:08:10 +0000262 fib::Entry& fibEntry = *fib.insert(Name()).first;
263 fibEntry.addNextHop(*face3, 10);
264 fibEntry.addNextHop(*face4, 20);
265 fibEntry.addNextHop(*face5, 30);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700266
267 shared_ptr<Interest> interest1 = makeInterest("/aS9FAyUV19", 286);
268 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000269 pitEntry->insertOrUpdateInRecord(*face1, *interest1);
270 pitEntry->insertOrUpdateOutRecord(*face3, *interest1);
271 pitEntry->insertOrUpdateOutRecord(*face4, *interest1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700272
273 lp::Nack nack3 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
274 pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
Junxiao Shi8d843142016-07-11 22:42:42 +0000275 strategy.afterReceiveNack(*face3, nack3, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700276
277 BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); // don't send Nack until all upstreams have Nacked
278
279 lp::Nack nack4 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
280 pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
Junxiao Shi8d843142016-07-11 22:42:42 +0000281 strategy.afterReceiveNack(*face4, nack4, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700282
283 BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000284 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700285 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
286 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
287}
288
289BOOST_AUTO_TEST_CASE(Timeout) // two upstreams, one times out, don't send Nack
290{
Junxiao Shia6de4292016-07-12 02:08:10 +0000291 fib::Entry& fibEntry = *fib.insert(Name()).first;
292 fibEntry.addNextHop(*face3, 10);
293 fibEntry.addNextHop(*face4, 20);
294 fibEntry.addNextHop(*face5, 30);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700295
296 shared_ptr<Interest> interest1 = makeInterest("/sIYw0TXWDj", 115);
297 interest1->setInterestLifetime(time::milliseconds(400));
298 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000299 pitEntry->insertOrUpdateInRecord(*face1, *interest1);
300 pitEntry->insertOrUpdateOutRecord(*face3, *interest1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700301
302 this->advanceClocks(time::milliseconds(300));
303 shared_ptr<Interest> interest2 = makeInterest("/sIYw0TXWDj", 223);
Junxiao Shi9cff7792016-08-01 21:45:11 +0000304 pitEntry->insertOrUpdateInRecord(*face1, *interest2);
305 pitEntry->insertOrUpdateOutRecord(*face4, *interest2);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700306
307 this->advanceClocks(time::milliseconds(200)); // face3 has timed out
308
309 lp::Nack nack4 = makeNack("/sIYw0TXWDj", 223, lp::NackReason::CONGESTION);
310 pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
Junxiao Shi8d843142016-07-11 22:42:42 +0000311 strategy.afterReceiveNack(*face4, nack4, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700312
313 BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
314}
315
316BOOST_FIXTURE_TEST_CASE(LiveDeadlock, UnitTestTimeFixture) // #3033 note-7
317{
318 /*
319 * /----------\
320 * | producer |
321 * \----------/
322 * |
323 * +---+
324 * | P |
325 * +---+
326 * |
327 * failed link
328 * |
329 * +---+
330 * | R |
331 * +---+
332 * ^ ^
333 * / \
334 * / \
335 * +---+ +---+
336 * | B | <---> | C |
337 * +---+ +---+
338 * ^ ^
339 * | |
340 * | |
341 * +---+ +---+
342 * | A | | D |
343 * +---+ +---+
344 * ^ ^
345 * | |
346 * /----------\ /----------\
347 * | consumer | | consumer |
348 * \----------/ \----------/
349 */
350
351 TopologyTester topo;
352 TopologyNode nodeP = topo.addForwarder("P"),
353 nodeR = topo.addForwarder("R"),
354 nodeA = topo.addForwarder("A"),
355 nodeB = topo.addForwarder("B"),
356 nodeC = topo.addForwarder("C"),
357 nodeD = topo.addForwarder("D");
358
359 for (TopologyNode node : {nodeP, nodeR, nodeA, nodeB, nodeC, nodeD}) {
360 topo.setStrategy<BestRouteStrategy2>(node);
361 }
362
363 const time::milliseconds LINK_DELAY(10);
364 shared_ptr<TopologyLink> linkPR = topo.addLink("PR", LINK_DELAY, {nodeP, nodeR}),
365 linkRB = topo.addLink("RB", LINK_DELAY, {nodeR, nodeB}),
366 linkRC = topo.addLink("RC", LINK_DELAY, {nodeR, nodeC}),
367 linkBC = topo.addLink("BC", LINK_DELAY, {nodeB, nodeC}),
368 linkBA = topo.addLink("BA", LINK_DELAY, {nodeB, nodeA}),
369 linkCD = topo.addLink("CD", LINK_DELAY, {nodeC, nodeD});
370
371 // TODO register the prefix on R->P but then set the face DOWN
372 // topo.registerPrefix(nodeR, linkPR->getFace(nodeR), "ndn:/P", 10);
373 topo.registerPrefix(nodeB, linkRB->getFace(nodeB), "ndn:/P", 20);
374 topo.registerPrefix(nodeB, linkBC->getFace(nodeB), "ndn:/P", 30);
375 topo.registerPrefix(nodeC, linkRC->getFace(nodeC), "ndn:/P", 20);
376 topo.registerPrefix(nodeC, linkBC->getFace(nodeC), "ndn:/P", 30);
377 topo.registerPrefix(nodeA, linkBA->getFace(nodeA), "ndn:/P", 30);
378 topo.registerPrefix(nodeD, linkCD->getFace(nodeD), "ndn:/P", 30);
379
380 ndn::Face& appA = topo.addAppFace("A", nodeA)->getClientFace();
381 ndn::Face& appD = topo.addAppFace("D", nodeD)->getClientFace();
382
383 int nNacksA = 0, nNacksD = 0;
384 appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
385 appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
386 this->advanceClocks(time::milliseconds(1), time::milliseconds(5));
387 appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
388 appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
389 this->advanceClocks(time::milliseconds(1), time::milliseconds(100));
390
391 // As long as at least one Nack arrives at each client, strategy behavior is correct.
392 // Whether both Interests are Nacked is a client face behavior, not strategy behavior.
393 BOOST_CHECK_GT(nNacksA, 0);
394 BOOST_CHECK_GT(nNacksD, 0);
395}
396
397template<lp::NackReason X, lp::NackReason Y, lp::NackReason R>
398struct NackReasonCombination
399{
400 lp::NackReason
401 getX() const
402 {
403 return X;
404 }
405
406 lp::NackReason
407 getY() const
408 {
409 return Y;
410 }
411
412 lp::NackReason
413 getExpectedResult() const
414 {
415 return R;
416 }
417};
418
419typedef boost::mpl::vector<
420 NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
421 NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION>,
422 NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION>,
423 NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
424 NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
425 NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE>,
426 NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
427 NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
428 NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE>
429 > NackReasonCombinations;
430
431BOOST_AUTO_TEST_CASE_TEMPLATE(CombineReasons, Combination, NackReasonCombinations)
432{
433 Combination combination;
434
Junxiao Shia6de4292016-07-12 02:08:10 +0000435 fib::Entry& fibEntry = *fib.insert(Name()).first;
436 fibEntry.addNextHop(*face3, 10);
437 fibEntry.addNextHop(*face4, 20);
438 fibEntry.addNextHop(*face5, 30);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700439
440 shared_ptr<Interest> interest1 = makeInterest("/F6sEwB24I", 282);
441 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
Junxiao Shi9cff7792016-08-01 21:45:11 +0000442 pitEntry->insertOrUpdateInRecord(*face1, *interest1);
443 pitEntry->insertOrUpdateOutRecord(*face3, *interest1);
444 pitEntry->insertOrUpdateOutRecord(*face4, *interest1);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700445
446 lp::Nack nack3 = makeNack("/F6sEwB24I", 282, combination.getX());
447 pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
Junxiao Shi8d843142016-07-11 22:42:42 +0000448 strategy.afterReceiveNack(*face3, nack3, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700449
450 BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
451
452 lp::Nack nack4 = makeNack("/F6sEwB24I", 282, combination.getY());
453 pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
Junxiao Shi8d843142016-07-11 22:42:42 +0000454 strategy.afterReceiveNack(*face4, nack4, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700455
456 BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
Junxiao Shi8ff0a862016-08-13 04:50:50 +0000457 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700458 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
459 BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), combination.getExpectedResult());
460}
461
462BOOST_AUTO_TEST_SUITE_END() // IncomingNack
463
464BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2
465BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700466
467} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800468} // namespace fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700469} // namespace nfd