blob: 5623ca8fa72885542c1905789e2f23421c57891a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, 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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoque53353462014-04-22 08:43:45 -050022#ifndef NLSR_LSA_HPP
23#define NLSR_LSA_HPP
24
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050026#include <ndn-cxx/util/scheduler.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050027#include <ndn-cxx/util/time.hpp>
28
akmhoque53353462014-04-22 08:43:45 -050029#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050030#include "name-prefix-list.hpp"
31#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050032
33namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050034
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050035class Nlsr;
36
akmhoque53353462014-04-22 08:43:45 -050037class Lsa
38{
39public:
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060040 Lsa(const std::string& lsaType)
akmhoque53353462014-04-22 08:43:45 -050041 : m_origRouter()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060042 , m_lsType(lsaType)
akmhoque53353462014-04-22 08:43:45 -050043 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050044 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050045 , m_expiringEventId()
46 {
47 }
48
akmhoque31d1d4b2014-05-05 22:08:14 -050049 const std::string&
akmhoque53353462014-04-22 08:43:45 -050050 getLsType() const
51 {
52 return m_lsType;
53 }
54
55 void
56 setLsSeqNo(uint32_t lsn)
57 {
58 m_lsSeqNo = lsn;
59 }
60
61 uint32_t
62 getLsSeqNo() const
63 {
64 return m_lsSeqNo;
65 }
66
akmhoque31d1d4b2014-05-05 22:08:14 -050067 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050068 getOrigRouter() const
69 {
70 return m_origRouter;
71 }
72
73 void
akmhoque31d1d4b2014-05-05 22:08:14 -050074 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050075 {
76 m_origRouter = org;
77 }
78
akmhoquec7a79b22014-05-26 08:06:19 -050079 const ndn::time::system_clock::TimePoint&
80 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050081 {
akmhoquec7a79b22014-05-26 08:06:19 -050082 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050083 }
84
85 void
akmhoquec7a79b22014-05-26 08:06:19 -050086 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050087 {
akmhoquec7a79b22014-05-26 08:06:19 -050088 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050089 }
90
91 void
92 setExpiringEventId(const ndn::EventId leei)
93 {
94 m_expiringEventId = leei;
95 }
96
97 ndn::EventId
98 getExpiringEventId() const
99 {
100 return m_expiringEventId;
101 }
102
103protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500104 ndn::Name m_origRouter;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600105 const std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500106 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500107 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500108 ndn::EventId m_expiringEventId;
109};
110
111class NameLsa: public Lsa
112{
113public:
114 NameLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600115 : Lsa(NameLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500116 , m_npl()
117 {
akmhoque53353462014-04-22 08:43:45 -0500118 }
119
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600120 NameLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500121 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500122 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500123
akmhoquec8a10f72014-04-25 18:42:55 -0500124 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500125 getNpl()
126 {
127 return m_npl;
128 }
129
130 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500131 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500132 {
133 m_npl.insert(name);
134 }
135
136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500138 {
139 m_npl.remove(name);
140 }
141
akmhoque31d1d4b2014-05-05 22:08:14 -0500142 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500143 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500144
145 std::string
146 getData();
147
148 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500150
151 void
152 writeLog();
153
154private:
akmhoquec8a10f72014-04-25 18:42:55 -0500155 NamePrefixList m_npl;
alvy49b1c0c2014-12-19 13:57:46 -0600156public:
157 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500158};
159
akmhoque53353462014-04-22 08:43:45 -0500160class AdjLsa: public Lsa
161{
162public:
alvydce3f182015-04-09 11:23:30 -0500163 typedef AdjacencyList::const_iterator const_iterator;
164
akmhoque53353462014-04-22 08:43:45 -0500165 AdjLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600166 : Lsa(AdjLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500167 , m_adl()
168 {
akmhoque53353462014-04-22 08:43:45 -0500169 }
170
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600171 AdjLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500172 const ndn::time::system_clock::TimePoint& lt,
173 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500174
akmhoquec8a10f72014-04-25 18:42:55 -0500175 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500176 getAdl()
177 {
178 return m_adl;
179 }
180
181 void
182 addAdjacent(Adjacent adj)
183 {
184 m_adl.insert(adj);
185 }
186
akmhoque31d1d4b2014-05-05 22:08:14 -0500187 const ndn::Name
188 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500189
190 std::string
191 getData();
192
193 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500194 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500195
196 uint32_t
197 getNoLink()
198 {
199 return m_noLink;
200 }
201
202 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500203 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500204
205 void
206 addNptEntries(Nlsr& pnlsr);
207
208 void
209 removeNptEntries(Nlsr& pnlsr);
210
akmhoque674b0b12014-05-20 14:33:28 -0500211 void
212 writeLog();
213
alvydce3f182015-04-09 11:23:30 -0500214public:
215 const_iterator
216 begin() const
217 {
218 return m_adl.begin();
219 }
220
221 const_iterator
222 end() const
223 {
224 return m_adl.end();
225 }
226
akmhoque53353462014-04-22 08:43:45 -0500227private:
228 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500229 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600230
231public:
232 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500233};
234
akmhoqueb6450b12014-04-24 00:01:03 -0500235class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500236{
237public:
akmhoqueb6450b12014-04-24 00:01:03 -0500238 CoordinateLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600239 : Lsa(CoordinateLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500240 , m_corRad(0)
241 , m_corTheta(0)
242 {
akmhoque53353462014-04-22 08:43:45 -0500243 }
244
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600245 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500246 const ndn::time::system_clock::TimePoint& lt,
247 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500248
akmhoque31d1d4b2014-05-05 22:08:14 -0500249 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500250 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500251
252 std::string
253 getData();
254
255 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500256 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500257
258 double
akmhoqueb6450b12014-04-24 00:01:03 -0500259 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500260 {
akmhoque53353462014-04-22 08:43:45 -0500261 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500262 }
263
264 void
265 setCorRadius(double cr)
266 {
akmhoque157b0a42014-05-13 00:26:37 -0500267 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500268 }
269
270 double
akmhoqueb6450b12014-04-24 00:01:03 -0500271 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500272 {
273 return m_corTheta;
274 }
275
276 void
277 setCorTheta(double ct)
278 {
279 m_corTheta = ct;
280 }
281
282 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500283 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500284
akmhoque674b0b12014-05-20 14:33:28 -0500285 void
286 writeLog();
287
akmhoque53353462014-04-22 08:43:45 -0500288private:
289 double m_corRad;
290 double m_corTheta;
291
alvy49b1c0c2014-12-19 13:57:46 -0600292public:
293 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500294};
295
alvydce3f182015-04-09 11:23:30 -0500296std::ostream&
297operator<<(std::ostream& os, const AdjLsa& adjLsa);
298
akmhoque53353462014-04-22 08:43:45 -0500299}//namespace nlsr
300
301#endif //NLSR_LSA_HPP