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