blob: 2881d8845507bfd9cffca202b074f64e5527121f [file] [log] [blame]
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Saurab Dulal427e0122019-11-28 11:58:02 -06003 * Copyright (c) 2014-2020, Regents of the University of California,
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00004 * 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.
10 *
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
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000026#include "test-common.hpp"
27#include "nlsr.hpp"
28#include "name-prefix-list.hpp"
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060029#include "lsa.hpp"
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000030
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000031namespace nlsr {
32namespace test {
33
34class LsaSegmentStorageFixture : public UnitTestTimeFixture
35{
36public:
37 LsaSegmentStorageFixture()
Ashlesh Gawande15052402018-12-12 20:20:00 -060038 : face(m_ioService, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060039 , conf(face, m_keyChain)
Ashlesh Gawande15052402018-12-12 20:20:00 -060040 , confProcessor(conf)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060041 , nlsr(face, m_keyChain, conf)
42 , lsdb(nlsr.m_lsdb)
Ashlesh Gawande15052402018-12-12 20:20:00 -060043 , segmentPublisher(face, m_keyChain)
44 , numValidationSignal(0)
45 , afterSegmentValidatedConnection(lsdb.afterSegmentValidatedSignal.connect(
46 [this] (const ndn::Data& data) { ++numValidationSignal; }))
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000047 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060048 std::string config = R"CONF(
49 trust-anchor
50 {
51 type any
52 }
53 )CONF";
54 conf.m_validator.load(config, "config-file-from-string");
55
56 nlsr.initialize();
57
58 this->advanceClocks(ndn::time::milliseconds(10));
59
60 face.sentInterests.clear();
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000061 }
62
Ashlesh Gawande15052402018-12-12 20:20:00 -060063 void
64 makeLsaContent(const ndn::Name& interestName, int numNames = 1000)
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060065 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060066 NamePrefixList npl1;
67 for (int i = 0; i < numNames; ++i) {
68 npl1.insert("name1-" + std::to_string(i));
69 }
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060070 NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12,
Ashlesh Gawanded65786a2018-03-30 01:17:58 -050071 ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), npl1);
Ashlesh Gawande15052402018-12-12 20:20:00 -060072 segmentPublisher.publish(interestName, interestName,
73 ndn::encoding::makeStringBlock(ndn::tlv::Content, nameLsa.serialize()),
74 ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000075 }
76
77 void
78 receiveLsaInterest(const ndn::Name& baseInterestName, uint64_t segmentNo,
79 bool isSegmentZero)
80 {
81 if (isSegmentZero) {
82 lsdb.processInterest(ndn::Name(), ndn::Interest(baseInterestName));
83 }
84 else {
85 ndn::Name nextInterestName(baseInterestName);
86 nextInterestName.appendSegment(segmentNo);
87 lsdb.processInterest(ndn::Name(), ndn::Interest(nextInterestName));
88 advanceClocks(ndn::time::milliseconds(1), 10);
89 }
90 }
91
92public:
93 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060094 ConfParameter conf;
Ashlesh Gawande15052402018-12-12 20:20:00 -060095 DummyConfFileProcessor confProcessor;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000096 Nlsr nlsr;
97 Lsdb& lsdb;
Ashlesh Gawande15052402018-12-12 20:20:00 -060098 psync::SegmentPublisher segmentPublisher;
99
100 int numValidationSignal;
101 ndn::util::signal::ScopedConnection afterSegmentValidatedConnection;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000102};
103
104BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture)
105
106BOOST_AUTO_TEST_CASE(Basic)
107{
108 ndn::Name lsaInterestName("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME");
109 lsaInterestName.appendNumber(12);
110
Ashlesh Gawande15052402018-12-12 20:20:00 -0600111 lsdb.expressInterest(lsaInterestName, 0);
112 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000113
Ashlesh Gawande15052402018-12-12 20:20:00 -0600114 makeLsaContent(lsaInterestName);
115 advanceClocks(ndn::time::milliseconds(10));
116
117 for (const auto& interest : face.sentInterests) {
118 segmentPublisher.replyFromStore(interest.getName());
119 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000120 }
121
Ashlesh Gawande15052402018-12-12 20:20:00 -0600122 // 3 data segments should be in the storage
123 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 3);
124 BOOST_CHECK_EQUAL(numValidationSignal, 3);
125 numValidationSignal = 0;
126 face.sentInterests.clear();
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000127
Ashlesh Gawande15052402018-12-12 20:20:00 -0600128 // Remove older LSA from storage upon receiving that of higher sequence
129 ndn::Name lsaInterestName2("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME");
130 lsaInterestName2.appendNumber(13);
131 lsdb.expressInterest(lsaInterestName2, 0);
132 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000133
Ashlesh Gawande15052402018-12-12 20:20:00 -0600134 makeLsaContent(lsaInterestName2, 1);
135 advanceClocks(ndn::time::milliseconds(10));
136 // Should have cleared all the three segments for the previous interest w/ seq 12
137 // And add one segment for this sequence 13
138 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 1);
139 BOOST_CHECK_EQUAL(numValidationSignal, 1);
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000140
Ashlesh Gawande15052402018-12-12 20:20:00 -0600141 // Scheduled removal of LSA
142 advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
143 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0);
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -0600144}
145
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000146BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage
147
148} // namespace test
149} // namespace nlsr