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