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