blob: 7aaf32a336fc889a691a7ef5bfe0a3fea801011f [file] [log] [blame]
Ashlesh Gawande214032e2020-12-22 17:20:14 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, The University of Memphis,
Ashlesh Gawande214032e2020-12-22 17:20:14 -05004 * 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 Pesavento8de8a8b2022-05-12 01:26:43 -040024
25#include "tests/io-key-chain-fixture.hpp"
26#include "tests/test-common.hpp"
Ashlesh Gawande214032e2020-12-22 17:20:14 -050027
Davide Pesavento288141a2024-02-13 17:30:35 -050028namespace nlsr::tests {
Ashlesh Gawande214032e2020-12-22 17:20:14 -050029
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040030class HelloProtocolFixture : public IoKeyChainFixture
Ashlesh Gawande214032e2020-12-22 17:20:14 -050031{
32public:
33 HelloProtocolFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040034 : face(m_io, m_keyChain, {true, true})
Ashlesh Gawande214032e2020-12-22 17:20:14 -050035 , 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 Gawande5d93aa52020-06-13 18:57:45 -070072 BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, false);
Ashlesh Gawande214032e2020-12-22 17:20:14 -050073 }
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 Gawande5d93aa52020-06-13 18:57:45 -070083 BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, true);
Ashlesh Gawande214032e2020-12-22 17:20:14 -050084 }
85 BOOST_CHECK_EQUAL(adjList.findAdjacent(ndn::Name(ACTIVE_NEIGHBOR))->getStatus(),
86 Adjacent::STATUS_INACTIVE);
87 }
88
89public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000090 ndn::DummyClientFace face;
Ashlesh Gawande214032e2020-12-22 17:20:14 -050091 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 Pesaventod1f1df82022-03-12 16:40:37 -050099BOOST_FIXTURE_TEST_SUITE(TestHelloProtocol, HelloProtocolFixture)
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500100
101BOOST_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
108BOOST_AUTO_TEST_CASE(HelloInterestTimeoutLS) // #5139
109{
110 checkHelloInterestTimeout();
111}
112
113BOOST_AUTO_TEST_CASE(HelloInterestTimeoutHR) // #5139
114{
115 conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
116 checkHelloInterestTimeout();
117}
118
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -0700119BOOST_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 Pesaventoe28d8752022-03-19 03:55:25 -0400133 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 Gawandee63b7fa2021-04-06 21:43:17 -0700137
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 Gawande214032e2020-12-22 17:20:14 -0500151BOOST_AUTO_TEST_SUITE_END()
152
Davide Pesavento288141a2024-02-13 17:30:35 -0500153} // namespace nlsr::tests