blob: cd9fcf3c123ff1f7875e63e8ba6214a02af980db [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, 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
22#include "publisher/lsdb-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
31namespace nlsr {
32namespace test {
33
34void
laqinfand22da512017-05-25 17:29:53 -050035processDatasetInterest(ndn::util::DummyClientFace& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080036 std::function<bool(const ndn::Block&)> isSameType)
37{
laqinfand22da512017-05-25 17:29:53 -050038 face.processEvents(ndn::time::milliseconds(30));
39 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();
45 BOOST_CHECK_EQUAL(isSameType(*it), true);
46 ++it;
47
48 BOOST_CHECK(it == parser.elements_end());
49
laqinfand22da512017-05-25 17:29:53 -050050 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080051}
52
53void
laqinfand22da512017-05-25 17:29:53 -050054checkErrorResponse(ndn::util::DummyClientFace& face, uint64_t expectedCode)
Jiewen Tana0497d82015-02-02 21:59:18 -080055{
laqinfand22da512017-05-25 17:29:53 -050056 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Jiewen Tana0497d82015-02-02 21:59:18 -080057
laqinfand22da512017-05-25 17:29:53 -050058 ndn::nfd::ControlResponse response(face.sentData[0].getContent().blockFromValue());
Jiewen Tana0497d82015-02-02 21:59:18 -080059 BOOST_CHECK_EQUAL(response.getCode(), expectedCode);
60
laqinfand22da512017-05-25 17:29:53 -050061 face.sentData.clear();
Jiewen Tana0497d82015-02-02 21:59:18 -080062}
63
64BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture)
65
laqinfand22da512017-05-25 17:29:53 -050066BOOST_AUTO_TEST_CASE(Localhost)
Jiewen Tana0497d82015-02-02 21:59:18 -080067{
68 // Install adjacency LSA
69 AdjLsa adjLsa;
70 adjLsa.setOrigRouter("/RouterA");
71 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
72 lsdb.installAdjLsa(adjLsa);
73
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060074 std::vector<double> angles = {20.00, 30.00};
75
Jiewen Tana0497d82015-02-02 21:59:18 -080076 // Install coordinate LSA
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060077 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
Jiewen Tana0497d82015-02-02 21:59:18 -080078 lsdb.installCoordinateLsa(coordinateLsa);
79
80 // Install Name LSA
81 NameLsa nameLsa;
82 nameLsa.setOrigRouter("/RouterA");
83 nameLsa.addName("/RouterA/name1");
84 lsdb.installNameLsa(nameLsa);
85
Jiewen Tana0497d82015-02-02 21:59:18 -080086 // Request adjacency LSAs
laqinfand22da512017-05-25 17:29:53 -050087 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("adjacencies")));
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
laqinfand22da512017-05-25 17:29:53 -050092 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("coordinates")));
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
laqinfand22da512017-05-25 17:29:53 -050097 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("names")));
Jiewen Tana0497d82015-02-02 21:59:18 -080098 processDatasetInterest(face,
99 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
100
101 // Request LSDB Status
laqinfand22da512017-05-25 17:29:53 -0500102 face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("list")));
Jiewen Tana0497d82015-02-02 21:59:18 -0800103 processDatasetInterest(face,
104 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
105}
106
laqinfand22da512017-05-25 17:29:53 -0500107
108BOOST_AUTO_TEST_CASE(Routername)
Jiewen Tana0497d82015-02-02 21:59:18 -0800109{
laqinfand22da512017-05-25 17:29:53 -0500110 //Install adjacencies LSA
111 AdjLsa adjLsa;
112 adjLsa.setOrigRouter("/RouterA");
113 addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10);
114 lsdb.installAdjLsa(adjLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800115
laqinfand22da512017-05-25 17:29:53 -0500116 std::vector<double> angles = {20.00, 30.00};
Jiewen Tana0497d82015-02-02 21:59:18 -0800117
laqinfand22da512017-05-25 17:29:53 -0500118 //Install coordinate LSA
119 CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles);
120 lsdb.installCoordinateLsa(coordinateLsa);
Jiewen Tana0497d82015-02-02 21:59:18 -0800121
laqinfand22da512017-05-25 17:29:53 -0500122 // Request adjacency LSAs
123 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("adjacencies")));
124 processDatasetInterest(face,
125 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800126
laqinfand22da512017-05-25 17:29:53 -0500127 // Request coordinate LSAs
128 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("coordinates")));
129 processDatasetInterest(face,
130 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800131
laqinfand22da512017-05-25 17:29:53 -0500132 // Request Name LSAs
133 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("names")));
134 processDatasetInterest(face,
135 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800136
laqinfand22da512017-05-25 17:29:53 -0500137 // Request LSDB Status
138 face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("list")));
139 processDatasetInterest(face,
140 [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::LsdbStatus; });
Jiewen Tana0497d82015-02-02 21:59:18 -0800141}
142
143BOOST_AUTO_TEST_SUITE_END()
144
145} // namespace test
146} // namespace nlsr