blob: 2ec5d352c8795cc49571ae66e0013c35de80880b [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 Gawande0db4d4d2020-02-05 20:30:02 -080059 adjLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080060 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
61 lsdb.installAdjLsa(adjLsa);
62
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060063 std::vector<double> angles = {20.00, 30.00};
64
Jiewen Tana0497d82015-02-02 21:59:18 -080065 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060066 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Jiewen Tana0497d82015-02-02 21:59:18 -080067 lsdb.installCoordinateLsa(coordinateLsa);
68
69 // Install Name LSA
70 NameLsa nameLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080071 nameLsa.m_originRouter = "/RouterA";
Jiewen Tana0497d82015-02-02 21:59:18 -080072 nameLsa.addName("/RouterA/name1");
73 lsdb.installNameLsa(nameLsa);
74
laqinfan35731852017-08-08 06:17:39 -050075 // Install routing table
76 RoutingTableEntry rte1("desrouter1");
77 const ndn::Name& DEST_ROUTER = rte1.getDestination();
78
79 NextHop nh = createNextHop("udp://face-test1", 10);
80
81 rt1.addNextHop(DEST_ROUTER, nh);
82
Jiewen Tana0497d82015-02-02 21:59:18 -080083 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000084 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080085 processDatasetInterest(face,
86 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
87
88 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000089 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080090 processDatasetInterest(face,
91 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
92
93 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000094 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080095 processDatasetInterest(face,
96 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
97
laqinfan35731852017-08-08 06:17:39 -050098 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +000099 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -0800100 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500101 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000102 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800103}
104
laqinfand22da512017-05-25 17:29:53 -0500105BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800106{
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600107 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500108 regRouterPrefix.append("nlsr");
109 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600110 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500111
Saurab Dulal427e0122019-11-28 11:58:02 -0600112 nlsr::test::checkPrefixRegistered(face,regRouterPrefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500113
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600114 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -0500115 AdjLsa adjLsa;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800116 adjLsa.m_originRouter = "/RouterA";
laqinfand22da512017-05-25 17:29:53 -0500117 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
118 lsdb.installAdjLsa(adjLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800119
laqinfand22da512017-05-25 17:29:53 -0500120 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800121
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600122 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -0500123 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
124 lsdb.installCoordinateLsa(coordinateLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800125
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600126 // Install routing table
laqinfan35731852017-08-08 06:17:39 -0500127 RoutingTableEntry rte1("desrouter1");
128 const ndn::Name& DEST_ROUTER = rte1.getDestination();
129
130 NextHop nh = createNextHop("udp://face-test1", 10);
131
132 rt1.addNextHop(DEST_ROUTER, nh);
133
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600134 ndn::Name routerName(conf.getRouterPrefix());
135 routerName.append("nlsr");
136
laqinfand22da512017-05-25 17:29:53 -0500137 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600138 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500139 processDatasetInterest(face,
140 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800141
laqinfand22da512017-05-25 17:29:53 -0500142 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600143 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500144 processDatasetInterest(face,
145 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800146
laqinfand22da512017-05-25 17:29:53 -0500147 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600148 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500149 processDatasetInterest(face,
150 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800151
laqinfan35731852017-08-08 06:17:39 -0500152 // Request Routing Table
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600153 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")));
laqinfand22da512017-05-25 17:29:53 -0500154 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500155 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000156 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800157}
158
159BOOST_AUTO_TEST_SUITE_END()
160
161} // namespace test
162} // namespace nlsr