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