alvy | 297f416 | 2015-03-03 17:15:33 -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, |
alvy | 297f416 | 2015-03-03 17:15:33 -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 | */ |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 21 | |
| 22 | #include "update/prefix-update-processor.hpp" |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 23 | #include "nlsr.hpp" |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 24 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 25 | #include "tests/io-key-chain-fixture.hpp" |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 26 | #include "tests/test-common.hpp" |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 27 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 28 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 29 | #include <ndn-cxx/security/interest-signer.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/security/signing-helpers.hpp> |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 31 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 32 | #include <boost/filesystem/operations.hpp> |
| 33 | #include <boost/filesystem/path.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 34 | #include <boost/lexical_cast.hpp> |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 35 | #include <boost/property_tree/info_parser.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 36 | #include <boost/property_tree/ptree.hpp> |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 37 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 38 | namespace nlsr { |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 39 | namespace test { |
| 40 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 41 | using namespace ndn; |
| 42 | |
| 43 | class PrefixUpdateFixture : public IoKeyChainFixture |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 44 | { |
| 45 | public: |
| 46 | PrefixUpdateFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 47 | : face(m_io, m_keyChain, {true, true}) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 48 | , siteIdentityName(ndn::Name("site")) |
| 49 | , opIdentityName(ndn::Name("site").append(ndn::Name("%C1.Operator"))) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 50 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 51 | , confProcessor(conf) |
| 52 | , nlsr(face, m_keyChain, conf) |
| 53 | , namePrefixList(conf.getNamePrefixList()) |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 54 | , SITE_CERT_PATH(boost::filesystem::current_path() / std::string("site.cert")) |
| 55 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 56 | // Site cert |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 57 | siteIdentity = m_keyChain.createIdentity(siteIdentityName); |
| 58 | saveIdentityCert(siteIdentity, SITE_CERT_PATH.string()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 59 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 60 | // Operator cert |
| 61 | opIdentity = addSubCertificate(opIdentityName, siteIdentity); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 62 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 63 | // Create certificate and load it to the validator |
| 64 | conf.initializeKey(); |
| 65 | |
| 66 | conf.loadCertToValidator(siteIdentity.getDefaultKey().getDefaultCertificate()); |
| 67 | conf.loadCertToValidator(opIdentity.getDefaultKey().getDefaultCertificate()); |
| 68 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 69 | std::ifstream inputFile; |
| 70 | inputFile.open(std::string("nlsr.conf")); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 71 | BOOST_REQUIRE(inputFile.is_open()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 72 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 73 | boost::property_tree::ptree pt; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 74 | boost::property_tree::read_info(inputFile, pt); |
| 75 | for (const auto& tn : pt) { |
| 76 | if (tn.first == "security") { |
| 77 | for (const auto& it : tn.second) { |
| 78 | if (it.first == "prefix-update-validator") { |
| 79 | conf.getPrefixUpdateValidator().load(it.second, std::string("nlsr.conf")); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | inputFile.close(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 85 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 86 | m_keyChain.createIdentity(conf.getRouterPrefix()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 87 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 88 | this->advanceClocks(ndn::time::milliseconds(10)); |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 89 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 90 | face.sentInterests.clear(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 91 | } |
| 92 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 93 | void sendInterestForPublishedData() |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 94 | { |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 95 | // Need to send an interest now since ChronoSync |
| 96 | // no longer does face->put(*data) in publishData. |
| 97 | // Instead it does it in onInterest |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 98 | ndn::Name lsaInterestName = conf.getLsaPrefix(); |
| 99 | lsaInterestName.append(conf.getSiteName()); |
| 100 | lsaInterestName.append(conf.getRouterName()); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 101 | lsaInterestName.append(boost::lexical_cast<std::string>(Lsa::Type::NAME)); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 102 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 103 | lsaInterestName.appendNumber(nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 104 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 105 | auto lsaInterest = std::make_shared<Interest>(lsaInterestName); |
| 106 | lsaInterest->setCanBePrefix(true); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 107 | face.receive(*lsaInterest); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 108 | this->advanceClocks(ndn::time::milliseconds(100)); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 109 | } |
| 110 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 111 | bool |
| 112 | wasRoutingUpdatePublished() |
| 113 | { |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 114 | sendInterestForPublishedData(); |
| 115 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 116 | const ndn::Name& lsaPrefix = conf.getLsaPrefix(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 117 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 118 | const auto& it = std::find_if(face.sentData.begin(), face.sentData.end(), |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 119 | [lsaPrefix] (const ndn::Data& data) { |
| 120 | return lsaPrefix.isPrefixOf(data.getName()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 121 | } |
| 122 | ); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 123 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 124 | return (it != face.sentData.end()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 125 | } |
| 126 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 127 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 128 | ndn::DummyClientFace face; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 129 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 130 | ndn::Name siteIdentityName; |
| 131 | ndn::security::pib::Identity siteIdentity; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 132 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 133 | ndn::Name opIdentityName; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 134 | ndn::Name routerIdName; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 135 | ndn::security::pib::Identity opIdentity; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 136 | ndn::security::pib::Identity routerId; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 137 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 138 | ConfParameter conf; |
| 139 | DummyConfFileProcessor confProcessor; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 140 | Nlsr nlsr; |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 141 | NamePrefixList& namePrefixList; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 142 | |
| 143 | const boost::filesystem::path SITE_CERT_PATH; |
| 144 | }; |
| 145 | |
| 146 | BOOST_FIXTURE_TEST_SUITE(TestPrefixUpdateProcessor, PrefixUpdateFixture) |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(Basic) |
| 149 | { |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 150 | uint64_t nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 151 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 152 | ndn::nfd::ControlParameters parameters; |
| 153 | parameters.setName("/prefix/to/advertise/"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 154 | |
| 155 | // Control Command format: /<prefix>/<management-module>/<command-verb>/<control-parameters> |
| 156 | // /<timestamp>/<random-value>/<signed-interests-components> |
| 157 | |
| 158 | // Advertise |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 159 | ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 160 | |
| 161 | // append /<control-parameters> |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 162 | advertiseCommand.append(ndn::tlv::GenericNameComponent, parameters.wireEncode()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 163 | |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 164 | ndn::security::InterestSigner signer(m_keyChain); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 165 | |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 166 | // InterestSigner::makeCommandInterest() will append the last |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 167 | // three components: (<timestamp>/<random-value>/<signed-interests-components>) |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 168 | auto advertiseInterest = signer.makeCommandInterest(advertiseCommand, |
| 169 | ndn::security::signingByIdentity(opIdentity)); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 170 | |
| 171 | face.receive(advertiseInterest); |
| 172 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 173 | this->advanceClocks(ndn::time::milliseconds(10)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 174 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 175 | NamePrefixList& namePrefixList = conf.getNamePrefixList(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 176 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 177 | BOOST_REQUIRE_EQUAL(namePrefixList.size(), 1); |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(namePrefixList.getNames().front(), parameters.getName()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 179 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 180 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 181 | |
| 182 | face.sentData.clear(); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 183 | nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 184 | |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 185 | // Withdraw |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 186 | ndn::Name withdrawCommand("/localhost/nlsr/prefix-update/withdraw"); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 187 | withdrawCommand.append(ndn::tlv::GenericNameComponent, parameters.wireEncode()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 188 | |
Davide Pesavento | 6184c20 | 2021-05-17 02:28:03 -0400 | [diff] [blame] | 189 | auto withdrawInterest= signer.makeCommandInterest(withdrawCommand, |
| 190 | ndn::security::signingByIdentity(opIdentity)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 191 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 192 | face.receive(withdrawInterest); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 193 | this->advanceClocks(ndn::time::milliseconds(10)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 194 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 195 | BOOST_CHECK_EQUAL(namePrefixList.size(), 0); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 196 | |
| 197 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 198 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 199 | } |
| 200 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 201 | BOOST_AUTO_TEST_SUITE_END() |
| 202 | |
| 203 | } // namespace test |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 204 | } // namespace nlsr |