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