blob: 586abc2b3f278b2816dc35240ffaf1679a16d709 [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/*
Davide Pesaventod90338d2021-01-07 17:50:05 -05003 * Copyright (c) 2014-2021, 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>
Nick Gordon5c467f02016-07-13 13:40:10 -050033
akmhoque53353462014-04-22 08:43:45 -050034namespace nlsr {
Nick Gordon5c467f02016-07-13 13:40:10 -050035
akmhoque53353462014-04-22 08:43:45 -050036class SequencingManager
37{
38public:
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -060039 SequencingManager(const std::string& filePath, int hypState);
akmhoque53353462014-04-22 08:43:45 -050040
Ashlesh Gawande57a87172020-05-09 19:47:06 -070041 void
42 setLsaSeq(uint64_t seqNo, Lsa::Type lsaType)
43 {
44 switch (lsaType) {
45 case Lsa::Type::ADJACENCY:
46 m_adjLsaSeq = seqNo;
47 break;
48 case Lsa::Type::COORDINATE:
49 m_corLsaSeq = seqNo;
50 break;
51 case Lsa::Type::NAME:
52 m_nameLsaSeq = seqNo;
53 break;
54 default:
55 return;
56 }
57 }
58
59 uint64_t
60 getLsaSeq(Lsa::Type lsaType)
61 {
62 switch (lsaType) {
63 case Lsa::Type::ADJACENCY:
64 return m_adjLsaSeq;
65 case Lsa::Type::COORDINATE:
66 return m_corLsaSeq;
67 case Lsa::Type::NAME:
68 return m_nameLsaSeq;
69 default:
70 return 0;
71 }
72 }
73
akmhoque53353462014-04-22 08:43:45 -050074 uint64_t
75 getNameLsaSeq() const
76 {
77 return m_nameLsaSeq;
78 }
79
80 void
81 setNameLsaSeq(uint64_t nlsn)
82 {
83 m_nameLsaSeq = nlsn;
akmhoque53353462014-04-22 08:43:45 -050084 }
85
86 uint64_t
87 getAdjLsaSeq() const
88 {
89 return m_adjLsaSeq;
90 }
91
92 void
93 setAdjLsaSeq(uint64_t alsn)
94 {
95 m_adjLsaSeq = alsn;
akmhoque53353462014-04-22 08:43:45 -050096 }
97
98 uint64_t
99 getCorLsaSeq() const
100 {
101 return m_corLsaSeq;
102 }
103
104 void
105 setCorLsaSeq(uint64_t clsn)
106 {
107 m_corLsaSeq = clsn;
akmhoque53353462014-04-22 08:43:45 -0500108 }
109
akmhoquefdbddb12014-05-02 18:35:19 -0500110 void
111 increaseNameLsaSeq()
112 {
113 m_nameLsaSeq++;
akmhoquefdbddb12014-05-02 18:35:19 -0500114 }
115
116 void
117 increaseAdjLsaSeq()
118 {
119 m_adjLsaSeq++;
akmhoquefdbddb12014-05-02 18:35:19 -0500120 }
121
122 void
123 increaseCorLsaSeq()
124 {
125 m_corLsaSeq++;
akmhoque53353462014-04-22 08:43:45 -0500126 }
127
128 void
Vince Lehman0bcf9a32014-12-10 11:24:45 -0600129 writeSeqNoToFile() const;
akmhoque53353462014-04-22 08:43:45 -0500130
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600131PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque53353462014-04-22 08:43:45 -0500132 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600133 initiateSeqNoFromFile();
akmhoque53353462014-04-22 08:43:45 -0500134
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600135private:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500136 /*! \brief Set the sequence file directory
akmhoque53353462014-04-22 08:43:45 -0500137
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500138 If the string is empty, home directory is set as sequence file directory
139
140 \param filePath The directory where sequence file will be stored
141 */
142 void
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600143 setSeqFileDirectory(const std::string& filePath);
akmhoque53353462014-04-22 08:43:45 -0500144
akmhoque2f423352014-06-03 11:49:35 -0500145 void
Vince Lehman904c2412014-09-23 19:36:11 -0500146 writeLog() const;
akmhoque2f423352014-06-03 11:49:35 -0500147
akmhoque53353462014-04-22 08:43:45 -0500148private:
Ashlesh Gawande55d1b5c2019-12-19 16:21:58 -0600149 uint64_t m_nameLsaSeq = 0;
150 uint64_t m_adjLsaSeq = 0;
151 uint64_t m_corLsaSeq = 0;
akmhoque53353462014-04-22 08:43:45 -0500152 std::string m_seqFileNameWithPath;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600153
154PUBLIC_WITH_TESTS_ELSE_PRIVATE:
155 int m_hyperbolicState;
akmhoque53353462014-04-22 08:43:45 -0500156};
157
Nick Gordonfad8e252016-08-11 14:21:38 -0500158} // namespace nlsr
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500159#endif // NLSR_SEQUENCING_MANAGER_HPP