blob: dd098c05edb31ed5ec352b487573d0778ad8f75c [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento8de8a8b2022-05-12 01:26:43 -04002/*
Davide Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, The University of Memphis,
Vince Lehman6151e952015-02-16 12:36:00 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
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 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
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
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehman6151e952015-02-16 12:36:00 -060021
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050022#include "sequencing-manager.hpp"
Davide Pesaventocb065f12019-12-27 01:03:34 -050023
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040024#include "tests/boost-test.hpp"
25
26#include <boost/filesystem/operations.hpp>
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050027#include <fstream>
28
Davide Pesavento288141a2024-02-13 17:30:35 -050029namespace nlsr::tests {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050030
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040031using namespace ndn;
32
33class SequencingManagerFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050034{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050035public:
36 SequencingManagerFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040037 : m_seqManager("/tmp", HYPERBOLIC_STATE_OFF)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050038 {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050039 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050040
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050041 ~SequencingManagerFixture()
42 {
43 boost::filesystem::remove(seqFile);
44 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050045
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050046 void
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060047 writeToFile(const std::string& testSeq)
48 {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050049 std::ofstream outputFile(seqFile, std::ofstream::trunc);
50 outputFile << testSeq;
51 outputFile.close();
52 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050053
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050054 void
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060055 initiateFromFile()
56 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060057 m_seqManager.initiateSeqNoFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050058 }
59
60 void
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060061 checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor)
62 {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050063 BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050064 BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050065 BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor);
66 }
67
Ashlesh Gawande85998a12017-12-07 22:22:13 -060068public:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050069 std::string seqFile = "/tmp/nlsrSeqNo.txt";
70 SequencingManager m_seqManager;
71};
72
73BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture)
74
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050075BOOST_AUTO_TEST_CASE(SeparateSeqNumber)
Vince Lehman6151e952015-02-16 12:36:00 -060076{
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060077 initiateFromFile();
78 checkSeqNumbers(0, 0, 0);
79
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050080 // LS
81 writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0");
Ashlesh Gawande85998a12017-12-07 22:22:13 -060082 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF;
83 initiateFromFile();
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060084 checkSeqNumbers(100 + 10, 100 + 10, 0);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050085
86 // HR
87 writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100");
Ashlesh Gawande85998a12017-12-07 22:22:13 -060088 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON;
89 initiateFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050090 // AdjLsa is set to 0 since HR is on
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060091 checkSeqNumbers(100 + 10, 0, 100 + 10);
92}
93
94BOOST_AUTO_TEST_CASE(CorruptFile)
95{
96 writeToFile("NameLsaSeq");
97 initiateFromFile();
98 checkSeqNumbers(10, 10, 0);
Vince Lehman6151e952015-02-16 12:36:00 -060099}
100
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500101BOOST_AUTO_TEST_SUITE_END()
102
Davide Pesavento288141a2024-02-13 17:30:35 -0500103} // namespace nlsr::tests