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 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 22 | #include "test-common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 23 | #include "sequencing-manager.hpp" |
| 24 | #include <boost/test/unit_test.hpp> |
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 { |
| 33 | |
| 34 | namespace test { |
| 35 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 36 | class SequencingManagerFixture : public BaseFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 37 | { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 38 | public: |
| 39 | SequencingManagerFixture() |
| 40 | : m_seqNumbers("") |
| 41 | , m_seqManager() |
| 42 | { |
| 43 | setFileDir(); |
| 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 | ~SequencingManagerFixture() |
| 47 | { |
| 48 | boost::filesystem::remove(seqFile); |
| 49 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 50 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 51 | void |
| 52 | setFileDir() { |
| 53 | m_seqManager.setSeqFileDirectory("/tmp"); |
| 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 |
| 57 | writeToFile(const std::string& testSeq) { |
| 58 | std::ofstream outputFile(seqFile, std::ofstream::trunc); |
| 59 | outputFile << testSeq; |
| 60 | outputFile.close(); |
| 61 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 62 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 63 | void |
| 64 | initiateFromFile(const int& type) { |
| 65 | m_seqManager.initiateSeqNoFromFile(type); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) { |
| 70 | BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name); |
| 71 | |
| 72 | BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj); |
| 73 | |
| 74 | BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | std::string m_seqNumbers; |
| 79 | std::string seqFile = "/tmp/nlsrSeqNo.txt"; |
| 80 | SequencingManager m_seqManager; |
| 81 | }; |
| 82 | |
| 83 | BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture) |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE(CombinedSeqNumber) |
| 86 | { |
| 87 | // LS |
| 88 | writeToFile("27121653322350672"); |
| 89 | |
| 90 | initiateFromFile(HYPERBOLIC_STATE_OFF); |
| 91 | |
| 92 | checkSeqNumbers(24667+10, 80+10, 0); |
| 93 | |
| 94 | // HR |
| 95 | writeToFile("27121653322350672"); |
| 96 | |
| 97 | initiateFromFile(HYPERBOLIC_STATE_ON); |
| 98 | |
| 99 | // AdjLsa is set to 0 since HR is on |
| 100 | checkSeqNumbers(24667+10, 0, 0+10); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 101 | } |
| 102 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 103 | BOOST_AUTO_TEST_CASE(SeparateSeqNumber) |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 104 | { |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 105 | // LS |
| 106 | writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0"); |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 107 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 108 | initiateFromFile(HYPERBOLIC_STATE_OFF); |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 109 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 110 | checkSeqNumbers(100+10, 100+10, 0); |
| 111 | |
| 112 | // HR |
| 113 | writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100"); |
| 114 | |
| 115 | initiateFromFile(HYPERBOLIC_STATE_ON); |
| 116 | |
| 117 | // AdjLsa is set to 0 since HR is on |
| 118 | checkSeqNumbers(100+10, 0, 100+10); |
Vince Lehman | 6151e95 | 2015-02-16 12:36:00 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 121 | BOOST_AUTO_TEST_SUITE_END() |
| 122 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 123 | } // namespace test |
| 124 | } // namespace nlsr |