blob: 070c06dc2f78c28457081a7d23a7708dbde5c55e [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();
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050048 BOOST_CHECK_EQUAL(isSameType(*it++), true);
Jiewen Tana0497d82015-02-02 21:59:18 -080049 BOOST_CHECK(it == parser.elements_end());
50
laqinfand22da512017-05-25 17:29:53 -050051 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080052}
53
Jiewen Tana0497d82015-02-02 21:59:18 -080054BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
55
laqinfand22da512017-05-25 17:29:53 -050056BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080057{
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050058 checkPrefixRegistered(Nlsr::LOCALHOST_PREFIX);
59
Jiewen Tana0497d82015-02-02 21:59:18 -080060 // Install adjacency LSA
61 AdjLsa adjLsa;
62 adjLsa.setOrigRouter("/RouterA");
63 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
64 lsdb.installAdjLsa(adjLsa);
65
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060066 std::vector<double> angles = {20.00, 30.00};
67
Jiewen Tana0497d82015-02-02 21:59:18 -080068 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060069 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Jiewen Tana0497d82015-02-02 21:59:18 -080070 lsdb.installCoordinateLsa(coordinateLsa);
71
72 // Install Name LSA
73 NameLsa nameLsa;
74 nameLsa.setOrigRouter("/RouterA");
75 nameLsa.addName("/RouterA/name1");
76 lsdb.installNameLsa(nameLsa);
77
laqinfan35731852017-08-08 06:17:39 -050078 // Install routing table
79 RoutingTableEntry rte1("desrouter1");
80 const ndn::Name& DEST_ROUTER = rte1.getDestination();
81
82 NextHop nh = createNextHop("udp://face-test1", 10);
83
84 rt1.addNextHop(DEST_ROUTER, nh);
85
Jiewen Tana0497d82015-02-02 21:59:18 -080086 // Request adjacency LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000087 face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080088 processDatasetInterest(face,
89 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
90
91 // Request coordinate LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000092 face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080093 processDatasetInterest(face,
94 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
95
96 // Request Name LSAs
Junxiao Shi008c9b12019-01-13 23:15:56 +000097 face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -080098 processDatasetInterest(face,
99 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
100
laqinfan35731852017-08-08 06:17:39 -0500101 // Request Routing Table
Junxiao Shi008c9b12019-01-13 23:15:56 +0000102 face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
Jiewen Tana0497d82015-02-02 21:59:18 -0800103 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500104 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000105 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800106}
107
laqinfand22da512017-05-25 17:29:53 -0500108BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800109{
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600110 ndn::Name regRouterPrefix(conf.getRouterPrefix());
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500111 regRouterPrefix.append("nlsr");
112 // Should already be added to dispatcher
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600113 BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500114
115 checkPrefixRegistered(regRouterPrefix);
116
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600117 // Install adjacencies LSA
laqinfand22da512017-05-25 17:29:53 -0500118 AdjLsa adjLsa;
119 adjLsa.setOrigRouter("/RouterA");
120 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
121 lsdb.installAdjLsa(adjLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800122
laqinfand22da512017-05-25 17:29:53 -0500123 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800124
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600125 // Install coordinate LSA
laqinfand22da512017-05-25 17:29:53 -0500126 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
127 lsdb.installCoordinateLsa(coordinateLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800128
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600129 // Install routing table
laqinfan35731852017-08-08 06:17:39 -0500130 RoutingTableEntry rte1("desrouter1");
131 const ndn::Name& DEST_ROUTER = rte1.getDestination();
132
133 NextHop nh = createNextHop("udp://face-test1", 10);
134
135 rt1.addNextHop(DEST_ROUTER, nh);
136
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600137 ndn::Name routerName(conf.getRouterPrefix());
138 routerName.append("nlsr");
139
laqinfand22da512017-05-25 17:29:53 -0500140 // Request adjacency LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600141 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500142 processDatasetInterest(face,
143 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800144
laqinfand22da512017-05-25 17:29:53 -0500145 // Request coordinate LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600146 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500147 processDatasetInterest(face,
148 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800149
laqinfand22da512017-05-25 17:29:53 -0500150 // Request Name LSAs
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600151 face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
laqinfand22da512017-05-25 17:29:53 -0500152 processDatasetInterest(face,
153 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800154
laqinfan35731852017-08-08 06:17:39 -0500155 // Request Routing Table
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600156 face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")));
laqinfand22da512017-05-25 17:29:53 -0500157 processDatasetInterest(face,
laqinfan35731852017-08-08 06:17:39 -0500158 [] (const ndn::Block& block) {
laqinfana073e2e2018-01-15 21:17:24 +0000159 return block.type() == ndn::tlv::nlsr::RoutingTable; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800160}
161
162BOOST_AUTO_TEST_SUITE_END()
163
164} // namespace test
165} // namespace nlsr