blob: 2e71585e20f648a6d6b923d92553099d0032ee16 [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 Pesaventod1f1df82022-03-12 16:40:37 -05003 * Copyright (c) 2014-2022, 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
Jiewen Tana0497d82015-02-02 21:59:18 -080027namespace nlsr {
28namespace test {
29
Davide Pesaventod1f1df82022-03-12 16:40:37 -050030BOOST_FIXTURE_TEST_SUITE(TestDatasetInterestHandler, PublisherFixture)
Jiewen Tana0497d82015-02-02 21:59:18 -080031
laqinfand22da512017-05-25 17:29:53 -050032BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080033{
Davide Pesaventod1f1df82022-03-12 16:40:37 -050034 checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050035
Jiewen Tana0497d82015-02-02 21:59:18 -080036 // Install adjacency LSA
37 AdjLsa adjLsa;
Ashlesh Gawande57a87172020-05-09 19:47:06 -070038 adjLsa.m_expirationTimePoint = ndn::time::system_clock::now() + 3600_s;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080039 adjLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080040 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070041 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080042
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060043 std::vector<double> angles = {20.00, 30.00};
44
Jiewen Tana0497d82015-02-02 21:59:18 -080045 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060046 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070047 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080048
laqinfan35731852017-08-08 06:17:39 -050049 // Install routing table
50 RoutingTableEntry rte1("desrouter1");
51 const ndn::Name& DEST_ROUTER = rte1.getDestination();
52
53 NextHop nh = createNextHop("udp://face-test1", 10);
laqinfan35731852017-08-08 06:17:39 -050054 rt1.addNextHop(DEST_ROUTER, nh);
55
Jiewen Tana0497d82015-02-02 21:59:18 -080056 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000057 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040058 processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080059
60 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000061 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040062 processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080063
64 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000065 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040066 processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -080067
laqinfan35731852017-08-08 06:17:39 -050068 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +000069 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040070 processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -080071}
72
Davide Pesavento6002e6a2021-03-17 15:37:32 -040073BOOST_AUTO_TEST_CASE(RouterName)
Jiewen Tana0497d82015-02-02 21:59:18 -080074{
Ashlesh Gawande85998a12017-12-07 22:22:13 -060075 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050076 regRouterPrefix.append("nlsr");
77 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -060078 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050079
Davide Pesaventod1f1df82022-03-12 16:40:37 -050080 checkPrefixRegistered(face,regRouterPrefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050081
Ashlesh Gawande85998a12017-12-07 22:22:13 -060082 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -050083 AdjLsa adjLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080084 adjLsa.m_originRouter = "/RouterA";
laqinfand22da512017-05-25 17:29:53 -050085 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070086 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080087
laqinfand22da512017-05-25 17:29:53 -050088 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -080089
Ashlesh Gawande85998a12017-12-07 22:22:13 -060090 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -050091 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070092 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080093
Ashlesh Gawande85998a12017-12-07 22:22:13 -060094 // Install routing table
laqinfan35731852017-08-08 06:17:39 -050095 RoutingTableEntry rte1("desrouter1");
laqinfan35731852017-08-08 06:17:39 -050096 NextHop nh = createNextHop("udp://face-test1", 10);
Davide Pesavento6002e6a2021-03-17 15:37:32 -040097 rt1.addNextHop(rte1.getDestination(), nh);
laqinfan35731852017-08-08 06:17:39 -050098
Ashlesh Gawande85998a12017-12-07 22:22:13 -060099 ndn::Name routerName(conf.getRouterPrefix());
100 routerName.append("nlsr");
101
laqinfand22da512017-05-25 17:29:53 -0500102 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600103 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400104 processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800105
laqinfand22da512017-05-25 17:29:53 -0500106 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600107 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400108 processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800109
laqinfand22da512017-05-25 17:29:53 -0500110 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600111 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400112 processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800113
laqinfan35731852017-08-08 06:17:39 -0500114 // Request Routing Table
Davide Pesavento6002e6a2021-03-17 15:37:32 -0400115 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")).setCanBePrefix(true));
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400116 processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800117}
118
119BOOST_AUTO_TEST_SUITE_END()
120
121} // namespace test
122} // namespace nlsr