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 | /* |
| 3 | * Copyright (c) 2014-2021, 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 | |
| 27 | #include "../test-common.hpp" |
| 28 | #include "../control-commands.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 | |
| 35 | class NfdRibCommandProcessorFixture : public nlsr::test::UnitTestTimeFixture |
| 36 | { |
| 37 | public: |
| 38 | NfdRibCommandProcessorFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 39 | : face(m_ioService, 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 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 46 | addIdentity(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 | { |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 57 | ndn::Interest interest(prefix.append(parameters.wireEncode())); |
| 58 | interest.setCanBePrefix(false); |
| 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: |
| 91 | ndn::util::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 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 101 | typedef boost::mpl::vector<update::NfdRibRegisterCommand, |
| 102 | update::NfdRibUnregisterCommand> Commands; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 103 | |
| 104 | BOOST_FIXTURE_TEST_SUITE(TestNfdRibCommandProcessor, NfdRibCommandProcessorFixture) |
| 105 | |
| 106 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersSuccess, NfdRibCommand, Commands) |
| 107 | { |
| 108 | ndn::nfd::ControlParameters parameters; |
| 109 | parameters.setName("/test/prefixA"); |
| 110 | |
| 111 | BOOST_CHECK(processor.validateParameters<NfdRibCommand>(parameters)); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersFailure, NfdRibCommand, Commands) |
| 115 | { |
| 116 | ndn::nfd::ControlParameters parameters; |
| 117 | parameters.setName("/test/prefixA").setCost(10); |
| 118 | |
| 119 | bool wasValidated = true; |
| 120 | try { |
| 121 | processor.validateParameters<NfdRibCommand>(parameters); |
| 122 | } |
| 123 | catch (...) { |
| 124 | wasValidated = false; |
| 125 | } |
| 126 | BOOST_CHECK(!wasValidated); |
| 127 | } |
| 128 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 129 | BOOST_AUTO_TEST_CASE(onReceiveInterestRegisterCommand) |
| 130 | { |
| 131 | ndn::Name name("/localhost/nlsr/rib/register"); |
| 132 | ndn::Name prefixName("/test/prefixA"); |
| 133 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 134 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 135 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 136 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 137 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 138 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 1); |
| 139 | std::list<ndn::Name> names = namePrefixes.getNames(); |
| 140 | auto itr = std::find(names.begin(), names.end(), prefixName); |
| 141 | if (itr == namePrefixes.getNames().end()) { |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 142 | BOOST_FAIL("Prefix was not inserted!"); |
| 143 | } |
| 144 | BOOST_CHECK_EQUAL((*itr), prefixName); |
| 145 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 146 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(onReceiveInterestUnregisterCommand) |
| 150 | { |
| 151 | ndn::Name name("/localhost/nlsr/rib/unregister"); |
| 152 | ndn::Name prefixName("/test/prefixA"); |
| 153 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 154 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 155 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 156 | namePrefixes.insert(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 157 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 158 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 159 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 160 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 161 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 162 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | BOOST_AUTO_TEST_CASE(onReceiveInterestInvalidPrefix) |
| 166 | { |
| 167 | ndn::Name name("/localhost/invalid/rib/register"); |
| 168 | ndn::Name prefixName("/test/prefixA"); |
| 169 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 170 | parameters.setName(prefixName); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 171 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 172 | sendCommand(name, parameters); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 173 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(namePrefixes.getNames().size(), 0); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 175 | |
| 176 | // Cannot use routingUpdatePublish test now since in |
| 177 | // initialize nlsr calls buildOwnNameLsa which publishes the routing update |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 178 | BOOST_CHECK(nameLsaSeqNoBeforeInterest == nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | BOOST_AUTO_TEST_SUITE_END() |
| 182 | |
| 183 | } // namespace test |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 184 | } // namespace nlsr |