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 | /* |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, 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" |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 23 | #include "route/fib.hpp" |
| 24 | #include "route/routing-table.hpp" |
| 25 | #include "lsdb.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 26 | #include "../test-common.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 27 | |
| 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
| 33 | class NamePrefixTableFixture : public UnitTestTimeFixture |
| 34 | { |
| 35 | public: |
| 36 | NamePrefixTableFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 37 | : face(m_ioService, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 38 | , conf(face, m_keyChain) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 39 | , confProcessor(conf) |
| 40 | , lsdb(face, m_keyChain, conf) |
| 41 | , fib(face, m_scheduler, conf.getAdjacencyList(), conf, m_keyChain) |
| 42 | , rt(m_scheduler, lsdb, conf) |
| 43 | , npt(conf.getRouterPrefix(), fib, rt, rt.afterRoutingChange, lsdb.onLsdbModified) |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 44 | { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 47 | bool |
| 48 | isNameInNpt(const ndn::Name& name) |
| 49 | { |
| 50 | auto it = std::find_if(npt.begin(), npt.end(), |
| 51 | [&] (const auto& entry) { return name == entry->getNamePrefix(); }); |
| 52 | return it != npt.end(); |
| 53 | } |
| 54 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 55 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 56 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 57 | ConfParameter conf; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 58 | DummyConfFileProcessor confProcessor; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 59 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 60 | Lsdb lsdb; |
| 61 | Fib fib; |
| 62 | RoutingTable rt; |
| 63 | NamePrefixTable npt; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE(TestNamePrefixTable) |
| 67 | |
| 68 | BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture) |
| 69 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 70 | rt.m_routingCalcInterval = 0_s; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 71 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 72 | 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] | 73 | |
| 74 | ndn::Name buptRouterName("/ndn/cn/edu/bupt/%C1.Router/bupthub"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 75 | 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] | 76 | |
| 77 | // This router's Adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 78 | conf.getAdjacencyList().insert(bupt); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 79 | AdjLsa thisRouterAdjLsa(thisRouter.getName(), 1, |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 80 | ndn::time::system_clock::now() + 3600_s, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 81 | 2, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 82 | conf.getAdjacencyList()); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 83 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 84 | lsdb.installLsa(std::make_shared<AdjLsa>(thisRouterAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 85 | |
| 86 | // BUPT Adjacency LSA |
| 87 | AdjacencyList buptAdjacencies; |
| 88 | buptAdjacencies.insert(thisRouter); |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 89 | AdjLsa buptAdjLsa(buptRouterName, 1, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 90 | ndn::time::system_clock::now() + ndn::time::seconds(5), |
| 91 | 0 , buptAdjacencies); |
| 92 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 93 | lsdb.installLsa(std::make_shared<AdjLsa>(buptAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 94 | |
| 95 | // BUPT Name LSA |
| 96 | ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt"); |
| 97 | |
Nick Gordon | 96861ca | 2017-10-17 18:25:21 -0500 | [diff] [blame] | 98 | NamePrefixList buptNames{buptAdvertisedName}; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 99 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 100 | 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] | 101 | buptNames); |
| 102 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 103 | lsdb.installLsa(std::make_shared<NameLsa>(buptNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 104 | |
| 105 | // Advance clocks to expire LSAs |
| 106 | this->advanceClocks(ndn::time::seconds(15)); |
| 107 | |
| 108 | // LSA expirations should cause NPT entries to be completely removed |
| 109 | NamePrefixTable::const_iterator it = npt.begin(); |
| 110 | BOOST_REQUIRE(it == npt.end()); |
| 111 | |
| 112 | // Install new name LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 113 | NameLsa buptNewNameLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 114 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 115 | buptNames); |
| 116 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 117 | lsdb.installLsa(std::make_shared<NameLsa>(buptNewNameLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 118 | |
| 119 | this->advanceClocks(ndn::time::seconds(1)); |
| 120 | |
| 121 | // Install new adjacency LSA |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 122 | AdjLsa buptNewAdjLsa(buptRouterName, 12, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 123 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 124 | 0, buptAdjacencies); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 125 | lsdb.installLsa(std::make_shared<AdjLsa>(buptNewAdjLsa)); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 126 | |
| 127 | this->advanceClocks(ndn::time::seconds(1)); |
| 128 | |
| 129 | // Each NPT entry should have a destination router |
| 130 | it = npt.begin(); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 131 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptRouterName); |
| 132 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 133 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 134 | |
| 135 | ++it; |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 136 | BOOST_REQUIRE_EQUAL((*it)->getNamePrefix(), buptAdvertisedName); |
| 137 | BOOST_REQUIRE_EQUAL((*it)->getRteList().size(), 1); |
| 138 | BOOST_CHECK_EQUAL((*(*it)->getRteList().begin())->getDestination(), buptRouterName); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | BOOST_FIXTURE_TEST_CASE(AddEntryToPool, NamePrefixTableFixture) |
| 142 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 143 | RoutingTablePoolEntry rtpe1("router1"); |
| 144 | |
| 145 | npt.addRtpeToPool(rtpe1); |
| 146 | |
| 147 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
| 148 | BOOST_CHECK_EQUAL(*(npt.m_rtpool.find("router1")->second), rtpe1); |
| 149 | } |
| 150 | |
| 151 | BOOST_FIXTURE_TEST_CASE(RemoveEntryFromPool, NamePrefixTableFixture) |
| 152 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 153 | RoutingTablePoolEntry rtpe1("router1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 154 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 155 | |
| 156 | npt.addRtpeToPool(rtpe1); |
| 157 | |
| 158 | npt.deleteRtpeFromPool(rtpePtr); |
| 159 | |
| 160 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 0); |
| 161 | BOOST_CHECK_EQUAL(npt.m_rtpool.count("router1"), 0); |
| 162 | } |
| 163 | |
| 164 | BOOST_FIXTURE_TEST_CASE(AddRoutingEntryToNptEntry, NamePrefixTableFixture) |
| 165 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 166 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 167 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = npt.addRtpeToPool(rtpe1); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 168 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
| 169 | |
| 170 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 171 | |
| 172 | NamePrefixTable::NptEntryList::iterator nItr = |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 173 | std::find_if(npt.m_table.begin(), |
| 174 | npt.m_table.end(), |
| 175 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 176 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 177 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 178 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 179 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 180 | std::list<std::shared_ptr<RoutingTablePoolEntry>>::iterator rItr = |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 181 | std::find(rtpeList.begin(), |
| 182 | rtpeList.end(), |
| 183 | rtpePtr); |
| 184 | BOOST_CHECK_EQUAL(**rItr, *rtpePtr); |
| 185 | } |
| 186 | |
| 187 | BOOST_FIXTURE_TEST_CASE(RemoveRoutingEntryFromNptEntry, NamePrefixTableFixture) |
| 188 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 189 | RoutingTablePoolEntry rtpe1("/ndn/memphis/rtr1", 0); |
| 190 | |
| 191 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 192 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 193 | |
| 194 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 195 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/altrtr"); |
| 196 | |
| 197 | npt.removeEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 198 | |
| 199 | NamePrefixTable::NptEntryList::iterator nItr = |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 200 | std::find_if(npt.m_table.begin(), |
| 201 | npt.m_table.end(), |
| 202 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 203 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 204 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 205 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 206 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 207 | |
| 208 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 209 | BOOST_CHECK_EQUAL(npt.m_rtpool.size(), 1); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 212 | BOOST_FIXTURE_TEST_CASE(AddNptEntryPtrToRoutingEntry, NamePrefixTableFixture) |
| 213 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 214 | NamePrefixTableEntry npte1("/ndn/memphis/rtr2"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 215 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 216 | |
| 217 | npt.addEntry("/ndn/memphis/rtr2", "/ndn/memphis/rtr1"); |
| 218 | |
| 219 | NamePrefixTable::NptEntryList::iterator nItr = |
| 220 | std::find_if(npt.m_table.begin(), |
| 221 | npt.m_table.end(), |
| 222 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 223 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 224 | }); |
| 225 | |
| 226 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 227 | |
| 228 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 229 | |
| 230 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 231 | |
| 232 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 233 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 234 | auto nptSharedPtr = nptIterator->second.lock(); |
| 235 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 236 | } |
| 237 | |
| 238 | BOOST_FIXTURE_TEST_CASE(RemoveNptEntryPtrFromRoutingEntry, NamePrefixTableFixture) |
| 239 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 240 | NamePrefixTableEntry npte1("/ndn/memphis/rtr1"); |
| 241 | NamePrefixTableEntry npte2("/ndn/memphis/rtr2"); |
| 242 | RoutingTableEntry rte1("/ndn/memphis/destination1"); |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 243 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte1)); |
| 244 | npt.m_table.push_back(std::make_shared<NamePrefixTableEntry>(npte2)); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 245 | |
| 246 | npt.addEntry(npte1.getNamePrefix(), rte1.getDestination()); |
| 247 | // We have to add two entries, otherwise the routing pool entry will be deleted. |
| 248 | npt.addEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 249 | npt.removeEntry(npte2.getNamePrefix(), rte1.getDestination()); |
| 250 | |
| 251 | NamePrefixTable::NptEntryList::iterator nItr = |
| 252 | std::find_if(npt.m_table.begin(), |
| 253 | npt.m_table.end(), |
| 254 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 255 | return entry->getNamePrefix() == npte1.getNamePrefix(); |
| 256 | }); |
| 257 | |
| 258 | std::list<std::shared_ptr<RoutingTablePoolEntry>> rtpeList = (*nItr)->getRteList(); |
| 259 | |
| 260 | BOOST_CHECK_EQUAL(rtpeList.size(), 1); |
| 261 | |
| 262 | auto& namePrefixPtrs = rtpeList.front()->namePrefixTableEntries; |
| 263 | |
| 264 | // We should have removed the second one |
| 265 | BOOST_CHECK_EQUAL(namePrefixPtrs.size(), 1); |
| 266 | |
| 267 | auto nptIterator = namePrefixPtrs.find(npte1.getNamePrefix()); |
| 268 | |
| 269 | BOOST_REQUIRE(nptIterator != namePrefixPtrs.end()); |
| 270 | auto nptSharedPtr = nptIterator->second.lock(); |
| 271 | BOOST_CHECK_EQUAL(*nptSharedPtr, npte1); |
| 272 | } |
| 273 | |
| 274 | BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture) |
| 275 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 276 | const ndn::Name destination = ndn::Name{"/ndn/destination1"}; |
| 277 | NextHop hop1{"upd4://10.0.0.1", 0}; |
| 278 | NextHop hop2{"udp4://10.0.0.2", 1}; |
| 279 | NextHop hop3{"udp4://10.0.0.3", 2}; |
| 280 | const NamePrefixTableEntry entry1{"/ndn/router1"}; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 281 | npt.addEntry(entry1.getNamePrefix(), destination); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 282 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 283 | rt.addNextHop(destination, hop1); |
| 284 | rt.addNextHop(destination, hop2); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 285 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 286 | npt.updateWithNewRoute(rt.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 287 | |
| 288 | // At this point the NamePrefixTableEntry should have two NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 289 | auto nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 290 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 291 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 292 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 293 | BOOST_REQUIRE(nameIterator != npt.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 294 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 295 | auto iterator = npt.m_rtpool.find(destination); |
| 296 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 297 | auto nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(nextHops.size(), 2); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 299 | |
| 300 | // Add the other NextHop |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 301 | rt.addNextHop(destination, hop3); |
| 302 | npt.updateWithNewRoute(rt.m_rTable); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 303 | |
| 304 | // At this point the NamePrefixTableEntry should have three NextHops. |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 305 | nameIterator = std::find_if(npt.begin(), npt.end(), |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 306 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 307 | return entry1.getNamePrefix() == entry->getNamePrefix(); |
| 308 | }); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 309 | BOOST_REQUIRE(nameIterator != npt.end()); |
| 310 | iterator = npt.m_rtpool.find(destination); |
| 311 | BOOST_REQUIRE(iterator != npt.m_rtpool.end()); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 312 | nextHops = (iterator->second)->getNexthopList(); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 313 | BOOST_CHECK_EQUAL(nextHops.size(), 3); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 316 | BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture) |
| 317 | { |
| 318 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
| 319 | NamePrefixList npl1; |
| 320 | ndn::Name n1("name1"); |
| 321 | ndn::Name n2("name2"); |
| 322 | ndn::Name router1("/router1/1"); |
| 323 | |
| 324 | npl1.insert(n1); |
| 325 | npl1.insert(n2); |
| 326 | |
| 327 | NameLsa nlsa1(router1, 12, testTimePoint, npl1); |
| 328 | std::shared_ptr<Lsa> lsaPtr = std::make_shared<NameLsa>(nlsa1); |
| 329 | |
| 330 | BOOST_CHECK(npt.begin() == npt.end()); |
| 331 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 332 | BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Router + 2 names |
| 333 | |
| 334 | BOOST_CHECK(isNameInNpt(n1)); |
| 335 | BOOST_CHECK(isNameInNpt(n2)); |
| 336 | |
| 337 | ndn::Name n3("name3"); |
| 338 | auto nlsa = std::static_pointer_cast<NameLsa>(lsaPtr); |
| 339 | nlsa->removeName(n2); |
| 340 | nlsa->addName(n3); |
| 341 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::UPDATED, {n3}, {n2}); |
| 342 | BOOST_CHECK(isNameInNpt(n1)); |
| 343 | BOOST_CHECK(!isNameInNpt(n2)); // Removed |
| 344 | BOOST_CHECK(isNameInNpt(n3)); |
| 345 | |
| 346 | BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Still router + 2 names |
| 347 | |
| 348 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 349 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 350 | |
| 351 | // Adj and Coordinate LSAs router |
| 352 | ndn::Name router2("/router2/2"); |
| 353 | AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList()); |
| 354 | lsaPtr = std::make_shared<AdjLsa>(adjLsa); |
| 355 | BOOST_CHECK(npt.begin() == npt.end()); |
| 356 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 357 | BOOST_CHECK_EQUAL(npt.m_table.size(), 1); |
| 358 | BOOST_CHECK(isNameInNpt(router2)); |
| 359 | |
| 360 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 361 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 362 | |
| 363 | ndn::Name router3("/router3/3"); |
| 364 | CoordinateLsa corLsa(router3, 12, testTimePoint, 2, {3}); |
| 365 | lsaPtr = std::make_shared<CoordinateLsa>(corLsa); |
| 366 | BOOST_CHECK(npt.begin() == npt.end()); |
| 367 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {}); |
| 368 | BOOST_CHECK_EQUAL(npt.m_table.size(), 1); |
| 369 | BOOST_CHECK(isNameInNpt(router3)); |
| 370 | |
| 371 | npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {}); |
| 372 | BOOST_CHECK_EQUAL(npt.m_table.size(), 0); |
| 373 | } |
| 374 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 375 | BOOST_AUTO_TEST_SUITE_END() |
| 376 | |
| 377 | } // namespace test |
| 378 | } // namespace nlsr |