blob: 05e5a0f198470d6ff30a5bb000f2ddb32851abcf [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
laqinfan35731852017-08-08 06:17:39 -05003 * Copyright (c) 2014-2018, 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
28#include "../boost-test.hpp"
29#include "../test-common.hpp"
30
31#include <ndn-cxx/util/dummy-client-face.hpp>
laqinfand22da512017-05-25 17:29:53 -050032#include <ndn-cxx/security/key-chain.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050033#include <ndn-cxx/security/pib/identity.hpp>
34
35#include <ndn-cxx/util/io.hpp>
laqinfand22da512017-05-25 17:29:53 -050036
37#include <boost/filesystem.hpp>
38
39using namespace ndn;
Jiewen Tana0497d82015-02-02 21:59:18 -080040
41namespace nlsr {
42namespace test {
43
44class PublisherFixture : public BaseFixture
45{
46public:
47 PublisherFixture()
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050048 : face(m_ioService, m_keyChain, {true, true})
49 , nlsr(m_ioService, m_scheduler, face, m_keyChain)
laqinfand22da512017-05-25 17:29:53 -050050 , lsdb(nlsr.getLsdb())
laqinfan35731852017-08-08 06:17:39 -050051 , rt1(nlsr.getRoutingTable())
Jiewen Tana0497d82015-02-02 21:59:18 -080052 {
laqinfand22da512017-05-25 17:29:53 -050053 nlsr.getConfParameter().setNetwork("/ndn");
54 nlsr.getConfParameter().setRouterName("/This/Router");
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050055
56 routerId = addIdentity("/ndn/This/Router");
57
laqinfand22da512017-05-25 17:29:53 -050058 nlsr.initialize();
Ashlesh Gawande793e8702017-08-01 15:59:26 -050059 face.processEvents(ndn::time::milliseconds(100));
Jiewen Tana0497d82015-02-02 21:59:18 -080060 }
61
62 void
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050063 checkPrefixRegistered(const Name& prefix)
64 {
65 bool registerCommandEmitted = false;
66 for (const auto& interest : face.sentInterests) {
67 if (interest.getName().size() > 4 && interest.getName().get(3) == name::Component("register")) {
68 name::Component test = interest.getName().get(4);
69 ndn::nfd::ControlParameters params(test.blockFromValue());
70 if (params.getName() == prefix) {
71 registerCommandEmitted = true;
72 break;
73 }
74 }
75 }
76 BOOST_CHECK(registerCommandEmitted);
77 }
78
79 void
Jiewen Tana0497d82015-02-02 21:59:18 -080080 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
81 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050082 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050083 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080084 }
85
86 void
87 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
88 {
89 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
90 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
91 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
92 }
93
94 void
95 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
96 {
97 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
98
99 tlv::AdjacencyLsa tlvLsa;
100 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
101
102 checkTlvAdjLsa(tlvLsa, lsa);
103 }
104
105 void
106 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
107 {
108 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
109
110 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
111
112 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
113 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -0500114 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -0800115 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
116 ++it;
117 }
118 }
119
laqinfan35731852017-08-08 06:17:39 -0500120 NextHop
121 createNextHop(const std::string& faceUri, double cost)
122 {
123 NextHop nexthop(faceUri, cost);
124 return nexthop;
125 }
126
Jiewen Tana0497d82015-02-02 21:59:18 -0800127 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600128 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -0800129 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600130 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -0800131 radius, angle);
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800132 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800133 }
134
135 void
136 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
137 {
138 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
139
140 tlv::CoordinateLsa tlvLsa;
141 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
142
143 checkTlvCoordinateLsa(tlvLsa, lsa);
144 }
145
146 void
147 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
148 {
149 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
150
151 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600152 BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta());
Jiewen Tana0497d82015-02-02 21:59:18 -0800153 }
154
155 void
156 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
157 {
158 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
159
160 tlv::NameLsa tlvLsa;
161 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
162
163 checkTlvNameLsa(tlvLsa, lsa);
164 }
165
166 void
167 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
168 {
169 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
170
171 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
172
Nick Gordonf14ec352017-07-24 16:09:58 -0500173 for (const ndn::Name& name : lsa.getNpl().getNames()) {
Jiewen Tana0497d82015-02-02 21:59:18 -0800174 BOOST_CHECK_EQUAL(*it, name);
175 ++it;
176 }
177 }
178
179public:
laqinfand22da512017-05-25 17:29:53 -0500180 ndn::util::DummyClientFace face;
laqinfand22da512017-05-25 17:29:53 -0500181
182 Nlsr nlsr;
183 Lsdb& lsdb;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500184
185 ndn::security::pib::Identity routerId;
laqinfan35731852017-08-08 06:17:39 -0500186 RoutingTable& rt1;
Jiewen Tana0497d82015-02-02 21:59:18 -0800187};
188
189} // namespace test
190} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -0600191
192#endif // NLSR_PUBLISHER_FIXTURE_HPP