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 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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> |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame] | 31 | #include <boost/mp11/list.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 33 | namespace nlsr::tests { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 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 | |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame] | 100 | using Commands = boost::mp11::mp_list< |
| 101 | update::NfdRibRegisterCommand, |
| 102 | update::NfdRibUnregisterCommand |
| 103 | >; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 104 | |
| 105 | BOOST_FIXTURE_TEST_SUITE(TestNfdRibCommandProcessor, NfdRibCommandProcessorFixture) |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersSuccess, NfdRibCommand, Commands) |
| 108 | { |
| 109 | ndn::nfd::ControlParameters parameters; |
| 110 | parameters.setName("/test/prefixA"); |
| 111 | |
| 112 | BOOST_CHECK(processor.validateParameters<NfdRibCommand>(parameters)); |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersFailure, NfdRibCommand, Commands) |
| 116 | { |
| 117 | ndn::nfd::ControlParameters parameters; |
| 118 | parameters.setName("/test/prefixA").setCost(10); |
| 119 | |
| 120 | bool wasValidated = true; |
| 121 | try { |
| 122 | processor.validateParameters<NfdRibCommand>(parameters); |
| 123 | } |
| 124 | catch (...) { |
| 125 | wasValidated = false; |
| 126 | } |
| 127 | BOOST_CHECK(!wasValidated); |
| 128 | } |
| 129 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 130 | BOOST_AUTO_TEST_CASE(OnReceiveInterestRegisterCommand) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 131 | { |
| 132 | ndn::Name name("/localhost/nlsr/rib/register"); |
| 133 | ndn::Name prefixName("/test/prefixA"); |
| 134 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 135 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 136 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 137 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 138 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 1); |
| 140 | std::list<ndn::Name> names = namePrefixes.getNames(); |
| 141 | auto itr = std::find(names.begin(), names.end(), prefixName); |
| 142 | if (itr == namePrefixes.getNames().end()) { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 143 | BOOST_FAIL("Prefix was not inserted!"); |
| 144 | } |
| 145 | BOOST_CHECK_EQUAL((*itr), prefixName); |
| 146 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 147 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 148 | } |
| 149 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 150 | BOOST_AUTO_TEST_CASE(OnReceiveInterestUnregisterCommand) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 151 | { |
| 152 | ndn::Name name("/localhost/nlsr/rib/unregister"); |
| 153 | ndn::Name prefixName("/test/prefixA"); |
| 154 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 155 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 156 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 157 | namePrefixes.insert(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 158 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 159 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 160 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 161 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 162 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 163 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 164 | } |
| 165 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 166 | BOOST_AUTO_TEST_CASE(OnReceiveInterestInvalidPrefix) |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 167 | { |
| 168 | ndn::Name name("/localhost/invalid/rib/register"); |
| 169 | ndn::Name prefixName("/test/prefixA"); |
| 170 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 171 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 172 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 173 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 174 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 176 | |
| 177 | // Cannot use routingUpdatePublish test now since in |
| 178 | // initialize nlsr calls buildOwnNameLsa which publishes the routing update |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 179 | BOOST_CHECK(nameLsaSeqNoBeforeInterest == nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | BOOST_AUTO_TEST_SUITE_END() |
| 183 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 184 | } // namespace nlsr::tests |