blob: 6ea3449c9ca52a98187b0e4bea7429e14d2576a6 [file] [log] [blame]
Ashlesh Gawande214032e2020-12-22 17:20:14 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventod1f1df82022-03-12 16:40:37 -05003 * Copyright (c) 2014-2022, 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
28namespace nlsr {
29namespace test {
30
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040031class HelloProtocolFixture : public IoKeyChainFixture
Ashlesh Gawande214032e2020-12-22 17:20:14 -050032{
33public:
34 HelloProtocolFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040035 : face(m_io, m_keyChain, {true, true})
Ashlesh Gawande214032e2020-12-22 17:20:14 -050036 , 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 Gawande5d93aa52020-06-13 18:57:45 -070073 BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, false);
Ashlesh Gawande214032e2020-12-22 17:20:14 -050074 }
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 Gawande5d93aa52020-06-13 18:57:45 -070084 BOOST_CHECK_EQUAL(nlsr.m_lsdb.m_isBuildAdjLsaScheduled, true);
Ashlesh Gawande214032e2020-12-22 17:20:14 -050085 }
86 BOOST_CHECK_EQUAL(adjList.findAdjacent(ndn::Name(ACTIVE_NEIGHBOR))->getStatus(),
87 Adjacent::STATUS_INACTIVE);
88 }
89
90public:
91 ndn::util::DummyClientFace face;
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 Pesaventod1f1df82022-03-12 16:40:37 -0500100BOOST_FIXTURE_TEST_SUITE(TestHelloProtocol, HelloProtocolFixture)
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500101
102BOOST_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
109BOOST_AUTO_TEST_CASE(HelloInterestTimeoutLS) // #5139
110{
111 checkHelloInterestTimeout();
112}
113
114BOOST_AUTO_TEST_CASE(HelloInterestTimeoutHR) // #5139
115{
116 conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
117 checkHelloInterestTimeout();
118}
119
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -0700120BOOST_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 Pesaventoe28d8752022-03-19 03:55:25 -0400134 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 Gawandee63b7fa2021-04-06 21:43:17 -0700138
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 Gawande214032e2020-12-22 17:20:14 -0500152BOOST_AUTO_TEST_SUITE_END()
153
154} // namespace test
Davide Pesaventod1f1df82022-03-12 16:40:37 -0500155} // namespace nlsr