akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #ifndef NLSR_LSA_HPP |
| 23 | #define NLSR_LSA_HPP |
| 24 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 25 | #include <boost/cstdint.hpp> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 26 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 27 | #include <ndn-cxx/util/time.hpp> |
| 28 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | #include "adjacent.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 30 | #include "name-prefix-list.hpp" |
| 31 | #include "adjacency-list.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | |
| 33 | namespace nlsr { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 34 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | class Lsa |
| 36 | { |
| 37 | public: |
| 38 | Lsa() |
| 39 | : m_origRouter() |
| 40 | , m_lsSeqNo() |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 41 | , m_expirationTimePoint() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | , m_expiringEventId() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | |
| 47 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | setLsType(const std::string& lst) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | { |
| 50 | m_lsType = lst; |
| 51 | } |
| 52 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 53 | const std::string& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | 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 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 71 | const ndn::Name& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | getOrigRouter() const |
| 73 | { |
| 74 | return m_origRouter; |
| 75 | } |
| 76 | |
| 77 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | setOrigRouter(const ndn::Name& org) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | { |
| 80 | m_origRouter = org; |
| 81 | } |
| 82 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 83 | const ndn::time::system_clock::TimePoint& |
| 84 | getExpirationTimePoint() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 86 | return m_expirationTimePoint; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 90 | setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 92 | m_expirationTimePoint = lt; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 93 | } |
| 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 | |
| 107 | protected: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 108 | ndn::Name m_origRouter; |
| 109 | std::string m_lsType; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | uint32_t m_lsSeqNo; |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 111 | ndn::time::system_clock::TimePoint m_expirationTimePoint; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 112 | ndn::EventId m_expiringEventId; |
| 113 | }; |
| 114 | |
| 115 | class NameLsa: public Lsa |
| 116 | { |
| 117 | public: |
| 118 | NameLsa() |
| 119 | : Lsa() |
| 120 | , m_npl() |
| 121 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 122 | setLsType(NameLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 123 | } |
| 124 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 125 | NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 126 | const ndn::time::system_clock::TimePoint& lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 127 | NamePrefixList& npl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 129 | NamePrefixList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | getNpl() |
| 131 | { |
| 132 | return m_npl; |
| 133 | } |
| 134 | |
| 135 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 136 | addName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 137 | { |
| 138 | m_npl.insert(name); |
| 139 | } |
| 140 | |
| 141 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 142 | removeName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 143 | { |
| 144 | m_npl.remove(name); |
| 145 | } |
| 146 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 147 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 148 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 149 | |
| 150 | std::string |
| 151 | getData(); |
| 152 | |
| 153 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 154 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 155 | |
| 156 | void |
| 157 | writeLog(); |
| 158 | |
| 159 | private: |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 160 | NamePrefixList m_npl; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 161 | public: |
| 162 | static const std::string TYPE_STRING; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 163 | }; |
| 164 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 165 | class AdjLsa: public Lsa |
| 166 | { |
| 167 | public: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame^] | 168 | typedef AdjacencyList::const_iterator const_iterator; |
| 169 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | AdjLsa() |
| 171 | : Lsa() |
| 172 | , m_adl() |
| 173 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 174 | setLsType(AdjLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 175 | } |
| 176 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 177 | AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 178 | const ndn::time::system_clock::TimePoint& lt, |
| 179 | uint32_t nl , AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 181 | AdjacencyList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 182 | getAdl() |
| 183 | { |
| 184 | return m_adl; |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | addAdjacent(Adjacent adj) |
| 189 | { |
| 190 | m_adl.insert(adj); |
| 191 | } |
| 192 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 193 | const ndn::Name |
| 194 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 195 | |
| 196 | std::string |
| 197 | getData(); |
| 198 | |
| 199 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 200 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 201 | |
| 202 | uint32_t |
| 203 | getNoLink() |
| 204 | { |
| 205 | return m_noLink; |
| 206 | } |
| 207 | |
| 208 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 209 | isEqualContent(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 210 | |
| 211 | void |
| 212 | addNptEntries(Nlsr& pnlsr); |
| 213 | |
| 214 | void |
| 215 | removeNptEntries(Nlsr& pnlsr); |
| 216 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 217 | void |
| 218 | writeLog(); |
| 219 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame^] | 220 | public: |
| 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 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 233 | private: |
| 234 | uint32_t m_noLink; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 235 | AdjacencyList m_adl; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 236 | |
| 237 | public: |
| 238 | static const std::string TYPE_STRING; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 239 | }; |
| 240 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 241 | class CoordinateLsa: public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 242 | { |
| 243 | public: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 244 | CoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 245 | : Lsa() |
| 246 | , m_corRad(0) |
| 247 | , m_corTheta(0) |
| 248 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 249 | setLsType(CoordinateLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 250 | } |
| 251 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 252 | CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 253 | const ndn::time::system_clock::TimePoint& lt, |
| 254 | double r, double theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 256 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 257 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 258 | |
| 259 | std::string |
| 260 | getData(); |
| 261 | |
| 262 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 263 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 264 | |
| 265 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 266 | getCorRadius() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 267 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 268 | return m_corRad; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void |
| 272 | setCorRadius(double cr) |
| 273 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 274 | m_corRad = cr; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 278 | getCorTheta() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 279 | { |
| 280 | return m_corTheta; |
| 281 | } |
| 282 | |
| 283 | void |
| 284 | setCorTheta(double ct) |
| 285 | { |
| 286 | m_corTheta = ct; |
| 287 | } |
| 288 | |
| 289 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 290 | isEqualContent(const CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 291 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 292 | void |
| 293 | writeLog(); |
| 294 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 295 | private: |
| 296 | double m_corRad; |
| 297 | double m_corTheta; |
| 298 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 299 | public: |
| 300 | static const std::string TYPE_STRING; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 301 | }; |
| 302 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame^] | 303 | std::ostream& |
| 304 | operator<<(std::ostream& os, const AdjLsa& adjLsa); |
| 305 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 306 | }//namespace nlsr |
| 307 | |
| 308 | #endif //NLSR_LSA_HPP |