akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, 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 | * |
| 20 | * \author A K M Mahmudul Hoque <ahoque1@memphis.edu> |
| 21 | * |
| 22 | **/ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 23 | #ifndef NLSR_ROUTING_TABLE_HPP |
| 24 | #define NLSR_ROUTING_TABLE_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | |
| 26 | #include <iostream> |
| 27 | #include <utility> |
| 28 | #include <string> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 29 | #include <boost/cstdint.hpp> |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/scheduler.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 32 | #include "conf-parameter.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | #include "routing-table-entry.hpp" |
| 34 | |
| 35 | namespace nlsr { |
| 36 | |
| 37 | class Nlsr; |
| 38 | class NextHop; |
| 39 | |
| 40 | class RoutingTable |
| 41 | { |
| 42 | public: |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 43 | RoutingTable(ndn::Scheduler& scheduler) |
| 44 | : m_scheduler(scheduler) |
| 45 | , m_NO_NEXT_HOP(-12345) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 46 | , m_routingCalcInterval(static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | { |
| 48 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 49 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 50 | /*! \brief Calculates a list of next hops for each router in the network. |
| 51 | \param pnlsr The NLSR object that contains the LSAs needed for adj. info. |
| 52 | |
| 53 | Calculates the list of next hops to every other router in the network. |
| 54 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 55 | void |
| 56 | calculate(Nlsr& pnlsr); |
| 57 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 58 | /*! \brief Adds a next hop to a routing table entry. |
| 59 | \param destRouter The destination router whose RTE we want to modify. |
| 60 | \param nh The next hop to add to the RTE. |
| 61 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 62 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | addNextHop(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 65 | /*! \brief Adds a next hop to a routing table entry in a dry run scenario. |
| 66 | \param destRouter The destination router whose RTE we want to modify. |
| 67 | \param nh The next hop to add to the router. |
| 68 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 70 | addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 71 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 72 | RoutingTableEntry* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 73 | findRoutingTableEntry(const ndn::Name& destRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 75 | /*! \brief Schedules a calculation event in the event scheduler. |
| 76 | \param pnlsr The NLSR whose scheduling status is needed. |
| 77 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | void |
| 79 | scheduleRoutingTableCalculation(Nlsr& pnlsr); |
| 80 | |
| 81 | int |
| 82 | getNoNextHop() |
| 83 | { |
| 84 | return m_NO_NEXT_HOP; |
| 85 | } |
| 86 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 87 | void |
| 88 | setRoutingCalcInterval(uint32_t interval) |
| 89 | { |
| 90 | m_routingCalcInterval = ndn::time::seconds(interval); |
| 91 | } |
| 92 | |
| 93 | const ndn::time::seconds& |
| 94 | getRoutingCalcInterval() const |
| 95 | { |
| 96 | return m_routingCalcInterval; |
| 97 | } |
| 98 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 99 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 100 | /*! \brief Calculates a link-state routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 101 | void |
| 102 | calculateLsRoutingTable(Nlsr& pnlsr); |
| 103 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 104 | /*! \brief Calculates a HR routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | void |
| 106 | calculateHypRoutingTable(Nlsr& pnlsr); |
| 107 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 108 | /*! \brief Calculates a dry-run HR routing table. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 109 | void |
| 110 | calculateHypDryRoutingTable(Nlsr& pnlsr); |
| 111 | |
| 112 | void |
| 113 | clearRoutingTable(); |
| 114 | |
| 115 | void |
| 116 | clearDryRoutingTable(); |
| 117 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 118 | void |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 119 | writeLog(int hyperbolicState); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 120 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 121 | private: |
| 122 | ndn::Scheduler& m_scheduler; |
| 123 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | const int m_NO_NEXT_HOP; |
| 125 | |
| 126 | std::list<RoutingTableEntry> m_rTable; |
| 127 | std::list<RoutingTableEntry> m_dryTable; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 128 | |
| 129 | ndn::time::seconds m_routingCalcInterval; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | }; |
| 131 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 132 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 133 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 134 | #endif //NLSR_ROUTING_TABLE_HPP |