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 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 22 | #include "nlsr.hpp" |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 23 | #include "test-common.hpp" |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 24 | #include "control-commands.hpp" |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 25 | #include "logger.hpp" |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 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 | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 28 | |
| 29 | namespace nlsr { |
| 30 | namespace test { |
| 31 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 32 | using std::shared_ptr; |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 33 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 34 | class NlsrFixture : public MockNfdMgmtFixture |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | NlsrFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 38 | : nlsr(m_ioService, m_scheduler, m_face, m_keyChain) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 39 | , lsdb(nlsr.getLsdb()) |
| 40 | , neighbors(nlsr.getAdjacencyList()) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 41 | , nSuccessCallbacks(0) |
| 42 | , nFailureCallbacks(0) |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 43 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 44 | nlsr.getConfParameter().setNetwork("/ndn"); |
| 45 | nlsr.getConfParameter().setSiteName("/site"); |
| 46 | nlsr.getConfParameter().setRouterName("/%C1.Router/this-router"); |
| 47 | nlsr.getConfParameter().buildRouterPrefix(); |
| 48 | |
| 49 | addIdentity(nlsr.getConfParameter().getRouterPrefix()); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
| 53 | receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver) |
| 54 | { |
| 55 | ndn::Name dataName(sender); |
| 56 | dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion(); |
| 57 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 58 | ndn::Data data(dataName); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 59 | |
| 60 | nlsr.m_helloProtocol.onContentValidated(data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 61 | } |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 62 | |
| 63 | public: |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 64 | Nlsr nlsr; |
| 65 | Lsdb& lsdb; |
| 66 | AdjacencyList& neighbors; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 67 | uint32_t nSuccessCallbacks; |
| 68 | uint32_t nFailureCallbacks; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture) |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 72 | |
| 73 | BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors) |
| 74 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 75 | // Simulate loading configuration file |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 76 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 77 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 78 | neighbors.insert(neighborA); |
| 79 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 80 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 81 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 82 | neighbors.insert(neighborB); |
| 83 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 84 | Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 85 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 86 | neighbors.insert(neighborC); |
| 87 | |
| 88 | nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 89 | |
| 90 | nlsr.initialize(); |
| 91 | |
| 92 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 93 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 94 | BOOST_CHECK_EQUAL(it->getLinkCost(), 0); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost) |
| 99 | { |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 100 | // Simulate loading configuration file |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 101 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), 25, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 102 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 103 | neighbors.insert(neighborA); |
| 104 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 105 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 106 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 107 | neighbors.insert(neighborB); |
| 108 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 109 | Adjacent neighborC("/ndn/neighborC", ndn::FaceUri("udp4://10.0.0.3"), 17, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 110 | Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 111 | neighbors.insert(neighborC); |
| 112 | |
| 113 | nlsr.initialize(); |
| 114 | |
| 115 | std::list<Adjacent> neighborList = neighbors.getAdjList(); |
| 116 | for (std::list<Adjacent>::iterator it = neighborList.begin(); it != neighborList.end(); ++it) { |
| 117 | BOOST_CHECK(it->getLinkCost() != 0); |
| 118 | } |
| 119 | } |
| 120 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 121 | BOOST_AUTO_TEST_CASE(SetEventIntervals) |
| 122 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 123 | // Simulate loading configuration file |
| 124 | ConfParameter& conf = nlsr.getConfParameter(); |
| 125 | conf.setAdjLsaBuildInterval(3); |
| 126 | conf.setFirstHelloInterval(6); |
| 127 | conf.setRoutingCalcInterval(9); |
| 128 | |
| 129 | nlsr.initialize(); |
| 130 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 131 | const Lsdb& lsdb = nlsr.getLsdb(); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 132 | const RoutingTable& rt = nlsr.getRoutingTable(); |
| 133 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 134 | BOOST_CHECK_EQUAL(lsdb.getAdjLsaBuildInterval(), ndn::time::seconds(3)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 135 | BOOST_CHECK_EQUAL(nlsr.getFirstHelloInterval(), 6); |
| 136 | BOOST_CHECK_EQUAL(rt.getRoutingCalcInterval(), ndn::time::seconds(9)); |
| 137 | } |
| 138 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 139 | BOOST_AUTO_TEST_CASE(FaceCreateEvent) |
| 140 | { |
| 141 | // Setting constants for the unit test |
| 142 | const uint32_t faceId = 1; |
| 143 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 144 | |
| 145 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 146 | Adjacent::STATUS_INACTIVE, 0, 0); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 147 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 148 | BOOST_REQUIRE_EQUAL(nlsr.getAdjacencyList().insert(neighbor), 0); |
| 149 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 150 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 151 | |
| 152 | // Build, sign, and send the Face Event |
| 153 | ndn::nfd::FaceEventNotification event; |
| 154 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 155 | .setRemoteUri(faceUri) |
| 156 | .setFaceId(faceId); |
| 157 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 158 | data->setContent(event.wireEncode()); |
| 159 | nlsr.getKeyChain().sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 160 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 161 | |
| 162 | // Move the clocks forward so that the Face processes the event. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 163 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 164 | |
| 165 | // Need to explicitly provide a FaceUri object, because the |
| 166 | // conversion will attempt to create Name objects. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 167 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 168 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 169 | BOOST_CHECK_EQUAL(iterator->getFaceId(), faceId); |
| 170 | } |
| 171 | |
| 172 | BOOST_AUTO_TEST_CASE(FaceCreateEventNoMatch) |
| 173 | { |
| 174 | // Setting constants for the unit test |
| 175 | const uint32_t faceId = 1; |
| 176 | const std::string eventUri = "udp4://10.0.0.1:6363"; |
| 177 | const std::string neighborUri = "udp4://10.0.0.2:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 178 | |
| 179 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(neighborUri), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 180 | Adjacent::STATUS_INACTIVE, 0, 0); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 181 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 182 | nlsr.getAdjacencyList().insert(neighbor); |
| 183 | |
| 184 | // Build, sign, and send the Face Event |
| 185 | ndn::nfd::FaceEventNotification event; |
| 186 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 187 | .setRemoteUri(eventUri) |
| 188 | .setFaceId(faceId); |
| 189 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 190 | data->setContent(event.wireEncode()); |
| 191 | nlsr.getKeyChain().sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 192 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 193 | |
| 194 | // Move the clocks forward so that the Face processes the event. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 195 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 196 | |
| 197 | // The Face URIs did not match, so this neighbor should be unconfigured. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 198 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::FaceUri(neighborUri)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 199 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 200 | BOOST_CHECK_EQUAL(iterator->getFaceId(), 0); |
| 201 | } |
| 202 | |
| 203 | BOOST_AUTO_TEST_CASE(FaceCreateEventAlreadyConfigured) |
| 204 | { |
| 205 | // Setting constants for the unit test |
| 206 | const uint32_t eventFaceId = 1; |
| 207 | const uint32_t neighborFaceId = 2; |
| 208 | const std::string faceUri = "udp4://10.0.0.1:6363"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 209 | |
| 210 | Adjacent neighbor("/ndn/neighborA", ndn::FaceUri(faceUri), 10, |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 211 | Adjacent::STATUS_ACTIVE, 0, neighborFaceId); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 212 | nlsr.getAdjacencyList().insert(neighbor); |
| 213 | |
| 214 | // Build, sign, and send the Face Event |
| 215 | ndn::nfd::FaceEventNotification event; |
| 216 | event.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 217 | .setRemoteUri(faceUri) |
| 218 | .setFaceId(eventFaceId); |
| 219 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>("/localhost/nfd/faces/events/%FE%00"); |
| 220 | data->setContent(event.wireEncode()); |
| 221 | nlsr.getKeyChain().sign(*data); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 222 | m_face.receive(*data); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 223 | |
| 224 | // Move the clocks forward so that the Face processes the event. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 225 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 226 | |
| 227 | // Since the neighbor was already configured, this (simply erroneous) event should have no effect. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 228 | auto iterator = nlsr.getAdjacencyList().findAdjacent(ndn::FaceUri(faceUri)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 229 | BOOST_REQUIRE(iterator != nlsr.getAdjacencyList().end()); |
| 230 | BOOST_CHECK_EQUAL(iterator->getFaceId(), neighborFaceId); |
| 231 | } |
| 232 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 233 | BOOST_AUTO_TEST_CASE(FaceDestroyEvent) |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 234 | { |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 235 | // Simulate loading configuration file |
| 236 | ConfParameter& conf = nlsr.getConfParameter(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 237 | |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 238 | conf.setAdjLsaBuildInterval(0); |
| 239 | conf.setRoutingCalcInterval(0); |
| 240 | |
| 241 | // Add active neighbors |
| 242 | AdjacencyList& neighbors = nlsr.getAdjacencyList(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 243 | uint64_t destroyFaceId = 128; |
| 244 | |
| 245 | // Create a neighbor whose Face will be destroyed |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 246 | Adjacent failNeighbor("/ndn/neighborA", ndn::FaceUri("udp4://10.0.0.1"), |
| 247 | 10, Adjacent::STATUS_ACTIVE, 0, destroyFaceId); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 248 | neighbors.insert(failNeighbor); |
| 249 | |
| 250 | // Create an additional neighbor so an adjacency LSA can be built after the face is destroyed |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 251 | Adjacent otherNeighbor("/ndn/neighborB", ndn::FaceUri("udp4://10.0.0.2"), |
| 252 | 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 253 | neighbors.insert(otherNeighbor); |
| 254 | |
| 255 | nlsr.initialize(); |
| 256 | |
| 257 | // Simulate successful HELLO responses |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 258 | lsdb.scheduleAdjLsaBuild(); |
| 259 | |
| 260 | // Set up adjacency LSAs |
| 261 | // This router |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 262 | Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.3"), |
| 263 | 10, Adjacent::STATUS_ACTIVE, 0, 256); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 264 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 265 | AdjLsa ownAdjLsa(conf.getRouterPrefix(), 10, |
| 266 | ndn::time::system_clock::now(), 1, neighbors); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 267 | lsdb.installAdjLsa(ownAdjLsa); |
| 268 | |
| 269 | // Router that will fail |
| 270 | AdjacencyList failAdjacencies; |
| 271 | failAdjacencies.insert(thisRouter); |
| 272 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 273 | AdjLsa failAdjLsa("/ndn/neighborA", 10, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 274 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 275 | 1, failAdjacencies); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 276 | |
| 277 | lsdb.installAdjLsa(failAdjLsa); |
| 278 | |
| 279 | // Other router |
| 280 | AdjacencyList otherAdjacencies; |
| 281 | otherAdjacencies.insert(thisRouter); |
| 282 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 283 | AdjLsa otherAdjLsa("/ndn/neighborB", 10, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 284 | ndn::time::system_clock::now() + ndn::time::seconds(3600), |
| 285 | 1, otherAdjacencies); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 286 | |
| 287 | lsdb.installAdjLsa(otherAdjLsa); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 288 | |
| 289 | // Run the scheduler to build an adjacency LSA |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 290 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 291 | |
| 292 | // Make sure an adjacency LSA was built |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 293 | ndn::Name key = ndn::Name(nlsr.getConfParameter().getRouterPrefix()) |
| 294 | .append(std::to_string(Lsa::Type::ADJACENCY)); |
Vince Lehman | 41b173e | 2015-05-07 14:13:26 -0500 | [diff] [blame] | 295 | AdjLsa* lsa = lsdb.findAdjLsa(key); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 296 | BOOST_REQUIRE(lsa != nullptr); |
| 297 | |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 298 | uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 299 | nlsr.getLsdb().getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 300 | |
| 301 | // Make sure the routing table was calculated |
| 302 | RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 303 | BOOST_REQUIRE(rtEntry != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 304 | BOOST_REQUIRE_EQUAL(rtEntry->getNexthopList().size(), 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 305 | |
| 306 | // Receive FaceEventDestroyed notification |
| 307 | ndn::nfd::FaceEventNotification event; |
| 308 | event.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 309 | .setFaceId(destroyFaceId); |
| 310 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 311 | 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] | 312 | data->setContent(event.wireEncode()); |
| 313 | nlsr.getKeyChain().sign(*data); |
| 314 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 315 | m_face.receive(*data); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 316 | |
| 317 | // Run the scheduler to build an adjacency LSA |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 318 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 319 | |
| 320 | Adjacent updatedNeighbor = neighbors.getAdjacent(failNeighbor.getName()); |
| 321 | |
| 322 | BOOST_CHECK_EQUAL(updatedNeighbor.getFaceId(), 0); |
| 323 | BOOST_CHECK_EQUAL(updatedNeighbor.getInterestTimedOutNo(), |
| 324 | nlsr.getConfParameter().getInterestRetryNumber()); |
| 325 | BOOST_CHECK_EQUAL(updatedNeighbor.getStatus(), Adjacent::STATUS_INACTIVE); |
alvy | 46ccaae | 2015-06-25 14:13:39 -0500 | [diff] [blame] | 326 | |
| 327 | lsa = lsdb.findAdjLsa(key); |
| 328 | BOOST_REQUIRE(lsa != nullptr); |
| 329 | |
| 330 | BOOST_CHECK_EQUAL(lsa->getLsSeqNo(), lastAdjLsaSeqNo + 1); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 331 | |
| 332 | // Make sure the routing table was recalculated |
| 333 | rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName()); |
| 334 | BOOST_CHECK(rtEntry == nullptr); |
| 335 | } |
| 336 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 337 | BOOST_AUTO_TEST_CASE(GetCertificate) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 338 | { |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 339 | // Create certificate |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 340 | ndn::Name identityName("/TestNLSR/identity"); |
| 341 | identityName.appendVersion(); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 342 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 343 | ndn::security::pib::Identity identity = nlsr.getKeyChain(). |
| 344 | createIdentity(identityName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 345 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 346 | ndn::security::v2::Certificate certificate = |
| 347 | identity.getDefaultKey().getDefaultCertificate(); |
| 348 | |
| 349 | const ndn::Name certKey = certificate.getKeyName(); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 350 | |
| 351 | BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr); |
| 352 | |
| 353 | // Certificate should be retrievable from the CertificateStore |
| 354 | nlsr.loadCertToPublish(certificate); |
| 355 | |
| 356 | BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr); |
| 357 | |
| 358 | nlsr.getCertificateStore().clear(); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 361 | BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix) |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 362 | { |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 363 | nlsr.initialize(); |
| 364 | |
| 365 | BOOST_CHECK_EQUAL(nlsr.getLsdbDatasetHandler().getRouterNameCommandPrefix(), |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 366 | ndn::Name("/ndn/site/%C1.Router/this-router/lsdb")); |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 367 | } |
| 368 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 369 | BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse) |
| 370 | { |
| 371 | // Configure NLSR |
| 372 | ConfParameter& conf = nlsr.getConfParameter(); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 373 | |
| 374 | conf.setAdjLsaBuildInterval(1); |
| 375 | |
| 376 | // Add neighbors |
| 377 | // Router A |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 378 | ndn::Name neighborAName("/ndn/site/%C1.Router/routerA"); |
| 379 | Adjacent neighborA(neighborAName, ndn::FaceUri("udp4://10.0.0.1"), |
| 380 | 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 381 | neighbors.insert(neighborA); |
| 382 | |
| 383 | // Router B |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 384 | ndn::Name neighborBName("/ndn/site/%C1.Router/routerB"); |
| 385 | Adjacent neighborB(neighborBName, ndn::FaceUri("udp4://10.0.0.1"), |
| 386 | 0, Adjacent::STATUS_INACTIVE, 0, 0); |
| 387 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 388 | neighbors.insert(neighborB); |
| 389 | |
| 390 | nlsr.initialize(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 391 | |
| 392 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 393 | |
| 394 | // Receive HELLO response from Router A |
| 395 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 396 | this->advanceClocks(ndn::time::seconds(1), 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 397 | |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 398 | ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(std::to_string(Lsa::Type::ADJACENCY)); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 399 | |
| 400 | // Adjacency LSA should be built even though other router is INACTIVE |
| 401 | AdjLsa* lsa = lsdb.findAdjLsa(lsaKey); |
| 402 | BOOST_REQUIRE(lsa != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(lsa->getAdl().size(), 1); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 404 | |
| 405 | // Receive HELLO response from Router B |
| 406 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
| 407 | |
| 408 | // Both routers become INACTIVE and HELLO Interests have timed out |
| 409 | for (Adjacent& adjacency : neighbors.getAdjList()) { |
| 410 | adjacency.setStatus(Adjacent::STATUS_INACTIVE); |
| 411 | adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 412 | } |
| 413 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 414 | this->advanceClocks(ndn::time::seconds(1), 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 415 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 416 | // Adjacency LSA should have been removed since this router's adjacencies are |
| 417 | // INACTIVE and have timed out |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 418 | lsa = lsdb.findAdjLsa(lsaKey); |
| 419 | BOOST_CHECK(lsa == nullptr); |
| 420 | |
| 421 | // Receive HELLO response from Router A and B |
| 422 | receiveHelloData(neighborAName, conf.getRouterPrefix()); |
| 423 | receiveHelloData(neighborBName, conf.getRouterPrefix()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 424 | this->advanceClocks(ndn::time::seconds(1), 10); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 425 | |
| 426 | // Adjacency LSA should be built |
| 427 | lsa = lsdb.findAdjLsa(lsaKey); |
| 428 | BOOST_REQUIRE(lsa != nullptr); |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 429 | BOOST_CHECK_EQUAL(lsa->getAdl().size(), 2); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 432 | BOOST_AUTO_TEST_CASE(CanonizeUris) |
| 433 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 434 | ndn::Name neighborAName("/ndn/site/%C1.Router/routerA"); |
| 435 | ndn::FaceUri faceUriA("udp://10.0.0.1"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 436 | Adjacent neighborA(neighborAName, faceUriA, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 437 | neighbors.insert(neighborA); |
| 438 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 439 | ndn::Name neighborBName("/ndn/site/%C1.Router/routerB"); |
| 440 | ndn::FaceUri faceUriB("udp://10.0.0.2"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 441 | Adjacent neighborB(neighborBName, faceUriB, 0, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 442 | neighbors.insert(neighborB); |
| 443 | |
| 444 | int nCanonizationsLeft = nlsr.getAdjacencyList().getAdjList().size(); |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 445 | std::function<void(void)> finallyCallback = [this] { |
| 446 | nlsr.initialize(); |
| 447 | }; |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 448 | std::function<void(std::list<Adjacent>::iterator)> thenCallback = |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 449 | [this, &thenCallback, &finallyCallback, &nCanonizationsLeft] |
| 450 | (std::list<Adjacent>::iterator iterator) { |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 451 | nCanonizationsLeft--; |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 452 | nlsr.canonizeNeighborUris(iterator, thenCallback, finallyCallback); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 453 | }; |
| 454 | nlsr.canonizeNeighborUris(nlsr.getAdjacencyList().getAdjList().begin(), |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 455 | [&thenCallback, &finallyCallback] |
| 456 | (std::list<Adjacent>::iterator iterator) { |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 457 | thenCallback(iterator); |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 458 | }, |
| 459 | finallyCallback); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 460 | while (nCanonizationsLeft != 0) { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 461 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 462 | } |
| 463 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 464 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborAName).getFaceUri(), |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 465 | ndn::FaceUri("udp4://10.0.0.1:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 466 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 467 | BOOST_CHECK_EQUAL(nlsr.getAdjacencyList().getAdjacent(neighborBName).getFaceUri(), |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 468 | ndn::FaceUri("udp4://10.0.0.2:6363")); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 469 | } |
| 470 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 471 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchSuccess) |
| 472 | { |
| 473 | bool hasResult = false; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 474 | |
| 475 | nlsr.initializeFaces([&hasResult] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 476 | hasResult = true; |
| 477 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 478 | BOOST_CHECK_EQUAL(faces.front().getFaceId(), 25401); |
| 479 | BOOST_CHECK_EQUAL(faces.back().getFaceId(), 25402); |
| 480 | }, |
| 481 | [] (uint32_t code, const std::string& reason) {}); |
| 482 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 483 | this->advanceClocks(ndn::time::milliseconds(100), 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 484 | |
| 485 | ndn::nfd::FaceStatus payload1; |
| 486 | payload1.setFaceId(25401); |
| 487 | ndn::nfd::FaceStatus payload2; |
| 488 | payload2.setFaceId(25402); |
| 489 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 490 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 491 | this->advanceClocks(ndn::time::milliseconds(100), 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 492 | BOOST_CHECK(hasResult); |
| 493 | } |
| 494 | |
| 495 | BOOST_AUTO_TEST_CASE(FaceDatasetFetchFailure) |
| 496 | { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 497 | nlsr.initializeFaces([](const std::vector<ndn::nfd::FaceStatus>& faces) {}, |
| 498 | [this](uint32_t code, const std::string& reason){ |
| 499 | this->nFailureCallbacks++; |
| 500 | }); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 501 | this->advanceClocks(ndn::time::milliseconds(100), 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 502 | |
| 503 | ndn::Name payload; |
| 504 | this->sendDataset("/localhost/nfd/faces/list", payload); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 505 | this->advanceClocks(ndn::time::milliseconds(100), 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 506 | |
| 507 | BOOST_CHECK_EQUAL(nFailureCallbacks, 1); |
| 508 | BOOST_CHECK_EQUAL(nSuccessCallbacks, 0); |
| 509 | } |
| 510 | |
| 511 | BOOST_AUTO_TEST_CASE(FaceDatasetProcess) |
| 512 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 513 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"), |
| 514 | 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 515 | neighbors.insert(neighborA); |
| 516 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 517 | Adjacent neighborB("/ndn/neighborB", ndn::FaceUri("udp4://192.168.0.101:6363"), |
| 518 | 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 519 | neighbors.insert(neighborB); |
| 520 | |
| 521 | ndn::nfd::FaceStatus payload1; |
| 522 | payload1.setFaceId(1) |
| 523 | .setRemoteUri("udp4://192.168.0.100:6363"); |
| 524 | ndn::nfd::FaceStatus payload2; |
| 525 | payload2.setFaceId(2) |
| 526 | .setRemoteUri("udp4://192.168.0.101:6363"); |
| 527 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload1, payload2}; |
| 528 | |
| 529 | nlsr.processFaceDataset(faceStatuses); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 530 | |
| 531 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 532 | |
| 533 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), payload1.getFaceId()); |
| 534 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborB").getFaceId(), payload2.getFaceId()); |
| 535 | } |
| 536 | |
| 537 | BOOST_AUTO_TEST_CASE(UnconfiguredNeighbor) |
| 538 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 539 | Adjacent neighborA("/ndn/neighborA", ndn::FaceUri("udp4://192.168.0.100:6363"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 540 | neighbors.insert(neighborA); |
| 541 | |
| 542 | ndn::nfd::FaceStatus payload; |
| 543 | payload.setFaceId(1) |
| 544 | .setRemoteUri("udp4://192.168.0.101:6363"); // Note dissimilar Face URI. |
| 545 | std::vector<ndn::nfd::FaceStatus> faceStatuses = {payload}; |
| 546 | |
| 547 | nlsr.processFaceDataset(faceStatuses); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 548 | this->advanceClocks(ndn::time::milliseconds(20), 5); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 549 | |
| 550 | AdjacencyList adjList = nlsr.getAdjacencyList(); |
| 551 | |
| 552 | BOOST_CHECK_EQUAL(adjList.getAdjacent("/ndn/neighborA").getFaceId(), 0); |
| 553 | } |
| 554 | |
| 555 | BOOST_AUTO_TEST_CASE(FaceDatasetPeriodicFetch) |
| 556 | { |
| 557 | int nNameMatches = 0; |
| 558 | ndn::Name datasetPrefix("/localhost/nfd/faces/list"); |
| 559 | ndn::nfd::CommandOptions options; |
| 560 | ndn::time::milliseconds defaultTimeout = options.getTimeout(); |
| 561 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 562 | int fetchInterval(1); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 563 | ConfParameter& conf = nlsr.getConfParameter(); |
| 564 | conf.setFaceDatasetFetchInterval(fetchInterval); |
| 565 | conf.setFaceDatasetFetchTries(0); |
| 566 | |
| 567 | nlsr.initializeFaces(std::bind(&Nlsr::processFaceDataset, &nlsr, _1), |
| 568 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, &nlsr, _1, _2, 0)); |
| 569 | |
| 570 | // Elapse the default timeout time of the interest. |
| 571 | this->advanceClocks(defaultTimeout); |
| 572 | |
| 573 | // Check that we have one interest for face list in the sent interests. |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 574 | for (const ndn::Interest& interest : m_face.sentInterests) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 575 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 576 | nNameMatches++; |
| 577 | } |
| 578 | } |
| 579 | BOOST_CHECK_EQUAL(nNameMatches, 1); |
| 580 | |
| 581 | // Elapse the clock by the reschedule time (that we set) |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 582 | this->advanceClocks(ndn::time::seconds(fetchInterval)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 583 | // Elapse the default timeout on the interest. |
| 584 | this->advanceClocks(defaultTimeout); |
| 585 | // Plus a little more to let the events process. |
| 586 | this->advanceClocks(ndn::time::seconds(1)); |
| 587 | |
| 588 | // Check that we now have two interests |
| 589 | nNameMatches = 0; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 590 | for (const ndn::Interest& interest : m_face.sentInterests) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 591 | if (datasetPrefix.isPrefixOf(interest.getName())) { |
| 592 | nNameMatches++; |
| 593 | } |
| 594 | } |
| 595 | BOOST_CHECK_EQUAL(nNameMatches, 2); |
| 596 | } |
| 597 | |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 598 | BOOST_AUTO_TEST_SUITE_END() |
| 599 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 600 | } // namespace test |
| 601 | } // namespace nlsr |