Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | |
| 22 | #include "publisher/lsdb-status-publisher.hpp" |
| 23 | #include "tlv/lsdb-status.hpp" |
| 24 | #include "tlv/tlv-nlsr.hpp" |
| 25 | |
| 26 | #include "publisher-fixture.hpp" |
| 27 | #include "../boost-test.hpp" |
| 28 | |
| 29 | namespace nlsr { |
| 30 | namespace test { |
| 31 | |
| 32 | BOOST_FIXTURE_TEST_SUITE(PublisherTestLsdbStatusPublisher, PublisherFixture) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Basic) |
| 35 | { |
| 36 | // Install adjacency LSAs |
| 37 | // Adjacency LSA for RouterA |
| 38 | AdjLsa routerAAdjLsa; |
| 39 | routerAAdjLsa.setOrigRouter("/RouterA"); |
| 40 | addAdjacency(routerAAdjLsa, "/RouterA/adjacency1", "udp://face-1", 10); |
| 41 | lsdb.installAdjLsa(routerAAdjLsa); |
| 42 | |
| 43 | // Adjacency LSA for RouterB |
| 44 | AdjLsa routerBAdjLsa; |
| 45 | routerBAdjLsa.setOrigRouter("/RouterB"); |
| 46 | routerBAdjLsa.setLsSeqNo(5); |
| 47 | addAdjacency(routerBAdjLsa, "/RouterB/adjacency1", "udp://face-1", 10); |
| 48 | addAdjacency(routerBAdjLsa, "/RouterB/adjacency2", "udp://face-2", 20); |
| 49 | addAdjacency(routerBAdjLsa, "/RouterB/adjacency3", "udp://face-3", 30); |
| 50 | lsdb.installAdjLsa(routerBAdjLsa); |
| 51 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 52 | std::vector<double> anglesA = {20.00}, |
| 53 | anglesB = {543.21}, |
| 54 | anglesC = {0.02, 2.25}; |
| 55 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 56 | // Install coordinate LSAs |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 57 | CoordinateLsa routerACorLsa = createCoordinateLsa("/RouterA", 10.0, anglesA); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 58 | lsdb.installCoordinateLsa(routerACorLsa); |
| 59 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 60 | CoordinateLsa routerBCorLsa = createCoordinateLsa("/RouterB", 123.45, anglesB); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 61 | lsdb.installCoordinateLsa(routerBCorLsa); |
| 62 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 63 | CoordinateLsa routerCCorLsa = createCoordinateLsa("/RouterC", 0.01, anglesC); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 64 | lsdb.installCoordinateLsa(routerCCorLsa); |
| 65 | |
| 66 | // Install Name LSAs |
| 67 | // Name LSA for RouterA |
| 68 | NameLsa routerANameLsa; |
| 69 | routerANameLsa.setOrigRouter("/RouterA"); |
| 70 | routerANameLsa.addName("/RouterA/name1"); |
| 71 | lsdb.installNameLsa(routerANameLsa); |
| 72 | |
| 73 | // Name LSA for RouterB |
| 74 | NameLsa routerBNameLsa; |
| 75 | routerBNameLsa.setOrigRouter("/RouterB"); |
| 76 | routerBNameLsa.addName("/RouterB/name1"); |
| 77 | routerBNameLsa.addName("/RouterB/name2"); |
| 78 | routerBNameLsa.addName("/RouterB/name3"); |
| 79 | lsdb.installNameLsa(routerBNameLsa); |
| 80 | |
| 81 | ndn::Name thisRouter("/This/Router"); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 82 | AdjacencyLsaPublisher adjacencyLsaPublisher(lsdb, *face, keyChain); |
| 83 | CoordinateLsaPublisher coordinateLsaPublisher(lsdb, *face, keyChain); |
| 84 | NameLsaPublisher nameLsaPublisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 85 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 86 | LsdbStatusPublisher publisher(lsdb, *face, keyChain, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 87 | adjacencyLsaPublisher, |
| 88 | coordinateLsaPublisher, |
| 89 | nameLsaPublisher); |
| 90 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 91 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 92 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(LsdbStatusPublisher::DATASET_COMPONENT); |
| 93 | |
| 94 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 95 | face->processEvents(ndn::time::milliseconds(1)); |
| 96 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 97 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 98 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 99 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 100 | parser.parse(); |
| 101 | |
| 102 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 103 | |
| 104 | BOOST_CHECK_EQUAL(it->type(), ndn::tlv::nlsr::LsdbStatus); |
| 105 | |
| 106 | tlv::LsdbStatus lsdbStatusTlv; |
| 107 | BOOST_REQUIRE_NO_THROW(lsdbStatusTlv.wireDecode(*it)); |
| 108 | |
| 109 | BOOST_CHECK_EQUAL(lsdbStatusTlv.hasAdjacencyLsas(), true); |
| 110 | |
| 111 | // Check adjacency LSAs |
| 112 | std::list<tlv::AdjacencyLsa>::const_iterator adjLsaIt = lsdbStatusTlv.getAdjacencyLsas().begin(); |
| 113 | checkTlvAdjLsa(*adjLsaIt, routerAAdjLsa); |
| 114 | |
| 115 | ++adjLsaIt; |
| 116 | checkTlvAdjLsa(*adjLsaIt, routerBAdjLsa); |
| 117 | |
| 118 | // Check coordinate LSAs |
| 119 | std::list<tlv::CoordinateLsa>::const_iterator corLsaIt = |
| 120 | lsdbStatusTlv.getCoordinateLsas().begin(); |
| 121 | checkTlvCoordinateLsa(*corLsaIt, routerACorLsa); |
| 122 | |
| 123 | ++corLsaIt; |
| 124 | checkTlvCoordinateLsa(*corLsaIt, routerBCorLsa); |
| 125 | |
| 126 | ++corLsaIt; |
| 127 | checkTlvCoordinateLsa(*corLsaIt, routerCCorLsa); |
| 128 | |
| 129 | // Check Name LSAs |
| 130 | std::list<tlv::NameLsa>::const_iterator nameLsaIt = lsdbStatusTlv.getNameLsas().begin(); |
| 131 | checkTlvNameLsa(*nameLsaIt, routerANameLsa); |
| 132 | |
| 133 | ++nameLsaIt; |
| 134 | checkTlvNameLsa(*nameLsaIt, routerBNameLsa); |
| 135 | } |
| 136 | |
| 137 | BOOST_AUTO_TEST_SUITE_END() |
| 138 | |
| 139 | } // namespace test |
| 140 | } // namespace nlsr |