blob: 8b27986c996c78d60cdbcf765ef8c1ea9968936d [file] [log] [blame]
Junxiao Shi49e11e72014-12-14 19:46:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04002/*
3 * Copyright (c) 2014-2019, 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"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040027
28#include "tests/test-common.hpp"
29#include "tests/daemon/global-io-fixture.hpp"
Junxiao Shi49e11e72014-12-14 19:46:05 -070030#include "tests/daemon/face/dummy-face.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040031#include "dummy-strategy.hpp"
32
Junxiao Shi49e11e72014-12-14 19:46:05 -070033#include <boost/range/adaptor/filtered.hpp>
Junxiao Shib84e6742016-07-19 13:16:22 +000034#include <boost/range/adaptor/transformed.hpp>
35#include <boost/range/algorithm/copy.hpp>
Junxiao Shi49e11e72014-12-14 19:46:05 -070036
Junxiao Shi49e11e72014-12-14 19:46:05 -070037namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080038namespace fw {
Junxiao Shi49e11e72014-12-14 19:46:05 -070039namespace tests {
40
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080041using namespace nfd::tests;
42
Junxiao Shicde37ad2015-12-24 01:02:05 -070043BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040044BOOST_FIXTURE_TEST_SUITE(TestStrategy, GlobalIoFixture)
Junxiao Shi49e11e72014-12-14 19:46:05 -070045
Junxiao Shi91f6ee02016-12-29 21:44:44 +000046// Strategy registry is tested in table/strategy-choice.t.cpp and strategy-instantiation.t.cpp
47
Junxiao Shi49e11e72014-12-14 19:46:05 -070048class FaceTableAccessTestStrategy : public DummyStrategy
49{
50public:
51 explicit
52 FaceTableAccessTestStrategy(Forwarder& forwarder)
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000053 : DummyStrategy(forwarder)
Junxiao Shi49e11e72014-12-14 19:46:05 -070054 {
Junxiao Shiae04d342016-07-19 13:20:22 +000055 this->afterAddFace.connect([this] (const Face& face) {
56 this->addedFaces.push_back(face.getId());
Junxiao Shi49e11e72014-12-14 19:46:05 -070057 });
Junxiao Shiae04d342016-07-19 13:20:22 +000058 this->beforeRemoveFace.connect([this] (const Face& face) {
59 this->removedFaces.push_back(face.getId());
Junxiao Shi49e11e72014-12-14 19:46:05 -070060 });
61 }
62
63 std::vector<FaceId>
64 getLocalFaces()
65 {
66 auto enumerable = this->getFaceTable() |
Junxiao Shib84e6742016-07-19 13:16:22 +000067 boost::adaptors::filtered([] (Face& face) {
68 return face.getScope() == ndn::nfd::FACE_SCOPE_LOCAL;
69 }) |
70 boost::adaptors::transformed([] (Face& face) {
71 return face.getId();
Junxiao Shi49e11e72014-12-14 19:46:05 -070072 });
73
74 std::vector<FaceId> results;
Junxiao Shib84e6742016-07-19 13:16:22 +000075 boost::copy(enumerable, std::back_inserter(results));
Junxiao Shi49e11e72014-12-14 19:46:05 -070076 return results;
77 }
78
79public:
80 std::vector<FaceId> addedFaces;
81 std::vector<FaceId> removedFaces;
82};
83
84BOOST_AUTO_TEST_CASE(FaceTableAccess)
85{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040086 FaceTable faceTable;
87 Forwarder forwarder(faceTable);
Junxiao Shi49e11e72014-12-14 19:46:05 -070088 FaceTableAccessTestStrategy strategy(forwarder);
89
90 auto face1 = make_shared<DummyFace>();
Junxiao Shicde37ad2015-12-24 01:02:05 -070091 auto face2 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040092 faceTable.add(face1);
93 faceTable.add(face2);
Junxiao Shi49e11e72014-12-14 19:46:05 -070094 FaceId id1 = face1->getId();
95 FaceId id2 = face2->getId();
96
97 BOOST_CHECK(strategy.getLocalFaces() == std::vector<FaceId>{id2});
98
99 face2->close();
100 face1->close();
101
102 BOOST_CHECK((strategy.addedFaces == std::vector<FaceId>{id1, id2}));
103 BOOST_CHECK((strategy.removedFaces == std::vector<FaceId>{id2, id1}));
104}
105
Junxiao Shifab9e0d2017-02-02 06:04:59 +0000106// LookupFib is tested in Fw/TestLinkForwarding test suite.
Junxiao Shi0dba0102016-09-06 01:57:53 +0000107
Junxiao Shicde37ad2015-12-24 01:02:05 -0700108BOOST_AUTO_TEST_SUITE_END() // TestStrategy
109BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700110
111} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800112} // namespace fw
Junxiao Shi49e11e72014-12-14 19:46:05 -0700113} // namespace nfd