blob: 9cb349d22d5fa98b97dcb051dc697715749c068a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande57a87172020-05-09 19:47:06 -07002/*
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -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/>.
Ashlesh Gawande57a87172020-05-09 19:47:06 -070020 */
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_SEQUENCING_MANAGER_HPP
23#define NLSR_SEQUENCING_MANAGER_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Ashlesh Gawande85998a12017-12-07 22:22:13 -060025#include "conf-parameter.hpp"
Ashlesh Gawande57a87172020-05-09 19:47:06 -070026#include "lsa/lsa.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060027#include "test-access-control.hpp"
akmhoquefdbddb12014-05-02 18:35:19 -050028
akmhoquec8a10f72014-04-25 18:42:55 -050029#include <ndn-cxx/face.hpp>
akmhoque53353462014-04-22 08:43:45 -050030
Ashlesh Gawande85998a12017-12-07 22:22:13 -060031#include <list>
32#include <string>
33#include <boost/cstdint.hpp>
Nick Gordon5c467f02016-07-13 13:40:10 -050034
akmhoque53353462014-04-22 08:43:45 -050035namespace nlsr {
Nick Gordon5c467f02016-07-13 13:40:10 -050036
akmhoque53353462014-04-22 08:43:45 -050037class SequencingManager
38{
39public:
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060040 SequencingManager(const std::string& filePath, int hypState);
akmhoque53353462014-04-22 08:43:45 -050041
Ashlesh Gawande57a87172020-05-09 19:47:06 -070042 void
43 setLsaSeq(uint64_t seqNo, Lsa::Type lsaType)
44 {
45 switch (lsaType) {
46 case Lsa::Type::ADJACENCY:
47 m_adjLsaSeq = seqNo;
48 break;
49 case Lsa::Type::COORDINATE:
50 m_corLsaSeq = seqNo;
51 break;
52 case Lsa::Type::NAME:
53 m_nameLsaSeq = seqNo;
54 break;
55 default:
56 return;
57 }
58 }
59
60 uint64_t
61 getLsaSeq(Lsa::Type lsaType)
62 {
63 switch (lsaType) {
64 case Lsa::Type::ADJACENCY:
65 return m_adjLsaSeq;
66 case Lsa::Type::COORDINATE:
67 return m_corLsaSeq;
68 case Lsa::Type::NAME:
69 return m_nameLsaSeq;
70 default:
71 return 0;
72 }
73 }
74
akmhoque53353462014-04-22 08:43:45 -050075 uint64_t
76 getNameLsaSeq() const
77 {
78 return m_nameLsaSeq;
79 }
80
81 void
82 setNameLsaSeq(uint64_t nlsn)
83 {
84 m_nameLsaSeq = nlsn;
akmhoque53353462014-04-22 08:43:45 -050085 }
86
87 uint64_t
88 getAdjLsaSeq() const
89 {
90 return m_adjLsaSeq;
91 }
92
93 void
94 setAdjLsaSeq(uint64_t alsn)
95 {
96 m_adjLsaSeq = alsn;
akmhoque53353462014-04-22 08:43:45 -050097 }
98
99 uint64_t
100 getCorLsaSeq() const
101 {
102 return m_corLsaSeq;
103 }
104
105 void
106 setCorLsaSeq(uint64_t clsn)
107 {
108 m_corLsaSeq = clsn;
akmhoque53353462014-04-22 08:43:45 -0500109 }
110
akmhoquefdbddb12014-05-02 18:35:19 -0500111 void
112 increaseNameLsaSeq()
113 {
114 m_nameLsaSeq++;
akmhoquefdbddb12014-05-02 18:35:19 -0500115 }
116
117 void
118 increaseAdjLsaSeq()
119 {
120 m_adjLsaSeq++;
akmhoquefdbddb12014-05-02 18:35:19 -0500121 }
122
123 void
124 increaseCorLsaSeq()
125 {
126 m_corLsaSeq++;
akmhoque53353462014-04-22 08:43:45 -0500127 }
128
129 void
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600130 writeSeqNoToFile() const;
akmhoque53353462014-04-22 08:43:45 -0500131
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600132PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque53353462014-04-22 08:43:45 -0500133 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600134 initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -0500135
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600136private:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500137 /*! \brief Set the sequence file directory
akmhoque53353462014-04-22 08:43:45 -0500138
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500139 If the string is empty, home directory is set as sequence file directory
140
141 \param filePath The directory where sequence file will be stored
142 */
143 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600144 setSeqFileDirectory(const std::string& filePath);
akmhoque53353462014-04-22 08:43:45 -0500145
akmhoque2f423352014-06-03 11:49:35 -0500146 void
Vince Lehman904c2412014-09-23 19:36:11 -0500147 writeLog() const;
akmhoque2f423352014-06-03 11:49:35 -0500148
akmhoque53353462014-04-22 08:43:45 -0500149private:
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -0600150 uint64_t m_nameLsaSeq = 0;
151 uint64_t m_adjLsaSeq = 0;
152 uint64_t m_corLsaSeq = 0;
akmhoque53353462014-04-22 08:43:45 -0500153 std::string m_seqFileNameWithPath;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600154
155PUBLIC_WITH_TESTS_ELSE_PRIVATE:
156 int m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500157};
158
Nick Gordonfad8e252016-08-11 14:21:38 -0500159} // namespace nlsr
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500160#endif // NLSR_SEQUENCING_MANAGER_HPP