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