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 | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 49 | writeToFile(const std::string& testSeq) { |
| 50 | std::ofstream outputFile(seqFile, std::ofstream::trunc); |
| 51 | outputFile << testSeq; |
| 52 | outputFile.close(); |
| 53 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 55 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 56 | initiateFromFile() { |
| 57 | m_seqManager.initiateSeqNoFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void |
| 61 | checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) { |
| 62 | BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name); |
| 63 | |
| 64 | BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj); |
| 65 | |
| 66 | BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor); |
| 67 | } |
| 68 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 69 | public: |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 70 | std::string seqFile = "/tmp/nlsrSeqNo.txt"; |
| 71 | SequencingManager m_seqManager; |
| 72 | }; |
| 73 | |
| 74 | BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture) |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(CombinedSeqNumber) |
| 77 | { |
| 78 | // LS |
| 79 | writeToFile("27121653322350672"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 80 | m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF; |
| 81 | initiateFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 82 | checkSeqNumbers(24667+10, 80+10, 0); |
| 83 | |
| 84 | // HR |
| 85 | writeToFile("27121653322350672"); |
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 |
| 89 | checkSeqNumbers(24667+10, 0, 0+10); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(SeparateSeqNumber) |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 93 | { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 94 | // LS |
| 95 | writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 96 | m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF; |
| 97 | initiateFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 98 | checkSeqNumbers(100+10, 100+10, 0); |
| 99 | |
| 100 | // HR |
| 101 | writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 102 | m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON; |
| 103 | initiateFromFile(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 104 | // AdjLsa is set to 0 since HR is on |
| 105 | checkSeqNumbers(100+10, 0, 100+10); |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 106 | } |
| 107 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 108 | BOOST_AUTO_TEST_SUITE_END() |
| 109 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 110 | } // namespace test |
| 111 | } // namespace nlsr |