Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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/>. |
| 20 | **/ |
| 21 | |
| 22 | #include "communication/sync-protocol-adapter.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame^] | 23 | #include "tests/test-common.hpp" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 24 | |
| 25 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 26 | |
| 27 | #include <boost/mpl/int.hpp> |
| 28 | #include <boost/mpl/vector.hpp> |
| 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
| 33 | using namespace ndn; |
| 34 | |
| 35 | class SyncProtocolAdapterFixture : public UnitTestTimeFixture |
| 36 | { |
| 37 | public: |
| 38 | SyncProtocolAdapterFixture() |
| 39 | : syncPrefix("/localhop/ndn/nlsr/sync/") |
| 40 | , nameLsaUserPrefix("/localhop/ndn/nlsr/LSA/NAME") |
| 41 | , syncInterestLifetime(time::seconds(60)) |
| 42 | { |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame^] | 43 | syncPrefix.appendVersion(4); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | template <int32_t T> |
| 47 | void |
| 48 | addNodes() |
| 49 | { |
| 50 | for (int i = 0; i < 2; i++) { |
| 51 | faces[i] = std::make_shared<ndn::util::DummyClientFace>(m_ioService, |
| 52 | util::DummyClientFace::Options{true, true}); |
| 53 | userPrefixes[i] = Name(nameLsaUserPrefix).appendNumber(i); |
| 54 | nodes[i] = std::make_shared<SyncProtocolAdapter>(*faces[i], T, syncPrefix, |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame^] | 55 | userPrefixes[i], |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 56 | syncInterestLifetime, |
| 57 | [i, this] (const ndn::Name& updateName, |
| 58 | uint64_t highSeq) { |
| 59 | prefixToSeq[i].emplace(updateName, highSeq); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | faces[0]->linkTo(*faces[1]); |
| 64 | advanceClocks(ndn::time::milliseconds(10), 10); |
| 65 | } |
| 66 | |
| 67 | public: |
| 68 | Name syncPrefix, nameLsaUserPrefix; |
| 69 | Name userPrefixes[2]; |
| 70 | time::milliseconds syncInterestLifetime; |
| 71 | std::shared_ptr<ndn::util::DummyClientFace> faces[2]; |
| 72 | std::shared_ptr<SyncProtocolAdapter> nodes[2]; |
| 73 | std::map<ndn::Name, uint64_t> prefixToSeq[2]; |
| 74 | }; |
| 75 | |
| 76 | using boost::mpl::int_; |
| 77 | using Protocols = boost::mpl::vector<int_<SYNC_PROTOCOL_CHRONOSYNC>, int_<SYNC_PROTOCOL_PSYNC>>; |
| 78 | |
| 79 | BOOST_FIXTURE_TEST_SUITE(TestSyncProtocolAdapter, SyncProtocolAdapterFixture) |
| 80 | |
| 81 | BOOST_AUTO_TEST_CASE_TEMPLATE(Sync, SyncProtocol, Protocols) |
| 82 | { |
| 83 | addNodes<SyncProtocol::value>(); |
| 84 | |
| 85 | nodes[0]->publishUpdate(userPrefixes[0], 10); |
| 86 | advanceClocks(ndn::time::milliseconds(1000), 100); |
| 87 | |
| 88 | auto it = prefixToSeq[1].find(userPrefixes[0]); |
| 89 | BOOST_CHECK(it != prefixToSeq[1].end()); |
| 90 | BOOST_CHECK_EQUAL(it->first, userPrefixes[0]); |
| 91 | BOOST_CHECK_EQUAL(it->second, 10); |
| 92 | |
| 93 | nodes[1]->publishUpdate(userPrefixes[1], 100); |
| 94 | advanceClocks(ndn::time::milliseconds(1000), 100); |
| 95 | |
| 96 | it = prefixToSeq[0].find(userPrefixes[1]); |
| 97 | BOOST_CHECK(it != prefixToSeq[0].end()); |
| 98 | BOOST_CHECK_EQUAL(it->first, userPrefixes[1]); |
| 99 | BOOST_CHECK_EQUAL(it->second, 100); |
| 100 | |
| 101 | Name adjLsaUserPrefix("/localhop/ndn/nlsr/LSA/ADJACENCY"); |
| 102 | nodes[0]->addUserNode(adjLsaUserPrefix); |
| 103 | advanceClocks(ndn::time::milliseconds(1000), 100); |
| 104 | nodes[0]->publishUpdate(adjLsaUserPrefix, 10); |
| 105 | advanceClocks(ndn::time::milliseconds(1000), 100); |
| 106 | |
| 107 | it = prefixToSeq[1].find(adjLsaUserPrefix); |
| 108 | BOOST_CHECK(it != prefixToSeq[1].end()); |
| 109 | BOOST_CHECK_EQUAL(it->first, adjLsaUserPrefix); |
| 110 | BOOST_CHECK_EQUAL(it->second, 10); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_SUITE_END() |
| 114 | |
| 115 | } // namespace test |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame^] | 116 | } // namespace nlsr |