Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, The University of Memphis, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 4 | * 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 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 22 | #include "publisher/dataset-interest-handler.hpp" |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 23 | #include "tests/test-common.hpp" |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 24 | #include "tlv/tlv-nlsr.hpp" |
| 25 | |
| 26 | #include "publisher-fixture.hpp" |
| 27 | #include "../boost-test.hpp" |
| 28 | |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 29 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 30 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 31 | #include <iostream> |
| 32 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 33 | namespace nlsr { |
| 34 | namespace test { |
| 35 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 36 | static void |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 37 | processDatasetInterest(ndn::util::DummyClientFace& face, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 38 | std::function<bool(const ndn::Block&)> isSameType) |
| 39 | { |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 40 | face.processEvents(30_ms); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 41 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 42 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 43 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 44 | ndn::Block parser(face.sentData[0].getContent()); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 45 | 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 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 53 | face.sentData.clear(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 56 | BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbDatasetInterestHandler, PublisherFixture) |
| 57 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 58 | BOOST_AUTO_TEST_CASE(Localhost) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 59 | { |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 60 | checkPrefixRegistered(Nlsr::LOCALHOST_PREFIX); |
| 61 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 62 | // 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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 68 | std::vector<double> angles = {20.00, 30.00}; |
| 69 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 70 | // Install coordinate LSA |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 71 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 72 | 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 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 80 | // 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 Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 88 | // Request adjacency LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 89 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 90 | processDatasetInterest(face, |
| 91 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; }); |
| 92 | |
| 93 | // Request coordinate LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 94 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 95 | processDatasetInterest(face, |
| 96 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; }); |
| 97 | |
| 98 | // Request Name LSAs |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 99 | face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 100 | processDatasetInterest(face, |
| 101 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; }); |
| 102 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 103 | // Request Routing Table |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 104 | face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true)); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 105 | processDatasetInterest(face, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 106 | [] (const ndn::Block& block) { |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 107 | return block.type() == ndn::tlv::nlsr::RoutingTable; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 108 | } |
| 109 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 110 | BOOST_AUTO_TEST_CASE(Routername) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 111 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 112 | ndn::Name regRouterPrefix(conf.getRouterPrefix()); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 113 | regRouterPrefix.append("nlsr"); |
| 114 | // Should already be added to dispatcher |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 115 | BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 116 | |
| 117 | checkPrefixRegistered(regRouterPrefix); |
| 118 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 119 | // Install adjacencies LSA |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 120 | AdjLsa adjLsa; |
| 121 | adjLsa.setOrigRouter("/RouterA"); |
| 122 | addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10); |
| 123 | lsdb.installAdjLsa(adjLsa); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 124 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 125 | std::vector<double> angles = {20.00, 30.00}; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 126 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 127 | // Install coordinate LSA |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 128 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
| 129 | lsdb.installCoordinateLsa(coordinateLsa); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 130 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 131 | // Install routing table |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 132 | 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 Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 139 | ndn::Name routerName(conf.getRouterPrefix()); |
| 140 | routerName.append("nlsr"); |
| 141 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 142 | // Request adjacency LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 143 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 144 | processDatasetInterest(face, |
| 145 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 146 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 147 | // Request coordinate LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 148 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 149 | processDatasetInterest(face, |
| 150 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 151 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 152 | // Request Name LSAs |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 153 | face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true)); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 154 | processDatasetInterest(face, |
| 155 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 156 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 157 | // Request Routing Table |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame^] | 158 | face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table"))); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 159 | processDatasetInterest(face, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 160 | [] (const ndn::Block& block) { |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 161 | return block.type() == ndn::tlv::nlsr::RoutingTable; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_SUITE_END() |
| 165 | |
| 166 | } // namespace test |
| 167 | } // namespace nlsr |