Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, The University of Memphis, |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -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_TLV_LSDB_STATUS_HPP |
| 23 | #define NLSR_TLV_LSDB_STATUS_HPP |
| 24 | |
| 25 | #include "adjacency-lsa.hpp" |
| 26 | #include "coordinate-lsa.hpp" |
| 27 | #include "name-lsa.hpp" |
| 28 | |
| 29 | #include <ndn-cxx/util/time.hpp> |
| 30 | #include <ndn-cxx/encoding/block.hpp> |
| 31 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 32 | #include <ndn-cxx/encoding/tlv.hpp> |
| 33 | #include <ndn-cxx/name.hpp> |
| 34 | |
| 35 | #include <list> |
| 36 | |
| 37 | namespace nlsr { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 38 | namespace tlv { |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 39 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 40 | /*! \brief Data abstraction for LsdbStatus |
| 41 | * |
| 42 | * LsdbStatus := LSDB-STATUS-TYPE TLV-LENGTH |
| 43 | * AdjacencyLsa* |
| 44 | * CoordinateLsa* |
| 45 | * NameLsa* |
| 46 | * |
| 47 | * \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 48 | */ |
| 49 | class LsdbStatus |
| 50 | { |
| 51 | public: |
| 52 | class Error : public ndn::tlv::Error |
| 53 | { |
| 54 | public: |
| 55 | explicit |
| 56 | Error(const std::string& what) |
| 57 | : ndn::tlv::Error(what) |
| 58 | { |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | typedef std::list<AdjacencyLsa> AdjacencyLsaList; |
| 63 | typedef std::list<CoordinateLsa> CoordinateLsaList; |
| 64 | typedef std::list<NameLsa> NameLsaList; |
| 65 | |
| 66 | LsdbStatus(); |
| 67 | |
| 68 | explicit |
| 69 | LsdbStatus(const ndn::Block& block); |
| 70 | |
| 71 | const std::list<AdjacencyLsa>& |
| 72 | getAdjacencyLsas() const |
| 73 | { |
| 74 | return m_adjacencyLsas; |
| 75 | } |
| 76 | |
| 77 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 78 | addAdjacencyLsa(const AdjacencyLsa& adjacencyLsa); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 79 | |
| 80 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 81 | clearAdjacencyLsas(); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 82 | |
| 83 | bool |
| 84 | hasAdjacencyLsas() |
| 85 | { |
| 86 | return m_hasAdjacencyLsas; |
| 87 | } |
| 88 | |
| 89 | const std::list<CoordinateLsa>& |
| 90 | getCoordinateLsas() const |
| 91 | { |
| 92 | return m_coordinateLsas; |
| 93 | } |
| 94 | |
| 95 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 96 | addCoordinateLsa(const CoordinateLsa& coordinateLsa); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 97 | |
| 98 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 99 | clearCoordinateLsas(); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 100 | |
| 101 | bool |
| 102 | hasCoordinateLsas() |
| 103 | { |
| 104 | return m_hasCoordinateLsas; |
| 105 | } |
| 106 | |
| 107 | const std::list<NameLsa>& |
| 108 | getNameLsas() const |
| 109 | { |
| 110 | return m_nameLsas; |
| 111 | } |
| 112 | |
| 113 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 114 | addNameLsa(const NameLsa& nameLsa); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 115 | |
| 116 | LsdbStatus& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 117 | clearNameLsas(); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 118 | |
| 119 | bool |
| 120 | hasNameLsas() |
| 121 | { |
| 122 | return m_hasNameLsas; |
| 123 | } |
| 124 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 125 | /*! \brief Encodes the LSA objects and some info for each LSA using |
| 126 | * the method in TAG. |
| 127 | * |
| 128 | * This function will TLV-format the LSA objects and some LSA |
| 129 | * info using the implementation specified by TAG. Usually this is |
| 130 | * called with an estimator first to guess how long the buffer needs |
| 131 | * to be, then with an encoder to do the real work. This process is |
| 132 | * automated by the other wireEncode. |
| 133 | * \sa LsdbStatus::wireEncode() |
| 134 | */ |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 135 | template<ndn::encoding::Tag TAG> |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 136 | size_t |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 137 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 138 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 139 | /*! \brief Create a TLV encoding of this object. |
| 140 | * |
| 141 | * Create a block containing the TLV encoding of this object. That |
| 142 | * involves two steps: estimating the size that the information will |
| 143 | * take up, and then creating a buffer of that size and encoding the |
| 144 | * information into it. Both steps are accomplished by |
| 145 | * LsdbStatus::wireEncode(ndn::EncodingImpl<TAG>&) |
| 146 | */ |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 147 | const ndn::Block& |
| 148 | wireEncode() const; |
| 149 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 150 | /*! \brief Populate this object by decoding the one contained in the |
| 151 | * given block. |
| 152 | */ |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 153 | void |
| 154 | wireDecode(const ndn::Block& wire); |
| 155 | |
| 156 | private: |
| 157 | AdjacencyLsaList m_adjacencyLsas; |
| 158 | CoordinateLsaList m_coordinateLsas; |
| 159 | NameLsaList m_nameLsas; |
| 160 | |
| 161 | bool m_hasAdjacencyLsas; |
| 162 | bool m_hasCoordinateLsas; |
| 163 | bool m_hasNameLsas; |
| 164 | |
| 165 | mutable ndn::Block m_wire; |
| 166 | }; |
| 167 | |
| 168 | std::ostream& |
| 169 | operator<<(std::ostream& os, const LsdbStatus& lsdbStatus); |
| 170 | |
| 171 | } // namespace tlv |
| 172 | } // namespace nlsr |
| 173 | |
| 174 | #endif // NLSR_TLV_LSDB_STATUS_HPP |