Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, The University of Memphis, |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [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/>. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 21 | |
| 22 | #include "statistics.hpp" |
| 23 | #include "test-common.hpp" |
| 24 | #include "hello-protocol.hpp" |
| 25 | #include "lsdb.hpp" |
| 26 | #include "nlsr.hpp" |
| 27 | |
| 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 33 | class StatisticsFixture : public UnitTestTimeFixture |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | StatisticsFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 37 | : face(m_ioService, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 38 | , conf(face, m_keyChain) |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 39 | , confProcessor(conf) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 40 | , nlsr(face, m_keyChain, conf) |
| 41 | , lsdb(nlsr.m_lsdb) |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 42 | , hello(nlsr.m_helloProtocol) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 43 | , collector(nlsr.m_statsCollector) |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 44 | { |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 45 | // Otherwise code coverage node fails with default 60 seconds lifetime |
| 46 | conf.setSyncInterestLifetime(1000); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 47 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 48 | addIdentity(conf.getRouterPrefix()); |
| 49 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 50 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
| 51 | face.sentInterests.clear(); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /*! |
| 55 | * \brief Checks if lsa interest was received and data for interest was sent |
| 56 | * |
| 57 | * \param interestPrefix is an interest name prefix |
| 58 | * \param lsaType indicates whether the lsa is a name, adjacency, or coordinate |
| 59 | * \param seqNo sequence number that will be appended to an interest name |
| 60 | * \param receivedInterestType is the specific Statisitcs::PacketType interest that is received |
| 61 | * \param sentDataType is the Statistics::PacketType data being sent upon interest process |
| 62 | * |
| 63 | * This is a general function that can be used for all three types of lsa. Calling processInterest() |
| 64 | * from lsdb will cause the statsCollector to increment the incoming interest type and increment the |
| 65 | * outgoing data type. |
| 66 | */ |
| 67 | void |
| 68 | receiveInterestAndCheckSentStats(const std::string& interestPrefix, |
| 69 | const std::string& lsaType, |
| 70 | uint32_t seqNo, |
| 71 | Statistics::PacketType receivedInterestType, |
| 72 | Statistics::PacketType sentDataType) |
| 73 | { |
| 74 | size_t rcvBefore = collector.getStatistics().get(receivedInterestType); |
| 75 | size_t sentBefore = collector.getStatistics().get(sentDataType); |
| 76 | |
| 77 | ndn::Name interestName = ndn::Name(ndn::Name(interestPrefix + lsaType).appendNumber(seqNo)); |
| 78 | lsdb.processInterest(ndn::Name(), ndn::Interest(interestName)); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 79 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 80 | |
| 81 | BOOST_CHECK_EQUAL(collector.getStatistics().get(receivedInterestType), rcvBefore + 1); |
| 82 | BOOST_CHECK_EQUAL(collector.getStatistics().get(sentDataType), sentBefore + 1); |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | * \brief Checks if statistics update after an lsa interest is sent |
| 87 | * |
| 88 | * \param prefix is an interest prefix |
| 89 | * \param lsaType indicates whether the lsa is a name, adjacency, or coordinate |
| 90 | * \param seqNo is the sequence number |
| 91 | * \param statsType is a statistical PacketType |
| 92 | * |
| 93 | * The function is called to initiate an expressInterest call in lsdb and to check if the |
| 94 | * expected statistical packetType was incremented. |
| 95 | */ |
| 96 | void |
| 97 | sendInterestAndCheckStats(const std::string& prefix, |
| 98 | const std::string& lsaType, |
| 99 | uint32_t seqNo, |
| 100 | Statistics::PacketType statsType) |
| 101 | { |
| 102 | size_t sentBefore = collector.getStatistics().get(statsType); |
| 103 | |
| 104 | lsdb.expressInterest(ndn::Name(prefix + lsaType).appendNumber(seqNo), 0, |
| 105 | ndn::time::steady_clock::TimePoint::min()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 106 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 107 | |
| 108 | BOOST_CHECK_EQUAL(collector.getStatistics().get(statsType), sentBefore + 1); |
| 109 | } |
| 110 | |
| 111 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 112 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 113 | ConfParameter conf; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 114 | DummyConfFileProcessor confProcessor; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 115 | Nlsr nlsr; |
| 116 | |
| 117 | Lsdb& lsdb; |
| 118 | HelloProtocol& hello; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 119 | StatsCollector& collector; |
| 120 | }; |
| 121 | |
| 122 | BOOST_FIXTURE_TEST_SUITE(TestStatistics, StatisticsFixture) |
| 123 | |
| 124 | |
| 125 | // A statistical PacketType is directly incremented (without signals). |
| 126 | BOOST_AUTO_TEST_CASE(StatsIncrement) |
| 127 | { |
| 128 | Statistics stats; |
| 129 | BOOST_CHECK_EQUAL(stats.get(Statistics::PacketType::SENT_HELLO_INTEREST), 0); |
| 130 | stats.increment(Statistics::PacketType::SENT_HELLO_INTEREST); |
| 131 | BOOST_CHECK_EQUAL(stats.get(Statistics::PacketType::SENT_HELLO_INTEREST), 1); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * After a PacketType has been incremented, the resetAll() function is called, which sets all |
| 136 | * statistical packetType counts to 0 |
| 137 | */ |
| 138 | BOOST_AUTO_TEST_CASE(StatsReset) |
| 139 | { |
| 140 | Statistics stats; |
| 141 | stats.increment(Statistics::PacketType::SENT_HELLO_INTEREST); |
| 142 | stats.resetAll(); |
| 143 | BOOST_CHECK_EQUAL(stats.get(Statistics::PacketType::SENT_HELLO_INTEREST), 0); |
| 144 | } |
| 145 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 146 | /* |
| 147 | * This tests hello interests and hello data statistical collection by constructing an adjacency lsa |
| 148 | * and calling functions that trigger the sending and receiving hello of interests/data. |
| 149 | */ |
| 150 | BOOST_AUTO_TEST_CASE(SendHelloInterest) |
| 151 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 152 | Adjacent other("/ndn/router/other", ndn::FaceUri("udp4://other"), 25, Adjacent::STATUS_INACTIVE, 0, 0); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 153 | |
| 154 | // This router's Adjacency LSA |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 155 | conf.getAdjacencyList().insert(other); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 156 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 157 | ndn::Name otherName(other.getName()); |
| 158 | otherName.append("NLSR"); |
| 159 | otherName.append("INFO"); |
| 160 | otherName.append(conf.getRouterPrefix().wireEncode()); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 161 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 162 | hello.expressInterest(otherName, 1); |
| 163 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 164 | |
| 165 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::SENT_HELLO_INTEREST), 1); |
| 166 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 167 | ndn::Name thisName(conf.getRouterPrefix()); |
| 168 | thisName.append("NLSR"); |
| 169 | thisName.append("INFO"); |
| 170 | thisName.append(other.getName().wireEncode()); |
| 171 | |
| 172 | ndn::Interest interest(thisName); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 173 | hello.processInterest(ndn::Name(), interest); |
| 174 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 175 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 176 | |
| 177 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_HELLO_INTEREST), 1); |
| 178 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::SENT_HELLO_DATA), 1); |
| 179 | |
| 180 | // Receive Hello Data |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 181 | ndn::Name dataName = otherName; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 182 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 183 | ndn::Data data(dataName); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 184 | hello.onContentValidated(data); |
| 185 | |
| 186 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_HELLO_DATA), 1); |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * An interest is sent for each lsa type (name, adjacency, coordinate). The respective statistics are |
| 191 | * totaled and checked. |
| 192 | */ |
| 193 | BOOST_AUTO_TEST_CASE(LsdbSendLsaInterest) |
| 194 | { |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 195 | const std::string interestPrefix("/localhop/ndn/nlsr/LSA/site/%C1.Router/router/"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 196 | uint32_t seqNo = 1; |
| 197 | |
| 198 | // Adjacency LSA |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 199 | sendInterestAndCheckStats(interestPrefix, boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY), |
| 200 | seqNo, Statistics::PacketType::SENT_ADJ_LSA_INTEREST); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 201 | |
| 202 | // Coordinate LSA |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 203 | sendInterestAndCheckStats(interestPrefix, boost::lexical_cast<std::string>(Lsa::Type::COORDINATE), |
| 204 | seqNo, Statistics::PacketType::SENT_COORD_LSA_INTEREST); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 205 | |
| 206 | // Name LSA |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 207 | sendInterestAndCheckStats(interestPrefix, boost::lexical_cast<std::string>(Lsa::Type::NAME), |
| 208 | seqNo, Statistics::PacketType::SENT_NAME_LSA_INTEREST); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 209 | |
| 210 | // 3 total lsa interests were sent |
| 211 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::SENT_LSA_INTEREST), 3); |
| 212 | } |
| 213 | |
| 214 | /* |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 215 | * Tests the statistics collected upon processing incoming lsa |
| 216 | * interests and respective outgoing data. This process will trigger |
| 217 | * both an increment for received lsa interest and sent lsa data. |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 218 | * |
| 219 | * /sa receiveInterestAndCheckSentStats |
| 220 | */ |
| 221 | BOOST_AUTO_TEST_CASE(LsdbReceiveInterestSendData) |
| 222 | { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 223 | // Adjacency LSA |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 224 | lsdb.buildAndInstallOwnAdjLsa(); |
| 225 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 226 | auto adjLsa = lsdb.findLsa<AdjLsa>(conf.getRouterPrefix()); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 227 | uint32_t seqNo = adjLsa->getSeqNo(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 228 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 229 | Adjacent adjacency("adjacency"); |
| 230 | adjacency.setStatus(Adjacent::STATUS_ACTIVE); |
| 231 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 232 | adjLsa->addAdjacent(adjacency); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 233 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 234 | lsdb.installLsa(adjLsa); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 235 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 236 | const std::string interestPrefix("/localhop/ndn/nlsr/LSA/site/%C1.Router/this-router/"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 237 | |
| 238 | // Receive Adjacency LSA Interest |
| 239 | receiveInterestAndCheckSentStats(interestPrefix, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 240 | boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY), |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 241 | seqNo, |
| 242 | Statistics::PacketType::RCV_ADJ_LSA_INTEREST, |
| 243 | Statistics::PacketType::SENT_ADJ_LSA_DATA); |
| 244 | |
| 245 | // Name LSA |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 246 | auto nameLsa = std::static_pointer_cast<NameLsa>(lsdb.findLsa(conf.getRouterPrefix(), Lsa::Type::NAME)); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 247 | BOOST_ASSERT(nameLsa != nullptr); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 248 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 249 | seqNo = nameLsa->getSeqNo(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 250 | |
| 251 | nameLsa->addName(ndn::Name("/ndn/name")); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 252 | lsdb.installLsa(nameLsa); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 253 | |
| 254 | // Receive Name LSA Interest |
| 255 | receiveInterestAndCheckSentStats(interestPrefix, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 256 | boost::lexical_cast<std::string>(Lsa::Type::NAME), |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 257 | seqNo, |
| 258 | Statistics::PacketType::RCV_NAME_LSA_INTEREST, |
| 259 | Statistics::PacketType::SENT_NAME_LSA_DATA); |
| 260 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 261 | // // Coordinate LSA |
| 262 | lsdb.buildAndInstallOwnCoordinateLsa(); |
| 263 | ndn::Name coorLsaKey = conf.getRouterPrefix(); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 264 | coorLsaKey.append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE)); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 265 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 266 | auto coorLsa = lsdb.findLsa<CoordinateLsa>(conf.getRouterPrefix()); |
| 267 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 268 | seqNo = coorLsa->getSeqNo(); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 269 | coorLsa->setCorTheta({20.0, 30.0}); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 270 | lsdb.installLsa(coorLsa); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 271 | |
| 272 | // Receive Adjacency LSA Interest |
| 273 | receiveInterestAndCheckSentStats(interestPrefix, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 274 | boost::lexical_cast<std::string>(Lsa::Type::COORDINATE), |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 275 | seqNo, |
| 276 | Statistics::PacketType::RCV_COORD_LSA_INTEREST, |
| 277 | Statistics::PacketType::SENT_COORD_LSA_DATA); |
| 278 | |
| 279 | // 3 different lsa type interests should be received |
| 280 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_LSA_INTEREST), 3); |
| 281 | |
| 282 | // data should have been sent 3x, once per lsa type |
| 283 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::SENT_LSA_DATA), 3); |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * Data for each lsa type (name, adjacency, coordinate) is sent to the lsdb and statistics are |
| 288 | * checked to verify the respective statistical PacketType has been received. |
| 289 | */ |
| 290 | BOOST_AUTO_TEST_CASE(LsdbReceiveData) |
| 291 | { |
| 292 | ndn::Name routerName("/ndn/cs/%C1.Router/router1"); |
| 293 | uint32_t seqNo = 1; |
| 294 | ndn::time::system_clock::TimePoint MAX_TIME = ndn::time::system_clock::TimePoint::max(); |
| 295 | |
| 296 | // adjacency lsa |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 297 | ndn::Name adjInterest("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/ADJACENCY/"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 298 | adjInterest.appendNumber(seqNo); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 299 | AdjLsa aLsa(routerName, seqNo, MAX_TIME, 1, conf.getAdjacencyList()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 300 | lsdb.installLsa(std::make_shared<AdjLsa>(aLsa)); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 301 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 302 | lsdb.afterFetchLsa(aLsa.wireEncode().getBuffer(), adjInterest); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 303 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_ADJ_LSA_DATA), 1); |
| 304 | |
| 305 | // coordinate lsa |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 306 | ndn::Name coordInterest("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/COORDINATE/"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 307 | coordInterest.appendNumber(seqNo); |
| 308 | std::vector<double> angles = {20.0, 30.0}; |
| 309 | CoordinateLsa cLsa(routerName, seqNo, MAX_TIME, 2.5, angles); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 310 | lsdb.installLsa(std::make_shared<CoordinateLsa>(cLsa)); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 311 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 312 | lsdb.afterFetchLsa(cLsa.wireEncode().getBuffer(), coordInterest); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 313 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_COORD_LSA_DATA), 1); |
| 314 | |
| 315 | // name lsa |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 316 | ndn::Name interestName("/localhop/ndn/nlsr/LSA/cs/%C1.Router/router1/NAME/"); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 317 | interestName.appendNumber(seqNo); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 318 | NameLsa nlsa(routerName, seqNo, MAX_TIME, conf.getNamePrefixList()); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 319 | lsdb.installLsa(std::make_shared<NameLsa>(nlsa)); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 320 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 321 | lsdb.afterFetchLsa(nlsa.wireEncode().getBuffer(), interestName); |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 322 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_NAME_LSA_DATA), 1); |
| 323 | |
| 324 | // 3 lsa data types should be received |
| 325 | BOOST_CHECK_EQUAL(collector.getStatistics().get(Statistics::PacketType::RCV_LSA_DATA), 3); |
| 326 | } |
| 327 | |
| 328 | BOOST_AUTO_TEST_SUITE_END() |
| 329 | |
| 330 | } // namespace test |
| 331 | } // namespace nlsr |