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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 19 | **/ |
Davide Pesavento | a08dc3f | 2018-05-24 00:40:28 -0400 | [diff] [blame] | 20 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 21 | #include "routing-table.hpp" |
| 22 | #include "nlsr.hpp" |
| 23 | #include "map.hpp" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 24 | #include "conf-parameter.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | #include "routing-table-calculator.hpp" |
| 26 | #include "routing-table-entry.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 27 | #include "name-prefix-table.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 28 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 30 | #include <iostream> |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 31 | #include <list> |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 32 | #include <string> |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 33 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | namespace nlsr { |
| 35 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 36 | INIT_LOGGER(route.RoutingTable); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 37 | |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 38 | RoutingTable::RoutingTable(ndn::Scheduler& scheduler) |
Davide Pesavento | a08dc3f | 2018-05-24 00:40:28 -0400 | [diff] [blame] | 39 | : afterRoutingChange{std::make_unique<AfterRoutingChange>()} |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 40 | , m_scheduler(scheduler) |
| 41 | , m_NO_NEXT_HOP{-12345} |
| 42 | , m_routingCalcInterval{static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)} |
| 43 | { |
| 44 | } |
| 45 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | void |
| 47 | RoutingTable::calculate(Nlsr& pnlsr) |
| 48 | { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 49 | pnlsr.getLsdb().writeCorLsdbLog(); |
| 50 | pnlsr.getLsdb().writeNameLsdbLog(); |
| 51 | pnlsr.getLsdb().writeAdjLsdbLog(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 52 | pnlsr.getNamePrefixTable().writeLog(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 53 | if (pnlsr.getIsRoutingTableCalculating() == false) { |
| 54 | //setting routing table calculation |
| 55 | pnlsr.setIsRoutingTableCalculating(true); |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 56 | |
| 57 | bool isHrEnabled = pnlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF; |
| 58 | |
| 59 | if ((!isHrEnabled |
| 60 | && |
| 61 | pnlsr.getLsdb() |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 62 | .doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()} |
| 63 | .append(std::to_string(Lsa::Type::ADJACENCY)), Lsa::Type::ADJACENCY)) |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 64 | || |
| 65 | (isHrEnabled |
| 66 | && |
| 67 | pnlsr.getLsdb() |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 68 | .doesLsaExist(ndn::Name{pnlsr.getConfParameter().getRouterPrefix()} |
| 69 | .append(std::to_string(Lsa::Type::COORDINATE)), Lsa::Type::COORDINATE))) { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 70 | if (pnlsr.getIsBuildAdjLsaSheduled() != 1) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 71 | NLSR_LOG_TRACE("Clearing old routing table"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | clearRoutingTable(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 73 | // for dry run options |
| 74 | clearDryRoutingTable(); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 75 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 76 | NLSR_LOG_DEBUG("Calculating routing table"); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 77 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | // calculate Link State routing |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 79 | if ((pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) |
| 80 | || (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | calculateLsRoutingTable(pnlsr); |
| 82 | } |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 83 | // calculate hyperbolic |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 84 | if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 85 | calculateHypRoutingTable(pnlsr, false); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | } |
| 87 | //calculate dry hyperbolic routing |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 88 | if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) { |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 89 | calculateHypRoutingTable(pnlsr, true); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 91 | // Inform the NPT that updates have been made |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 92 | NLSR_LOG_DEBUG("Calling Update NPT With new Route"); |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 93 | (*afterRoutingChange)(m_rTable); |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 94 | writeLog(pnlsr.getConfParameter().getHyperbolicState()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 95 | pnlsr.getNamePrefixTable().writeLog(); |
| 96 | pnlsr.getFib().writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 97 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 98 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 99 | NLSR_LOG_DEBUG("Adjacency building is scheduled, so" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 100 | " routing table can not be calculated :("); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 101 | } |
| 102 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 103 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 104 | NLSR_LOG_DEBUG("No Adj LSA of router itself," |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 105 | " so Routing table can not be calculated :("); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | clearRoutingTable(); |
| 107 | clearDryRoutingTable(); // for dry run options |
| 108 | // need to update NPT here |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 109 | NLSR_LOG_DEBUG("Calling Update NPT With new Route"); |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 110 | (*afterRoutingChange)(m_rTable); |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 111 | writeLog(pnlsr.getConfParameter().getHyperbolicState()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 112 | pnlsr.getNamePrefixTable().writeLog(); |
| 113 | pnlsr.getFib().writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 114 | //debugging purpose end |
| 115 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 116 | pnlsr.setIsRouteCalculationScheduled(false); //clear scheduled flag |
| 117 | pnlsr.setIsRoutingTableCalculating(false); //unsetting routing table calculation |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 119 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | scheduleRoutingTableCalculation(pnlsr); |
| 121 | } |
| 122 | } |
| 123 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | void |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 125 | RoutingTable::calculateLsRoutingTable(Nlsr& nlsr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 127 | NLSR_LOG_DEBUG("RoutingTable::calculateLsRoutingTable Called"); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 128 | |
| 129 | Map map; |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 130 | map.createFromAdjLsdb(nlsr.getLsdb().getAdjLsdb().begin(), nlsr.getLsdb().getAdjLsdb().end()); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 131 | map.writeLog(); |
| 132 | |
| 133 | size_t nRouters = map.getMapSize(); |
| 134 | |
| 135 | LinkStateRoutingTableCalculator calculator(nRouters); |
| 136 | |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 137 | calculator.calculatePath(map, *this, nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 141 | RoutingTable::calculateHypRoutingTable(Nlsr& nlsr, bool isDryRun) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | { |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 143 | Map map; |
Nick Gordon | 22b5c95 | 2017-08-10 17:48:15 -0500 | [diff] [blame] | 144 | map.createFromCoordinateLsdb(nlsr.getLsdb().getCoordinateLsdb().begin(), |
| 145 | nlsr.getLsdb().getCoordinateLsdb().end()); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 146 | map.writeLog(); |
| 147 | |
| 148 | size_t nRouters = map.getMapSize(); |
| 149 | |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 150 | HyperbolicRoutingCalculator calculator(nRouters, isDryRun, |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 151 | nlsr.getConfParameter().getRouterPrefix()); |
| 152 | |
Saurab Dulal | 72b2b25 | 2019-01-22 16:58:08 -0600 | [diff] [blame^] | 153 | calculator.calculatePath(map, *this, nlsr.getLsdb(), nlsr.getAdjacencyList()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void |
| 157 | RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr) |
| 158 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 159 | if (pnlsr.getIsRouteCalculationScheduled() != true) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 160 | NLSR_LOG_DEBUG("Scheduling routing table calculation in " << m_routingCalcInterval); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 161 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 162 | m_scheduler.scheduleEvent(m_routingCalcInterval, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 163 | std::bind(&RoutingTable::calculate, this, std::ref(pnlsr))); |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 164 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 165 | pnlsr.setIsRouteCalculationScheduled(true); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 170 | routingTableEntryCompare(RoutingTableEntry& rte, ndn::Name& destRouter) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 171 | { |
| 172 | return rte.getDestination() == destRouter; |
| 173 | } |
| 174 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 175 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 176 | RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 178 | NLSR_LOG_DEBUG("Adding " << nh << " for destination: " << destRouter); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 179 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 180 | RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 181 | if (rteChk == 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 182 | RoutingTableEntry rte(destRouter); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 183 | rte.getNexthopList().addNextHop(nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 184 | m_rTable.push_back(rte); |
| 185 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 186 | else { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 187 | rteChk->getNexthopList().addNextHop(nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 191 | RoutingTableEntry* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 192 | RoutingTable::findRoutingTableEntry(const ndn::Name& destRouter) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | { |
| 194 | std::list<RoutingTableEntry>::iterator it = std::find_if(m_rTable.begin(), |
| 195 | m_rTable.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 196 | std::bind(&routingTableEntryCompare, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 197 | _1, destRouter)); |
| 198 | if (it != m_rTable.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 199 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 200 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 201 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 205 | RoutingTable::writeLog(int hyperbolicState) |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 206 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 207 | NLSR_LOG_DEBUG("---------------Routing Table------------------"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 208 | for (std::list<RoutingTableEntry>::iterator it = m_rTable.begin() ; |
| 209 | it != m_rTable.end(); ++it) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 210 | NLSR_LOG_DEBUG("Destination: " << (*it).getDestination()); |
| 211 | NLSR_LOG_DEBUG("Nexthops: "); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 212 | (*it).getNexthopList().writeLog(); |
| 213 | } |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 214 | |
| 215 | if (hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 216 | NLSR_LOG_DEBUG("--------Hyperbolic Routing Table(Dry)---------"); |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 217 | for (std::list<RoutingTableEntry>::iterator it = m_dryTable.begin() ; |
| 218 | it != m_dryTable.end(); ++it) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 219 | NLSR_LOG_DEBUG("Destination: " << (*it).getDestination()); |
| 220 | NLSR_LOG_DEBUG("Nexthops: "); |
akmhoque | dcee936 | 2014-08-05 22:58:01 -0500 | [diff] [blame] | 221 | (*it).getNexthopList().writeLog(); |
| 222 | } |
| 223 | } |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 224 | } |
| 225 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 226 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 227 | RoutingTable::addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 229 | NLSR_LOG_DEBUG("Adding " << nh << " to dry table for destination: " << destRouter); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 230 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 231 | std::list<RoutingTableEntry>::iterator it = std::find_if(m_dryTable.begin(), |
| 232 | m_dryTable.end(), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 233 | std::bind(&routingTableEntryCompare, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 234 | _1, destRouter)); |
| 235 | if (it == m_dryTable.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 236 | RoutingTableEntry rte(destRouter); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 237 | rte.getNexthopList().addNextHop(nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 238 | m_dryTable.push_back(rte); |
| 239 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 240 | else { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 241 | (*it).getNexthopList().addNextHop(nh); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 246 | RoutingTable::clearRoutingTable() |
| 247 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 248 | if (m_rTable.size() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 249 | m_rTable.clear(); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | RoutingTable::clearDryRoutingTable() |
| 255 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 256 | if (m_dryTable.size() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 257 | m_dryTable.clear(); |
| 258 | } |
| 259 | } |
| 260 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 261 | } // namespace nlsr |