blob: 5a28b032a33daaa5a1b0b695689d77e7aacaf1d3 [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 Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, 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 Pesavento8de8a8b2022-05-12 01:26:43 -040025#include "tests/publisher/publisher-fixture.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080026
Davide Pesavento288141a2024-02-13 17:30:35 -050027namespace nlsr::tests {
Jiewen Tana0497d82015-02-02 21:59:18 -080028
Davide Pesaventod1f1df82022-03-12 16:40:37 -050029BOOST_FIXTURE_TEST_SUITE(TestDatasetInterestHandler, PublisherFixture)
Jiewen Tana0497d82015-02-02 21:59:18 -080030
laqinfand22da512017-05-25 17:29:53 -050031BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080032{
Davide Pesaventod1f1df82022-03-12 16:40:37 -050033 checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050034
Jiewen Tana0497d82015-02-02 21:59:18 -080035 // Install adjacency LSA
36 AdjLsa adjLsa;
Ashlesh Gawande57a87172020-05-09 19:47:06 -070037 adjLsa.m_expirationTimePoint = ndn::time::system_clock::now() + 3600_s;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080038 adjLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080039 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070040 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080041
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060042 std::vector<double> angles = {20.00, 30.00};
43
Jiewen Tana0497d82015-02-02 21:59:18 -080044 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060045 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070046 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080047
laqinfan35731852017-08-08 06:17:39 -050048 // Install routing table
49 RoutingTableEntry rte1("desrouter1");
50 const ndn::Name& DEST_ROUTER = rte1.getDestination();
51
52 NextHop nh = createNextHop("udp://face-test1", 10);
laqinfan35731852017-08-08 06:17:39 -050053 rt1.addNextHop(DEST_ROUTER, nh);
54
Jiewen Tana0497d82015-02-02 21:59:18 -080055 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000056 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040057 processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080058
59 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000060 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040061 processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080062
63 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000064 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040065 processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080066
laqinfan35731852017-08-08 06:17:39 -050067 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +000068 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040069 processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -080070}
71
Davide Pesavento6002e6a2021-03-17 15:37:32 -040072BOOST_AUTO_TEST_CASE(RouterName)
Jiewen Tana0497d82015-02-02 21:59:18 -080073{
Ashlesh Gawande85998a12017-12-07 22:22:13 -060074 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050075 regRouterPrefix.append("nlsr");
76 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -060077 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050078
Davide Pesaventod1f1df82022-03-12 16:40:37 -050079 checkPrefixRegistered(face,regRouterPrefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050080
Ashlesh Gawande85998a12017-12-07 22:22:13 -060081 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -050082 AdjLsa adjLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080083 adjLsa.m_originRouter = "/RouterA";
laqinfand22da512017-05-25 17:29:53 -050084 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070085 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080086
laqinfand22da512017-05-25 17:29:53 -050087 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -080088
Ashlesh Gawande85998a12017-12-07 22:22:13 -060089 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -050090 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070091 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080092
Ashlesh Gawande85998a12017-12-07 22:22:13 -060093 // Install routing table
laqinfan35731852017-08-08 06:17:39 -050094 RoutingTableEntry rte1("desrouter1");
laqinfan35731852017-08-08 06:17:39 -050095 NextHop nh = createNextHop("udp://face-test1", 10);
Davide Pesavento6002e6a2021-03-17 15:37:32 -040096 rt1.addNextHop(rte1.getDestination(), nh);
laqinfan35731852017-08-08 06:17:39 -050097
Ashlesh Gawande85998a12017-12-07 22:22:13 -060098 ndn::Name routerName(conf.getRouterPrefix());
99 routerName.append("nlsr");
100
laqinfand22da512017-05-25 17:29:53 -0500101 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600102 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400103 processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800104
laqinfand22da512017-05-25 17:29:53 -0500105 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600106 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400107 processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800108
laqinfand22da512017-05-25 17:29:53 -0500109 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600110 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400111 processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800112
laqinfan35731852017-08-08 06:17:39 -0500113 // Request Routing Table
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400114 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")).setCanBePrefix(true));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400115 processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800116}
117
118BOOST_AUTO_TEST_SUITE_END()
119
Davide Pesavento288141a2024-02-13 17:30:35 -0500120} // namespace nlsr::tests