blob: 544f01dffa5c17fd688864e547b6a23558ae011f [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:
alvydce3f182015-04-09 11:23:30 -0500168 typedef AdjacencyList::const_iterator const_iterator;
169
akmhoque53353462014-04-22 08:43:45 -0500170 AdjLsa()
171 : Lsa()
172 , m_adl()
173 {
alvy49b1c0c2014-12-19 13:57:46 -0600174 setLsType(AdjLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500175 }
176
akmhoque31d1d4b2014-05-05 22:08:14 -0500177 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500178 const ndn::time::system_clock::TimePoint& lt,
179 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500180
akmhoquec8a10f72014-04-25 18:42:55 -0500181 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500182 getAdl()
183 {
184 return m_adl;
185 }
186
187 void
188 addAdjacent(Adjacent adj)
189 {
190 m_adl.insert(adj);
191 }
192
akmhoque31d1d4b2014-05-05 22:08:14 -0500193 const ndn::Name
194 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500195
196 std::string
197 getData();
198
199 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500200 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500201
202 uint32_t
203 getNoLink()
204 {
205 return m_noLink;
206 }
207
208 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500209 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500210
211 void
212 addNptEntries(Nlsr& pnlsr);
213
214 void
215 removeNptEntries(Nlsr& pnlsr);
216
akmhoque674b0b12014-05-20 14:33:28 -0500217 void
218 writeLog();
219
alvydce3f182015-04-09 11:23:30 -0500220public:
221 const_iterator
222 begin() const
223 {
224 return m_adl.begin();
225 }
226
227 const_iterator
228 end() const
229 {
230 return m_adl.end();
231 }
232
akmhoque53353462014-04-22 08:43:45 -0500233private:
234 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500235 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600236
237public:
238 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500239};
240
akmhoqueb6450b12014-04-24 00:01:03 -0500241class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500242{
243public:
akmhoqueb6450b12014-04-24 00:01:03 -0500244 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500245 : Lsa()
246 , m_corRad(0)
247 , m_corTheta(0)
248 {
alvy49b1c0c2014-12-19 13:57:46 -0600249 setLsType(CoordinateLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500250 }
251
akmhoque31d1d4b2014-05-05 22:08:14 -0500252 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500253 const ndn::time::system_clock::TimePoint& lt,
254 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500255
akmhoque31d1d4b2014-05-05 22:08:14 -0500256 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500257 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500258
259 std::string
260 getData();
261
262 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500263 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500264
265 double
akmhoqueb6450b12014-04-24 00:01:03 -0500266 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500267 {
akmhoque53353462014-04-22 08:43:45 -0500268 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500269 }
270
271 void
272 setCorRadius(double cr)
273 {
akmhoque157b0a42014-05-13 00:26:37 -0500274 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500275 }
276
277 double
akmhoqueb6450b12014-04-24 00:01:03 -0500278 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500279 {
280 return m_corTheta;
281 }
282
283 void
284 setCorTheta(double ct)
285 {
286 m_corTheta = ct;
287 }
288
289 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500290 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500291
akmhoque674b0b12014-05-20 14:33:28 -0500292 void
293 writeLog();
294
akmhoque53353462014-04-22 08:43:45 -0500295private:
296 double m_corRad;
297 double m_corTheta;
298
alvy49b1c0c2014-12-19 13:57:46 -0600299public:
300 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500301};
302
alvydce3f182015-04-09 11:23:30 -0500303std::ostream&
304operator<<(std::ostream& os, const AdjLsa& adjLsa);
305
akmhoque53353462014-04-22 08:43:45 -0500306}//namespace nlsr
307
308#endif //NLSR_LSA_HPP