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: |
| 168 | AdjLsa() |
| 169 | : Lsa() |
| 170 | , m_adl() |
| 171 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 172 | setLsType(AdjLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 173 | } |
| 174 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 175 | AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 176 | const ndn::time::system_clock::TimePoint& lt, |
| 177 | uint32_t nl , AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 178 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 179 | AdjacencyList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | getAdl() |
| 181 | { |
| 182 | return m_adl; |
| 183 | } |
| 184 | |
| 185 | void |
| 186 | addAdjacent(Adjacent adj) |
| 187 | { |
| 188 | m_adl.insert(adj); |
| 189 | } |
| 190 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 191 | const ndn::Name |
| 192 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | |
| 194 | std::string |
| 195 | getData(); |
| 196 | |
| 197 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 198 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 199 | |
| 200 | uint32_t |
| 201 | getNoLink() |
| 202 | { |
| 203 | return m_noLink; |
| 204 | } |
| 205 | |
| 206 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 207 | isEqualContent(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 208 | |
| 209 | void |
| 210 | addNptEntries(Nlsr& pnlsr); |
| 211 | |
| 212 | void |
| 213 | removeNptEntries(Nlsr& pnlsr); |
| 214 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 215 | void |
| 216 | writeLog(); |
| 217 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 218 | private: |
| 219 | uint32_t m_noLink; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 220 | AdjacencyList m_adl; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 221 | |
| 222 | public: |
| 223 | static const std::string TYPE_STRING; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 224 | }; |
| 225 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 226 | class CoordinateLsa: public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 227 | { |
| 228 | public: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 229 | CoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 230 | : Lsa() |
| 231 | , m_corRad(0) |
| 232 | , m_corTheta(0) |
| 233 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 234 | setLsType(CoordinateLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 235 | } |
| 236 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 237 | CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 238 | const ndn::time::system_clock::TimePoint& lt, |
| 239 | double r, double theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 240 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 241 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 242 | getKey() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | |
| 244 | std::string |
| 245 | getData(); |
| 246 | |
| 247 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 248 | initializeFromContent(const std::string& content); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 249 | |
| 250 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 251 | getCorRadius() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 252 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 253 | return m_corRad; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void |
| 257 | setCorRadius(double cr) |
| 258 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 259 | m_corRad = cr; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 263 | getCorTheta() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 264 | { |
| 265 | return m_corTheta; |
| 266 | } |
| 267 | |
| 268 | void |
| 269 | setCorTheta(double ct) |
| 270 | { |
| 271 | m_corTheta = ct; |
| 272 | } |
| 273 | |
| 274 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 275 | isEqualContent(const CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 276 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 277 | void |
| 278 | writeLog(); |
| 279 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 280 | private: |
| 281 | double m_corRad; |
| 282 | double m_corTheta; |
| 283 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 284 | public: |
| 285 | static const std::string TYPE_STRING; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 286 | }; |
| 287 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | }//namespace nlsr |
| 289 | |
| 290 | #endif //NLSR_LSA_HPP |