blob: f5b37fa5026a6c1a4b71accf80f731c2c553dcf3 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, The University of Memphis,
Jiewen Tana0497d82015-02-02 21:59:18 -08004 * 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
dmcoomes9f936662017-03-02 10:33:09 -060022#ifndef NLSR_PUBLISHER_FIXTURE_HPP
23#define NLSR_PUBLISHER_FIXTURE_HPP
24
laqinfan35731852017-08-08 06:17:39 -050025#include "publisher/dataset-interest-handler.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080026#include "nlsr.hpp"
27
Davide Pesaventocb065f12019-12-27 01:03:34 -050028#include "tests/test-common.hpp"
Jiewen Tana0497d82015-02-02 21:59:18 -080029
30#include <ndn-cxx/util/dummy-client-face.hpp>
laqinfand22da512017-05-25 17:29:53 -050031#include <ndn-cxx/security/key-chain.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050032#include <ndn-cxx/security/pib/identity.hpp>
33
34#include <ndn-cxx/util/io.hpp>
laqinfand22da512017-05-25 17:29:53 -050035
36#include <boost/filesystem.hpp>
37
38using namespace ndn;
Jiewen Tana0497d82015-02-02 21:59:18 -080039
40namespace nlsr {
41namespace test {
42
43class PublisherFixture : public BaseFixture
44{
45public:
46 PublisherFixture()
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050047 : face(m_ioService, m_keyChain, {true, true})
Ashlesh Gawande85998a12017-12-07 22:22:13 -060048 , conf(face)
49 , confProcessor(conf)
50 , nlsr(face, m_keyChain, conf)
51 , lsdb(nlsr.m_lsdb)
52 , rt1(nlsr.m_routingTable)
Jiewen Tana0497d82015-02-02 21:59:18 -080053 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060054 routerId = addIdentity(conf.getRouterPrefix());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050055
laqinfand22da512017-05-25 17:29:53 -050056 nlsr.initialize();
Ashlesh Gawande793e8702017-08-01 15:59:26 -050057 face.processEvents(ndn::time::milliseconds(100));
Jiewen Tana0497d82015-02-02 21:59:18 -080058 }
59
60 void
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050061 checkPrefixRegistered(const Name& prefix)
62 {
63 bool registerCommandEmitted = false;
64 for (const auto& interest : face.sentInterests) {
65 if (interest.getName().size() > 4 && interest.getName().get(3) == name::Component("register")) {
66 name::Component test = interest.getName().get(4);
67 ndn::nfd::ControlParameters params(test.blockFromValue());
68 if (params.getName() == prefix) {
69 registerCommandEmitted = true;
70 break;
71 }
72 }
73 }
74 BOOST_CHECK(registerCommandEmitted);
75 }
76
77 void
Jiewen Tana0497d82015-02-02 21:59:18 -080078 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
79 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050080 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050081 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080082 }
83
84 void
85 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
86 {
87 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
88 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
89 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
90 }
91
92 void
93 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
94 {
95 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
96
97 tlv::AdjacencyLsa tlvLsa;
98 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
99
100 checkTlvAdjLsa(tlvLsa, lsa);
101 }
102
103 void
104 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
105 {
106 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
107
108 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
109
110 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
111 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -0500112 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -0800113 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
114 ++it;
115 }
116 }
117
laqinfan35731852017-08-08 06:17:39 -0500118 NextHop
119 createNextHop(const std::string& faceUri, double cost)
120 {
121 NextHop nexthop(faceUri, cost);
122 return nexthop;
123 }
124
Jiewen Tana0497d82015-02-02 21:59:18 -0800125 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600126 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -0800127 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600128 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -0800129 radius, angle);
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800130 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800131 }
132
133 void
134 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
135 {
136 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
137
138 tlv::CoordinateLsa tlvLsa;
139 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
140
141 checkTlvCoordinateLsa(tlvLsa, lsa);
142 }
143
144 void
145 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
146 {
147 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
148
149 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600150 BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta());
Jiewen Tana0497d82015-02-02 21:59:18 -0800151 }
152
153 void
154 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
155 {
156 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
157
158 tlv::NameLsa tlvLsa;
159 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
160
161 checkTlvNameLsa(tlvLsa, lsa);
162 }
163
164 void
165 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
166 {
167 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
168
169 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
170
Nick Gordonf14ec352017-07-24 16:09:58 -0500171 for (const ndn::Name& name : lsa.getNpl().getNames()) {
Jiewen Tana0497d82015-02-02 21:59:18 -0800172 BOOST_CHECK_EQUAL(*it, name);
173 ++it;
174 }
175 }
176
177public:
laqinfand22da512017-05-25 17:29:53 -0500178 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600179 ConfParameter conf;
180 DummyConfFileProcessor confProcessor;
laqinfand22da512017-05-25 17:29:53 -0500181 Nlsr nlsr;
182 Lsdb& lsdb;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500183
184 ndn::security::pib::Identity routerId;
laqinfan35731852017-08-08 06:17:39 -0500185 RoutingTable& rt1;
Jiewen Tana0497d82015-02-02 21:59:18 -0800186};
187
188} // namespace test
189} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -0600190
191#endif // NLSR_PUBLISHER_FIXTURE_HPP