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 | /* |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 4 | * 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 Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 26 | #include "nlsr.hpp" |
| 27 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 28 | // #include "lsa.hpp" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 29 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame^] | 30 | #include "tests/io-key-chain-fixture.hpp" |
| 31 | #include "tests/test-common.hpp" |
| 32 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 33 | namespace nlsr { |
| 34 | namespace test { |
| 35 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame^] | 36 | class LsaSegmentStorageFixture : public IoKeyChainFixture |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | LsaSegmentStorageFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame^] | 40 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 41 | , conf(face, m_keyChain) |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 42 | , confProcessor(conf) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 43 | , nlsr(face, m_keyChain, conf) |
| 44 | , lsdb(nlsr.m_lsdb) |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 45 | , segmentPublisher(face, m_keyChain) |
| 46 | , numValidationSignal(0) |
| 47 | , afterSegmentValidatedConnection(lsdb.afterSegmentValidatedSignal.connect( |
| 48 | [this] (const ndn::Data& data) { ++numValidationSignal; })) |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 49 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 50 | std::string config = R"CONF( |
| 51 | trust-anchor |
| 52 | { |
| 53 | type any |
| 54 | } |
| 55 | )CONF"; |
| 56 | conf.m_validator.load(config, "config-file-from-string"); |
| 57 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 58 | this->advanceClocks(ndn::time::milliseconds(10)); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 59 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 62 | void |
| 63 | makeLsaContent(const ndn::Name& interestName, int numNames = 1000) |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 64 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 65 | NamePrefixList npl1; |
| 66 | for (int i = 0; i < numNames; ++i) { |
| 67 | npl1.insert("name1-" + std::to_string(i)); |
| 68 | } |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 69 | NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 70 | ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), |
| 71 | npl1); |
| 72 | segmentPublisher.publish(interestName, interestName, nameLsa.wireEncode(), |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 73 | ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
| 77 | receiveLsaInterest(const ndn::Name& baseInterestName, uint64_t segmentNo, |
| 78 | bool isSegmentZero) |
| 79 | { |
| 80 | if (isSegmentZero) { |
| 81 | lsdb.processInterest(ndn::Name(), ndn::Interest(baseInterestName)); |
| 82 | } |
| 83 | else { |
| 84 | ndn::Name nextInterestName(baseInterestName); |
| 85 | nextInterestName.appendSegment(segmentNo); |
| 86 | lsdb.processInterest(ndn::Name(), ndn::Interest(nextInterestName)); |
| 87 | advanceClocks(ndn::time::milliseconds(1), 10); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public: |
| 92 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 93 | ConfParameter conf; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 94 | DummyConfFileProcessor confProcessor; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 95 | Nlsr nlsr; |
| 96 | Lsdb& lsdb; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 97 | psync::SegmentPublisher segmentPublisher; |
| 98 | |
| 99 | int numValidationSignal; |
| 100 | ndn::util::signal::ScopedConnection afterSegmentValidatedConnection; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture) |
| 104 | |
| 105 | BOOST_AUTO_TEST_CASE(Basic) |
| 106 | { |
| 107 | ndn::Name lsaInterestName("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME"); |
| 108 | lsaInterestName.appendNumber(12); |
| 109 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 110 | lsdb.expressInterest(lsaInterestName, 0); |
| 111 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 112 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 113 | makeLsaContent(lsaInterestName); |
| 114 | advanceClocks(ndn::time::milliseconds(10)); |
| 115 | |
| 116 | for (const auto& interest : face.sentInterests) { |
| 117 | segmentPublisher.replyFromStore(interest.getName()); |
| 118 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 121 | // 3 data segments should be in the storage |
| 122 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 3); |
| 123 | BOOST_CHECK_EQUAL(numValidationSignal, 3); |
| 124 | numValidationSignal = 0; |
| 125 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 126 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 127 | // Remove older LSA from storage upon receiving that of higher sequence |
| 128 | ndn::Name lsaInterestName2("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME"); |
| 129 | lsaInterestName2.appendNumber(13); |
| 130 | lsdb.expressInterest(lsaInterestName2, 0); |
| 131 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 132 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 133 | makeLsaContent(lsaInterestName2, 1); |
| 134 | advanceClocks(ndn::time::milliseconds(10)); |
| 135 | // Should have cleared all the three segments for the previous interest w/ seq 12 |
| 136 | // And add one segment for this sequence 13 |
| 137 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 1); |
| 138 | BOOST_CHECK_EQUAL(numValidationSignal, 1); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 139 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 140 | // Scheduled removal of LSA |
| 141 | advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
| 142 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0); |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 143 | } |
| 144 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 145 | BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage |
| 146 | |
| 147 | } // namespace test |
| 148 | } // namespace nlsr |