blob: 1b80a82f54ba7984d3e986d680fcc395ceec9afa [file] [log] [blame]
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande30d96e42021-03-21 19:15:33 -07002/*
Junxiao Shi43f37a02023-08-09 00:09:00 +00003 * Copyright (c) 2014-2023, The University of Memphis,
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -05004 * 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 Gawande30d96e42021-03-21 19:15:33 -070020 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050021
22#include "communication/sync-protocol-adapter.hpp"
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040023
24#include "tests/boost-test.hpp"
25#include "tests/io-key-chain-fixture.hpp"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050026
27#include <ndn-cxx/util/dummy-client-face.hpp>
28
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050029namespace nlsr {
30namespace test {
31
Junxiao Shi43f37a02023-08-09 00:09:00 +000032using ndn::Name;
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050033
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040034class SyncProtocolAdapterFixture : public IoKeyChainFixture
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050035{
36public:
37 SyncProtocolAdapterFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040038 : syncPrefix("/localhop/ndn/nlsr/sync")
39 , nameLsaUserPrefix("/localhop/ndn/nlsr/LSA/NAME")
Junxiao Shi43f37a02023-08-09 00:09:00 +000040 , syncInterestLifetime(60_s)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050041 {
Davide Pesaventocb065f12019-12-27 01:03:34 -050042 syncPrefix.appendVersion(4);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050043 }
44
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050045 void
46 addNodes()
47 {
48 for (int i = 0; i < 2; i++) {
Junxiao Shi43f37a02023-08-09 00:09:00 +000049 faces[i] = std::make_shared<ndn::DummyClientFace>(m_io, ndn::DummyClientFace::Options{true, true});
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050050 userPrefixes[i] = Name(nameLsaUserPrefix).appendNumber(i);
Junxiao Shi43f37a02023-08-09 00:09:00 +000051 nodes[i] = std::make_shared<SyncProtocolAdapter>(
52 *faces[i], m_keyChain, SyncProtocol::PSYNC, syncPrefix, userPrefixes[i],
53 syncInterestLifetime,
54 [i, this] (const Name& updateName, uint64_t highSeq, uint64_t incomingFaceId) {
55 prefixToSeq[i].emplace(updateName, highSeq);
56 });
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050057 }
58
59 faces[0]->linkTo(*faces[1]);
Junxiao Shi43f37a02023-08-09 00:09:00 +000060 advanceClocks(10_ms, 10);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050061 }
62
63public:
Junxiao Shi43f37a02023-08-09 00:09:00 +000064 Name syncPrefix;
65 Name nameLsaUserPrefix;
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050066 Name userPrefixes[2];
Junxiao Shi43f37a02023-08-09 00:09:00 +000067 ndn::time::milliseconds syncInterestLifetime;
68 std::shared_ptr<ndn::DummyClientFace> faces[2];
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050069 std::shared_ptr<SyncProtocolAdapter> nodes[2];
Junxiao Shi43f37a02023-08-09 00:09:00 +000070 std::map<Name, uint64_t> prefixToSeq[2];
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050071};
72
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070073BOOST_AUTO_TEST_SUITE(TestSyncProtocolAdapter)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050074
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070075BOOST_FIXTURE_TEST_CASE(Basic, SyncProtocolAdapterFixture)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050076{
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070077 addNodes();
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050078
79 nodes[0]->publishUpdate(userPrefixes[0], 10);
Junxiao Shi43f37a02023-08-09 00:09:00 +000080 advanceClocks(1_s, 100);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050081
82 auto it = prefixToSeq[1].find(userPrefixes[0]);
83 BOOST_CHECK(it != prefixToSeq[1].end());
84 BOOST_CHECK_EQUAL(it->first, userPrefixes[0]);
85 BOOST_CHECK_EQUAL(it->second, 10);
86
87 nodes[1]->publishUpdate(userPrefixes[1], 100);
Junxiao Shi43f37a02023-08-09 00:09:00 +000088 advanceClocks(1_s, 100);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050089
90 it = prefixToSeq[0].find(userPrefixes[1]);
91 BOOST_CHECK(it != prefixToSeq[0].end());
92 BOOST_CHECK_EQUAL(it->first, userPrefixes[1]);
93 BOOST_CHECK_EQUAL(it->second, 100);
94
95 Name adjLsaUserPrefix("/localhop/ndn/nlsr/LSA/ADJACENCY");
96 nodes[0]->addUserNode(adjLsaUserPrefix);
Junxiao Shi43f37a02023-08-09 00:09:00 +000097 advanceClocks(1_s, 100);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050098 nodes[0]->publishUpdate(adjLsaUserPrefix, 10);
Junxiao Shi43f37a02023-08-09 00:09:00 +000099 advanceClocks(1_s, 100);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500100
101 it = prefixToSeq[1].find(adjLsaUserPrefix);
102 BOOST_CHECK(it != prefixToSeq[1].end());
103 BOOST_CHECK_EQUAL(it->first, adjLsaUserPrefix);
104 BOOST_CHECK_EQUAL(it->second, 10);
105}
106
107BOOST_AUTO_TEST_SUITE_END()
108
109} // namespace test
Davide Pesaventocb065f12019-12-27 01:03:34 -0500110} // namespace nlsr