Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 6 | * |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 9 | * |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 11 | * 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 Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 15 | * 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 Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 22 | #include "nlsr.hpp" |
| 23 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 24 | // #include "lsa.hpp" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 25 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 26 | #include "tests/io-key-chain-fixture.hpp" |
| 27 | #include "tests/test-common.hpp" |
| 28 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 29 | namespace nlsr { |
| 30 | namespace test { |
| 31 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 32 | class LsaSegmentStorageFixture : public IoKeyChainFixture |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 33 | { |
| 34 | public: |
| 35 | LsaSegmentStorageFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 36 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 37 | , conf(face, m_keyChain) |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 38 | , confProcessor(conf) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 39 | , nlsr(face, m_keyChain, conf) |
| 40 | , lsdb(nlsr.m_lsdb) |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 41 | , segmentPublisher(face, m_keyChain) |
| 42 | , numValidationSignal(0) |
| 43 | , afterSegmentValidatedConnection(lsdb.afterSegmentValidatedSignal.connect( |
| 44 | [this] (const ndn::Data& data) { ++numValidationSignal; })) |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 45 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 46 | 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 Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 54 | this->advanceClocks(ndn::time::milliseconds(10)); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 55 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 58 | void |
| 59 | makeLsaContent(const ndn::Name& interestName, int numNames = 1000) |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 60 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 61 | NamePrefixList npl1; |
| 62 | for (int i = 0; i < numNames; ++i) { |
| 63 | npl1.insert("name1-" + std::to_string(i)); |
| 64 | } |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 65 | NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 66 | ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), |
| 67 | npl1); |
| 68 | segmentPublisher.publish(interestName, interestName, nameLsa.wireEncode(), |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 69 | ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 70 | } |
| 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 | |
| 87 | public: |
| 88 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 89 | ConfParameter conf; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 90 | DummyConfFileProcessor confProcessor; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 91 | Nlsr nlsr; |
| 92 | Lsdb& lsdb; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 93 | psync::SegmentPublisher segmentPublisher; |
| 94 | |
| 95 | int numValidationSignal; |
| 96 | ndn::util::signal::ScopedConnection afterSegmentValidatedConnection; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture) |
| 100 | |
| 101 | BOOST_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 Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 106 | lsdb.expressInterest(lsaInterestName, 0, 0); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 107 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 108 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 109 | 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 Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 117 | // 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 Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 122 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 123 | // 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 Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 126 | lsdb.expressInterest(lsaInterestName2, 0, 0); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 127 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 128 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 129 | 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 Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 135 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 136 | // Scheduled removal of LSA |
| 137 | advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
| 138 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0); |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 139 | } |
| 140 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 141 | BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage |
| 142 | |
| 143 | } // namespace test |
| 144 | } // namespace nlsr |