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 | /* |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, 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" |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 30 | #include "route/name-prefix-table.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 31 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 32 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | namespace nlsr { |
| 35 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | class NextHop; |
| 37 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 38 | /*! \brief Data abstraction for routing table status |
| 39 | * |
| 40 | * RtStatus := RT-STATUS-TYPE TLV-LENGTH |
| 41 | * RouteTableEntry* |
| 42 | * |
| 43 | * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset |
| 44 | */ |
| 45 | class RoutingTableStatus |
| 46 | { |
| 47 | public: |
| 48 | using Error = ndn::tlv::Error; |
| 49 | |
| 50 | RoutingTableStatus() = default; |
| 51 | |
| 52 | RoutingTableStatus(const ndn::Block& block) |
| 53 | { |
| 54 | wireDecode(block); |
| 55 | } |
| 56 | |
| 57 | const std::list<RoutingTableEntry>& |
| 58 | getRoutingTableEntry() const |
| 59 | { |
| 60 | return m_rTable; |
| 61 | } |
| 62 | |
| 63 | const std::list<RoutingTableEntry>& |
| 64 | getDryRoutingTableEntry() const |
| 65 | { |
| 66 | return m_dryTable; |
| 67 | } |
| 68 | |
| 69 | const ndn::Block& |
| 70 | wireEncode() const; |
| 71 | |
| 72 | private: |
| 73 | void |
| 74 | wireDecode(const ndn::Block& wire); |
| 75 | |
| 76 | template<ndn::encoding::Tag TAG> |
| 77 | size_t |
| 78 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 79 | |
| 80 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 81 | std::list<RoutingTableEntry> m_dryTable; |
| 82 | std::list<RoutingTableEntry> m_rTable; |
| 83 | mutable ndn::Block m_wire; |
| 84 | }; |
| 85 | |
| 86 | std::ostream& |
| 87 | operator<<(std::ostream& os, const RoutingTableStatus& rts); |
| 88 | |
| 89 | class RoutingTable : public RoutingTableStatus |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | { |
| 91 | public: |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 92 | explicit |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 93 | RoutingTable(ndn::Scheduler& scheduler, Lsdb& lsdb, ConfParameter& confParam); |
| 94 | |
| 95 | ~RoutingTable() |
| 96 | { |
| 97 | m_afterLsdbModified.disconnect(); |
| 98 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 99 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 100 | /*! \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] | 101 | * |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 102 | * 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] | 103 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 104 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 105 | calculate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 107 | /*! \brief Adds a next hop to a routing table entry. |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 108 | * \param destRouter The destination router whose RTE we want to modify. |
| 109 | * \param nh The next hop to add to the RTE. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 110 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 111 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 112 | addNextHop(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 114 | /*! \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] | 115 | * \param destRouter The destination router whose RTE we want to modify. |
| 116 | * \param nh The next hop to add to the router. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 117 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 119 | addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 121 | RoutingTableEntry* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 122 | findRoutingTableEntry(const ndn::Name& destRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 123 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 124 | /*! \brief Schedules a calculation event in the event scheduler only |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 125 | * if one isn't already scheduled. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 126 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 127 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 128 | scheduleRoutingTableCalculation(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 131 | /*! \brief Calculates a link-state routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 133 | calculateLsRoutingTable(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 134 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 135 | /*! \brief Calculates a HR routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 136 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 137 | calculateHypRoutingTable(bool isDryRun); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 138 | |
| 139 | void |
| 140 | clearRoutingTable(); |
| 141 | |
| 142 | void |
| 143 | clearDryRoutingTable(); |
| 144 | |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 145 | public: |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 146 | AfterRoutingChange afterRoutingChange; |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 147 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 148 | private: |
| 149 | ndn::Scheduler& m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 150 | Lsdb& m_lsdb; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 151 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 152 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 153 | ndn::time::seconds m_routingCalcInterval; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 154 | bool m_isRoutingTableCalculating; |
| 155 | bool m_isRouteCalculationScheduled; |
| 156 | |
| 157 | ConfParameter& m_confParam; |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 158 | ndn::signal::Connection m_afterLsdbModified; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 159 | int32_t m_hyperbolicState; |
| 160 | bool m_ownAdjLsaExist = false; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 163 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 164 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 165 | #endif // NLSR_ROUTING_TABLE_HPP |