Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, 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 | |
| 34 | /*! |
| 35 | \brief Data abstraction for Lsa |
| 36 | Lsa := LSA-TYPE TLV-LENGTH |
| 37 | Name |
| 38 | SequenceNumber |
| 39 | ExpirationTimePoint |
| 40 | */ |
| 41 | class Lsa |
| 42 | { |
| 43 | public: |
| 44 | class Error : public ndn::tlv::Error |
| 45 | { |
| 46 | public: |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 47 | using ndn::tlv::Error::Error; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | enum class Type { |
| 51 | ADJACENCY, |
| 52 | COORDINATE, |
| 53 | NAME, |
| 54 | BASE |
| 55 | }; |
| 56 | |
| 57 | protected: |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 58 | Lsa(const ndn::Name& originRouter, uint64_t seqNo, |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 59 | ndn::time::system_clock::time_point expirationTimePoint); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 60 | |
| 61 | Lsa() = default; |
| 62 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 63 | Lsa(const Lsa& lsa); |
| 64 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 65 | public: |
| 66 | virtual |
| 67 | ~Lsa() = default; |
| 68 | |
| 69 | virtual Type |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 70 | getType() const = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 71 | |
| 72 | void |
| 73 | setSeqNo(uint64_t seqNo) |
| 74 | { |
| 75 | m_seqNo = seqNo; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 76 | m_wire.reset(); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | uint64_t |
| 80 | getSeqNo() const |
| 81 | { |
| 82 | return m_seqNo; |
| 83 | } |
| 84 | |
| 85 | const ndn::Name& |
| 86 | getOriginRouter() const |
| 87 | { |
| 88 | return m_originRouter; |
| 89 | } |
| 90 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 91 | ndn::Name |
| 92 | getOriginRouterCopy() const |
| 93 | { |
| 94 | return m_originRouter; |
| 95 | } |
| 96 | |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 97 | const ndn::time::system_clock::time_point& |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 98 | getExpirationTimePoint() const |
| 99 | { |
| 100 | return m_expirationTimePoint; |
| 101 | } |
| 102 | |
| 103 | void |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 104 | setExpirationTimePoint(const ndn::time::system_clock::time_point& lt) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 105 | { |
| 106 | m_expirationTimePoint = lt; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 107 | m_wire.reset(); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void |
| 111 | setExpiringEventId(ndn::scheduler::EventId eid) |
| 112 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 113 | m_expiringEventId = eid; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 116 | /*! Get data common to all LSA types for printing purposes. |
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 std::string |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 119 | toString() const = 0; |
| 120 | |
| 121 | virtual std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 122 | update(const std::shared_ptr<Lsa>& lsa) = 0; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 123 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 124 | virtual const ndn::Block& |
| 125 | wireEncode() const = 0; |
| 126 | |
| 127 | protected: |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 128 | template<ndn::encoding::Tag TAG> |
| 129 | size_t |
| 130 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 131 | |
| 132 | void |
| 133 | wireDecode(const ndn::Block& wire); |
| 134 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 135 | std::string |
| 136 | getString() const; |
| 137 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 138 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 139 | ndn::Name m_originRouter; |
| 140 | uint64_t m_seqNo = 0; |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 141 | ndn::time::system_clock::time_point m_expirationTimePoint; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 142 | ndn::scheduler::ScopedEventId m_expiringEventId; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 143 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 144 | mutable ndn::Block m_wire; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Lsa); |
| 148 | |
| 149 | std::ostream& |
| 150 | operator<<(std::ostream& os, const Lsa::Type& type); |
| 151 | |
| 152 | std::istream& |
| 153 | operator>>(std::istream& is, Lsa::Type& type); |
| 154 | |
| 155 | } // namespace nlsr |
| 156 | |
| 157 | #endif // NLSR_LSA_LSA_HPP |