Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 "test-common.hpp" |
| 27 | #include "nlsr.hpp" |
| 28 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 29 | #include "lsa.hpp" |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 30 | |
| 31 | #include <boost/test/unit_test.hpp> |
| 32 | |
| 33 | namespace nlsr { |
| 34 | namespace test { |
| 35 | |
| 36 | class LsaSegmentStorageFixture : public UnitTestTimeFixture |
| 37 | { |
| 38 | public: |
| 39 | LsaSegmentStorageFixture() |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 40 | : face(m_ioService, m_keyChain, {true, true}) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 41 | , conf(face) |
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 | |
| 58 | nlsr.initialize(); |
| 59 | |
| 60 | this->advanceClocks(ndn::time::milliseconds(10)); |
| 61 | |
| 62 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 65 | void |
| 66 | makeLsaContent(const ndn::Name& interestName, int numNames = 1000) |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 67 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 68 | NamePrefixList npl1; |
| 69 | for (int i = 0; i < numNames; ++i) { |
| 70 | npl1.insert("name1-" + std::to_string(i)); |
| 71 | } |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 72 | NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12, |
Ashlesh Gawande | d65786a | 2018-03-30 01:17:58 -0500 | [diff] [blame] | 73 | ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), npl1); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 74 | segmentPublisher.publish(interestName, interestName, |
| 75 | ndn::encoding::makeStringBlock(ndn::tlv::Content, nameLsa.serialize()), |
| 76 | ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void |
| 80 | receiveLsaInterest(const ndn::Name& baseInterestName, uint64_t segmentNo, |
| 81 | bool isSegmentZero) |
| 82 | { |
| 83 | if (isSegmentZero) { |
| 84 | lsdb.processInterest(ndn::Name(), ndn::Interest(baseInterestName)); |
| 85 | } |
| 86 | else { |
| 87 | ndn::Name nextInterestName(baseInterestName); |
| 88 | nextInterestName.appendSegment(segmentNo); |
| 89 | lsdb.processInterest(ndn::Name(), ndn::Interest(nextInterestName)); |
| 90 | advanceClocks(ndn::time::milliseconds(1), 10); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | public: |
| 95 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 96 | ConfParameter conf; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 97 | DummyConfFileProcessor confProcessor; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 98 | Nlsr nlsr; |
| 99 | Lsdb& lsdb; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 100 | psync::SegmentPublisher segmentPublisher; |
| 101 | |
| 102 | int numValidationSignal; |
| 103 | ndn::util::signal::ScopedConnection afterSegmentValidatedConnection; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture) |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(Basic) |
| 109 | { |
| 110 | ndn::Name lsaInterestName("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME"); |
| 111 | lsaInterestName.appendNumber(12); |
| 112 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 113 | lsdb.expressInterest(lsaInterestName, 0); |
| 114 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 115 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 116 | makeLsaContent(lsaInterestName); |
| 117 | advanceClocks(ndn::time::milliseconds(10)); |
| 118 | |
| 119 | for (const auto& interest : face.sentInterests) { |
| 120 | segmentPublisher.replyFromStore(interest.getName()); |
| 121 | advanceClocks(ndn::time::milliseconds(10)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 124 | // 3 data segments should be in the storage |
| 125 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 3); |
| 126 | BOOST_CHECK_EQUAL(numValidationSignal, 3); |
| 127 | numValidationSignal = 0; |
| 128 | face.sentInterests.clear(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 129 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 130 | // Remove older LSA from storage upon receiving that of higher sequence |
| 131 | ndn::Name lsaInterestName2("/ndn/NLSR/LSA/other-site/%C1.Router/other-router/NAME"); |
| 132 | lsaInterestName2.appendNumber(13); |
| 133 | lsdb.expressInterest(lsaInterestName2, 0); |
| 134 | advanceClocks(ndn::time::milliseconds(10)); |
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 | makeLsaContent(lsaInterestName2, 1); |
| 137 | advanceClocks(ndn::time::milliseconds(10)); |
| 138 | // Should have cleared all the three segments for the previous interest w/ seq 12 |
| 139 | // And add one segment for this sequence 13 |
| 140 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 1); |
| 141 | BOOST_CHECK_EQUAL(numValidationSignal, 1); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 142 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame^] | 143 | // Scheduled removal of LSA |
| 144 | advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT)); |
| 145 | BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0); |
Ashlesh Gawande | 8c6d8c8 | 2018-02-28 21:41:31 -0600 | [diff] [blame] | 146 | } |
| 147 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 148 | BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage |
| 149 | |
| 150 | } // namespace test |
| 151 | } // namespace nlsr |