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 | /* |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 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" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 23 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 24 | #include "tests/io-key-chain-fixture.hpp" |
| 25 | #include "tests/test-common.hpp" |
| 26 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 27 | #include <ndn-cxx/ims/in-memory-storage-fifo.hpp> |
| 28 | #include <ndn-cxx/util/segmenter.hpp> |
| 29 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 33 | class LsaSegmentStorageFixture : public IoKeyChainFixture |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | LsaSegmentStorageFixture() |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 37 | { |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 38 | afterSegmentValidatedConn = lsdb.afterSegmentValidatedSignal.connect([this] (auto&&...) { |
| 39 | ++numValidationSignal; |
| 40 | }); |
| 41 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 42 | std::string config = R"CONF( |
| 43 | trust-anchor |
| 44 | { |
| 45 | type any |
| 46 | } |
| 47 | )CONF"; |
| 48 | conf.m_validator.load(config, "config-file-from-string"); |
| 49 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 50 | this->advanceClocks(ndn::time::milliseconds(10)); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 51 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 54 | void |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 55 | makeLsaContent(ndn::Name interestName, int numNames = 1000) |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 56 | { |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 57 | const ndn::time::seconds refreshTime{LSA_REFRESH_TIME_DEFAULT}; |
| 58 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 59 | NamePrefixList npl1; |
| 60 | for (int i = 0; i < numNames; ++i) { |
| 61 | npl1.insert("name1-" + std::to_string(i)); |
| 62 | } |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 63 | NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12, |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 64 | ndn::time::system_clock::now() + refreshTime, npl1); |
| 65 | |
| 66 | interestName.appendVersion(); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 67 | ndn::Segmenter segmenter(m_keyChain, ndn::security::SigningInfo()); |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 68 | auto segments = segmenter.segment(nameLsa.wireEncode(), interestName, |
| 69 | ndn::MAX_NDN_PACKET_SIZE / 2, refreshTime); |
| 70 | for (const auto& seg : segments) { |
| 71 | ims.insert(*seg, refreshTime); |
| 72 | } |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 76 | sendReplies() |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 77 | { |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 78 | for (const auto& interest : face.sentInterests) { |
| 79 | if (auto data = ims.find(interest.getName()); data) { |
| 80 | face.put(*data); |
| 81 | } |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 82 | } |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 83 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 87 | ndn::DummyClientFace face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 88 | ConfParameter conf{face, m_keyChain}; |
| 89 | DummyConfFileProcessor confProcessor{conf}; |
| 90 | Nlsr nlsr{face, m_keyChain, conf}; |
| 91 | Lsdb& lsdb{nlsr.m_lsdb}; |
| 92 | ndn::InMemoryStorageFifo ims{100}; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 93 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 94 | int numValidationSignal = 0; |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 95 | ndn::signal::ScopedConnection afterSegmentValidatedConn; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture) |
| 99 | |
| 100 | BOOST_AUTO_TEST_CASE(Basic) |
| 101 | { |
| 102 | ndn::Name lsaInterestName("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME"); |
| 103 | lsaInterestName.appendNumber(12); |
| 104 | |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 105 | lsdb.expressInterest(lsaInterestName, 0, 0); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 106 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 107 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 108 | makeLsaContent(lsaInterestName); |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 109 | BOOST_CHECK_EQUAL(ims.size(), 3); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 110 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 111 | // 1st segment |
| 112 | sendReplies(); |
| 113 | advanceClocks(ndn::time::milliseconds(10)); |
| 114 | // 2nd and 3rd segments |
| 115 | sendReplies(); |
| 116 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 117 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 118 | // 3 data segments should be in the storage |
| 119 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 3); |
| 120 | BOOST_CHECK_EQUAL(numValidationSignal, 3); |
| 121 | numValidationSignal = 0; |
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); |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 130 | sendReplies(); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 131 | advanceClocks(ndn::time::milliseconds(10)); |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame] | 132 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 133 | // Should have cleared all the three segments for the previous interest w/ seq 12 |
| 134 | // And add one segment for this sequence 13 |
| 135 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 1); |
| 136 | BOOST_CHECK_EQUAL(numValidationSignal, 1); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 137 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 138 | // Scheduled removal of LSA |
| 139 | advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
| 140 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0); |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 141 | } |
| 142 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 143 | BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage |
| 144 | |
| 145 | } // namespace test |
| 146 | } // namespace nlsr |