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