Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [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, |
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/>. |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 20 | */ |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 21 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 22 | #ifndef NLSR_TESTS_PUBLISHER_FIXTURE_HPP |
| 23 | #define NLSR_TESTS_PUBLISHER_FIXTURE_HPP |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 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 | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 28 | #include "tests/io-key-chain-fixture.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 30 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 31 | namespace nlsr { |
| 32 | namespace test { |
| 33 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 34 | class PublisherFixture : public IoKeyChainFixture |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | PublisherFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 38 | : face(m_io, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 39 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 40 | , confProcessor(conf) |
| 41 | , nlsr(face, m_keyChain, conf) |
| 42 | , lsdb(nlsr.m_lsdb) |
| 43 | , rt1(nlsr.m_routingTable) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 44 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 45 | routerId = m_keyChain.createIdentity(conf.getRouterPrefix()); |
| 46 | advanceClocks(100_ms); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void |
| 50 | addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost) |
| 51 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 52 | Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 53 | lsa.addAdjacent(std::move(adjacency)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 54 | } |
| 55 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 56 | NextHop |
| 57 | createNextHop(const std::string& faceUri, double cost) |
| 58 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 59 | return {faceUri, cost}; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 60 | } |
| 61 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 62 | CoordinateLsa |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 63 | createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 64 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 65 | return {origin, 1, ndn::time::system_clock::now(), radius, angle}; |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | processDatasetInterest(std::function<bool(const ndn::Block&)> isSameType) |
| 70 | { |
| 71 | advanceClocks(30_ms); |
| 72 | |
| 73 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
| 74 | ndn::Block parser(face.sentData[0].getContent()); |
| 75 | parser.parse(); |
| 76 | face.sentData.clear(); |
| 77 | |
| 78 | auto it = parser.elements_begin(); |
| 79 | BOOST_CHECK(isSameType(*it++)); |
| 80 | BOOST_CHECK(it == parser.elements_end()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 83 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 84 | ndn::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 85 | ConfParameter conf; |
| 86 | DummyConfFileProcessor confProcessor; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 87 | Nlsr nlsr; |
| 88 | Lsdb& lsdb; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 89 | |
| 90 | ndn::security::pib::Identity routerId; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 91 | RoutingTable& rt1; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace test |
| 95 | } // namespace nlsr |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 96 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 97 | #endif // NLSR_TESTS_PUBLISHER_FIXTURE_HPP |