blob: bbb37a757f7c0d01d9dd13026e9ff0b3b0dae3d0 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
laqinfan35731852017-08-08 06:17:39 -05003 * Copyright (c) 2014-2018, 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
36void
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{
laqinfand22da512017-05-25 17:29:53 -050040 face.processEvents(ndn::time::milliseconds(30));
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
laqinfand22da512017-05-25 17:29:53 -050089 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("adjacencies")));
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
laqinfand22da512017-05-25 17:29:53 -050094 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("coordinates")));
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
laqinfand22da512017-05-25 17:29:53 -050099 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("names")));
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
104 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/routing-table")));
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 -0500110
111BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800112{
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500113 ndn::Name regRouterPrefix(nlsr.getConfParameter().getRouterPrefix());
114 regRouterPrefix.append("nlsr");
115 // Should already be added to dispatcher
116 BOOST_CHECK_THROW(nlsr.getDispatcher().addTopPrefix(regRouterPrefix), std::out_of_range);
117
118 checkPrefixRegistered(regRouterPrefix);
119
laqinfand22da512017-05-25 17:29:53 -0500120 //Install adjacencies LSA
121 AdjLsa adjLsa;
122 adjLsa.setOrigRouter("/RouterA");
123 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
124 lsdb.installAdjLsa(adjLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800125
laqinfand22da512017-05-25 17:29:53 -0500126 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800127
laqinfand22da512017-05-25 17:29:53 -0500128 //Install coordinate LSA
129 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
130 lsdb.installCoordinateLsa(coordinateLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800131
laqinfan35731852017-08-08 06:17:39 -0500132 //Install routing table
133 RoutingTableEntry rte1("desrouter1");
134 const ndn::Name& DEST_ROUTER = rte1.getDestination();
135
136 NextHop nh = createNextHop("udp://face-test1", 10);
137
138 rt1.addNextHop(DEST_ROUTER, nh);
139
laqinfand22da512017-05-25 17:29:53 -0500140 // Request adjacency LSAs
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500141 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("adjacencies")));
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 Gawandecba0ae22018-03-27 17:57:56 -0500146 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("coordinates")));
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 Gawandecba0ae22018-03-27 17:57:56 -0500151 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/lsdb").append("names")));
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 Gawandecba0ae22018-03-27 17:57:56 -0500156 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/nlsr/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