blob: 6ba85c9e5240ce78152001317b920aa7d4512bdc [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 {
alvy49b1c0c2014-12-19 13:57:46 -0600123 setLsType(NameLsa::TYPE_STRING);
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;
alvy49b1c0c2014-12-19 13:57:46 -0600162public:
163 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500164};
165
akmhoque53353462014-04-22 08:43:45 -0500166class AdjLsa: public Lsa
167{
168public:
169 AdjLsa()
170 : Lsa()
171 , m_adl()
172 {
alvy49b1c0c2014-12-19 13:57:46 -0600173 setLsType(AdjLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500174 }
175
akmhoque31d1d4b2014-05-05 22:08:14 -0500176 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500177 const ndn::time::system_clock::TimePoint& lt,
178 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500179
akmhoquec8a10f72014-04-25 18:42:55 -0500180 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500181 getAdl()
182 {
183 return m_adl;
184 }
185
186 void
187 addAdjacent(Adjacent adj)
188 {
189 m_adl.insert(adj);
190 }
191
akmhoque31d1d4b2014-05-05 22:08:14 -0500192 const ndn::Name
193 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500194
195 std::string
196 getData();
197
198 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500199 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500200
201 uint32_t
202 getNoLink()
203 {
204 return m_noLink;
205 }
206
207 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500208 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500209
210 void
211 addNptEntries(Nlsr& pnlsr);
212
213 void
214 removeNptEntries(Nlsr& pnlsr);
215
akmhoque674b0b12014-05-20 14:33:28 -0500216 void
217 writeLog();
218
akmhoque53353462014-04-22 08:43:45 -0500219private:
220 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500221 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600222
223public:
224 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500225};
226
akmhoqueb6450b12014-04-24 00:01:03 -0500227class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500228{
229public:
akmhoqueb6450b12014-04-24 00:01:03 -0500230 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500231 : Lsa()
232 , m_corRad(0)
233 , m_corTheta(0)
234 {
alvy49b1c0c2014-12-19 13:57:46 -0600235 setLsType(CoordinateLsa::TYPE_STRING);
akmhoque53353462014-04-22 08:43:45 -0500236 }
237
akmhoque31d1d4b2014-05-05 22:08:14 -0500238 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500239 const ndn::time::system_clock::TimePoint& lt,
240 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500241
akmhoque31d1d4b2014-05-05 22:08:14 -0500242 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500243 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500244
245 std::string
246 getData();
247
248 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500249 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500250
251 double
akmhoqueb6450b12014-04-24 00:01:03 -0500252 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500253 {
akmhoque53353462014-04-22 08:43:45 -0500254 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500255 }
256
257 void
258 setCorRadius(double cr)
259 {
akmhoque157b0a42014-05-13 00:26:37 -0500260 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500261 }
262
263 double
akmhoqueb6450b12014-04-24 00:01:03 -0500264 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500265 {
266 return m_corTheta;
267 }
268
269 void
270 setCorTheta(double ct)
271 {
272 m_corTheta = ct;
273 }
274
275 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500276 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500277
akmhoque674b0b12014-05-20 14:33:28 -0500278 void
279 writeLog();
280
akmhoque53353462014-04-22 08:43:45 -0500281private:
282 double m_corRad;
283 double m_corTheta;
284
alvy49b1c0c2014-12-19 13:57:46 -0600285public:
286 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500287};
288
akmhoque53353462014-04-22 08:43:45 -0500289}//namespace nlsr
290
291#endif //NLSR_LSA_HPP