blob: c797815fe443ec7973c849e6e0a5c3e93434e1d2 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
akmhoque53353462014-04-22 08:43:45 -050035class Lsa
36{
37public:
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060038 Lsa(const std::string& lsaType)
akmhoque53353462014-04-22 08:43:45 -050039 : m_origRouter()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060040 , m_lsType(lsaType)
akmhoque53353462014-04-22 08:43:45 -050041 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050042 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050043 , m_expiringEventId()
44 {
45 }
46
akmhoque31d1d4b2014-05-05 22:08:14 -050047 const std::string&
akmhoque53353462014-04-22 08:43:45 -050048 getLsType() const
49 {
50 return m_lsType;
51 }
52
53 void
54 setLsSeqNo(uint32_t lsn)
55 {
56 m_lsSeqNo = lsn;
57 }
58
59 uint32_t
60 getLsSeqNo() const
61 {
62 return m_lsSeqNo;
63 }
64
akmhoque31d1d4b2014-05-05 22:08:14 -050065 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050066 getOrigRouter() const
67 {
68 return m_origRouter;
69 }
70
71 void
akmhoque31d1d4b2014-05-05 22:08:14 -050072 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050073 {
74 m_origRouter = org;
75 }
76
akmhoquec7a79b22014-05-26 08:06:19 -050077 const ndn::time::system_clock::TimePoint&
78 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050079 {
akmhoquec7a79b22014-05-26 08:06:19 -050080 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050081 }
82
83 void
akmhoquec7a79b22014-05-26 08:06:19 -050084 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050085 {
akmhoquec7a79b22014-05-26 08:06:19 -050086 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050087 }
88
89 void
90 setExpiringEventId(const ndn::EventId leei)
91 {
92 m_expiringEventId = leei;
93 }
94
95 ndn::EventId
96 getExpiringEventId() const
97 {
98 return m_expiringEventId;
99 }
100
101protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 ndn::Name m_origRouter;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600103 const std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500104 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500105 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500106 ndn::EventId m_expiringEventId;
107};
108
109class NameLsa: public Lsa
110{
111public:
112 NameLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600113 : Lsa(NameLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500114 , m_npl()
115 {
akmhoque53353462014-04-22 08:43:45 -0500116 }
117
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600118 NameLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500119 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500120 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500121
akmhoquec8a10f72014-04-25 18:42:55 -0500122 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500123 getNpl()
124 {
125 return m_npl;
126 }
127
128 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500129 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500130 {
131 m_npl.insert(name);
132 }
133
134 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500135 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500136 {
137 m_npl.remove(name);
138 }
139
akmhoque31d1d4b2014-05-05 22:08:14 -0500140 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500141 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500142
143 std::string
144 getData();
145
146 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500148
149 void
150 writeLog();
151
152private:
akmhoquec8a10f72014-04-25 18:42:55 -0500153 NamePrefixList m_npl;
alvy49b1c0c2014-12-19 13:57:46 -0600154public:
155 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500156};
157
akmhoque53353462014-04-22 08:43:45 -0500158class AdjLsa: public Lsa
159{
160public:
alvydce3f182015-04-09 11:23:30 -0500161 typedef AdjacencyList::const_iterator const_iterator;
162
akmhoque53353462014-04-22 08:43:45 -0500163 AdjLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600164 : Lsa(AdjLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500165 , m_adl()
166 {
akmhoque53353462014-04-22 08:43:45 -0500167 }
168
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600169 AdjLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500170 const ndn::time::system_clock::TimePoint& lt,
171 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500172
akmhoquec8a10f72014-04-25 18:42:55 -0500173 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500174 getAdl()
175 {
176 return m_adl;
177 }
178
179 void
180 addAdjacent(Adjacent adj)
181 {
182 m_adl.insert(adj);
183 }
184
akmhoque31d1d4b2014-05-05 22:08:14 -0500185 const ndn::Name
186 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500187
188 std::string
189 getData();
190
191 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500192 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500193
194 uint32_t
195 getNoLink()
196 {
197 return m_noLink;
198 }
199
200 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500201 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500202
203 void
204 addNptEntries(Nlsr& pnlsr);
205
206 void
207 removeNptEntries(Nlsr& pnlsr);
208
akmhoque674b0b12014-05-20 14:33:28 -0500209 void
210 writeLog();
211
alvydce3f182015-04-09 11:23:30 -0500212public:
213 const_iterator
214 begin() const
215 {
216 return m_adl.begin();
217 }
218
219 const_iterator
220 end() const
221 {
222 return m_adl.end();
223 }
224
akmhoque53353462014-04-22 08:43:45 -0500225private:
226 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500227 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600228
229public:
230 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500231};
232
akmhoqueb6450b12014-04-24 00:01:03 -0500233class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500234{
235public:
akmhoqueb6450b12014-04-24 00:01:03 -0500236 CoordinateLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600237 : Lsa(CoordinateLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500238 , m_corRad(0)
239 , m_corTheta(0)
240 {
akmhoque53353462014-04-22 08:43:45 -0500241 }
242
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600243 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500244 const ndn::time::system_clock::TimePoint& lt,
245 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500246
akmhoque31d1d4b2014-05-05 22:08:14 -0500247 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500248 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500249
250 std::string
251 getData();
252
253 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500254 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500255
256 double
akmhoqueb6450b12014-04-24 00:01:03 -0500257 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500258 {
akmhoque53353462014-04-22 08:43:45 -0500259 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500260 }
261
262 void
263 setCorRadius(double cr)
264 {
akmhoque157b0a42014-05-13 00:26:37 -0500265 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500266 }
267
268 double
akmhoqueb6450b12014-04-24 00:01:03 -0500269 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500270 {
271 return m_corTheta;
272 }
273
274 void
275 setCorTheta(double ct)
276 {
277 m_corTheta = ct;
278 }
279
280 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500281 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500282
akmhoque674b0b12014-05-20 14:33:28 -0500283 void
284 writeLog();
285
akmhoque53353462014-04-22 08:43:45 -0500286private:
287 double m_corRad;
288 double m_corTheta;
289
alvy49b1c0c2014-12-19 13:57:46 -0600290public:
291 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500292};
293
alvydce3f182015-04-09 11:23:30 -0500294std::ostream&
295operator<<(std::ostream& os, const AdjLsa& adjLsa);
296
akmhoque53353462014-04-22 08:43:45 -0500297}//namespace nlsr
298
299#endif //NLSR_LSA_HPP