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