blob: dabfe9d3b8b2283b5f0ec6b2724ae9062b0324fb [file] [log] [blame]
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -07002/*
Alexander Afanasyev135288c2022-04-23 23:06:56 -04003 * Copyright (c) 2014-2022, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00006 *
Alexander Afanasyev135288c2022-04-23 23:06:56 -04007 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00009 *
Alexander Afanasyev135288c2022-04-23 23:06:56 -040010 * NLSR is free software: you can redistribute it and/or modify it under the terms
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000011 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
Alexander Afanasyev135288c2022-04-23 23:06:56 -040014 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
Alexander Afanasyev135288c2022-04-23 23:06:56 -040019 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000020 */
21
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000022#include "nlsr.hpp"
23#include "name-prefix-list.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080024// #include "lsa.hpp"
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000025
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040026#include "tests/io-key-chain-fixture.hpp"
27#include "tests/test-common.hpp"
28
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000029namespace nlsr {
30namespace test {
31
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040032class LsaSegmentStorageFixture : public IoKeyChainFixture
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000033{
34public:
35 LsaSegmentStorageFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040036 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060037 , conf(face, m_keyChain)
Ashlesh Gawande15052402018-12-12 20:20:00 -060038 , confProcessor(conf)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060039 , nlsr(face, m_keyChain, conf)
40 , lsdb(nlsr.m_lsdb)
Ashlesh Gawande15052402018-12-12 20:20:00 -060041 , segmentPublisher(face, m_keyChain)
42 , numValidationSignal(0)
43 , afterSegmentValidatedConnection(lsdb.afterSegmentValidatedSignal.connect(
44 [this] (const ndn::Data& data) { ++numValidationSignal; }))
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000045 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060046 std::string config = R"CONF(
47 trust-anchor
48 {
49 type any
50 }
51 )CONF";
52 conf.m_validator.load(config, "config-file-from-string");
53
Ashlesh Gawande15052402018-12-12 20:20:00 -060054 this->advanceClocks(ndn::time::milliseconds(10));
Ashlesh Gawande15052402018-12-12 20:20:00 -060055 face.sentInterests.clear();
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000056 }
57
Ashlesh Gawande15052402018-12-12 20:20:00 -060058 void
59 makeLsaContent(const ndn::Name& interestName, int numNames = 1000)
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060060 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060061 NamePrefixList npl1;
62 for (int i = 0; i < numNames; ++i) {
63 npl1.insert("name1-" + std::to_string(i));
64 }
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060065 NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080066 ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT),
67 npl1);
68 segmentPublisher.publish(interestName, interestName, nameLsa.wireEncode(),
Ashlesh Gawande15052402018-12-12 20:20:00 -060069 ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000070 }
71
72 void
73 receiveLsaInterest(const ndn::Name& baseInterestName, uint64_t segmentNo,
74 bool isSegmentZero)
75 {
76 if (isSegmentZero) {
77 lsdb.processInterest(ndn::Name(), ndn::Interest(baseInterestName));
78 }
79 else {
80 ndn::Name nextInterestName(baseInterestName);
81 nextInterestName.appendSegment(segmentNo);
82 lsdb.processInterest(ndn::Name(), ndn::Interest(nextInterestName));
83 advanceClocks(ndn::time::milliseconds(1), 10);
84 }
85 }
86
87public:
88 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060089 ConfParameter conf;
Ashlesh Gawande15052402018-12-12 20:20:00 -060090 DummyConfFileProcessor confProcessor;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000091 Nlsr nlsr;
92 Lsdb& lsdb;
Ashlesh Gawande15052402018-12-12 20:20:00 -060093 psync::SegmentPublisher segmentPublisher;
94
95 int numValidationSignal;
96 ndn::util::signal::ScopedConnection afterSegmentValidatedConnection;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000097};
98
99BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture)
100
101BOOST_AUTO_TEST_CASE(Basic)
102{
103 ndn::Name lsaInterestName("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME");
104 lsaInterestName.appendNumber(12);
105
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400106 lsdb.expressInterest(lsaInterestName, 0, 0);
Ashlesh Gawande15052402018-12-12 20:20:00 -0600107 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000108
Ashlesh Gawande15052402018-12-12 20:20:00 -0600109 makeLsaContent(lsaInterestName);
110 advanceClocks(ndn::time::milliseconds(10));
111
112 for (const auto& interest : face.sentInterests) {
113 segmentPublisher.replyFromStore(interest.getName());
114 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000115 }
116
Ashlesh Gawande15052402018-12-12 20:20:00 -0600117 // 3 data segments should be in the storage
118 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 3);
119 BOOST_CHECK_EQUAL(numValidationSignal, 3);
120 numValidationSignal = 0;
121 face.sentInterests.clear();
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000122
Ashlesh Gawande15052402018-12-12 20:20:00 -0600123 // Remove older LSA from storage upon receiving that of higher sequence
124 ndn::Name lsaInterestName2("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME");
125 lsaInterestName2.appendNumber(13);
Alexander Afanasyev135288c2022-04-23 23:06:56 -0400126 lsdb.expressInterest(lsaInterestName2, 0, 0);
Ashlesh Gawande15052402018-12-12 20:20:00 -0600127 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000128
Ashlesh Gawande15052402018-12-12 20:20:00 -0600129 makeLsaContent(lsaInterestName2, 1);
130 advanceClocks(ndn::time::milliseconds(10));
131 // Should have cleared all the three segments for the previous interest w/ seq 12
132 // And add one segment for this sequence 13
133 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 1);
134 BOOST_CHECK_EQUAL(numValidationSignal, 1);
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000135
Ashlesh Gawande15052402018-12-12 20:20:00 -0600136 // Scheduled removal of LSA
137 advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
138 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0);
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -0600139}
140
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000141BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage
142
143} // namespace test
144} // namespace nlsr