Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 2 | /* |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 21 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 22 | #include "route/name-prefix-table.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 23 | #include "nlsr.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 24 | #include "../test-common.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 25 | |
| 26 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 27 | |
| 28 | namespace nlsr { |
| 29 | namespace test { |
| 30 | |
| 31 | class NamePrefixTableFixture : public UnitTestTimeFixture |
| 32 | { |
| 33 | public: |
| 34 | NamePrefixTableFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 35 | : face(m_ioService, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 36 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 37 | , nlsr(face, m_keyChain, conf) |
| 38 | , lsdb(nlsr.m_lsdb) |
| 39 | , npt(nlsr.m_namePrefixTable) |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 40 | { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 44 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 45 | ConfParameter conf; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 46 | Nlsr nlsr; |
| 47 | |
| 48 | Lsdb& lsdb; |
| 49 | NamePrefixTable& npt; |
| 50 | }; |
| 51 | |
| 52 | BOOST_AUTO_TEST_SUITE(TestNamePrefixTable) |
| 53 | |
| 54 | BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture) |
| 55 | { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 56 | conf.setNetwork("/ndn"); |
| 57 | conf.setSiteName("/router"); |
| 58 | conf.setRouterName("/a"); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 59 | conf.buildRouterAndSyncUserPrefix(); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 60 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 61 | RoutingTable& routingTable = nlsr.m_routingTable; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 62 | routingTable.setRoutingCalcInterval(0); |
| 63 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 64 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 65 | |
| 66 | ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 67 | Adjacent bupt(buptRouterName, ndn::FaceUri("udp4://10.0.0.2"), 0, Adjacent::STATUS_ACTIVE, 0, 0); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 68 | |
| 69 | // This router's Adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 70 | conf.getAdjacencyList().insert(bupt); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 71 | AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1, |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 72 | ndn::time::system_clock::now() + 3600_s, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 73 | 2, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 74 | conf.getAdjacencyList()); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 75 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 76 | lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 77 | |
| 78 | // BUPT Adjacency LSA |
| 79 | AdjacencyList buptAdjacencies; |
| 80 | buptAdjacencies.insert(thisRouter); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 81 | AdjLsa buptAdjLsa(buptRouterName, 1, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 82 | ndn::time::system_clock::now() + ndn::time::seconds(5), |
| 83 | 0 , buptAdjacencies); |
| 84 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 85 | lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 86 | |
| 87 | // BUPT Name LSA |
| 88 | ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt"); |
| 89 | |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 90 | NamePrefixList buptNames{buptAdvertisedName}; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 91 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 92 | NameLsa buptNameLsa(buptRouterName, 1, ndn::time::system_clock::now() + ndn::time::seconds(5), |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 93 | buptNames); |
| 94 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 95 | lsdb.installLsa(std::make_shared<NameLsa>(buptNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 96 | |
| 97 | // Advance clocks to expire LSAs |
| 98 | this->advanceClocks(ndn::time::seconds(15)); |
| 99 | |
| 100 | // LSA expirations should cause NPT entries to be completely removed |
| 101 | NamePrefixTable::const_iterator it = npt.begin(); |
| 102 | BOOST_REQUIRE(it == npt.end()); |
| 103 | |
| 104 | // Install new name LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 105 | NameLsa buptNewNameLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 106 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 107 | buptNames); |
| 108 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 109 | lsdb.installLsa(std::make_shared<NameLsa>(buptNewNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 110 | |
| 111 | this->advanceClocks(ndn::time::seconds(1)); |
| 112 | |
| 113 | // Install new adjacency LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 114 | AdjLsa buptNewAdjLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 115 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 116 | 0, buptAdjacencies); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 117 | lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 118 | |
| 119 | this->advanceClocks(ndn::time::seconds(1)); |
| 120 | |
| 121 | // Each NPT entry should have a destination router |
| 122 | it = npt.begin(); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 123 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptRouterName); |
| 124 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 125 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 126 | |
| 127 | ++it; |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 128 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptAdvertisedName); |
| 129 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 130 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | BOOST_FIXTURE_TEST_CASE(AddEntryToPool, NamePrefixTableFixture) |
| 134 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 135 | RoutingTablePoolEntry rtpe1("router1"); |
| 136 | |
| 137 | npt.addRtpeToPool(rtpe1); |
| 138 | |
| 139 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
| 140 | BOOST_CHECK_EQUAL(*(npt.m_rtpool.find("router1")->second), rtpe1); |
| 141 | } |
| 142 | |
| 143 | BOOST_FIXTURE_TEST_CASE(RemoveEntryFromPool, NamePrefixTableFixture) |
| 144 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 145 | RoutingTablePoolEntry rtpe1("router1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 146 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 147 | |
| 148 | npt.addRtpeToPool(rtpe1); |
| 149 | |
| 150 | npt.deleteRtpeFromPool(rtpePtr); |
| 151 | |
| 152 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 0); |
| 153 | BOOST_CHECK_EQUAL(npt.m_rtpool.count("router1"), 0); |
| 154 | } |
| 155 | |
| 156 | BOOST_FIXTURE_TEST_CASE(AddRoutingEntryToNptEntry, NamePrefixTableFixture) |
| 157 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 158 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 159 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 160 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
| 161 | |
| 162 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 163 | |
| 164 | NamePrefixTable::NptEntryList::iterator nItr = |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 165 | std::find_if(npt.m_table.begin(), |
| 166 | npt.m_table.end(), |
| 167 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 168 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 169 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 170 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 171 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 172 | std::list<std::shared_ptr<RoutingTablePoolEntry>>::iterator rItr = |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 173 | std::find(rtpeList.begin(), |
| 174 | rtpeList.end(), |
| 175 | rtpePtr); |
| 176 | BOOST_CHECK_EQUAL(**rItr, *rtpePtr); |
| 177 | } |
| 178 | |
| 179 | BOOST_FIXTURE_TEST_CASE(RemoveRoutingEntryFromNptEntry, NamePrefixTableFixture) |
| 180 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 181 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
| 182 | |
| 183 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 184 | npt.m_table.push_back(make_shared<NamePrefixTableEntry>(npte1)); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 185 | |
| 186 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 187 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/altrtr"); |
| 188 | |
| 189 | npt.removeEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 190 | |
| 191 | NamePrefixTable::NptEntryList::iterator nItr = |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 192 | std::find_if(npt.m_table.begin(), |
| 193 | npt.m_table.end(), |
| 194 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 195 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 196 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 197 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 198 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 199 | |
| 200 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 201 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 202 | } |
| 203 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 204 | BOOST_FIXTURE_TEST_CASE(AddNptEntryPtrToRoutingEntry, NamePrefixTableFixture) |
| 205 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 206 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
| 207 | npt.m_table.push_back(make_shared<NamePrefixTableEntry>(npte1)); |
| 208 | |
| 209 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 210 | |
| 211 | NamePrefixTable::NptEntryList::iterator nItr = |
| 212 | std::find_if(npt.m_table.begin(), |
| 213 | npt.m_table.end(), |
| 214 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 215 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 216 | }); |
| 217 | |
| 218 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 219 | |
| 220 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 221 | |
| 222 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 223 | |
| 224 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 225 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 226 | auto nptSharedPtr = nptIterator->second.lock(); |
| 227 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 228 | } |
| 229 | |
| 230 | BOOST_FIXTURE_TEST_CASE(RemoveNptEntryPtrFromRoutingEntry, NamePrefixTableFixture) |
| 231 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 232 | NamePrefixTableEntry npte1("/ndn/memphis/rtr1"); |
| 233 | NamePrefixTableEntry npte2("/ndn/memphis/rtr2"); |
| 234 | RoutingTableEntry rte1("/ndn/memphis/destination1"); |
| 235 | npt.m_table.push_back(make_shared<NamePrefixTableEntry>(npte1)); |
| 236 | npt.m_table.push_back(make_shared<NamePrefixTableEntry>(npte2)); |
| 237 | |
| 238 | npt.addEntry(npte1.getNamePrefix(), rte1.getDestination()); |
| 239 | // We have to add two entries, otherwise the routing pool entry will be deleted. |
| 240 | npt.addEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 241 | npt.removeEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 242 | |
| 243 | NamePrefixTable::NptEntryList::iterator nItr = |
| 244 | std::find_if(npt.m_table.begin(), |
| 245 | npt.m_table.end(), |
| 246 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 247 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 248 | }); |
| 249 | |
| 250 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 251 | |
| 252 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 253 | |
| 254 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 255 | |
| 256 | // We should have removed the second one |
| 257 | BOOST_CHECK_EQUAL(namePrefixPtrs.size(), 1); |
| 258 | |
| 259 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 260 | |
| 261 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 262 | auto nptSharedPtr = nptIterator->second.lock(); |
| 263 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 264 | } |
| 265 | |
| 266 | BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture) |
| 267 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 268 | RoutingTable& routingTable = nlsr.m_routingTable; |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 269 | const ndn::Name destination = ndn::Name{"/ndn/destination1"}; |
| 270 | NextHop hop1{"upd4://10.0.0.1", 0}; |
| 271 | NextHop hop2{"udp4://10.0.0.2", 1}; |
| 272 | NextHop hop3{"udp4://10.0.0.3", 2}; |
| 273 | const NamePrefixTableEntry entry1{"/ndn/router1"}; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 274 | npt.addEntry(entry1.getNamePrefix(), destination); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 275 | |
| 276 | routingTable.addNextHop(destination, hop1); |
| 277 | routingTable.addNextHop(destination, hop2); |
| 278 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 279 | npt.updateWithNewRoute(routingTable.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 280 | |
| 281 | // At this point the NamePrefixTableEntry should have two NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 282 | auto nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 283 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 284 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 285 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 286 | BOOST_REQUIRE(nameIterator != npt.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 287 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 288 | auto iterator = npt.m_rtpool.find(destination); |
| 289 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 290 | auto nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(nextHops.size(), 2); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 292 | |
| 293 | // Add the other NextHop |
| 294 | routingTable.addNextHop(destination, hop3); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 295 | npt.updateWithNewRoute(routingTable.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 296 | |
| 297 | // At this point the NamePrefixTableEntry should have three NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 298 | nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 299 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 300 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 301 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 302 | BOOST_REQUIRE(nameIterator != npt.end()); |
| 303 | iterator = npt.m_rtpool.find(destination); |
| 304 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 305 | nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 306 | BOOST_CHECK_EQUAL(nextHops.size(), 3); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 309 | BOOST_AUTO_TEST_SUITE_END() |
| 310 | |
| 311 | } // namespace test |
| 312 | } // namespace nlsr |