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/lsa-publisher.hpp" |
| 23 | #include "tlv/adjacency.hpp" |
| 24 | #include "tlv/adjacency-lsa.hpp" |
| 25 | #include "tlv/tlv-nlsr.hpp" |
| 26 | |
| 27 | #include "publisher-fixture.hpp" |
| 28 | #include "../boost-test.hpp" |
| 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
| 33 | BOOST_FIXTURE_TEST_SUITE(PublisherTestLsaPublisher, PublisherFixture) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic) |
| 36 | { |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 37 | ndn::Name thisRouter("/RouterA"); |
| 38 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 39 | // Adjacency LSA for RouterA |
| 40 | AdjLsa routerALsa; |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 41 | routerALsa.setOrigRouter(thisRouter); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 42 | addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10); |
| 43 | lsdb.installAdjLsa(routerALsa); |
| 44 | |
| 45 | // Adjacency LSA for RouterB |
| 46 | AdjLsa routerBLsa; |
| 47 | routerBLsa.setOrigRouter("/RouterB"); |
| 48 | routerBLsa.setLsSeqNo(5); |
| 49 | addAdjacency(routerBLsa, "/RouterB/adjacency1", "udp://face-1", 10); |
| 50 | addAdjacency(routerBLsa, "/RouterB/adjacency2", "udp://face-2", 20); |
| 51 | addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30); |
| 52 | lsdb.installAdjLsa(routerBLsa); |
| 53 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 54 | AdjacencyLsaPublisher publisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 55 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 56 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 57 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(AdjacencyLsaPublisher::DATASET_COMPONENT); |
| 58 | |
| 59 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 60 | face->processEvents(ndn::time::milliseconds(1)); |
| 61 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 62 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
| 63 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 64 | parser.parse(); |
| 65 | |
| 66 | // Check RouterB LSA |
| 67 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 68 | checkTlvAdjLsa(*it, routerBLsa); |
| 69 | |
| 70 | // Check RouterA LSA |
| 71 | it++; |
| 72 | checkTlvAdjLsa(*it, routerALsa); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE(CoordinateLsaBasic) |
| 76 | { |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 77 | ndn::Name thisRouter("/RouterA"); |
| 78 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 79 | std::vector<double> anglesA, anglesB, anglesC; |
| 80 | anglesA.push_back(20.00); |
| 81 | anglesB.push_back(543.21); |
| 82 | // Setting two angles for testing routerCLsa |
| 83 | anglesC.push_back(0.02); |
| 84 | anglesC.push_back(1.23); |
| 85 | |
| 86 | CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, anglesA); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 87 | lsdb.installCoordinateLsa(routerALsa); |
| 88 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 89 | CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, anglesB); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 90 | lsdb.installCoordinateLsa(routerBLsa); |
| 91 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 92 | CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, anglesC); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 93 | lsdb.installCoordinateLsa(routerCLsa); |
| 94 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 95 | CoordinateLsaPublisher publisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 96 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 97 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 98 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT); |
| 99 | |
| 100 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 101 | face->processEvents(ndn::time::milliseconds(1)); |
| 102 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 103 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
| 104 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 105 | parser.parse(); |
| 106 | |
| 107 | // Check RouterC LSA |
| 108 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 109 | checkTlvCoordinateLsa(*it, routerCLsa); |
| 110 | |
| 111 | // Check RouterB LSA |
| 112 | ++it; |
| 113 | checkTlvCoordinateLsa(*it, routerBLsa); |
| 114 | |
| 115 | // Check RouterA LSA |
| 116 | ++it; |
| 117 | checkTlvCoordinateLsa(*it, routerALsa); |
| 118 | } |
| 119 | |
| 120 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 121 | { |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 122 | ndn::Name thisRouter("/RouterA"); |
| 123 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 124 | // Name LSA for RouterA |
| 125 | NameLsa routerALsa; |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 126 | routerALsa.setOrigRouter(thisRouter.toUri()); |
| 127 | routerALsa.addName(ndn::Name(thisRouter).append("name1")); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 128 | lsdb.installNameLsa(routerALsa); |
| 129 | |
| 130 | // Name LSA for RouterB |
| 131 | NameLsa routerBLsa; |
| 132 | routerBLsa.setOrigRouter("/RouterB"); |
| 133 | routerBLsa.addName("/RouterB/name1"); |
| 134 | routerBLsa.addName("/RouterB/name2"); |
| 135 | routerBLsa.addName("/RouterB/name3"); |
| 136 | lsdb.installNameLsa(routerBLsa); |
| 137 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 138 | NameLsaPublisher publisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 139 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 140 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 141 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT); |
| 142 | |
| 143 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 144 | face->processEvents(ndn::time::milliseconds(1)); |
| 145 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 146 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
| 147 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 148 | parser.parse(); |
| 149 | |
| 150 | // Check RouterB LSA |
| 151 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 152 | checkTlvNameLsa(*it, routerBLsa); |
| 153 | |
| 154 | // Check RouterA LSA |
| 155 | it++; |
| 156 | checkTlvNameLsa(*it, routerALsa); |
| 157 | } |
| 158 | |
| 159 | BOOST_AUTO_TEST_SUITE_END() |
| 160 | |
| 161 | } // namespace test |
| 162 | } // namespace nlsr |