blob: 56696f8d299737d7308ffb5cdf54917e8c5a81fc [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/*
Saurab Dulal427e0122019-11-28 11:58:02 -06003 * Copyright (c) 2014-2020, 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
Junxiao Shi3e5120c2016-09-10 16:58:34 +000028#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080029
30namespace nlsr {
31namespace test {
32
Junxiao Shi008c9b12019-01-13 23:15:56 +000033static void
laqinfand22da512017-05-25 17:29:53 -050034processDatasetInterest(ndn::util::DummyClientFace& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080035 std::function<bool(const ndn::Block&)> isSameType)
36{
Junxiao Shi008c9b12019-01-13 23:15:56 +000037 face.processEvents(30_ms);
laqinfan35731852017-08-08 06:17:39 -050038
laqinfand22da512017-05-25 17:29:53 -050039 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Jiewen Tana0497d82015-02-02 21:59:18 -080040
laqinfand22da512017-05-25 17:29:53 -050041 ndn::Block parser(face.sentData[0].getContent());
Jiewen Tana0497d82015-02-02 21:59:18 -080042 parser.parse();
43
44 ndn::Block::element_const_iterator it = parser.elements_begin();
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050045 BOOST_CHECK_EQUAL(isSameType(*it++), true);
Jiewen Tana0497d82015-02-02 21:59:18 -080046 BOOST_CHECK(it == parser.elements_end());
47
laqinfand22da512017-05-25 17:29:53 -050048 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080049}
50
Jiewen Tana0497d82015-02-02 21:59:18 -080051BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
52
laqinfand22da512017-05-25 17:29:53 -050053BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080054{
Saurab Dulal427e0122019-11-28 11:58:02 -060055 nlsr::test::checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050056
Jiewen Tana0497d82015-02-02 21:59:18 -080057 // Install adjacency LSA
58 AdjLsa adjLsa;
Ashlesh Gawande57a87172020-05-09 19:47:06 -070059 adjLsa.m_expirationTimePoint = ndn::time::system_clock::now() + 3600_s;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080060 adjLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080061 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070062 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080063
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060064 std::vector<double> angles = {20.00, 30.00};
65
Jiewen Tana0497d82015-02-02 21:59:18 -080066 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060067 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -070068 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -080069
laqinfan35731852017-08-08 06:17:39 -050070 // Install routing table
71 RoutingTableEntry rte1("desrouter1");
72 const ndn::Name& DEST_ROUTER = rte1.getDestination();
73
74 NextHop nh = createNextHop("udp://face-test1", 10);
75
76 rt1.addNextHop(DEST_ROUTER, nh);
77
Jiewen Tana0497d82015-02-02 21:59:18 -080078 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000079 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080080 processDatasetInterest(face,
81 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
82
83 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000084 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080085 processDatasetInterest(face,
86 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
87
88 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000089 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080090 processDatasetInterest(face,
91 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
92
laqinfan35731852017-08-08 06:17:39 -050093 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +000094 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080095 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -050096 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +000097 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -080098}
99
laqinfand22da512017-05-25 17:29:53 -0500100BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800101{
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600102 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500103 regRouterPrefix.append("nlsr");
104 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600105 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500106
Saurab Dulal427e0122019-11-28 11:58:02 -0600107 nlsr::test::checkPrefixRegistered(face,regRouterPrefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500108
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600109 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -0500110 AdjLsa adjLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800111 adjLsa.m_originRouter = "/RouterA";
laqinfand22da512017-05-25 17:29:53 -0500112 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700113 lsdb.installLsa(std::make_shared<AdjLsa>(adjLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -0800114
laqinfand22da512017-05-25 17:29:53 -0500115 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800116
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600117 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -0500118 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700119 lsdb.installLsa(std::make_shared<CoordinateLsa>(coordinateLsa));
Jiewen Tana0497d82015-02-02 21:59:18 -0800120
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600121 // Install routing table
laqinfan35731852017-08-08 06:17:39 -0500122 RoutingTableEntry rte1("desrouter1");
123 const ndn::Name& DEST_ROUTER = rte1.getDestination();
124
125 NextHop nh = createNextHop("udp://face-test1", 10);
126
127 rt1.addNextHop(DEST_ROUTER, nh);
128
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600129 ndn::Name routerName(conf.getRouterPrefix());
130 routerName.append("nlsr");
131
laqinfand22da512017-05-25 17:29:53 -0500132 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600133 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500134 processDatasetInterest(face,
135 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800136
laqinfand22da512017-05-25 17:29:53 -0500137 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600138 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500139 processDatasetInterest(face,
140 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800141
laqinfand22da512017-05-25 17:29:53 -0500142 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600143 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500144 processDatasetInterest(face,
145 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800146
laqinfan35731852017-08-08 06:17:39 -0500147 // Request Routing Table
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600148 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")));
laqinfand22da512017-05-25 17:29:53 -0500149 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500150 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000151 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800152}
153
154BOOST_AUTO_TEST_SUITE_END()
155
156} // namespace test
157} // namespace nlsr