akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 2 | /* |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 19 | */ |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 20 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 21 | #ifndef NLSR_ROUTING_TABLE_HPP |
| 22 | #define NLSR_ROUTING_TABLE_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 23 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 24 | #include "conf-parameter.hpp" |
| 25 | #include "routing-table-entry.hpp" |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 26 | #include "signals.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 27 | #include "lsdb.hpp" |
| 28 | #include "route/fib.hpp" |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame^] | 29 | #include "test-access-control.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 30 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | namespace nlsr { |
| 34 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | class NextHop; |
| 36 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 37 | /*! \brief Data abstraction for routing table status |
| 38 | * |
| 39 | * RtStatus := RT-STATUS-TYPE TLV-LENGTH |
| 40 | * RouteTableEntry* |
| 41 | * |
| 42 | * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset |
| 43 | */ |
| 44 | class RoutingTableStatus |
| 45 | { |
| 46 | public: |
| 47 | using Error = ndn::tlv::Error; |
| 48 | |
| 49 | RoutingTableStatus() = default; |
| 50 | |
| 51 | RoutingTableStatus(const ndn::Block& block) |
| 52 | { |
| 53 | wireDecode(block); |
| 54 | } |
| 55 | |
| 56 | const std::list<RoutingTableEntry>& |
| 57 | getRoutingTableEntry() const |
| 58 | { |
| 59 | return m_rTable; |
| 60 | } |
| 61 | |
| 62 | const std::list<RoutingTableEntry>& |
| 63 | getDryRoutingTableEntry() const |
| 64 | { |
| 65 | return m_dryTable; |
| 66 | } |
| 67 | |
| 68 | const ndn::Block& |
| 69 | wireEncode() const; |
| 70 | |
| 71 | private: |
| 72 | void |
| 73 | wireDecode(const ndn::Block& wire); |
| 74 | |
| 75 | template<ndn::encoding::Tag TAG> |
| 76 | size_t |
| 77 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 78 | |
| 79 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 80 | std::list<RoutingTableEntry> m_dryTable; |
| 81 | std::list<RoutingTableEntry> m_rTable; |
| 82 | mutable ndn::Block m_wire; |
| 83 | }; |
| 84 | |
| 85 | std::ostream& |
| 86 | operator<<(std::ostream& os, const RoutingTableStatus& rts); |
| 87 | |
| 88 | class RoutingTable : public RoutingTableStatus |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 89 | { |
| 90 | public: |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 91 | explicit |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 92 | RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb, |
| 93 | NamePrefixTable& namePrefixTable, ConfParameter& confParam); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 94 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 95 | /*! \brief Calculates a list of next hops for each router in the network. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 96 | * |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 97 | * Calculates the list of next hops to every other router in the network. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 98 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 99 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 100 | calculate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 101 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 102 | /*! \brief Adds a next hop to a routing table entry. |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 103 | * \param destRouter The destination router whose RTE we want to modify. |
| 104 | * \param nh The next hop to add to the RTE. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 105 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 107 | addNextHop(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 108 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 109 | /*! \brief Adds a next hop to a routing table entry in a dry run scenario. |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 110 | * \param destRouter The destination router whose RTE we want to modify. |
| 111 | * \param nh The next hop to add to the router. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 112 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 114 | addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 115 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 116 | RoutingTableEntry* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 117 | findRoutingTableEntry(const ndn::Name& destRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 119 | /*! \brief Schedules a calculation event in the event scheduler only |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 120 | * if one isn't already scheduled. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 121 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 122 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 123 | scheduleRoutingTableCalculation(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 125 | void |
| 126 | setRoutingCalcInterval(uint32_t interval) |
| 127 | { |
| 128 | m_routingCalcInterval = ndn::time::seconds(interval); |
| 129 | } |
| 130 | |
| 131 | const ndn::time::seconds& |
| 132 | getRoutingCalcInterval() const |
| 133 | { |
| 134 | return m_routingCalcInterval; |
| 135 | } |
| 136 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 137 | uint64_t |
| 138 | getRtSize() |
| 139 | { |
| 140 | return m_rTable.size(); |
| 141 | } |
| 142 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 143 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 144 | /*! \brief Calculates a link-state routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 146 | calculateLsRoutingTable(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 147 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 148 | /*! \brief Calculates a HR routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 149 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 150 | calculateHypRoutingTable(bool isDryRun); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 151 | |
| 152 | void |
| 153 | clearRoutingTable(); |
| 154 | |
| 155 | void |
| 156 | clearDryRoutingTable(); |
| 157 | |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 158 | public: |
Nick Gordon | d40a588 | 2017-09-05 15:34:58 -0500 | [diff] [blame] | 159 | std::unique_ptr<AfterRoutingChange> afterRoutingChange; |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 160 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 161 | private: |
| 162 | ndn::Scheduler& m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 163 | Fib& m_fib; |
| 164 | Lsdb& m_lsdb; |
| 165 | NamePrefixTable& m_namePrefixTable; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 166 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 167 | ndn::time::seconds m_routingCalcInterval; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 168 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame^] | 169 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 170 | bool m_isRoutingTableCalculating; |
| 171 | bool m_isRouteCalculationScheduled; |
| 172 | |
| 173 | ConfParameter& m_confParam; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 174 | }; |
| 175 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 176 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 178 | #endif // NLSR_ROUTING_TABLE_HPP |