fw: Nack in multicast strategy
refs: #3176
Change-Id: I1ef43c277a6a251170b652bf77d5516912a5d630
diff --git a/tests/daemon/fw/strategy-no-route.t.cpp b/tests/daemon/fw/strategy-no-route.t.cpp
new file mode 100644
index 0000000..18f45a8
--- /dev/null
+++ b/tests/daemon/fw/strategy-no-route.t.cpp
@@ -0,0 +1,184 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2017, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * This test suite checks that a strategy returns Nack-NoRoute
+ * when there is no usable FIB nexthop.
+ */
+
+// Strategies returning Nack-NoRoute when there is no usable FIB nexthop,
+// sorted alphabetically.
+#include "fw/asf-strategy.hpp"
+#include "fw/best-route-strategy2.hpp"
+#include "fw/multicast-strategy.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/limited-io.hpp"
+#include "choose-strategy.hpp"
+#include "strategy-tester.hpp"
+#include "tests/daemon/face/dummy-face.hpp"
+#include <boost/mpl/copy_if.hpp>
+#include <boost/mpl/vector.hpp>
+
+namespace nfd {
+namespace fw {
+namespace tests {
+
+using namespace nfd::tests;
+
+template<typename S>
+class StrategyNoRouteFixture : public UnitTestTimeFixture
+{
+public:
+ StrategyNoRouteFixture()
+ : limitedIo(this)
+ , strategy(choose<StrategyTester<S>>(forwarder))
+ , fib(forwarder.getFib())
+ , pit(forwarder.getPit())
+ , face1(make_shared<DummyFace>())
+ , face2(make_shared<DummyFace>())
+ {
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ }
+
+public:
+ LimitedIo limitedIo;
+
+ Forwarder forwarder;
+ StrategyTester<S>& strategy;
+ Fib& fib;
+ Pit& pit;
+
+ shared_ptr<Face> face1;
+ shared_ptr<Face> face2;
+};
+
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestStrategyNoRoute, BaseFixture)
+
+template<typename S, typename C>
+class Test
+{
+public:
+ using Strategy = S;
+ using Case = C;
+};
+
+template<typename S>
+class EmptyNextHopList
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ void
+ insertFibEntry(StrategyNoRouteFixture<S>* fixture)
+ {
+ fixture->fib.insert(Name());
+ }
+};
+
+template<typename S>
+class NextHopIsDownstream
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ void
+ insertFibEntry(StrategyNoRouteFixture<S>* fixture)
+ {
+ fixture->fib.insert(Name()).first->addNextHop(*fixture->face1, 10);
+ }
+};
+
+template<typename S>
+class NextHopViolatesScope
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/localhop/P";
+ }
+
+ void
+ insertFibEntry(StrategyNoRouteFixture<S>* fixture)
+ {
+ fixture->fib.insert("/localhop").first->addNextHop(*fixture->face2, 10);
+ // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
+ }
+};
+
+using Tests = boost::mpl::vector<
+ Test<AsfStrategy, EmptyNextHopList<AsfStrategy>>,
+ Test<AsfStrategy, NextHopIsDownstream<AsfStrategy>>,
+ Test<AsfStrategy, NextHopViolatesScope<AsfStrategy>>,
+
+ Test<BestRouteStrategy2, EmptyNextHopList<BestRouteStrategy2>>,
+ Test<BestRouteStrategy2, NextHopIsDownstream<BestRouteStrategy2>>,
+ Test<BestRouteStrategy2, NextHopViolatesScope<BestRouteStrategy2>>,
+
+ Test<MulticastStrategy, EmptyNextHopList<MulticastStrategy>>,
+ Test<MulticastStrategy, NextHopIsDownstream<MulticastStrategy>>,
+ Test<MulticastStrategy, NextHopViolatesScope<MulticastStrategy>>
+>;
+
+BOOST_FIXTURE_TEST_CASE_TEMPLATE(IncomingInterest, T, Tests,
+ StrategyNoRouteFixture<typename T::Strategy>)
+{
+ typename T::Case scenario;
+ scenario.insertFibEntry(this);
+
+ shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
+ shared_ptr<pit::Entry> pitEntry = this->pit.insert(*interest).first;
+ pitEntry->insertOrUpdateInRecord(*this->face1, *interest);
+
+ BOOST_REQUIRE(this->strategy.waitForAction(
+ [&] { this->strategy.afterReceiveInterest(*this->face1, *interest, pitEntry); },
+ this->limitedIo, 2));
+
+ BOOST_REQUIRE_EQUAL(this->strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(this->strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest());
+
+ BOOST_REQUIRE_EQUAL(this->strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest());
+ BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].outFaceId, this->face1->getId());
+ BOOST_CHECK_EQUAL(this->strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestStrategyNoRoute
+BOOST_AUTO_TEST_SUITE_END() // Fw
+
+} // namespace tests
+} // namespace fw
+} // namespace nfd