Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, 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 | |
| 36 | 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 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 40 | face.processEvents(ndn::time::milliseconds(30)); |
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 | { |
| 60 | // 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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 66 | std::vector<double> angles = {20.00, 30.00}; |
| 67 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 68 | // Install coordinate LSA |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 69 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 70 | 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 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 78 | // 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 Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 86 | // Request adjacency LSAs |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 87 | face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("adjacencies"))); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 88 | processDatasetInterest(face, |
| 89 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; }); |
| 90 | |
| 91 | // Request coordinate LSAs |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 92 | face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("coordinates"))); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 93 | processDatasetInterest(face, |
| 94 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; }); |
| 95 | |
| 96 | // Request Name LSAs |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 97 | face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/lsdb").append("names"))); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 98 | processDatasetInterest(face, |
| 99 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; }); |
| 100 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 101 | // Request Routing Table |
| 102 | face.receive(ndn::Interest(ndn::Name("/localhost/nlsr/routing-table"))); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 103 | processDatasetInterest(face, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 104 | [] (const ndn::Block& block) { |
| 105 | return block.type() == ndn::tlv::nlsr::RouteTableEntry; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 106 | } |
| 107 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 108 | |
| 109 | BOOST_AUTO_TEST_CASE(Routername) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 110 | { |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 111 | //Install adjacencies LSA |
| 112 | AdjLsa adjLsa; |
| 113 | adjLsa.setOrigRouter("/RouterA"); |
| 114 | addAdjacency(adjLsa, "/RouterA/adjacency1", "udp://face-1", 10); |
| 115 | lsdb.installAdjLsa(adjLsa); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 116 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 117 | std::vector<double> angles = {20.00, 30.00}; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 118 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 119 | //Install coordinate LSA |
| 120 | CoordinateLsa coordinateLsa = createCoordinateLsa("/RouterA", 10.0, angles); |
| 121 | lsdb.installCoordinateLsa(coordinateLsa); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 122 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 123 | //Install routing table |
| 124 | RoutingTableEntry rte1("desrouter1"); |
| 125 | const ndn::Name& DEST_ROUTER = rte1.getDestination(); |
| 126 | |
| 127 | NextHop nh = createNextHop("udp://face-test1", 10); |
| 128 | |
| 129 | rt1.addNextHop(DEST_ROUTER, nh); |
| 130 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 131 | // Request adjacency LSAs |
| 132 | face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("adjacencies"))); |
| 133 | processDatasetInterest(face, |
| 134 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 135 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 136 | // Request coordinate LSAs |
| 137 | face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("coordinates"))); |
| 138 | processDatasetInterest(face, |
| 139 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 140 | |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 141 | // Request Name LSAs |
| 142 | face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/lsdb").append("names"))); |
| 143 | processDatasetInterest(face, |
| 144 | [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 145 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 146 | // Request Routing Table |
| 147 | face.receive(ndn::Interest(ndn::Name("/ndn/This/Router/routing-table"))); |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 148 | processDatasetInterest(face, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 149 | [] (const ndn::Block& block) { |
| 150 | return block.type() == ndn::tlv::nlsr::RouteTableEntry; }); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | BOOST_AUTO_TEST_SUITE_END() |
| 154 | |
| 155 | } // namespace test |
| 156 | } // namespace nlsr |