blob: 3afef2c8c444c64dea9cbfbe3f009fefe6b77419 [file] [log] [blame]
Nick Gordon4d2c6c02017-01-20 13:18:46 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -07002/*
Davide Pesavento384327d2025-01-02 01:40:23 -05003 * Copyright (c) 2014-2025, The University of Memphis,
Nick Gordon4d2c6c02017-01-20 13:18:46 -06004 * 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/>.
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070020 */
Nick Gordon4d2c6c02017-01-20 13:18:46 -060021
22#include "update/nfd-rib-command-processor.hpp"
Junxiao Shi008c9b12019-01-13 23:15:56 +000023#include "conf-parameter.hpp"
24#include "nlsr.hpp"
Nick Gordon4d2c6c02017-01-20 13:18:46 -060025
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040026#include "tests/io-key-chain-fixture.hpp"
27#include "tests/test-common.hpp"
Nick Gordon4d2c6c02017-01-20 13:18:46 -060028
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070029#include <boost/lexical_cast.hpp>
30
Davide Pesavento288141a2024-02-13 17:30:35 -050031namespace nlsr::tests {
Nick Gordon4d2c6c02017-01-20 13:18:46 -060032
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040033class NfdRibCommandProcessorFixture : public IoKeyChainFixture
Nick Gordon4d2c6c02017-01-20 13:18:46 -060034{
35public:
36 NfdRibCommandProcessorFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040037 : face(m_io, m_keyChain, {true, true})
Saurab Dulal427e0122019-11-28 11:58:02 -060038 , conf(face, m_keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060039 , confProcessor(conf)
40 , nlsr(face, m_keyChain, conf)
41 , namePrefixes(conf.getNamePrefixList())
42 , processor(nlsr.m_nfdRibCommandProcessor)
Nick Gordon4d2c6c02017-01-20 13:18:46 -060043 {
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040044 m_keyChain.createIdentity(conf.getRouterPrefix());
Nick Gordon4d2c6c02017-01-20 13:18:46 -060045
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050046 this->advanceClocks(ndn::time::milliseconds(10), 10);
Nick Gordon4d2c6c02017-01-20 13:18:46 -060047 face.sentInterests.clear();
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050048
Ashlesh Gawande15052402018-12-12 20:20:00 -060049 nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq();
Nick Gordon4d2c6c02017-01-20 13:18:46 -060050 }
51
Junxiao Shi008c9b12019-01-13 23:15:56 +000052 void
53 sendCommand(ndn::Name prefix, const ndn::nfd::ControlParameters& parameters)
Nick Gordon4d2c6c02017-01-20 13:18:46 -060054 {
Davide Pesavento968eb1a2025-01-07 00:46:05 -050055 ndn::Interest interest(prefix.append(parameters.wireEncode()));
Junxiao Shi008c9b12019-01-13 23:15:56 +000056 face.receive(interest);
57 this->advanceClocks(ndn::time::milliseconds(10), 10);
Nick Gordon4d2c6c02017-01-20 13:18:46 -060058 }
59
Ashlesh Gawande85998a12017-12-07 22:22:13 -060060 void sendInterestForPublishedData()
Junxiao Shi008c9b12019-01-13 23:15:56 +000061 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060062 ndn::Name lsaInterestName = conf.getLsaPrefix();
63 lsaInterestName.append(conf.getSiteName());
64 lsaInterestName.append(conf.getRouterName());
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080065 lsaInterestName.append(boost::lexical_cast<std::string>(Lsa::Type::NAME));
Ashlesh Gawande15052402018-12-12 20:20:00 -060066 lsaInterestName.appendNumber(nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq());
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050067
Ashlesh Gawande85998a12017-12-07 22:22:13 -060068 face.receive(ndn::Interest(lsaInterestName).setCanBePrefix(true));
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050069 this->advanceClocks(ndn::time::milliseconds(10), 10);
Ashlesh Gawande415676b2016-12-22 00:26:23 -060070 }
71
Nick Gordon4d2c6c02017-01-20 13:18:46 -060072 bool
73 wasRoutingUpdatePublished()
74 {
Ashlesh Gawande415676b2016-12-22 00:26:23 -060075 sendInterestForPublishedData();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050076
Ashlesh Gawande85998a12017-12-07 22:22:13 -060077 const ndn::Name& lsaPrefix = conf.getLsaPrefix();
Davide Pesavento968eb1a2025-01-07 00:46:05 -050078 auto it = std::find_if(face.sentData.begin(), face.sentData.end(),
79 [&] (const auto& data) { return lsaPrefix.isPrefixOf(data.getName()); });
80 return it != face.sentData.end();
Nick Gordon4d2c6c02017-01-20 13:18:46 -060081 }
82
83public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000084 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060085 ConfParameter conf;
86 DummyConfFileProcessor confProcessor;
Nick Gordon4d2c6c02017-01-20 13:18:46 -060087
88 Nlsr nlsr;
89 NamePrefixList& namePrefixes;
Ashlesh Gawande85998a12017-12-07 22:22:13 -060090 update::NfdRibCommandProcessor& processor;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050091 uint64_t nameLsaSeqNoBeforeInterest;
Nick Gordon4d2c6c02017-01-20 13:18:46 -060092};
93
Nick Gordon4d2c6c02017-01-20 13:18:46 -060094BOOST_FIXTURE_TEST_SUITE(TestNfdRibCommandProcessor, NfdRibCommandProcessorFixture)
95
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040096BOOST_AUTO_TEST_CASE(OnReceiveInterestRegisterCommand)
Nick Gordon4d2c6c02017-01-20 13:18:46 -060097{
98 ndn::Name name("/localhost/nlsr/rib/register");
99 ndn::Name prefixName("/test/prefixA");
100 ndn::nfd::ControlParameters parameters;
Junxiao Shi008c9b12019-01-13 23:15:56 +0000101 parameters.setName(prefixName);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600102
Junxiao Shi008c9b12019-01-13 23:15:56 +0000103 sendCommand(name, parameters);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600104
Nick Gordonf14ec352017-07-24 16:09:58 -0500105 BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 1);
106 std::list<ndn::Name> names = namePrefixes.getNames();
107 auto itr = std::find(names.begin(), names.end(), prefixName);
108 if (itr == namePrefixes.getNames().end()) {
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600109 BOOST_FAIL("Prefix was not inserted!");
110 }
111 BOOST_CHECK_EQUAL((*itr), prefixName);
112 BOOST_CHECK(wasRoutingUpdatePublished());
Ashlesh Gawande15052402018-12-12 20:20:00 -0600113 BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq());
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600114}
115
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400116BOOST_AUTO_TEST_CASE(OnReceiveInterestUnregisterCommand)
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600117{
118 ndn::Name name("/localhost/nlsr/rib/unregister");
119 ndn::Name prefixName("/test/prefixA");
120 ndn::nfd::ControlParameters parameters;
Junxiao Shi008c9b12019-01-13 23:15:56 +0000121 parameters.setName(prefixName);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600122
Nick Gordonf14ec352017-07-24 16:09:58 -0500123 namePrefixes.insert(prefixName);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600124
Junxiao Shi008c9b12019-01-13 23:15:56 +0000125 sendCommand(name, parameters);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600126
Nick Gordonf14ec352017-07-24 16:09:58 -0500127 BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600128 BOOST_CHECK(wasRoutingUpdatePublished());
Ashlesh Gawande15052402018-12-12 20:20:00 -0600129 BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq());
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600130}
131
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400132BOOST_AUTO_TEST_CASE(OnReceiveInterestInvalidPrefix)
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600133{
134 ndn::Name name("/localhost/invalid/rib/register");
135 ndn::Name prefixName("/test/prefixA");
136 ndn::nfd::ControlParameters parameters;
Junxiao Shi008c9b12019-01-13 23:15:56 +0000137 parameters.setName(prefixName);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600138
Junxiao Shi008c9b12019-01-13 23:15:56 +0000139 sendCommand(name, parameters);
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600140
Nick Gordonf14ec352017-07-24 16:09:58 -0500141 BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500142
143 // Cannot use routingUpdatePublish test now since in
144 // initialize nlsr calls buildOwnNameLsa which publishes the routing update
Ashlesh Gawande15052402018-12-12 20:20:00 -0600145 BOOST_CHECK(nameLsaSeqNoBeforeInterest == nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq());
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600146}
147
148BOOST_AUTO_TEST_SUITE_END()
149
Davide Pesavento288141a2024-02-13 17:30:35 -0500150} // namespace nlsr::tests