akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 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/>. |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -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 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 25 | #include "name-prefix-list.hpp" |
| 26 | #include "adjacent.hpp" |
| 27 | #include "adjacency-list.hpp" |
| 28 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 29 | #include <boost/cstdint.hpp> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/util/time.hpp> |
Nick Gordon | 0fa4c77 | 2017-10-23 13:33:03 -0500 | [diff] [blame] | 32 | #include <boost/tokenizer.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | namespace nlsr { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 35 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 36 | class Nlsr; |
| 37 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 38 | class Lsa |
| 39 | { |
| 40 | public: |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 41 | enum class Type { |
| 42 | ADJACENCY, |
| 43 | COORDINATE, |
| 44 | NAME, |
Nick Gordon | 9212bd4 | 2017-10-23 10:59:38 -0500 | [diff] [blame] | 45 | BASE, |
| 46 | MOCK |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | Lsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | : m_origRouter() |
| 51 | , m_lsSeqNo() |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 52 | , m_expirationTimePoint() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 53 | , m_expiringEventId() |
| 54 | { |
| 55 | } |
| 56 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 57 | virtual |
| 58 | ~Lsa() = default; |
| 59 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 60 | virtual Type |
| 61 | getType() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 62 | { |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 63 | return Type::BASE; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
| 67 | setLsSeqNo(uint32_t lsn) |
| 68 | { |
| 69 | m_lsSeqNo = lsn; |
| 70 | } |
| 71 | |
| 72 | uint32_t |
| 73 | getLsSeqNo() const |
| 74 | { |
| 75 | return m_lsSeqNo; |
| 76 | } |
| 77 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | const ndn::Name& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | getOrigRouter() const |
| 80 | { |
| 81 | return m_origRouter; |
| 82 | } |
| 83 | |
| 84 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 85 | setOrigRouter(const ndn::Name& org) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | { |
| 87 | m_origRouter = org; |
| 88 | } |
| 89 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 90 | const ndn::time::system_clock::TimePoint& |
| 91 | getExpirationTimePoint() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 92 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 93 | return m_expirationTimePoint; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 97 | setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 98 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 99 | m_expirationTimePoint = lt; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void |
| 103 | setExpiringEventId(const ndn::EventId leei) |
| 104 | { |
| 105 | m_expiringEventId = leei; |
| 106 | } |
| 107 | |
| 108 | ndn::EventId |
| 109 | getExpiringEventId() const |
| 110 | { |
| 111 | return m_expiringEventId; |
| 112 | } |
| 113 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 114 | /*! \brief Return the data that this LSA represents. |
| 115 | */ |
Nick Gordon | 9212bd4 | 2017-10-23 10:59:38 -0500 | [diff] [blame] | 116 | virtual std::string |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 117 | serialize() const = 0; |
Nick Gordon | 9212bd4 | 2017-10-23 10:59:38 -0500 | [diff] [blame] | 118 | |
Nick Gordon | 22cc1a8 | 2017-10-23 13:06:53 -0500 | [diff] [blame] | 119 | /*! \brief Gets the key for this LSA. |
| 120 | |
| 121 | Format is: \<router name\>/\<LSA type>\ |
| 122 | */ |
| 123 | const ndn::Name |
| 124 | getKey() const; |
| 125 | |
Nick Gordon | 2f62338 | 2017-11-03 13:49:31 -0500 | [diff] [blame] | 126 | /*! \brief Populate this LSA with content from the string "content". |
| 127 | \param content The string containing a valid serialization of LSA content. |
| 128 | |
| 129 | This method populates "this" LSA with data from the string. |
| 130 | */ |
Nick Gordon | 9212bd4 | 2017-10-23 10:59:38 -0500 | [diff] [blame] | 131 | virtual bool |
Nick Gordon | 2f62338 | 2017-11-03 13:49:31 -0500 | [diff] [blame] | 132 | deserialize(const std::string& content) noexcept = 0; |
Nick Gordon | 9212bd4 | 2017-10-23 10:59:38 -0500 | [diff] [blame] | 133 | |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 134 | virtual void |
| 135 | writeLog() const = 0; |
| 136 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 137 | protected: |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 138 | /*! Get data common to all LSA types. |
| 139 | |
| 140 | This method should be called by all LSA classes in their |
| 141 | serialize() method. |
| 142 | */ |
| 143 | std::string |
| 144 | getData() const; |
| 145 | |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 146 | /*! Print data common to all LSA types. |
| 147 | */ |
| 148 | std::string |
| 149 | toString() const; |
| 150 | |
Nick Gordon | 0fa4c77 | 2017-10-23 13:33:03 -0500 | [diff] [blame] | 151 | bool |
| 152 | deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator); |
| 153 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 154 | protected: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 155 | ndn::Name m_origRouter; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 156 | uint32_t m_lsSeqNo; |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 157 | ndn::time::system_clock::TimePoint m_expirationTimePoint; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 158 | ndn::EventId m_expiringEventId; |
| 159 | }; |
| 160 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 161 | class NameLsa : public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 162 | { |
| 163 | public: |
| 164 | NameLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 165 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 168 | NameLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 169 | const ndn::time::system_clock::TimePoint& lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 170 | NamePrefixList& npl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 171 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 172 | Lsa::Type |
| 173 | getType() const override |
| 174 | { |
| 175 | return Lsa::Type::NAME; |
| 176 | } |
| 177 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 178 | NamePrefixList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 179 | getNpl() |
| 180 | { |
| 181 | return m_npl; |
| 182 | } |
| 183 | |
Nick Gordon | 56d1fae | 2017-05-26 16:39:25 -0500 | [diff] [blame] | 184 | const NamePrefixList& |
| 185 | getNpl() const |
| 186 | { |
| 187 | return m_npl; |
| 188 | } |
| 189 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 190 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 191 | addName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 192 | { |
| 193 | m_npl.insert(name); |
| 194 | } |
| 195 | |
| 196 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 197 | removeName(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 198 | { |
| 199 | m_npl.remove(name); |
| 200 | } |
| 201 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 202 | /*! \brief Initializes this LSA object with content's data. |
| 203 | |
| 204 | \param content The data (e.g. name prefixes) to initialize this LSA with. |
| 205 | |
| 206 | This function initializes this object to represent the data |
| 207 | contained in content. The format for this is the same as for |
| 208 | getData(); getData() returns data of this format, in other words. |
| 209 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 210 | bool |
Nick Gordon | 2f62338 | 2017-11-03 13:49:31 -0500 | [diff] [blame] | 211 | deserialize(const std::string& content) noexcept override; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 212 | |
Nick Gordon | 56d1fae | 2017-05-26 16:39:25 -0500 | [diff] [blame] | 213 | bool |
| 214 | isEqualContent(const NameLsa& other) const; |
| 215 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 216 | void |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 217 | writeLog() const override; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 218 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 219 | /*! \brief Returns the data that this name LSA has. |
| 220 | |
| 221 | Format is: \<original router |
| 222 | prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix |
| 223 | 2\>|...|\<prefix n\>| |
| 224 | */ |
| 225 | std::string |
| 226 | serialize() const override; |
| 227 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | private: |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 229 | NamePrefixList m_npl; |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 230 | |
| 231 | friend std::ostream& |
| 232 | operator<<(std::ostream& os, const NameLsa& lsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 235 | class AdjLsa : public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 236 | { |
| 237 | public: |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 238 | typedef AdjacencyList::const_iterator const_iterator; |
| 239 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 240 | AdjLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 241 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 242 | } |
| 243 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 244 | AdjLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 245 | const ndn::time::system_clock::TimePoint& lt, |
| 246 | uint32_t nl , AdjacencyList& adl); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 247 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 248 | Lsa::Type |
| 249 | getType() const override |
| 250 | { |
| 251 | return Lsa::Type::ADJACENCY; |
| 252 | } |
| 253 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 254 | AdjacencyList& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | getAdl() |
| 256 | { |
| 257 | return m_adl; |
| 258 | } |
| 259 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 260 | const AdjacencyList& |
| 261 | getAdl() const |
| 262 | { |
| 263 | return m_adl; |
| 264 | } |
| 265 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 266 | void |
| 267 | addAdjacent(Adjacent adj) |
| 268 | { |
| 269 | m_adl.insert(adj); |
| 270 | } |
| 271 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 272 | /*! \brief Initializes this adj. LSA from the supplied content. |
| 273 | |
| 274 | \param content The content that this LSA is to have, formatted |
| 275 | according to getData(). |
| 276 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 277 | bool |
Nick Gordon | 2f62338 | 2017-11-03 13:49:31 -0500 | [diff] [blame] | 278 | deserialize(const std::string& content) noexcept override; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 279 | |
| 280 | uint32_t |
| 281 | getNoLink() |
| 282 | { |
| 283 | return m_noLink; |
| 284 | } |
| 285 | |
| 286 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 287 | isEqualContent(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 289 | /*! \brief Installs this LSA's name prefixes into the NPT. |
| 290 | |
| 291 | \param pnlsr The NLSR top-level whose NPT you want to install the |
| 292 | entries into. |
| 293 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 294 | void |
| 295 | addNptEntries(Nlsr& pnlsr); |
| 296 | |
| 297 | void |
| 298 | removeNptEntries(Nlsr& pnlsr); |
| 299 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 300 | void |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 301 | writeLog() const override; |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 302 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 303 | const_iterator |
| 304 | begin() const |
| 305 | { |
| 306 | return m_adl.begin(); |
| 307 | } |
| 308 | |
| 309 | const_iterator |
| 310 | end() const |
| 311 | { |
| 312 | return m_adl.end(); |
| 313 | } |
| 314 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 315 | /*! \brief Returns the data this adjacency LSA has. |
| 316 | |
| 317 | The format is: \<original |
| 318 | router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix |
| 319 | 1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri |
| 320 | n\>|\<cost n\>| |
| 321 | */ |
| 322 | std::string |
| 323 | serialize() const override; |
| 324 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | private: |
| 326 | uint32_t m_noLink; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 327 | AdjacencyList m_adl; |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 328 | |
| 329 | friend std::ostream& |
| 330 | operator<<(std::ostream& os, const AdjLsa& lsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 331 | }; |
| 332 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 333 | class CoordinateLsa : public Lsa |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 334 | { |
| 335 | public: |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 336 | CoordinateLsa() |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 337 | : m_corRad(0) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 338 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 341 | CoordinateLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 342 | const ndn::time::system_clock::TimePoint& lt, |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 343 | double r, std::vector<double> theta); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 344 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 345 | Lsa::Type |
| 346 | getType() const override |
| 347 | { |
| 348 | return Lsa::Type::COORDINATE; |
| 349 | } |
| 350 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 351 | /*! \brief Initializes this coordinate LSA with the data in content. |
| 352 | |
| 353 | \param content The string content that is used to build the LSA. |
| 354 | |
| 355 | This function initializes this LSA object to represent the data |
| 356 | specified by the parameter. The format that it is expecting is the |
| 357 | same as for getData(); |
| 358 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 359 | bool |
Nick Gordon | 2f62338 | 2017-11-03 13:49:31 -0500 | [diff] [blame] | 360 | deserialize(const std::string& content) noexcept override; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 361 | |
| 362 | double |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 363 | getCorRadius() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 364 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 365 | return m_corRad; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void |
| 369 | setCorRadius(double cr) |
| 370 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 371 | m_corRad = cr; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 372 | } |
| 373 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 374 | const std::vector<double> |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 375 | getCorTheta() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 376 | { |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 377 | return m_angles; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 381 | setCorTheta(std::vector<double> ct) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 382 | { |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 383 | m_angles = ct; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 387 | isEqualContent(const CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 388 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 389 | void |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 390 | writeLog() const override; |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 391 | |
Nick Gordon | faf49f4 | 2017-10-23 12:36:28 -0500 | [diff] [blame] | 392 | /*! \brief Returns the data that this coordinate LSA represents. |
| 393 | |
| 394 | The format is: \<original |
| 395 | router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>| |
| 396 | */ |
| 397 | std::string |
| 398 | serialize() const override; |
| 399 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 400 | private: |
| 401 | double m_corRad; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 402 | std::vector<double> m_angles; |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 403 | |
| 404 | friend std::ostream& |
| 405 | operator<<(std::ostream& os, const CoordinateLsa& lsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 406 | }; |
| 407 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 408 | std::ostream& |
Nick Gordon | ae0a047 | 2017-10-23 15:51:23 -0500 | [diff] [blame] | 409 | operator<<(std::ostream& os, const AdjLsa& lsa); |
| 410 | |
| 411 | std::ostream& |
| 412 | operator<<(std::ostream& os, const CoordinateLsa& lsa); |
| 413 | |
| 414 | std::ostream& |
| 415 | operator<<(std::ostream& os, const NameLsa& lsa); |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 416 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 417 | std::ostream& |
| 418 | operator<<(std::ostream& os, const Lsa::Type& type); |
| 419 | |
| 420 | std::istream& |
| 421 | operator>>(std::istream& is, Lsa::Type& type); |
| 422 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 423 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 424 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 425 | namespace std { |
| 426 | std::string |
| 427 | to_string(const nlsr::Lsa::Type& type); |
| 428 | } // namespace std |
| 429 | |
Nick Gordon | 56d1fae | 2017-05-26 16:39:25 -0500 | [diff] [blame] | 430 | #endif // NLSR_LSA_HPP |