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 | |
| 79 | CoordinateLsa routerALsa = createCoordinateLsa(thisRouter.toUri(), 10.0, 20.0); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 80 | lsdb.installCoordinateLsa(routerALsa); |
| 81 | |
| 82 | CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, 543.21); |
| 83 | lsdb.installCoordinateLsa(routerBLsa); |
| 84 | |
| 85 | CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, 0.02); |
| 86 | lsdb.installCoordinateLsa(routerCLsa); |
| 87 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 88 | CoordinateLsaPublisher publisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 89 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 90 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 91 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(CoordinateLsaPublisher::DATASET_COMPONENT); |
| 92 | |
| 93 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 94 | face->processEvents(ndn::time::milliseconds(1)); |
| 95 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 96 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
| 97 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 98 | parser.parse(); |
| 99 | |
| 100 | // Check RouterC LSA |
| 101 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 102 | checkTlvCoordinateLsa(*it, routerCLsa); |
| 103 | |
| 104 | // Check RouterB LSA |
| 105 | ++it; |
| 106 | checkTlvCoordinateLsa(*it, routerBLsa); |
| 107 | |
| 108 | // Check RouterA LSA |
| 109 | ++it; |
| 110 | checkTlvCoordinateLsa(*it, routerALsa); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 114 | { |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 115 | ndn::Name thisRouter("/RouterA"); |
| 116 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 117 | // Name LSA for RouterA |
| 118 | NameLsa routerALsa; |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 119 | routerALsa.setOrigRouter(thisRouter.toUri()); |
| 120 | routerALsa.addName(ndn::Name(thisRouter).append("name1")); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 121 | lsdb.installNameLsa(routerALsa); |
| 122 | |
| 123 | // Name LSA for RouterB |
| 124 | NameLsa routerBLsa; |
| 125 | routerBLsa.setOrigRouter("/RouterB"); |
| 126 | routerBLsa.addName("/RouterB/name1"); |
| 127 | routerBLsa.addName("/RouterB/name2"); |
| 128 | routerBLsa.addName("/RouterB/name3"); |
| 129 | lsdb.installNameLsa(routerBLsa); |
| 130 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 131 | NameLsaPublisher publisher(lsdb, *face, keyChain); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 132 | |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 133 | ndn::Name publishingPrefix = ndn::Name(thisRouter); |
| 134 | publishingPrefix.append(Lsdb::NAME_COMPONENT).append(NameLsaPublisher::DATASET_COMPONENT); |
| 135 | |
| 136 | publisher.publish(publishingPrefix); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 137 | face->processEvents(ndn::time::milliseconds(1)); |
| 138 | |
Junxiao Shi | c778e81 | 2016-07-14 15:44:26 +0000 | [diff] [blame] | 139 | BOOST_REQUIRE_EQUAL(face->sentData.size(), 1); |
| 140 | ndn::Block parser = face->sentData[0].getContent(); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 141 | parser.parse(); |
| 142 | |
| 143 | // Check RouterB LSA |
| 144 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 145 | checkTlvNameLsa(*it, routerBLsa); |
| 146 | |
| 147 | // Check RouterA LSA |
| 148 | it++; |
| 149 | checkTlvNameLsa(*it, routerALsa); |
| 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_SUITE_END() |
| 153 | |
| 154 | } // namespace test |
| 155 | } // namespace nlsr |