Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, The University of Memphis, |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -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/>. |
| 20 | */ |
| 21 | |
| 22 | #include "hello-protocol.hpp" |
| 23 | #include "nlsr.hpp" |
| 24 | #include "test-common.hpp" |
| 25 | |
| 26 | namespace nlsr { |
| 27 | namespace test { |
| 28 | |
| 29 | class HelloProtocolFixture : public UnitTestTimeFixture |
| 30 | { |
| 31 | public: |
| 32 | HelloProtocolFixture() |
| 33 | : face(m_ioService, m_keyChain, {true, true}) |
| 34 | , conf(face, m_keyChain) |
| 35 | , confProcessor(conf) |
| 36 | , adjList(conf.getAdjacencyList()) |
| 37 | , nlsr(face, m_keyChain, conf) |
| 38 | , helloProtocol(nlsr.m_helloProtocol) |
| 39 | { |
| 40 | ndn::FaceUri faceUri("udp4://10.0.0.1:6363"); |
| 41 | Adjacent adj1(ACTIVE_NEIGHBOR, faceUri, 10, Adjacent::STATUS_ACTIVE, 0, 300); |
| 42 | adjList.insert(adj1); |
| 43 | } |
| 44 | |
| 45 | int |
| 46 | checkHelloInterests(ndn::Name name) |
| 47 | { |
| 48 | int sent = 0; |
| 49 | for (const auto& i : face.sentInterests) { |
| 50 | if (name == i.getName().getPrefix(4)) { |
| 51 | sent++; |
| 52 | } |
| 53 | } |
| 54 | return sent; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | checkHelloInterestTimeout() |
| 59 | { |
| 60 | helloProtocol.sendHelloInterest(ndn::Name(ACTIVE_NEIGHBOR)); |
| 61 | this->advanceClocks(10_ms); |
| 62 | BOOST_CHECK_EQUAL(checkHelloInterests(ACTIVE_NEIGHBOR), 1); |
| 63 | this->advanceClocks(4_s); |
| 64 | BOOST_CHECK_EQUAL(checkHelloInterests(ACTIVE_NEIGHBOR), 2); |
| 65 | this->advanceClocks(4_s); |
| 66 | BOOST_CHECK_EQUAL(checkHelloInterests(ACTIVE_NEIGHBOR), 3); |
| 67 | if (conf.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 68 | BOOST_CHECK_EQUAL(nlsr.m_routingTable.m_isRouteCalculationScheduled, false); |
| 69 | } |
| 70 | else { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, false); |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 72 | } |
| 73 | BOOST_CHECK_EQUAL(adjList.findAdjacent(ndn::Name(ACTIVE_NEIGHBOR))->getStatus(), |
| 74 | Adjacent::STATUS_ACTIVE); |
| 75 | |
| 76 | this->advanceClocks(4_s); |
| 77 | BOOST_CHECK_EQUAL(checkHelloInterests(ACTIVE_NEIGHBOR), 3); |
| 78 | if (conf.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 79 | BOOST_CHECK_EQUAL(nlsr.m_routingTable.m_isRouteCalculationScheduled, true); |
| 80 | } |
| 81 | else { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, true); |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 83 | } |
| 84 | BOOST_CHECK_EQUAL(adjList.findAdjacent(ndn::Name(ACTIVE_NEIGHBOR))->getStatus(), |
| 85 | Adjacent::STATUS_INACTIVE); |
| 86 | } |
| 87 | |
| 88 | public: |
| 89 | ndn::util::DummyClientFace face; |
| 90 | ConfParameter conf; |
| 91 | DummyConfFileProcessor confProcessor; |
| 92 | AdjacencyList& adjList; |
| 93 | Nlsr nlsr; |
| 94 | HelloProtocol& helloProtocol; |
| 95 | const std::string ACTIVE_NEIGHBOR = "/ndn/site/%C1.Router/router-active"; |
| 96 | }; |
| 97 | |
| 98 | BOOST_FIXTURE_TEST_SUITE(HelloProtocol, HelloProtocolFixture) |
| 99 | |
| 100 | BOOST_AUTO_TEST_CASE(Basic) |
| 101 | { |
| 102 | this->advanceClocks(10_s); |
| 103 | checkPrefixRegistered(face, "/ndn/site/%C1.Router/this-router/nlsr/INFO"); |
| 104 | face.sentInterests.clear(); |
| 105 | } |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE(HelloInterestTimeoutLS) // #5139 |
| 108 | { |
| 109 | checkHelloInterestTimeout(); |
| 110 | } |
| 111 | |
| 112 | BOOST_AUTO_TEST_CASE(HelloInterestTimeoutHR) // #5139 |
| 113 | { |
| 114 | conf.setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 115 | checkHelloInterestTimeout(); |
| 116 | } |
| 117 | |
Ashlesh Gawande | e63b7fa | 2021-04-06 21:43:17 -0700 | [diff] [blame] | 118 | BOOST_AUTO_TEST_CASE(CheckHelloDataValidatedSignal) // # 5157 |
| 119 | { |
| 120 | int numOnInitialHelloDataValidates = 0; |
| 121 | helloProtocol.onInitialHelloDataValidated.connect( |
| 122 | [&] (const ndn::Name& neighbor) { |
| 123 | ++numOnInitialHelloDataValidates; |
| 124 | } |
| 125 | ); |
| 126 | |
| 127 | ndn::FaceUri faceUri("udp4://10.0.0.2:6363"); |
| 128 | Adjacent adj1("/ndn/site/%C1.Router/router-other", faceUri, 10, |
| 129 | Adjacent::STATUS_INACTIVE, 0, 300); |
| 130 | adjList.insert(adj1); |
| 131 | |
| 132 | ndn::Name dataName = adj1.getName() ; |
| 133 | dataName.append(nlsr::HelloProtocol::NLSR_COMPONENT); |
| 134 | dataName.append(nlsr::HelloProtocol::INFO_COMPONENT); |
| 135 | dataName.append(conf.getRouterPrefix().wireEncode()); |
| 136 | |
| 137 | ndn::Data data(ndn::Name(dataName).appendVersion()); |
| 138 | BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 0); |
| 139 | helloProtocol.onContentValidated(data); |
| 140 | BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 1); |
| 141 | BOOST_CHECK_EQUAL(adjList.getStatusOfNeighbor(adj1.getName()), Adjacent::STATUS_ACTIVE); |
| 142 | |
| 143 | // No state change of neighbor so no signal: |
| 144 | ndn::Data data2(ndn::Name(dataName).appendVersion()); |
| 145 | helloProtocol.onContentValidated(data2); |
| 146 | BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 1); |
| 147 | BOOST_CHECK_EQUAL(adjList.getStatusOfNeighbor(adj1.getName()), Adjacent::STATUS_ACTIVE); |
| 148 | } |
| 149 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 150 | BOOST_AUTO_TEST_SUITE_END() |
| 151 | |
| 152 | } // namespace test |
| 153 | } // namespace nlsr |