blob: 11f3f38eac362b4f369aced454e4cd24d056c5e9 [file] [log] [blame]
Junxiao Shi49e11e72014-12-14 19:46:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifab9e0d2017-02-02 06:04:59 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 Shi49e11e72014-12-14 19:46:05 -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/strategy.hpp"
27#include "dummy-strategy.hpp"
28#include "tests/daemon/face/dummy-face.hpp"
29#include <boost/range/adaptor/filtered.hpp>
Junxiao Shib84e6742016-07-19 13:16:22 +000030#include <boost/range/adaptor/transformed.hpp>
31#include <boost/range/algorithm/copy.hpp>
Junxiao Shi49e11e72014-12-14 19:46:05 -070032
33#include "tests/test-common.hpp"
34
35namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080036namespace fw {
Junxiao Shi49e11e72014-12-14 19:46:05 -070037namespace tests {
38
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080039using namespace nfd::tests;
40
Junxiao Shicde37ad2015-12-24 01:02:05 -070041BOOST_AUTO_TEST_SUITE(Fw)
42BOOST_FIXTURE_TEST_SUITE(TestStrategy, BaseFixture)
Junxiao Shi49e11e72014-12-14 19:46:05 -070043
Junxiao Shi91f6ee02016-12-29 21:44:44 +000044// Strategy registry is tested in table/strategy-choice.t.cpp and strategy-instantiation.t.cpp
45
Junxiao Shi49e11e72014-12-14 19:46:05 -070046class FaceTableAccessTestStrategy : public DummyStrategy
47{
48public:
49 explicit
50 FaceTableAccessTestStrategy(Forwarder& forwarder)
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000051 : DummyStrategy(forwarder)
Junxiao Shi49e11e72014-12-14 19:46:05 -070052 {
Junxiao Shiae04d342016-07-19 13:20:22 +000053 this->afterAddFace.connect([this] (const Face& face) {
54 this->addedFaces.push_back(face.getId());
Junxiao Shi49e11e72014-12-14 19:46:05 -070055 });
Junxiao Shiae04d342016-07-19 13:20:22 +000056 this->beforeRemoveFace.connect([this] (const Face& face) {
57 this->removedFaces.push_back(face.getId());
Junxiao Shi49e11e72014-12-14 19:46:05 -070058 });
59 }
60
61 std::vector<FaceId>
62 getLocalFaces()
63 {
64 auto enumerable = this->getFaceTable() |
Junxiao Shib84e6742016-07-19 13:16:22 +000065 boost::adaptors::filtered([] (Face& face) {
66 return face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL;
67 }) |
68 boost::adaptors::transformed([] (Face& face) {
69 return face.getId();
Junxiao Shi49e11e72014-12-14 19:46:05 -070070 });
71
72 std::vector<FaceId> results;
Junxiao Shib84e6742016-07-19 13:16:22 +000073 boost::copy(enumerable, std::back_inserter(results));
Junxiao Shi49e11e72014-12-14 19:46:05 -070074 return results;
75 }
76
77public:
78 std::vector<FaceId> addedFaces;
79 std::vector<FaceId> removedFaces;
80};
81
82BOOST_AUTO_TEST_CASE(FaceTableAccess)
83{
84 Forwarder forwarder;
85 FaceTableAccessTestStrategy strategy(forwarder);
86
87 auto face1 = make_shared<DummyFace>();
Junxiao Shicde37ad2015-12-24 01:02:05 -070088 auto face2 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
Junxiao Shi49e11e72014-12-14 19:46:05 -070089 forwarder.addFace(face1);
90 forwarder.addFace(face2);
91 FaceId id1 = face1->getId();
92 FaceId id2 = face2->getId();
93
94 BOOST_CHECK(strategy.getLocalFaces() == std::vector<FaceId>{id2});
95
96 face2->close();
97 face1->close();
98
99 BOOST_CHECK((strategy.addedFaces == std::vector<FaceId>{id1, id2}));
100 BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
101}
102
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000103// LookupFib is tested in Fw/TestLinkForwarding test suite.
Junxiao Shi0dba0102016-09-06 01:57:53 +0000104
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105BOOST_AUTO_TEST_SUITE_END() // TestStrategy
106BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700107
108} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800109} // namespace fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700110} // namespace nfd