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