blob: dcf5f0101c2f1097397ad8cb9edeecf2e388d624 [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:
38 Lsa()
39 : m_origRouter()
40 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050041 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050042 , m_expiringEventId()
43 {
44 }
45
46
47 void
akmhoque31d1d4b2014-05-05 22:08:14 -050048 setLsType(const std::string& lst)
akmhoque53353462014-04-22 08:43:45 -050049 {
50 m_lsType = lst;
51 }
52
akmhoque31d1d4b2014-05-05 22:08:14 -050053 const std::string&
akmhoque53353462014-04-22 08:43:45 -050054 getLsType() const
55 {
56 return m_lsType;
57 }
58
59 void
60 setLsSeqNo(uint32_t lsn)
61 {
62 m_lsSeqNo = lsn;
63 }
64
65 uint32_t
66 getLsSeqNo() const
67 {
68 return m_lsSeqNo;
69 }
70
akmhoque31d1d4b2014-05-05 22:08:14 -050071 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050072 getOrigRouter() const
73 {
74 return m_origRouter;
75 }
76
77 void
akmhoque31d1d4b2014-05-05 22:08:14 -050078 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050079 {
80 m_origRouter = org;
81 }
82
akmhoquec7a79b22014-05-26 08:06:19 -050083 const ndn::time::system_clock::TimePoint&
84 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050085 {
akmhoquec7a79b22014-05-26 08:06:19 -050086 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050087 }
88
89 void
akmhoquec7a79b22014-05-26 08:06:19 -050090 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050091 {
akmhoquec7a79b22014-05-26 08:06:19 -050092 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050093 }
94
95 void
96 setExpiringEventId(const ndn::EventId leei)
97 {
98 m_expiringEventId = leei;
99 }
100
101 ndn::EventId
102 getExpiringEventId() const
103 {
104 return m_expiringEventId;
105 }
106
107protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500108 ndn::Name m_origRouter;
109 std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500110 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500111 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500112 ndn::EventId m_expiringEventId;
113};
114
115class NameLsa: public Lsa
116{
117public:
118 NameLsa()
119 : Lsa()
120 , m_npl()
121 {
alvy49b1c0c2014-12-19 13:57:46 -0600122 setLsType(NameLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500123 }
124
akmhoque31d1d4b2014-05-05 22:08:14 -0500125 NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500126 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500127 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500128
akmhoquec8a10f72014-04-25 18:42:55 -0500129 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500130 getNpl()
131 {
132 return m_npl;
133 }
134
135 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500136 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500137 {
138 m_npl.insert(name);
139 }
140
141 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500142 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500143 {
144 m_npl.remove(name);
145 }
146
akmhoque31d1d4b2014-05-05 22:08:14 -0500147 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500148 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500149
150 std::string
151 getData();
152
153 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500154 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500155
156 void
157 writeLog();
158
159private:
akmhoquec8a10f72014-04-25 18:42:55 -0500160 NamePrefixList m_npl;
alvy49b1c0c2014-12-19 13:57:46 -0600161public:
162 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500163};
164
akmhoque53353462014-04-22 08:43:45 -0500165class AdjLsa: public Lsa
166{
167public:
168 AdjLsa()
169 : Lsa()
170 , m_adl()
171 {
alvy49b1c0c2014-12-19 13:57:46 -0600172 setLsType(AdjLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500173 }
174
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500176 const ndn::time::system_clock::TimePoint& lt,
177 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500178
akmhoquec8a10f72014-04-25 18:42:55 -0500179 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500180 getAdl()
181 {
182 return m_adl;
183 }
184
185 void
186 addAdjacent(Adjacent adj)
187 {
188 m_adl.insert(adj);
189 }
190
akmhoque31d1d4b2014-05-05 22:08:14 -0500191 const ndn::Name
192 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500193
194 std::string
195 getData();
196
197 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500198 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500199
200 uint32_t
201 getNoLink()
202 {
203 return m_noLink;
204 }
205
206 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500207 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500208
209 void
210 addNptEntries(Nlsr& pnlsr);
211
212 void
213 removeNptEntries(Nlsr& pnlsr);
214
akmhoque674b0b12014-05-20 14:33:28 -0500215 void
216 writeLog();
217
akmhoque53353462014-04-22 08:43:45 -0500218private:
219 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500220 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600221
222public:
223 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500224};
225
akmhoqueb6450b12014-04-24 00:01:03 -0500226class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500227{
228public:
akmhoqueb6450b12014-04-24 00:01:03 -0500229 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500230 : Lsa()
231 , m_corRad(0)
232 , m_corTheta(0)
233 {
alvy49b1c0c2014-12-19 13:57:46 -0600234 setLsType(CoordinateLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500235 }
236
akmhoque31d1d4b2014-05-05 22:08:14 -0500237 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500238 const ndn::time::system_clock::TimePoint& lt,
239 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500240
akmhoque31d1d4b2014-05-05 22:08:14 -0500241 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500242 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500243
244 std::string
245 getData();
246
247 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500248 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500249
250 double
akmhoqueb6450b12014-04-24 00:01:03 -0500251 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500252 {
akmhoque53353462014-04-22 08:43:45 -0500253 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500254 }
255
256 void
257 setCorRadius(double cr)
258 {
akmhoque157b0a42014-05-13 00:26:37 -0500259 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500260 }
261
262 double
akmhoqueb6450b12014-04-24 00:01:03 -0500263 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500264 {
265 return m_corTheta;
266 }
267
268 void
269 setCorTheta(double ct)
270 {
271 m_corTheta = ct;
272 }
273
274 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500275 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500276
akmhoque674b0b12014-05-20 14:33:28 -0500277 void
278 writeLog();
279
akmhoque53353462014-04-22 08:43:45 -0500280private:
281 double m_corRad;
282 double m_corTheta;
283
alvy49b1c0c2014-12-19 13:57:46 -0600284public:
285 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500286};
287
akmhoque53353462014-04-22 08:43:45 -0500288}//namespace nlsr
289
290#endif //NLSR_LSA_HPP