Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [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 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 22 | #ifndef NLSR_PUBLISHER_FIXTURE_HPP |
| 23 | #define NLSR_PUBLISHER_FIXTURE_HPP |
| 24 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 25 | #include "publisher/dataset-interest-handler.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 26 | #include "nlsr.hpp" |
| 27 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 29 | |
| 30 | #include <ndn-cxx/util/dummy-client-face.hpp> |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/security/key-chain.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 32 | #include <ndn-cxx/security/pib/identity.hpp> |
| 33 | |
| 34 | #include <ndn-cxx/util/io.hpp> |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 35 | |
| 36 | #include <boost/filesystem.hpp> |
| 37 | |
| 38 | using namespace ndn; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 39 | |
| 40 | namespace nlsr { |
| 41 | namespace test { |
| 42 | |
| 43 | class PublisherFixture : public BaseFixture |
| 44 | { |
| 45 | public: |
| 46 | PublisherFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 47 | : face(m_ioService, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame^] | 48 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 49 | , confProcessor(conf) |
| 50 | , nlsr(face, m_keyChain, conf) |
| 51 | , lsdb(nlsr.m_lsdb) |
| 52 | , rt1(nlsr.m_routingTable) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 53 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 54 | routerId = addIdentity(conf.getRouterPrefix()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 55 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 56 | nlsr.initialize(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 57 | face.processEvents(ndn::time::milliseconds(100)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void |
| 61 | addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost) |
| 62 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 63 | Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 64 | lsa.addAdjacent(std::move(adjacency)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void |
| 68 | checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa) |
| 69 | { |
| 70 | BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter()); |
| 71 | BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo()); |
| 72 | BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0)); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa) |
| 77 | { |
| 78 | BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa); |
| 79 | |
| 80 | tlv::AdjacencyLsa tlvLsa; |
| 81 | BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block)); |
| 82 | |
| 83 | checkTlvAdjLsa(tlvLsa, lsa); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa) |
| 88 | { |
| 89 | checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa); |
| 90 | |
| 91 | std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin(); |
| 92 | |
| 93 | for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) { |
| 94 | BOOST_CHECK_EQUAL(it->getName(), adjacency.getName()); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 95 | BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 96 | BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost()); |
| 97 | ++it; |
| 98 | } |
| 99 | } |
| 100 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 101 | NextHop |
| 102 | createNextHop(const std::string& faceUri, double cost) |
| 103 | { |
| 104 | NextHop nexthop(faceUri, cost); |
| 105 | return nexthop; |
| 106 | } |
| 107 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 108 | CoordinateLsa |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 109 | createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 110 | { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 111 | CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(), |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 112 | radius, angle); |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 113 | return lsa; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void |
| 117 | checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa) |
| 118 | { |
| 119 | BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa); |
| 120 | |
| 121 | tlv::CoordinateLsa tlvLsa; |
| 122 | BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block)); |
| 123 | |
| 124 | checkTlvCoordinateLsa(tlvLsa, lsa); |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa) |
| 129 | { |
| 130 | checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa); |
| 131 | |
| 132 | BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius()); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 133 | BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void |
| 137 | checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa) |
| 138 | { |
| 139 | BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa); |
| 140 | |
| 141 | tlv::NameLsa tlvLsa; |
| 142 | BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block)); |
| 143 | |
| 144 | checkTlvNameLsa(tlvLsa, lsa); |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa) |
| 149 | { |
| 150 | checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa); |
| 151 | |
| 152 | std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin(); |
| 153 | |
Nick Gordon | f14ec35 | 2017-07-24 16:09:58 -0500 | [diff] [blame] | 154 | for (const ndn::Name& name : lsa.getNpl().getNames()) { |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 155 | BOOST_CHECK_EQUAL(*it, name); |
| 156 | ++it; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | public: |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 161 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 162 | ConfParameter conf; |
| 163 | DummyConfFileProcessor confProcessor; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 164 | Nlsr nlsr; |
| 165 | Lsdb& lsdb; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 166 | |
| 167 | ndn::security::pib::Identity routerId; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 168 | RoutingTable& rt1; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | } // namespace test |
| 172 | } // namespace nlsr |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 173 | |
| 174 | #endif // NLSR_PUBLISHER_FIXTURE_HPP |