blob: d55f18aa593cb6fcc82f256a7bd112968b0d88a1 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05002/**
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, The University of Memphis,
Vince Lehman6151e952015-02-16 12:36:00 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehman6151e952015-02-16 12:36:00 -060021
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050022#include "sequencing-manager.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060023#include "test-common.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050024#include <boost/test/unit_test.hpp>
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050025#include <boost/filesystem.hpp>
26#include <string>
27#include <iostream>
28#include <fstream>
29
30using namespace ndn;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050031
32namespace nlsr {
33
34namespace test {
35
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050036class SequencingManagerFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050037{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050038public:
39 SequencingManagerFixture()
Ashlesh Gawande85998a12017-12-07 22:22:13 -060040 : m_seqManager("/tmp", HYPERBOLIC_STATE_OFF)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050041 {
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050042 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050043
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050044 ~SequencingManagerFixture()
45 {
46 boost::filesystem::remove(seqFile);
47 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050048
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050049 void
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050050 writeToFile(const std::string& testSeq) {
51 std::ofstream outputFile(seqFile, std::ofstream::trunc);
52 outputFile << testSeq;
53 outputFile.close();
54 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050055
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050056 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -060057 initiateFromFile() {
58 m_seqManager.initiateSeqNoFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050059 }
60
61 void
62 checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) {
63 BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name);
64
65 BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj);
66
67 BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor);
68 }
69
Ashlesh Gawande85998a12017-12-07 22:22:13 -060070public:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050071 std::string seqFile = "/tmp/nlsrSeqNo.txt";
72 SequencingManager m_seqManager;
73};
74
75BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture)
76
77BOOST_AUTO_TEST_CASE(CombinedSeqNumber)
78{
79 // LS
80 writeToFile("27121653322350672");
Ashlesh Gawande85998a12017-12-07 22:22:13 -060081 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF;
82 initiateFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050083 checkSeqNumbers(24667+10, 80+10, 0);
84
85 // HR
86 writeToFile("27121653322350672");
Ashlesh Gawande85998a12017-12-07 22:22:13 -060087 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON;
88 initiateFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050089 // AdjLsa is set to 0 since HR is on
90 checkSeqNumbers(24667+10, 0, 0+10);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050091}
92
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050093BOOST_AUTO_TEST_CASE(SeparateSeqNumber)
Vince Lehman6151e952015-02-16 12:36:00 -060094{
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050095 // LS
96 writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0");
Ashlesh Gawande85998a12017-12-07 22:22:13 -060097 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF;
98 initiateFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050099 checkSeqNumbers(100+10, 100+10, 0);
100
101 // HR
102 writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100");
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600103 m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON;
104 initiateFromFile();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500105 // AdjLsa is set to 0 since HR is on
106 checkSeqNumbers(100+10, 0, 100+10);
Vince Lehman6151e952015-02-16 12:36:00 -0600107}
108
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500109BOOST_AUTO_TEST_SUITE_END()
110
Nick Gordonfad8e252016-08-11 14:21:38 -0500111} // namespace test
112} // namespace nlsr