alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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/>. |
| 20 | **/ |
| 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 | |
| 25 | #include "../control-commands.hpp" |
| 26 | #include "../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"))) |
| 49 | , conf(face) |
| 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 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 62 | std::ifstream inputFile; |
| 63 | inputFile.open(std::string("nlsr.conf")); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 64 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 65 | BOOST_REQUIRE(inputFile.is_open()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 66 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 67 | boost::property_tree::ptree pt; |
| 68 | |
| 69 | boost::property_tree::read_info(inputFile, pt); |
| 70 | for (const auto& tn : pt) { |
| 71 | if (tn.first == "security") { |
| 72 | for (const auto& it : tn.second) { |
| 73 | if (it.first == "prefix-update-validator") { |
| 74 | conf.getPrefixUpdateValidator().load(it.second, std::string("nlsr.conf")); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | inputFile.close(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 80 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 81 | nlsr.loadCertToPublish(opIdentity.getDefaultKey().getDefaultCertificate()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 82 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 83 | addIdentity(conf.getRouterPrefix()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 84 | |
| 85 | // Initialize NLSR so a sync socket is created |
| 86 | nlsr.initialize(); |
| 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()); |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 101 | lsaInterestName.append(std::to_string(Lsa::Type::NAME)); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 102 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 103 | lsaInterestName.appendNumber(nlsr.m_lsdb.getSequencingManager().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: |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 128 | ndn::util::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; |
| 134 | ndn::security::pib::Identity opIdentity; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 135 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 136 | ConfParameter conf; |
| 137 | DummyConfFileProcessor confProcessor; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 138 | Nlsr nlsr; |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 139 | NamePrefixList& namePrefixList; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 140 | |
| 141 | const boost::filesystem::path SITE_CERT_PATH; |
| 142 | }; |
| 143 | |
| 144 | BOOST_FIXTURE_TEST_SUITE(TestPrefixUpdateProcessor, PrefixUpdateFixture) |
| 145 | |
| 146 | BOOST_AUTO_TEST_CASE(Basic) |
| 147 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 148 | uint64_t nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.getSequencingManager().getNameLsaSeq(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 149 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 150 | ndn::nfd::ControlParameters parameters; |
| 151 | parameters.setName("/prefix/to/advertise/"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 152 | |
| 153 | // Control Command format: /<prefix>/<management-module>/<command-verb>/<control-parameters> |
| 154 | // /<timestamp>/<random-value>/<signed-interests-components> |
| 155 | |
| 156 | // Advertise |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 157 | ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 158 | |
| 159 | // append /<control-parameters> |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 160 | advertiseCommand.append(parameters.wireEncode()); |
| 161 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 162 | ndn::security::CommandInterestSigner cis(m_keyChain); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 163 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 164 | // CommandInterestSigner::makeCommandInterest() will append the last |
| 165 | // three components: (<timestamp>/<random-value>/<signed-interests-components>) |
| 166 | ndn::Interest advertiseInterest = |
| 167 | cis.makeCommandInterest(advertiseCommand, |
| 168 | ndn::security::signingByIdentity(opIdentity)); |
| 169 | |
| 170 | face.receive(advertiseInterest); |
| 171 | |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 172 | this->advanceClocks(ndn::time::milliseconds(10)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 173 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 174 | NamePrefixList& namePrefixList = conf.getNamePrefixList(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 175 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 176 | BOOST_REQUIRE_EQUAL(namePrefixList.size(), 1); |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(namePrefixList.getNames().front(), parameters.getName()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 178 | |
| 179 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 180 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.getSequencingManager().getNameLsaSeq()); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 181 | |
| 182 | face.sentData.clear(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 183 | nameLsaSeqNoBeforeInterest = nlsr.m_lsdb.getSequencingManager().getNameLsaSeq(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 184 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 185 | //Withdraw |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 186 | ndn::Name withdrawCommand("/localhost/nlsr/prefix-update/withdraw"); |
| 187 | withdrawCommand.append(parameters.wireEncode()); |
| 188 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 189 | ndn::Interest withdrawInterest |
| 190 | = cis.makeCommandInterest(withdrawCommand, |
| 191 | ndn::security::signingByIdentity(opIdentity)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 192 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 193 | face.receive(withdrawInterest); |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 194 | this->advanceClocks(ndn::time::milliseconds(10)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 195 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(namePrefixList.size(), 0); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 197 | |
| 198 | BOOST_CHECK(wasRoutingUpdatePublished()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 199 | BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.getSequencingManager().getNameLsaSeq()); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 200 | } |
| 201 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 202 | BOOST_AUTO_TEST_SUITE_END() |
| 203 | |
| 204 | } // namespace test |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 205 | } // namespace nlsr |