Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 2 | /* |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [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/>. |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 20 | */ |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 21 | |
| 22 | #include "update/nfd-rib-command-processor.hpp" |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 23 | #include "adjacency-list.hpp" |
| 24 | #include "conf-parameter.hpp" |
| 25 | #include "nlsr.hpp" |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 26 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 27 | #include "tests/io-key-chain-fixture.hpp" |
| 28 | #include "tests/test-common.hpp" |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 29 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 30 | #include <boost/lexical_cast.hpp> |
| 31 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 32 | namespace nlsr { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 33 | namespace test { |
| 34 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 35 | class NfdRibCommandProcessorFixture : public IoKeyChainFixture |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 36 | { |
| 37 | public: |
| 38 | NfdRibCommandProcessorFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 39 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 40 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 41 | , confProcessor(conf) |
| 42 | , nlsr(face, m_keyChain, conf) |
| 43 | , namePrefixes(conf.getNamePrefixList()) |
| 44 | , processor(nlsr.m_nfdRibCommandProcessor) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 45 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 46 | m_keyChain.createIdentity(conf.getRouterPrefix()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 47 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 48 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 49 | face.sentInterests.clear(); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 50 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 51 | nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq(); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 52 | } |
| 53 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 54 | void |
| 55 | sendCommand(ndn::Name prefix, const ndn::nfd::ControlParameters& parameters) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 56 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 57 | ndn::Interest interest(prefix.append(ndn::tlv::GenericNameComponent, parameters.wireEncode())); |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 58 | face.receive(interest); |
| 59 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 60 | } |
| 61 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 62 | void sendInterestForPublishedData() |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 63 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 64 | ndn::Name lsaInterestName = conf.getLsaPrefix(); |
| 65 | lsaInterestName.append(conf.getSiteName()); |
| 66 | lsaInterestName.append(conf.getRouterName()); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 67 | lsaInterestName.append(boost::lexical_cast<std::string>(Lsa::Type::NAME)); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 68 | lsaInterestName.appendNumber(nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 69 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 70 | face.receive(ndn::Interest(lsaInterestName).setCanBePrefix(true)); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 71 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 72 | } |
| 73 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 74 | bool |
| 75 | wasRoutingUpdatePublished() |
| 76 | { |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 77 | sendInterestForPublishedData(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 78 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 79 | const ndn::Name& lsaPrefix = conf.getLsaPrefix(); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 80 | |
| 81 | const auto& it = std::find_if(face.sentData.begin(), face.sentData.end(), |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 82 | [&] (const ndn::Data& data) { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 83 | return lsaPrefix.isPrefixOf(data.getName()); |
| 84 | }); |
| 85 | |
| 86 | return (it != face.sentData.end()); |
| 87 | } |
| 88 | |
| 89 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 90 | ndn::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 91 | ConfParameter conf; |
| 92 | DummyConfFileProcessor confProcessor; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 93 | |
| 94 | Nlsr nlsr; |
| 95 | NamePrefixList& namePrefixes; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 96 | update::NfdRibCommandProcessor& processor; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 97 | uint64_t nameLsaSeqNoBeforeInterest; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 98 | }; |
| 99 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 100 | typedef boost::mpl::vector<update::NfdRibRegisterCommand, |
| 101 | update::NfdRibUnregisterCommand> Commands; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 102 | |
| 103 | BOOST_FIXTURE_TEST_SUITE(TestNfdRibCommandProcessor, NfdRibCommandProcessorFixture) |
| 104 | |
| 105 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersSuccess, NfdRibCommand, Commands) |
| 106 | { |
| 107 | ndn::nfd::ControlParameters parameters; |
| 108 | parameters.setName("/test/prefixA"); |
| 109 | |
| 110 | BOOST_CHECK(processor.validateParameters<NfdRibCommand>(parameters)); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersFailure, NfdRibCommand, Commands) |
| 114 | { |
| 115 | ndn::nfd::ControlParameters parameters; |
| 116 | parameters.setName("/test/prefixA").setCost(10); |
| 117 | |
| 118 | bool wasValidated = true; |
| 119 | try { |
| 120 | processor.validateParameters<NfdRibCommand>(parameters); |
| 121 | } |
| 122 | catch (...) { |
| 123 | wasValidated = false; |
| 124 | } |
| 125 | BOOST_CHECK(!wasValidated); |
| 126 | } |
| 127 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 128 | BOOST_AUTO_TEST_CASE(OnReceiveInterestRegisterCommand) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 129 | { |
| 130 | ndn::Name name("/localhost/nlsr/rib/register"); |
| 131 | ndn::Name prefixName("/test/prefixA"); |
| 132 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 133 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 134 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 135 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 136 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 1); |
| 138 | std::list<ndn::Name> names = namePrefixes.getNames(); |
| 139 | auto itr = std::find(names.begin(), names.end(), prefixName); |
| 140 | if (itr == namePrefixes.getNames().end()) { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 141 | BOOST_FAIL("Prefix was not inserted!"); |
| 142 | } |
| 143 | BOOST_CHECK_EQUAL((*itr), prefixName); |
| 144 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 145 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 146 | } |
| 147 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 148 | BOOST_AUTO_TEST_CASE(OnReceiveInterestUnregisterCommand) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 149 | { |
| 150 | ndn::Name name("/localhost/nlsr/rib/unregister"); |
| 151 | ndn::Name prefixName("/test/prefixA"); |
| 152 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 153 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 154 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 155 | namePrefixes.insert(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 156 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 157 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 158 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 160 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 161 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 162 | } |
| 163 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 164 | BOOST_AUTO_TEST_CASE(OnReceiveInterestInvalidPrefix) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 165 | { |
| 166 | ndn::Name name("/localhost/invalid/rib/register"); |
| 167 | ndn::Name prefixName("/test/prefixA"); |
| 168 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 169 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 170 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 171 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 172 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 174 | |
| 175 | // Cannot use routingUpdatePublish test now since in |
| 176 | // initialize nlsr calls buildOwnNameLsa which publishes the routing update |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 177 | BOOST_CHECK(nameLsaSeqNoBeforeInterest == nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | BOOST_AUTO_TEST_SUITE_END() |
| 181 | |
| 182 | } // namespace test |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 183 | } // namespace nlsr |