Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 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/>. |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 20 | **/ |
| 21 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 22 | #include "test-common.hpp" |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 23 | #include "control-commands.hpp" |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 24 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 25 | #include "nlsr.hpp" |
| 26 | |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 27 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 33 | using std::shared_ptr; |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 34 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 35 | class NlsrFixture : public UnitTestTimeFixture |
| 36 | { |
| 37 | public: |
| 38 | NlsrFixture() |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 39 | : face(std::make_shared<ndn::util::DummyClientFace>(g_ioService)) |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 40 | , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 41 | , lsdb(nlsr.getLsdb()) |
| 42 | , neighbors(nlsr.getAdjacencyList()) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver) |
| 48 | { |
| 49 | ndn::Name dataName(sender); |
| 50 | dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion(); |
| 51 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 52 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(dataName); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 53 | |
| 54 | nlsr.m_helloProtocol.onContentValidated(data); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 55 | } |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 56 | |
| 57 | public: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 58 | std::shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 59 | Nlsr nlsr; |
| 60 | Lsdb& lsdb; |
| 61 | AdjacencyList& neighbors; |
| 62 | }; |
| 63 | |
| 64 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture) |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 65 | |
| 66 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 67 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 68 | // Simulate loading configuration file |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 69 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 70 | neighbors.insert(neighborA); |
| 71 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 72 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 73 | neighbors.insert(neighborB); |
| 74 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 75 | Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 76 | neighbors.insert(neighborC); |
| 77 | |
| 78 | nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 79 | nlsr.getConfParameter().setNetwork(ndn::Name("/test")); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 80 | |
| 81 | nlsr.initialize(); |
| 82 | |
| 83 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 84 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 85 | BOOST_CHECK_EQUAL(it->getLinkCost(), 0); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 90 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 91 | // Simulate loading configuration file |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 92 | Adjacent neighborA("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 93 | neighbors.insert(neighborA); |
| 94 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 95 | Adjacent neighborB("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 96 | neighbors.insert(neighborB); |
| 97 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 98 | Adjacent neighborC("/ndn/neighborC", ndn::util::FaceUri("udp4://10.0.0.3"), 17, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 99 | neighbors.insert(neighborC); |
| 100 | |
| 101 | nlsr.initialize(); |
| 102 | |
| 103 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 104 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 105 | BOOST_CHECK(it->getLinkCost() != 0); |
| 106 | } |
| 107 | } |
| 108 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 109 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 110 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 111 | // Simulate loading configuration file |
| 112 | ConfParameter& conf = nlsr.getConfParameter(); |
| 113 | conf.setAdjLsaBuildInterval(3); |
| 114 | conf.setFirstHelloInterval(6); |
| 115 | conf.setRoutingCalcInterval(9); |
| 116 | |
| 117 | nlsr.initialize(); |
| 118 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 119 | const Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 120 | const RoutingTable& rt = nlsr.getRoutingTable(); |
| 121 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6); |
| 124 | BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9)); |
| 125 | } |
| 126 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 127 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, UnitTestTimeFixture) |
| 128 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 129 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 130 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 131 | Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 132 | |
| 133 | // Simulate loading configuration file |
| 134 | ConfParameter& conf = nlsr.getConfParameter(); |
| 135 | conf.setNetwork("/ndn"); |
| 136 | conf.setSiteName("/site"); |
| 137 | conf.setRouterName("/%C1.router/this-router"); |
| 138 | conf.setAdjLsaBuildInterval(0); |
| 139 | conf.setRoutingCalcInterval(0); |
| 140 | |
| 141 | // Add active neighbors |
| 142 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 143 | uint64_t destroyFaceId = 128; |
| 144 | |
| 145 | // Create a neighbor whose Face will be destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 146 | Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_ACTIVE, 0, |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 147 | destroyFaceId); |
| 148 | neighbors.insert(failNeighbor); |
| 149 | |
| 150 | // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 151 | Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 152 | neighbors.insert(otherNeighbor); |
| 153 | |
| 154 | nlsr.initialize(); |
| 155 | |
| 156 | // Simulate successful HELLO responses |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 157 | lsdb.scheduleAdjLsaBuild(); |
| 158 | |
| 159 | // Set up adjacency LSAs |
| 160 | // This router |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 161 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.3"), 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 162 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 163 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 164 | lsdb.installAdjLsa(ownAdjLsa); |
| 165 | |
| 166 | // Router that will fail |
| 167 | AdjacencyList failAdjacencies; |
| 168 | failAdjacencies.insert(thisRouter); |
| 169 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 170 | AdjLsa failAdjLsa("/ndn/neighborA", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 171 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, failAdjacencies); |
| 172 | |
| 173 | lsdb.installAdjLsa(failAdjLsa); |
| 174 | |
| 175 | // Other router |
| 176 | AdjacencyList otherAdjacencies; |
| 177 | otherAdjacencies.insert(thisRouter); |
| 178 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 179 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 180 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 181 | |
| 182 | lsdb.installAdjLsa(otherAdjLsa); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 183 | |
| 184 | // Run the scheduler to build an adjacency LSA |
| 185 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 186 | |
| 187 | // Make sure an adjacency LSA was built |
| 188 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 189 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 190 | BOOST_REQUIRE(lsa != nullptr); |
| 191 | |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 192 | uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 193 | nlsr.getLsdb().getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 194 | |
| 195 | // Make sure the routing table was calculated |
| 196 | RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 197 | BOOST_REQUIRE(rtEntry != nullptr); |
| 198 | BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().getSize(), 1); |
| 199 | |
| 200 | // Receive FaceEventDestroyed notification |
| 201 | ndn::nfd::FaceEventNotification event; |
| 202 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 203 | .setFaceId(destroyFaceId); |
| 204 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 205 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 206 | data->setContent(event.wireEncode()); |
| 207 | nlsr.getKeyChain().sign(*data); |
| 208 | |
| 209 | face->receive(*data); |
| 210 | |
| 211 | // Run the scheduler to build an adjacency LSA |
| 212 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 213 | |
| 214 | Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName()); |
| 215 | |
| 216 | BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0); |
| 217 | BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(), |
| 218 | nlsr.getConfParameter().getInterestRetryNumber()); |
| 219 | BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 220 | |
| 221 | lsa = lsdb.findAdjLsa(key); |
| 222 | BOOST_REQUIRE(lsa != nullptr); |
| 223 | |
| 224 | BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 225 | |
| 226 | // Make sure the routing table was recalculated |
| 227 | rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 228 | BOOST_CHECK(rtEntry == nullptr); |
| 229 | } |
| 230 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 231 | // Bug #2733 |
| 232 | // This test checks that when a face for an inactive node is destroyed, an |
| 233 | // Adjacency LSA build does not postpone the LSA refresh and cause RIB |
| 234 | // entries for other nodes' name prefixes to not be refreshed. |
| 235 | // |
| 236 | // This test is invalid when Issue #2732 is implemented since an Adjacency LSA |
| 237 | // refresh will not cause RIB entries for other nodes' name prefixes to be refreshed. |
| 238 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEventInactive, UnitTestTimeFixture) |
| 239 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 240 | std::shared_ptr<ndn::util::DummyClientFace> face = std::make_shared<ndn::util::DummyClientFace>(g_ioService); |
| 241 | Nlsr nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 242 | Lsdb& lsdb = nlsr.getLsdb(); |
| 243 | |
| 244 | // Simulate loading configuration file |
| 245 | ConfParameter& conf = nlsr.getConfParameter(); |
| 246 | conf.setNetwork("/ndn"); |
| 247 | conf.setSiteName("/site"); |
| 248 | conf.setRouterName("/%C1.router/this-router"); |
| 249 | conf.setFirstHelloInterval(0); |
| 250 | conf.setAdjLsaBuildInterval(0); |
| 251 | conf.setRoutingCalcInterval(0); |
| 252 | |
| 253 | // Add neighbors |
| 254 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
| 255 | |
| 256 | uint64_t destroyFaceId = 128; |
| 257 | |
| 258 | // Create an inactive neighbor whose Face will be destroyed |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 259 | Adjacent failNeighbor("/ndn/neighborA", ndn::util::FaceUri("udp4://10.0.0.1"), 10, Adjacent::STATUS_INACTIVE, 3, |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 260 | destroyFaceId); |
| 261 | neighbors.insert(failNeighbor); |
| 262 | |
| 263 | // Create an additional active neighbor so an adjacency LSA can be built |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 264 | Adjacent otherNeighbor("/ndn/neighborB", ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 265 | neighbors.insert(otherNeighbor); |
| 266 | |
| 267 | // Add a name for the neighbor to advertise |
| 268 | NamePrefixList nameList; |
| 269 | ndn::Name nameToAdvertise("/ndn/neighborB/name"); |
| 270 | nameList.insert(nameToAdvertise); |
| 271 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 272 | NameLsa nameLsa("/ndn/neighborB", 25, ndn::time::system_clock::now(), nameList); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 273 | lsdb.installNameLsa(nameLsa); |
| 274 | |
| 275 | nlsr.initialize(); |
| 276 | |
| 277 | // Simulate successful HELLO responses from neighbor B |
| 278 | lsdb.scheduleAdjLsaBuild(); |
| 279 | |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 280 | // Set up adjacency LSAs |
| 281 | // This router |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 282 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::util::FaceUri("udp4://10.0.0.2"), 25, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 283 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 284 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 285 | lsdb.installAdjLsa(ownAdjLsa); |
| 286 | |
| 287 | // Other ACTIVE router |
| 288 | AdjacencyList otherAdjacencies; |
| 289 | otherAdjacencies.insert(thisRouter); |
| 290 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 291 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 292 | ndn::time::system_clock::now() + ndn::time::seconds(3600), 1, otherAdjacencies); |
| 293 | |
| 294 | lsdb.installAdjLsa(otherAdjLsa); |
| 295 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 296 | // Run the scheduler to build an adjacency LSA |
| 297 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 298 | |
| 299 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 300 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
| 301 | BOOST_REQUIRE(lsa != nullptr); |
| 302 | |
| 303 | // Cancel previous LSA expiration event |
| 304 | g_scheduler.cancelEvent(lsa->getExpiringEventId()); |
| 305 | |
| 306 | // Set expiration time for own Adjacency LSA to earlier value for unit-test |
| 307 | // |
| 308 | // Expiration time is negative to offset the GRACE_PERIOD (10 seconds) automatically applied |
| 309 | // to expiration times |
| 310 | ndn::EventId id = lsdb.scheduleAdjLsaExpiration(key, lsa->getLsSeqNo(), -ndn::time::seconds(9)); |
| 311 | lsa->setExpiringEventId(id); |
| 312 | |
| 313 | // Generate a FaceEventDestroyed notification |
| 314 | ndn::nfd::FaceEventNotification event; |
| 315 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 316 | .setFaceId(destroyFaceId); |
| 317 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 318 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 319 | data->setContent(event.wireEncode()); |
| 320 | nlsr.getKeyChain().sign(*data); |
| 321 | |
| 322 | // Receive the FaceEventDestroyed notification |
| 323 | face->receive(*data); |
| 324 | |
| 325 | // Run the scheduler to expire the Adjacency LSA. The expiration should refresh the RIB |
| 326 | // entries associated with Neighbor B's advertised prefix. |
| 327 | face->sentInterests.clear(); |
| 328 | this->advanceClocks(ndn::time::seconds(1)); |
| 329 | |
| 330 | // The Face should have two sent Interests: the face event and a RIB registration |
| 331 | BOOST_REQUIRE(face->sentInterests.size() > 0); |
| 332 | const ndn::Interest& interest = face->sentInterests.back(); |
| 333 | |
| 334 | ndn::nfd::ControlParameters parameters; |
| 335 | ndn::Name::Component verb; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 336 | BOOST_REQUIRE_NO_THROW(extractRibCommandParameters(interest, |
| 337 | verb, |
| 338 | parameters)); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(verb, ndn::Name::Component("register")); |
| 340 | BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise); |
| 341 | } |
| 342 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 343 | BOOST_AUTO_TEST_CASE(GetCertificate) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 344 | { |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 345 | // Create certificate |
| 346 | ndn::Name identity("/TestNLSR/identity"); |
| 347 | identity.appendVersion(); |
| 348 | |
| 349 | ndn::KeyChain keyChain; |
| 350 | keyChain.createIdentity(identity); |
| 351 | ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 352 | std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 353 | |
| 354 | const ndn::Name certKey = certificate->getName().getPrefix(-1); |
| 355 | |
| 356 | BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr); |
| 357 | |
| 358 | // Certificate should be retrievable from the CertificateStore |
| 359 | nlsr.loadCertToPublish(certificate); |
| 360 | |
| 361 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 362 | |
| 363 | nlsr.getCertificateStore().clear(); |
| 364 | |
| 365 | // Certificate should be retrievable from the cache |
| 366 | nlsr.addCertificateToCache(certificate); |
| 367 | this->advanceClocks(ndn::time::milliseconds(10)); |
| 368 | |
| 369 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 370 | } |
| 371 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 372 | BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix) |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 373 | { |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 374 | // Simulate loading configuration file |
| 375 | ConfParameter& conf = nlsr.getConfParameter(); |
| 376 | conf.setNetwork("/ndn"); |
| 377 | conf.setSiteName("/site"); |
| 378 | conf.setRouterName("/%C1.router/this-router"); |
| 379 | |
| 380 | nlsr.initialize(); |
| 381 | |
| 382 | BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(), |
| 383 | ndn::Name("/ndn/site/%C1.router/this-router/lsdb")); |
| 384 | } |
| 385 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 386 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 387 | { |
| 388 | // Configure NLSR |
| 389 | ConfParameter& conf = nlsr.getConfParameter(); |
| 390 | conf.setNetwork("/ndn"); |
| 391 | conf.setSiteName("/site"); |
| 392 | |
| 393 | ndn::Name routerName("/%C1.Router/this-router"); |
| 394 | conf.setRouterName(routerName); |
| 395 | |
| 396 | conf.setAdjLsaBuildInterval(1); |
| 397 | |
| 398 | // Add neighbors |
| 399 | // Router A |
| 400 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 401 | Adjacent neighborA(neighborAName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 402 | neighbors.insert(neighborA); |
| 403 | |
| 404 | // Router B |
| 405 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 406 | Adjacent neighborB(neighborBName, ndn::util::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 407 | neighbors.insert(neighborB); |
| 408 | |
| 409 | nlsr.initialize(); |
| 410 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 411 | |
| 412 | // Receive HELLO response from Router A |
| 413 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 414 | this->advanceClocks(ndn::time::seconds(1)); |
| 415 | |
| 416 | ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING); |
| 417 | |
| 418 | // Adjacency LSA should be built even though other router is INACTIVE |
| 419 | AdjLsa* lsa = lsdb.findAdjLsa(lsaKey); |
| 420 | BOOST_REQUIRE(lsa != nullptr); |
| 421 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1); |
| 422 | |
| 423 | // Receive HELLO response from Router B |
| 424 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 425 | |
| 426 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 427 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 428 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 429 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 430 | } |
| 431 | |
| 432 | this->advanceClocks(ndn::time::seconds(1)); |
| 433 | |
| 434 | // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE |
| 435 | // and have timed out |
| 436 | lsa = lsdb.findAdjLsa(lsaKey); |
| 437 | BOOST_CHECK(lsa == nullptr); |
| 438 | |
| 439 | // Receive HELLO response from Router A and B |
| 440 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 441 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 442 | this->advanceClocks(ndn::time::seconds(1)); |
| 443 | |
| 444 | // Adjacency LSA should be built |
| 445 | lsa = lsdb.findAdjLsa(lsaKey); |
| 446 | BOOST_REQUIRE(lsa != nullptr); |
| 447 | BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2); |
| 448 | } |
| 449 | |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 450 | BOOST_AUTO_TEST_CASE(CanonizeUris) |
| 451 | { |
| 452 | ndn::Name neighborAName("/ndn/site/%C1.router/routerA"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 453 | ndn::util::FaceUri faceUriA("udp://10.0.0.1"); |
| 454 | Adjacent neighborA(neighborAName, faceUriA, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 455 | neighbors.insert(neighborA); |
| 456 | |
| 457 | ndn::Name neighborBName("/ndn/site/%C1.router/routerB"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 458 | ndn::util::FaceUri faceUriB("udp://10.0.0.2"); |
| 459 | Adjacent neighborB(neighborBName, faceUriB, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 460 | neighbors.insert(neighborB); |
| 461 | |
| 462 | int nCanonizationsLeft = nlsr.getAdjacencyList().getAdjList().size(); |
| 463 | std::function<void(std::list<Adjacent>::iterator)> thenCallback = |
| 464 | [this, &thenCallback, &nCanonizationsLeft] (std::list<Adjacent>::iterator iterator) { |
| 465 | nCanonizationsLeft--; |
| 466 | nlsr.canonizeNeighborUris(iterator, thenCallback); |
| 467 | }; |
| 468 | nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(), |
| 469 | [thenCallback] (std::list<Adjacent>::iterator iterator) { |
| 470 | thenCallback(iterator); |
| 471 | }); |
| 472 | while (nCanonizationsLeft != 0) { |
| 473 | this->advanceClocks(ndn::time::milliseconds(1)); |
| 474 | } |
| 475 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 476 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborAName).getFaceUri(), |
| 477 | ndn::util::FaceUri("udp4://10.0.0.1:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 478 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 479 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborBName).getFaceUri(), |
| 480 | ndn::util::FaceUri("udp4://10.0.0.2:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 481 | } |
| 482 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 483 | BOOST_AUTO_TEST_SUITE_END() |
| 484 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 485 | } // namespace test |
| 486 | } // namespace nlsr |