blob: 0266981a972062bf66225eb78c009a2827d09f60 [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/*
3 * Copyright (c) 2014-2021, 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 Pesaventocb065f12019-12-27 01:03:34 -050023#include "tests/test-common.hpp"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050024
25#include <ndn-cxx/util/dummy-client-face.hpp>
26
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070027#include <boost/lexical_cast.hpp>
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050028
29namespace nlsr {
30namespace test {
31
32using namespace ndn;
33
34class SyncProtocolAdapterFixture : public UnitTestTimeFixture
35{
36public:
37 SyncProtocolAdapterFixture()
38 : syncPrefix("/localhop/ndn/nlsr/sync/")
39 , nameLsaUserPrefix("/localhop/ndn/nlsr/LSA/NAME")
40 , syncInterestLifetime(time::seconds(60))
41 {
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++) {
49 faces[i] = std::make_shared<ndn::util::DummyClientFace>(m_ioService,
50 util::DummyClientFace::Options{true, true});
51 userPrefixes[i] = Name(nameLsaUserPrefix).appendNumber(i);
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070052 nodes[i] = std::make_shared<SyncProtocolAdapter>(*faces[i], SYNC_PROTOCOL_PSYNC, syncPrefix,
Davide Pesaventocb065f12019-12-27 01:03:34 -050053 userPrefixes[i],
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050054 syncInterestLifetime,
55 [i, this] (const ndn::Name& updateName,
56 uint64_t highSeq) {
57 prefixToSeq[i].emplace(updateName, highSeq);
58 });
59 }
60
61 faces[0]->linkTo(*faces[1]);
62 advanceClocks(ndn::time::milliseconds(10), 10);
63 }
64
65public:
66 Name syncPrefix, nameLsaUserPrefix;
67 Name userPrefixes[2];
68 time::milliseconds syncInterestLifetime;
69 std::shared_ptr<ndn::util::DummyClientFace> faces[2];
70 std::shared_ptr<SyncProtocolAdapter> nodes[2];
71 std::map<ndn::Name, uint64_t> prefixToSeq[2];
72};
73
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070074BOOST_AUTO_TEST_SUITE(TestSyncProtocolAdapter)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050075
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070076BOOST_FIXTURE_TEST_CASE(Basic, SyncProtocolAdapterFixture)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050077{
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070078 addNodes();
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050079
80 nodes[0]->publishUpdate(userPrefixes[0], 10);
81 advanceClocks(ndn::time::milliseconds(1000), 100);
82
83 auto it = prefixToSeq[1].find(userPrefixes[0]);
84 BOOST_CHECK(it != prefixToSeq[1].end());
85 BOOST_CHECK_EQUAL(it->first, userPrefixes[0]);
86 BOOST_CHECK_EQUAL(it->second, 10);
87
88 nodes[1]->publishUpdate(userPrefixes[1], 100);
89 advanceClocks(ndn::time::milliseconds(1000), 100);
90
91 it = prefixToSeq[0].find(userPrefixes[1]);
92 BOOST_CHECK(it != prefixToSeq[0].end());
93 BOOST_CHECK_EQUAL(it->first, userPrefixes[1]);
94 BOOST_CHECK_EQUAL(it->second, 100);
95
96 Name adjLsaUserPrefix("/localhop/ndn/nlsr/LSA/ADJACENCY");
97 nodes[0]->addUserNode(adjLsaUserPrefix);
98 advanceClocks(ndn::time::milliseconds(1000), 100);
99 nodes[0]->publishUpdate(adjLsaUserPrefix, 10);
100 advanceClocks(ndn::time::milliseconds(1000), 100);
101
102 it = prefixToSeq[1].find(adjLsaUserPrefix);
103 BOOST_CHECK(it != prefixToSeq[1].end());
104 BOOST_CHECK_EQUAL(it->first, adjLsaUserPrefix);
105 BOOST_CHECK_EQUAL(it->second, 10);
106}
107
108BOOST_AUTO_TEST_SUITE_END()
109
110} // namespace test
Davide Pesaventocb065f12019-12-27 01:03:34 -0500111} // namespace nlsr