akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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/>. |
| 19 | * |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 21 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 22 | #ifndef NLSR_ROUTING_TABLE_HPP |
| 23 | #define NLSR_ROUTING_TABLE_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 25 | #include "conf-parameter.hpp" |
| 26 | #include "routing-table-entry.hpp" |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 27 | #include "signals.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 28 | #include "lsdb.hpp" |
| 29 | #include "route/fib.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 30 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | #include <iostream> |
| 32 | #include <utility> |
| 33 | #include <string> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 34 | #include <boost/cstdint.hpp> |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 35 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 37 | namespace nlsr { |
| 38 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | class NextHop; |
| 40 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 41 | class RoutingTable : boost::noncopyable |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | { |
| 43 | public: |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 44 | explicit |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 45 | RoutingTable(ndn::Scheduler& scheduler, Fib& fib, Lsdb& lsdb, |
| 46 | NamePrefixTable& namePrefixTable, ConfParameter& confParam); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 47 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 48 | /*! \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] | 49 | * |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 50 | * 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] | 51 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 53 | calculate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 55 | /*! \brief Adds a next hop to a routing table entry. |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 56 | * \param destRouter The destination router whose RTE we want to modify. |
| 57 | * \param nh The next hop to add to the RTE. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 58 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 59 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 60 | addNextHop(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 62 | /*! \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] | 63 | * \param destRouter The destination router whose RTE we want to modify. |
| 64 | * \param nh The next hop to add to the router. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 65 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 67 | addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 68 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 69 | RoutingTableEntry* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 70 | findRoutingTableEntry(const ndn::Name& destRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 71 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 72 | /*! \brief Schedules a calculation event in the event scheduler only |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 73 | * if one isn't already scheduled. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 74 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 75 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 76 | scheduleRoutingTableCalculation(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 77 | |
| 78 | int |
| 79 | getNoNextHop() |
| 80 | { |
| 81 | return m_NO_NEXT_HOP; |
| 82 | } |
| 83 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 84 | void |
| 85 | setRoutingCalcInterval(uint32_t interval) |
| 86 | { |
| 87 | m_routingCalcInterval = ndn::time::seconds(interval); |
| 88 | } |
| 89 | |
| 90 | const ndn::time::seconds& |
| 91 | getRoutingCalcInterval() const |
| 92 | { |
| 93 | return m_routingCalcInterval; |
| 94 | } |
| 95 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 96 | const std::list<RoutingTableEntry>& |
| 97 | getRoutingTableEntry() const |
| 98 | { |
| 99 | return m_rTable; |
| 100 | } |
| 101 | |
| 102 | const std::list<RoutingTableEntry>& |
| 103 | getDryRoutingTableEntry() const |
| 104 | { |
| 105 | return m_dryTable; |
| 106 | } |
| 107 | |
| 108 | uint64_t |
| 109 | getRtSize() |
| 110 | { |
| 111 | return m_rTable.size(); |
| 112 | } |
| 113 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 114 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 115 | /*! \brief Calculates a link-state routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 116 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 117 | calculateLsRoutingTable(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 119 | /*! \brief Calculates a HR routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 121 | calculateHypRoutingTable(bool isDryRun); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 122 | |
| 123 | void |
| 124 | clearRoutingTable(); |
| 125 | |
| 126 | void |
| 127 | clearDryRoutingTable(); |
| 128 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 129 | void |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 130 | writeLog(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 131 | |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 132 | public: |
Nick Gordon | d40a588 | 2017-09-05 15:34:58 -0500 | [diff] [blame] | 133 | std::unique_ptr<AfterRoutingChange> afterRoutingChange; |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 134 | |
| 135 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 136 | std::list<RoutingTableEntry> m_rTable; |
| 137 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 138 | private: |
| 139 | ndn::Scheduler& m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 140 | Fib& m_fib; |
| 141 | Lsdb& m_lsdb; |
| 142 | NamePrefixTable& m_namePrefixTable; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 143 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 144 | const int m_NO_NEXT_HOP; |
| 145 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | std::list<RoutingTableEntry> m_dryTable; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 147 | |
| 148 | ndn::time::seconds m_routingCalcInterval; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 149 | |
| 150 | bool m_isRoutingTableCalculating; |
| 151 | bool m_isRouteCalculationScheduled; |
| 152 | |
| 153 | ConfParameter& m_confParam; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 154 | }; |
| 155 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 156 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 157 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 158 | #endif // NLSR_ROUTING_TABLE_HPP |