akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 21 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 22 | #include "sequencing-manager.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 23 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
| 25 | |
Davide Pesavento | b071654 | 2024-12-16 19:12:11 -0500 | [diff] [blame^] | 26 | #include <filesystem> |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 27 | #include <fstream> |
Davide Pesavento | b071654 | 2024-12-16 19:12:11 -0500 | [diff] [blame^] | 28 | #include <system_error> |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 30 | namespace nlsr::tests { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 32 | using namespace ndn; |
| 33 | |
| 34 | class SequencingManagerFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 36 | public: |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 37 | ~SequencingManagerFixture() |
| 38 | { |
Davide Pesavento | b071654 | 2024-12-16 19:12:11 -0500 | [diff] [blame^] | 39 | std::error_code ec; |
| 40 | std::filesystem::remove(m_seqFile, ec); // ignore error |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 41 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 42 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 43 | void |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 44 | writeToFile(const std::string& testSeq) |
| 45 | { |
Davide Pesavento | b071654 | 2024-12-16 19:12:11 -0500 | [diff] [blame^] | 46 | std::ofstream outputFile(m_seqFile, std::ofstream::trunc); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 47 | outputFile << testSeq; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 48 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 49 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 50 | void |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 51 | initiateFromFile() |
| 52 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 53 | m_seqManager.initiateSeqNoFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 57 | checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) |
| 58 | { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 59 | BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor); |
| 62 | } |
| 63 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 64 | public: |
Davide Pesavento | b071654 | 2024-12-16 19:12:11 -0500 | [diff] [blame^] | 65 | SequencingManager m_seqManager{"/tmp", HYPERBOLIC_STATE_OFF}; |
| 66 | |
| 67 | private: |
| 68 | std::filesystem::path m_seqFile{"/tmp/nlsrSeqNo.txt"}; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture) |
| 72 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 73 | BOOST_AUTO_TEST_CASE(SeparateSeqNumber) |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 74 | { |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 75 | initiateFromFile(); |
| 76 | checkSeqNumbers(0, 0, 0); |
| 77 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 78 | // LS |
| 79 | writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 80 | m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF; |
| 81 | initiateFromFile(); |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 82 | checkSeqNumbers(100 + 10, 100 + 10, 0); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 83 | |
| 84 | // HR |
| 85 | writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 86 | m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON; |
| 87 | initiateFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 88 | // AdjLsa is set to 0 since HR is on |
Ashlesh Gawande | 55d1b5c | 2019-12-19 16:21:58 -0600 | [diff] [blame] | 89 | checkSeqNumbers(100 + 10, 0, 100 + 10); |
| 90 | } |
| 91 | |
| 92 | BOOST_AUTO_TEST_CASE(CorruptFile) |
| 93 | { |
| 94 | writeToFile("NameLsaSeq"); |
| 95 | initiateFromFile(); |
| 96 | checkSeqNumbers(10, 10, 0); |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 97 | } |
| 98 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 99 | BOOST_AUTO_TEST_SUITE_END() |
| 100 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 101 | } // namespace nlsr::tests |