blob: ee96ba892fc47fd0c20a6a55ff781e8e9b911d22 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi008c9b12019-01-13 23:15:56 +00003 * Copyright (c) 2014-2019, 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/>.
20 **/
21
laqinfan35731852017-08-08 06:17:39 -050022#include "publisher/dataset-interest-handler.hpp"
laqinfand22da512017-05-25 17:29:53 -050023#include "tests/test-common.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080024#include "tlv/tlv-nlsr.hpp"
25
26#include "publisher-fixture.hpp"
27#include "../boost-test.hpp"
28
Junxiao Shi3e5120c2016-09-10 16:58:34 +000029#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Jiewen Tana0497d82015-02-02 21:59:18 -080030
laqinfan35731852017-08-08 06:17:39 -050031#include <iostream>
32
Jiewen Tana0497d82015-02-02 21:59:18 -080033namespace nlsr {
34namespace test {
35
Junxiao Shi008c9b12019-01-13 23:15:56 +000036static void
laqinfand22da512017-05-25 17:29:53 -050037processDatasetInterest(ndn::util::DummyClientFace& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080038 std::function<bool(const ndn::Block&)> isSameType)
39{
Junxiao Shi008c9b12019-01-13 23:15:56 +000040 face.processEvents(30_ms);
laqinfan35731852017-08-08 06:17:39 -050041
laqinfand22da512017-05-25 17:29:53 -050042 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Jiewen Tana0497d82015-02-02 21:59:18 -080043
laqinfand22da512017-05-25 17:29:53 -050044 ndn::Block parser(face.sentData[0].getContent());
Jiewen Tana0497d82015-02-02 21:59:18 -080045 parser.parse();
46
47 ndn::Block::element_const_iterator it = parser.elements_begin();
48 BOOST_CHECK_EQUAL(isSameType(*it), true);
49 ++it;
50
51 BOOST_CHECK(it == parser.elements_end());
52
laqinfand22da512017-05-25 17:29:53 -050053 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080054}
55
Jiewen Tana0497d82015-02-02 21:59:18 -080056BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
57
laqinfand22da512017-05-25 17:29:53 -050058BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080059{
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050060 checkPrefixRegistered(Nlsr::LOCALHOST_PREFIX);
61
Jiewen Tana0497d82015-02-02 21:59:18 -080062 // Install adjacency LSA
63 AdjLsa adjLsa;
64 adjLsa.setOrigRouter("/RouterA");
65 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
66 lsdb.installAdjLsa(adjLsa);
67
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060068 std::vector<double> angles = {20.00, 30.00};
69
Jiewen Tana0497d82015-02-02 21:59:18 -080070 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060071 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Jiewen Tana0497d82015-02-02 21:59:18 -080072 lsdb.installCoordinateLsa(coordinateLsa);
73
74 // Install Name LSA
75 NameLsa nameLsa;
76 nameLsa.setOrigRouter("/RouterA");
77 nameLsa.addName("/RouterA/name1");
78 lsdb.installNameLsa(nameLsa);
79
laqinfan35731852017-08-08 06:17:39 -050080 // Install routing table
81 RoutingTableEntry rte1("desrouter1");
82 const ndn::Name& DEST_ROUTER = rte1.getDestination();
83
84 NextHop nh = createNextHop("udp://face-test1", 10);
85
86 rt1.addNextHop(DEST_ROUTER, nh);
87
Jiewen Tana0497d82015-02-02 21:59:18 -080088 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000089 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080090 processDatasetInterest(face,
91 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
92
93 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000094 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080095 processDatasetInterest(face,
96 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
97
98 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000099 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -0800100 processDatasetInterest(face,
101 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
102
laqinfan35731852017-08-08 06:17:39 -0500103 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +0000104 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -0800105 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500106 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000107 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800108}
109
laqinfand22da512017-05-25 17:29:53 -0500110BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800111{
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600112 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500113 regRouterPrefix.append("nlsr");
114 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600115 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500116
117 checkPrefixRegistered(regRouterPrefix);
118
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600119 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -0500120 AdjLsa adjLsa;
121 adjLsa.setOrigRouter("/RouterA");
122 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
123 lsdb.installAdjLsa(adjLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800124
laqinfand22da512017-05-25 17:29:53 -0500125 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800126
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600127 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -0500128 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
129 lsdb.installCoordinateLsa(coordinateLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800130
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600131 // Install routing table
laqinfan35731852017-08-08 06:17:39 -0500132 RoutingTableEntry rte1("desrouter1");
133 const ndn::Name& DEST_ROUTER = rte1.getDestination();
134
135 NextHop nh = createNextHop("udp://face-test1", 10);
136
137 rt1.addNextHop(DEST_ROUTER, nh);
138
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600139 ndn::Name routerName(conf.getRouterPrefix());
140 routerName.append("nlsr");
141
laqinfand22da512017-05-25 17:29:53 -0500142 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600143 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500144 processDatasetInterest(face,
145 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800146
laqinfand22da512017-05-25 17:29:53 -0500147 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600148 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500149 processDatasetInterest(face,
150 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800151
laqinfand22da512017-05-25 17:29:53 -0500152 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600153 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500154 processDatasetInterest(face,
155 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800156
laqinfan35731852017-08-08 06:17:39 -0500157 // Request Routing Table
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600158 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")));
laqinfand22da512017-05-25 17:29:53 -0500159 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500160 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000161 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800162}
163
164BOOST_AUTO_TEST_SUITE_END()
165
166} // namespace test
167} // namespace nlsr