Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 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/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef NLSR_LSA_LSA_HPP |
| 23 | #define NLSR_LSA_LSA_HPP |
| 24 | |
Junxiao Shi | 2037764 | 2023-08-24 23:55:40 +0000 | [diff] [blame] | 25 | #include "common.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 26 | #include "test-access-control.hpp" |
| 27 | |
| 28 | #include <ndn-cxx/util/scheduler.hpp> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 29 | |
Junxiao Shi | 2037764 | 2023-08-24 23:55:40 +0000 | [diff] [blame] | 30 | #include <list> |
| 31 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 34 | /** |
| 35 | * @brief Represents a Link State Announcement (LSA). |
| 36 | * |
| 37 | * The base level LSA is encoded as: |
| 38 | * @code{.abnf} |
| 39 | * Lsa = LSA-TYPE TLV-LENGTH |
| 40 | * Name ; origin router |
| 41 | * SequenceNumber |
| 42 | * ExpirationTime |
| 43 | * @endcode |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 44 | */ |
| 45 | class Lsa |
| 46 | { |
| 47 | public: |
| 48 | class Error : public ndn::tlv::Error |
| 49 | { |
| 50 | public: |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 51 | using ndn::tlv::Error::Error; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | enum class Type { |
| 55 | ADJACENCY, |
| 56 | COORDINATE, |
| 57 | NAME, |
| 58 | BASE |
| 59 | }; |
| 60 | |
| 61 | protected: |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 62 | Lsa() = default; |
| 63 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 64 | Lsa(const ndn::Name& originRouter, uint64_t seqNo, |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 65 | ndn::time::system_clock::time_point expirationTimePoint); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 66 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 67 | explicit |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 68 | Lsa(const Lsa& lsa); |
| 69 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 70 | public: |
| 71 | virtual |
| 72 | ~Lsa() = default; |
| 73 | |
| 74 | virtual Type |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 75 | getType() const = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 76 | |
| 77 | void |
| 78 | setSeqNo(uint64_t seqNo) |
| 79 | { |
| 80 | m_seqNo = seqNo; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 81 | m_wire.reset(); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | uint64_t |
| 85 | getSeqNo() const |
| 86 | { |
| 87 | return m_seqNo; |
| 88 | } |
| 89 | |
| 90 | const ndn::Name& |
| 91 | getOriginRouter() const |
| 92 | { |
| 93 | return m_originRouter; |
| 94 | } |
| 95 | |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 96 | const ndn::time::system_clock::time_point& |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 97 | getExpirationTimePoint() const |
| 98 | { |
| 99 | return m_expirationTimePoint; |
| 100 | } |
| 101 | |
| 102 | void |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 103 | setExpirationTimePoint(const ndn::time::system_clock::time_point& lt) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 104 | { |
| 105 | m_expirationTimePoint = lt; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 106 | m_wire.reset(); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void |
| 110 | setExpiringEventId(ndn::scheduler::EventId eid) |
| 111 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 112 | m_expiringEventId = eid; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 115 | virtual std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 116 | update(const std::shared_ptr<Lsa>& lsa) = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 117 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 118 | virtual const ndn::Block& |
| 119 | wireEncode() const = 0; |
| 120 | |
| 121 | protected: |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 122 | template<ndn::encoding::Tag TAG> |
| 123 | size_t |
| 124 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 125 | |
| 126 | void |
| 127 | wireDecode(const ndn::Block& wire); |
| 128 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 129 | private: |
| 130 | virtual void |
| 131 | print(std::ostream& os) const = 0; |
| 132 | |
| 133 | friend std::ostream& |
| 134 | operator<<(std::ostream& os, const Lsa& lsa); |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 135 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 136 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 137 | ndn::Name m_originRouter; |
| 138 | uint64_t m_seqNo = 0; |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 139 | ndn::time::system_clock::time_point m_expirationTimePoint; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 140 | ndn::scheduler::ScopedEventId m_expiringEventId; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 141 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 142 | mutable ndn::Block m_wire; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Lsa); |
| 146 | |
| 147 | std::ostream& |
| 148 | operator<<(std::ostream& os, const Lsa::Type& type); |
| 149 | |
| 150 | std::istream& |
| 151 | operator>>(std::istream& is, Lsa::Type& type); |
| 152 | |
| 153 | } // namespace nlsr |
| 154 | |
| 155 | #endif // NLSR_LSA_LSA_HPP |