blob: ac2671fdc870e8cc738700309e055e18febdb099 [file] [log] [blame]
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, Regents of the University of California,
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00004 * 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +000026#include "test-common.hpp"
27#include "nlsr.hpp"
28#include "name-prefix-list.hpp"
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060029#include "lsa.hpp"
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000030
31#include <boost/test/unit_test.hpp>
32
33namespace nlsr {
34namespace test {
35
36class LsaSegmentStorageFixture : public UnitTestTimeFixture
37{
38public:
39 LsaSegmentStorageFixture()
Ashlesh Gawande15052402018-12-12 20:20:00 -060040 : face(m_ioService, m_keyChain, {true, true})
Ashlesh Gawande85998a12017-12-07 22:22:13 -060041 , conf(face)
Ashlesh Gawande15052402018-12-12 20:20:00 -060042 , confProcessor(conf)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060043 , nlsr(face, m_keyChain, conf)
44 , lsdb(nlsr.m_lsdb)
Ashlesh Gawande15052402018-12-12 20:20:00 -060045 , segmentPublisher(face, m_keyChain)
46 , numValidationSignal(0)
47 , afterSegmentValidatedConnection(lsdb.afterSegmentValidatedSignal.connect(
48 [this] (const ndn::Data& data) { ++numValidationSignal; }))
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000049 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060050 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +000063 }
64
Ashlesh Gawande15052402018-12-12 20:20:00 -060065 void
66 makeLsaContent(const ndn::Name& interestName, int numNames = 1000)
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060067 {
Ashlesh Gawande15052402018-12-12 20:20:00 -060068 NamePrefixList npl1;
69 for (int i = 0; i < numNames; ++i) {
70 npl1.insert("name1-" + std::to_string(i));
71 }
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -060072 NameLsa nameLsa("/ndn/other-site/%C1.Router/other-router", 12,
Ashlesh Gawanded65786a2018-03-30 01:17:58 -050073 ndn::time::system_clock::now() + ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT), npl1);
Ashlesh Gawande15052402018-12-12 20:20:00 -060074 segmentPublisher.publish(interestName, interestName,
75 ndn::encoding::makeStringBlock(ndn::tlv::Content, nameLsa.serialize()),
76 ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000077 }
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
94public:
95 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060096 ConfParameter conf;
Ashlesh Gawande15052402018-12-12 20:20:00 -060097 DummyConfFileProcessor confProcessor;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000098 Nlsr nlsr;
99 Lsdb& lsdb;
Ashlesh Gawande15052402018-12-12 20:20:00 -0600100 psync::SegmentPublisher segmentPublisher;
101
102 int numValidationSignal;
103 ndn::util::signal::ScopedConnection afterSegmentValidatedConnection;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000104};
105
106BOOST_FIXTURE_TEST_SUITE(TestLsaSegmentStorage, LsaSegmentStorageFixture)
107
108BOOST_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 Gawande15052402018-12-12 20:20:00 -0600113 lsdb.expressInterest(lsaInterestName, 0);
114 advanceClocks(ndn::time::milliseconds(10));
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000115
Ashlesh Gawande15052402018-12-12 20:20:00 -0600116 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +0000122 }
123
Ashlesh Gawande15052402018-12-12 20:20:00 -0600124 // 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +0000129
Ashlesh Gawande15052402018-12-12 20:20:00 -0600130 // 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +0000135
Ashlesh Gawande15052402018-12-12 20:20:00 -0600136 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 Chowdhuryc3ea26f2018-01-05 21:40:59 +0000142
Ashlesh Gawande15052402018-12-12 20:20:00 -0600143 // Scheduled removal of LSA
144 advanceClocks(ndn::time::seconds(LSA_REFRESH_TIME_DEFAULT));
145 BOOST_CHECK_EQUAL(lsdb.m_lsaStorage.size(), 0);
Ashlesh Gawande8c6d8c82018-02-28 21:41:31 -0600146}
147
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000148BOOST_AUTO_TEST_SUITE_END() // TestLsaSegmentStorage
149
150} // namespace test
151} // namespace nlsr