blob: ed0d87082a94ef528dc01dbe9e9ca3be3cfcc58b [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#ifndef NLSR_LSA_HPP
24#define NLSR_LSA_HPP
25
akmhoquefdbddb12014-05-02 18:35:19 -050026#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050027#include <ndn-cxx/util/scheduler.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050028#include <ndn-cxx/util/time.hpp>
29
akmhoque53353462014-04-22 08:43:45 -050030#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050031#include "name-prefix-list.hpp"
32#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050033
34namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050035
akmhoque53353462014-04-22 08:43:45 -050036class Lsa
37{
38public:
39 Lsa()
40 : m_origRouter()
41 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050042 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050043 , m_expiringEventId()
44 {
45 }
46
47
48 void
akmhoque31d1d4b2014-05-05 22:08:14 -050049 setLsType(const std::string& lst)
akmhoque53353462014-04-22 08:43:45 -050050 {
51 m_lsType = lst;
52 }
53
akmhoque31d1d4b2014-05-05 22:08:14 -050054 const std::string&
akmhoque53353462014-04-22 08:43:45 -050055 getLsType() const
56 {
57 return m_lsType;
58 }
59
60 void
61 setLsSeqNo(uint32_t lsn)
62 {
63 m_lsSeqNo = lsn;
64 }
65
66 uint32_t
67 getLsSeqNo() const
68 {
69 return m_lsSeqNo;
70 }
71
akmhoque31d1d4b2014-05-05 22:08:14 -050072 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050073 getOrigRouter() const
74 {
75 return m_origRouter;
76 }
77
78 void
akmhoque31d1d4b2014-05-05 22:08:14 -050079 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050080 {
81 m_origRouter = org;
82 }
83
akmhoquec7a79b22014-05-26 08:06:19 -050084 const ndn::time::system_clock::TimePoint&
85 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050086 {
akmhoquec7a79b22014-05-26 08:06:19 -050087 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050088 }
89
90 void
akmhoquec7a79b22014-05-26 08:06:19 -050091 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050092 {
akmhoquec7a79b22014-05-26 08:06:19 -050093 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050094 }
95
96 void
97 setExpiringEventId(const ndn::EventId leei)
98 {
99 m_expiringEventId = leei;
100 }
101
102 ndn::EventId
103 getExpiringEventId() const
104 {
105 return m_expiringEventId;
106 }
107
108protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500109 ndn::Name m_origRouter;
110 std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500111 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500112 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500113 ndn::EventId m_expiringEventId;
114};
115
116class NameLsa: public Lsa
117{
118public:
119 NameLsa()
120 : Lsa()
121 , m_npl()
122 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500123 setLsType("name");
akmhoque53353462014-04-22 08:43:45 -0500124 }
125
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500127 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500128 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500129
akmhoquec8a10f72014-04-25 18:42:55 -0500130 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500131 getNpl()
132 {
133 return m_npl;
134 }
135
136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500138 {
139 m_npl.insert(name);
140 }
141
142 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500143 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500144 {
145 m_npl.remove(name);
146 }
147
akmhoque31d1d4b2014-05-05 22:08:14 -0500148 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500149 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500150
151 std::string
152 getData();
153
154 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500156
157 void
158 writeLog();
159
160private:
akmhoquec8a10f72014-04-25 18:42:55 -0500161 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500162
163};
164
165std::ostream&
166operator<<(std::ostream& os, NameLsa& nLsa);
167
168class AdjLsa: public Lsa
169{
170public:
171 AdjLsa()
172 : Lsa()
173 , m_adl()
174 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 setLsType("adjacency");
akmhoque53353462014-04-22 08:43:45 -0500176 }
177
akmhoque31d1d4b2014-05-05 22:08:14 -0500178 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500179 const ndn::time::system_clock::TimePoint& lt,
180 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500181
akmhoquec8a10f72014-04-25 18:42:55 -0500182 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500183 getAdl()
184 {
185 return m_adl;
186 }
187
188 void
189 addAdjacent(Adjacent adj)
190 {
191 m_adl.insert(adj);
192 }
193
akmhoque31d1d4b2014-05-05 22:08:14 -0500194 const ndn::Name
195 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500196
197 std::string
198 getData();
199
200 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500201 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500202
203 uint32_t
204 getNoLink()
205 {
206 return m_noLink;
207 }
208
209 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500210 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500211
212 void
213 addNptEntries(Nlsr& pnlsr);
214
215 void
216 removeNptEntries(Nlsr& pnlsr);
217
akmhoque674b0b12014-05-20 14:33:28 -0500218 void
219 writeLog();
220
akmhoque53353462014-04-22 08:43:45 -0500221private:
222 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500223 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500224};
225
226std::ostream&
227operator<<(std::ostream& os, AdjLsa& aLsa);
228
akmhoqueb6450b12014-04-24 00:01:03 -0500229class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500230{
231public:
akmhoqueb6450b12014-04-24 00:01:03 -0500232 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500233 : Lsa()
234 , m_corRad(0)
235 , m_corTheta(0)
236 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500237 setLsType("coordinate");
akmhoque53353462014-04-22 08:43:45 -0500238 }
239
akmhoque31d1d4b2014-05-05 22:08:14 -0500240 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500241 const ndn::time::system_clock::TimePoint& lt,
242 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500243
akmhoque31d1d4b2014-05-05 22:08:14 -0500244 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500245 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500246
247 std::string
248 getData();
249
250 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500251 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500252
253 double
akmhoqueb6450b12014-04-24 00:01:03 -0500254 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500255 {
akmhoque53353462014-04-22 08:43:45 -0500256 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500257 }
258
259 void
260 setCorRadius(double cr)
261 {
akmhoque157b0a42014-05-13 00:26:37 -0500262 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500263 }
264
265 double
akmhoqueb6450b12014-04-24 00:01:03 -0500266 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500267 {
268 return m_corTheta;
269 }
270
271 void
272 setCorTheta(double ct)
273 {
274 m_corTheta = ct;
275 }
276
277 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500278 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500279
akmhoque674b0b12014-05-20 14:33:28 -0500280 void
281 writeLog();
282
akmhoque53353462014-04-22 08:43:45 -0500283private:
284 double m_corRad;
285 double m_corTheta;
286
287};
288
289std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500290operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500291
292
293}//namespace nlsr
294
295#endif //NLSR_LSA_HPP