Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 4 | * 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 Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 20 | */ |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 21 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 22 | #include "publisher/dataset-interest-handler.hpp" |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 23 | #include "tlv-nlsr.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 24 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 25 | #include "tests/publisher/publisher-fixture.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 26 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame^] | 27 | namespace nlsr::tests { |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 28 | |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 29 | BOOST_FIXTURE_TEST_SUITE(TestDatasetInterestHandler, PublisherFixture) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 30 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(Localhost) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 32 | { |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 33 | checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 34 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 35 | // Install adjacency LSA |
| 36 | AdjLsa adjLsa; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 37 | adjLsa.m_expirationTimePoint = ndn::time::system_clock::now() + 3600_s; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 38 | adjLsa.m_originRouter = "/RouterA"; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 39 | addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 40 | lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 41 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 42 | std::vector<double> angles = {20.00, 30.00}; |
| 43 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 44 | // Install coordinate LSA |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 45 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 46 | lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 47 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 48 | // Install routing table |
| 49 | RoutingTableEntry rte1("desrouter1"); |
| 50 | const ndn::Name& DEST_ROUTER = rte1.getDestination(); |
| 51 | |
| 52 | NextHop nh = createNextHop("udp://face-test1", 10); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 53 | rt1.addNextHop(DEST_ROUTER, nh); |
| 54 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 55 | // Request adjacency LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 56 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 57 | processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::AdjacencyLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 58 | |
| 59 | // Request coordinate LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 60 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 61 | processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::CoordinateLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 62 | |
| 63 | // Request Name LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 64 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 65 | processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::NameLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 66 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 67 | // Request Routing Table |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 68 | face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 69 | processDatasetInterest([] (const ndn::Block& block) { return block.type() == nlsr::tlv::RoutingTable; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Davide Pesavento | 6002e6a | 2021-03-17 15:37:32 -0400 | [diff] [blame] | 72 | BOOST_AUTO_TEST_CASE(RouterName) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 73 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 74 | ndn::Name regRouterPrefix(conf.getRouterPrefix()); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 75 | regRouterPrefix.append("nlsr"); |
| 76 | // Should already be added to dispatcher |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 77 | BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 78 | |
Davide Pesavento | d1f1df8 | 2022-03-12 16:40:37 -0500 | [diff] [blame] | 79 | checkPrefixRegistered(face,regRouterPrefix); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 80 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 81 | // Install adjacencies LSA |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 82 | AdjLsa adjLsa; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 83 | adjLsa.m_originRouter = "/RouterA"; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 84 | addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 85 | lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 86 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 87 | std::vector<double> angles = {20.00, 30.00}; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 88 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 89 | // Install coordinate LSA |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 90 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 91 | lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 92 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 93 | // Install routing table |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 94 | RoutingTableEntry rte1("desrouter1"); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 95 | NextHop nh = createNextHop("udp://face-test1", 10); |
Davide Pesavento | 6002e6a | 2021-03-17 15:37:32 -0400 | [diff] [blame] | 96 | rt1.addNextHop(rte1.getDestination(), nh); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 97 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 98 | ndn::Name routerName(conf.getRouterPrefix()); |
| 99 | routerName.append("nlsr"); |
| 100 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 101 | // Request adjacency LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 102 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 103 | processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::AdjacencyLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 104 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 105 | // Request coordinate LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 106 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 107 | processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::CoordinateLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 108 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 109 | // Request Name LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 110 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 111 | processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::NameLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 112 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 113 | // Request Routing Table |
Davide Pesavento | 6002e6a | 2021-03-17 15:37:32 -0400 | [diff] [blame] | 114 | face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")).setCanBePrefix(true)); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 115 | processDatasetInterest([] (const auto& block) { return block.type() == nlsr::tlv::RoutingTable; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | BOOST_AUTO_TEST_SUITE_END() |
| 119 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame^] | 120 | } // namespace nlsr::tests |