laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2018, The University of Memphis, |
| 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_ROUTING_TABLE_ENTRY_HPP |
| 23 | #define NLSR_TLV_ROUTING_TABLE_ENTRY_HPP |
| 24 | |
| 25 | #include "destination.hpp" |
| 26 | #include "nexthop.hpp" |
| 27 | |
| 28 | #include <ndn-cxx/util/time.hpp> |
| 29 | #include <ndn-cxx/encoding/block.hpp> |
| 30 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 31 | #include <ndn-cxx/encoding/tlv.hpp> |
| 32 | #include <ndn-cxx/name.hpp> |
| 33 | |
| 34 | #include <list> |
| 35 | |
| 36 | namespace nlsr { |
| 37 | namespace tlv { |
| 38 | |
| 39 | /*! \brief Data abstraction for RouteTableInfo |
| 40 | * |
| 41 | * RouteTableInfo := ROUTINGTABLE-TYPE TLV-LENGTH |
| 42 | * Destination |
| 43 | * NexthopList* |
| 44 | * |
| 45 | * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_DataSet |
| 46 | */ |
| 47 | class RoutingTable |
| 48 | { |
| 49 | public: |
| 50 | class Error : public ndn::tlv::Error |
| 51 | { |
| 52 | public: |
| 53 | explicit |
| 54 | Error(const std::string& what) |
| 55 | : ndn::tlv::Error(what) |
| 56 | { |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | typedef std::list<NextHop> HopList; |
| 61 | typedef HopList::const_iterator const_iterator; |
| 62 | |
| 63 | RoutingTable(); |
| 64 | |
| 65 | explicit |
| 66 | RoutingTable(const ndn::Block& block); |
| 67 | |
| 68 | const Destination& |
| 69 | getDestination() const |
| 70 | { |
| 71 | return m_des; |
| 72 | } |
| 73 | |
| 74 | RoutingTable& |
| 75 | setDestination(const Destination& des) |
| 76 | { |
| 77 | m_des = des; |
| 78 | m_wire.reset(); |
| 79 | return *this; |
| 80 | } |
| 81 | |
| 82 | uint64_t |
| 83 | getRtSize() const |
| 84 | { |
| 85 | return m_size; |
| 86 | } |
| 87 | |
| 88 | RoutingTable& |
| 89 | setRtSize(uint64_t size) |
| 90 | { |
| 91 | m_size = size; |
| 92 | m_wire.reset(); |
| 93 | return *this; |
| 94 | } |
| 95 | |
| 96 | bool |
| 97 | hasNexthops() const; |
| 98 | |
| 99 | const std::list<NextHop>& |
| 100 | getNextHops() const |
| 101 | { |
| 102 | return m_nexthops; |
| 103 | } |
| 104 | |
| 105 | RoutingTable& |
| 106 | addNexthops(const NextHop& nexthop); |
| 107 | |
| 108 | RoutingTable& |
| 109 | clearNexthops(); |
| 110 | |
| 111 | template<ndn::encoding::Tag TAG> |
| 112 | size_t |
| 113 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 114 | |
| 115 | const ndn::Block& |
| 116 | wireEncode() const; |
| 117 | |
| 118 | void |
| 119 | wireDecode(const ndn::Block& wire); |
| 120 | |
| 121 | const_iterator |
| 122 | begin() const; |
| 123 | |
| 124 | const_iterator |
| 125 | end() const; |
| 126 | |
| 127 | private: |
| 128 | Destination m_des; |
| 129 | uint64_t m_size; |
| 130 | bool m_hasNexthops; |
| 131 | HopList m_nexthops; |
| 132 | |
| 133 | mutable ndn::Block m_wire; |
| 134 | }; |
| 135 | |
| 136 | inline RoutingTable::const_iterator |
| 137 | RoutingTable::begin() const |
| 138 | { |
| 139 | return m_nexthops.begin(); |
| 140 | } |
| 141 | |
| 142 | inline RoutingTable::const_iterator |
| 143 | RoutingTable::end() const |
| 144 | { |
| 145 | return m_nexthops.end(); |
| 146 | } |
| 147 | |
| 148 | std::ostream& |
| 149 | operator<<(std::ostream& os, const RoutingTable& routetable); |
| 150 | |
| 151 | } // namespace tlv |
| 152 | } // namespace nlsr |
| 153 | |
| 154 | #endif // NLSR_TLV_ROUTING_TABLE_ENTRY_HPP |