blob: 698895ebea2db175e79b69b81864759783c57800 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Davide Pesavento6002e6a2021-03-17 15:37:32 -04003 * Copyright (c) 2014-2021, The University of Memphis,
Jiewen Tana0497d82015-02-02 21:59:18 -08004 * 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 Gawande0421bc62020-05-08 20:42:19 -070020 */
Jiewen Tana0497d82015-02-02 21:59:18 -080021
laqinfan35731852017-08-08 06:17:39 -050022#include "publisher/dataset-interest-handler.hpp"
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070023#include "tlv-nlsr.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080024
Davide Pesaventocb065f12019-12-27 01:03:34 -050025#include "tests/test-common.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080026#include "publisher-fixture.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080027
Jiewen Tana0497d82015-02-02 21:59:18 -080028namespace nlsr {
29namespace test {
30
Junxiao Shi008c9b12019-01-13 23:15:56 +000031static void
laqinfand22da512017-05-25 17:29:53 -050032processDatasetInterest(ndn::util::DummyClientFace& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080033 std::function<bool(const ndn::Block&)> isSameType)
34{
Junxiao Shi008c9b12019-01-13 23:15:56 +000035 face.processEvents(30_ms);
laqinfan35731852017-08-08 06:17:39 -050036
laqinfand22da512017-05-25 17:29:53 -050037 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Jiewen Tana0497d82015-02-02 21:59:18 -080038
laqinfand22da512017-05-25 17:29:53 -050039 ndn::Block parser(face.sentData[0].getContent());
Jiewen Tana0497d82015-02-02 21:59:18 -080040 parser.parse();
41
Davide Pesavento6002e6a2021-03-17 15:37:32 -040042 auto it = parser.elements_begin();
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050043 BOOST_CHECK_EQUAL(isSameType(*it++), true);
Jiewen Tana0497d82015-02-02 21:59:18 -080044 BOOST_CHECK(it == parser.elements_end());
45
laqinfand22da512017-05-25 17:29:53 -050046 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080047}
48
Jiewen Tana0497d82015-02-02 21:59:18 -080049BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
50
laqinfand22da512017-05-25 17:29:53 -050051BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080052{
Saurab Dulal427e0122019-11-28 11:58:02 -060053 nlsr::test::checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050054
Jiewen Tana0497d82015-02-02 21:59:18 -080055 // Install adjacency LSA
56 AdjLsa adjLsa;
Ashlesh Gawande57a87172020-05-09 19:47:06 -070057 adjLsa.m_expirationTimePoint = ndn::time::system_clock::now() + 3600_s;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080058 adjLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080059 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070060 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080061
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060062 std::vector<double> angles = {20.00, 30.00};
63
Jiewen Tana0497d82015-02-02 21:59:18 -080064 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060065 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070066 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080067
laqinfan35731852017-08-08 06:17:39 -050068 // Install routing table
69 RoutingTableEntry rte1("desrouter1");
70 const ndn::Name& DEST_ROUTER = rte1.getDestination();
71
72 NextHop nh = createNextHop("udp://face-test1", 10);
73
74 rt1.addNextHop(DEST_ROUTER, nh);
75
Jiewen Tana0497d82015-02-02 21:59:18 -080076 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000077 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080078 processDatasetInterest(face,
79 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
80
81 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000082 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080083 processDatasetInterest(face,
84 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
85
86 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000087 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080088 processDatasetInterest(face,
89 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
90
laqinfan35731852017-08-08 06:17:39 -050091 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +000092 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080093 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -050094 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +000095 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -080096}
97
Davide Pesavento6002e6a2021-03-17 15:37:32 -040098BOOST_AUTO_TEST_CASE(RouterName)
Jiewen Tana0497d82015-02-02 21:59:18 -080099{
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600100 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500101 regRouterPrefix.append("nlsr");
102 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600103 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500104
Saurab Dulal427e0122019-11-28 11:58:02 -0600105 nlsr::test::checkPrefixRegistered(face,regRouterPrefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500106
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600107 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -0500108 AdjLsa adjLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800109 adjLsa.m_originRouter = "/RouterA";
laqinfand22da512017-05-25 17:29:53 -0500110 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700111 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -0800112
laqinfand22da512017-05-25 17:29:53 -0500113 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800114
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600115 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -0500116 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700117 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -0800118
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600119 // Install routing table
laqinfan35731852017-08-08 06:17:39 -0500120 RoutingTableEntry rte1("desrouter1");
laqinfan35731852017-08-08 06:17:39 -0500121 NextHop nh = createNextHop("udp://face-test1", 10);
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400122 rt1.addNextHop(rte1.getDestination(), nh);
laqinfan35731852017-08-08 06:17:39 -0500123
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600124 ndn::Name routerName(conf.getRouterPrefix());
125 routerName.append("nlsr");
126
laqinfand22da512017-05-25 17:29:53 -0500127 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600128 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500129 processDatasetInterest(face,
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400130 [] (const auto& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800131
laqinfand22da512017-05-25 17:29:53 -0500132 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600133 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500134 processDatasetInterest(face,
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400135 [] (const auto& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800136
laqinfand22da512017-05-25 17:29:53 -0500137 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600138 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500139 processDatasetInterest(face,
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400140 [] (const auto& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800141
laqinfan35731852017-08-08 06:17:39 -0500142 // Request Routing Table
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400143 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500144 processDatasetInterest(face,
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400145 [] (const auto& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800146}
147
148BOOST_AUTO_TEST_SUITE_END()
149
150} // namespace test
151} // namespace nlsr