Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [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 | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 21 | |
| 22 | #include "communication/sync-protocol-adapter.hpp" |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 23 | |
| 24 | #include "tests/boost-test.hpp" |
| 25 | #include "tests/io-key-chain-fixture.hpp" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 26 | |
| 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 28 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 29 | namespace nlsr::tests { |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 30 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 31 | using ndn::Name; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 33 | class SyncProtocolAdapterFixture : public IoKeyChainFixture |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | SyncProtocolAdapterFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 37 | : syncPrefix("/localhop/ndn/nlsr/sync") |
| 38 | , nameLsaUserPrefix("/localhop/ndn/nlsr/LSA/NAME") |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 39 | , syncInterestLifetime(60_s) |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 40 | { |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 41 | syncPrefix.appendVersion(4); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 44 | void |
| 45 | addNodes() |
| 46 | { |
| 47 | for (int i = 0; i < 2; i++) { |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 48 | faces[i] = std::make_shared<ndn::DummyClientFace>(m_io, ndn::DummyClientFace::Options{true, true}); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 49 | userPrefixes[i] = Name(nameLsaUserPrefix).appendNumber(i); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 50 | nodes[i] = std::make_shared<SyncProtocolAdapter>( |
| 51 | *faces[i], m_keyChain, SyncProtocol::PSYNC, syncPrefix, userPrefixes[i], |
| 52 | syncInterestLifetime, |
| 53 | [i, this] (const Name& updateName, uint64_t highSeq, uint64_t incomingFaceId) { |
| 54 | prefixToSeq[i].emplace(updateName, highSeq); |
| 55 | }); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | faces[0]->linkTo(*faces[1]); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 59 | advanceClocks(10_ms, 10); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 63 | Name syncPrefix; |
| 64 | Name nameLsaUserPrefix; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 65 | Name userPrefixes[2]; |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 66 | time::milliseconds syncInterestLifetime; |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 67 | std::shared_ptr<ndn::DummyClientFace> faces[2]; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 68 | std::shared_ptr<SyncProtocolAdapter> nodes[2]; |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 69 | std::map<Name, uint64_t> prefixToSeq[2]; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 72 | BOOST_AUTO_TEST_SUITE(TestSyncProtocolAdapter) |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 73 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 74 | BOOST_FIXTURE_TEST_CASE(Basic, SyncProtocolAdapterFixture) |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 75 | { |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 76 | addNodes(); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 77 | |
| 78 | nodes[0]->publishUpdate(userPrefixes[0], 10); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 79 | advanceClocks(1_s, 100); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 80 | |
| 81 | auto it = prefixToSeq[1].find(userPrefixes[0]); |
| 82 | BOOST_CHECK(it != prefixToSeq[1].end()); |
| 83 | BOOST_CHECK_EQUAL(it->first, userPrefixes[0]); |
| 84 | BOOST_CHECK_EQUAL(it->second, 10); |
| 85 | |
| 86 | nodes[1]->publishUpdate(userPrefixes[1], 100); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 87 | advanceClocks(1_s, 100); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 88 | |
| 89 | it = prefixToSeq[0].find(userPrefixes[1]); |
| 90 | BOOST_CHECK(it != prefixToSeq[0].end()); |
| 91 | BOOST_CHECK_EQUAL(it->first, userPrefixes[1]); |
| 92 | BOOST_CHECK_EQUAL(it->second, 100); |
| 93 | |
| 94 | Name adjLsaUserPrefix("/localhop/ndn/nlsr/LSA/ADJACENCY"); |
| 95 | nodes[0]->addUserNode(adjLsaUserPrefix); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 96 | advanceClocks(1_s, 100); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 97 | nodes[0]->publishUpdate(adjLsaUserPrefix, 10); |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 98 | advanceClocks(1_s, 100); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 99 | |
| 100 | it = prefixToSeq[1].find(adjLsaUserPrefix); |
| 101 | BOOST_CHECK(it != prefixToSeq[1].end()); |
| 102 | BOOST_CHECK_EQUAL(it->first, adjLsaUserPrefix); |
| 103 | BOOST_CHECK_EQUAL(it->second, 10); |
| 104 | } |
| 105 | |
| 106 | BOOST_AUTO_TEST_SUITE_END() |
| 107 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 108 | } // namespace nlsr::tests |