blob: 840de0b76151a2daea05bc448460499b6a0dc0e8 [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
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})
Ashlesh Gawande85998a12017-12-07 22:22:13 -060049 , conf(face)
50 , confProcessor(conf)
51 , nlsr(face, m_keyChain, conf)
52 , lsdb(nlsr.m_lsdb)
53 , rt1(nlsr.m_routingTable)
Jiewen Tana0497d82015-02-02 21:59:18 -080054 {
Ashlesh Gawande85998a12017-12-07 22:22:13 -060055 routerId = addIdentity(conf.getRouterPrefix());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050056
laqinfand22da512017-05-25 17:29:53 -050057 nlsr.initialize();
Ashlesh Gawande793e8702017-08-01 15:59:26 -050058 face.processEvents(ndn::time::milliseconds(100));
Jiewen Tana0497d82015-02-02 21:59:18 -080059 }
60
61 void
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -050062 checkPrefixRegistered(const Name& prefix)
63 {
64 bool registerCommandEmitted = false;
65 for (const auto& interest : face.sentInterests) {
66 if (interest.getName().size() > 4 && interest.getName().get(3) == name::Component("register")) {
67 name::Component test = interest.getName().get(4);
68 ndn::nfd::ControlParameters params(test.blockFromValue());
69 if (params.getName() == prefix) {
70 registerCommandEmitted = true;
71 break;
72 }
73 }
74 }
75 BOOST_CHECK(registerCommandEmitted);
76 }
77
78 void
Jiewen Tana0497d82015-02-02 21:59:18 -080079 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
80 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050081 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050082 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080083 }
84
85 void
86 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
87 {
88 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
89 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
90 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
91 }
92
93 void
94 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
95 {
96 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
97
98 tlv::AdjacencyLsa tlvLsa;
99 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
100
101 checkTlvAdjLsa(tlvLsa, lsa);
102 }
103
104 void
105 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
106 {
107 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
108
109 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
110
111 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
112 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -0500113 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -0800114 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
115 ++it;
116 }
117 }
118
laqinfan35731852017-08-08 06:17:39 -0500119 NextHop
120 createNextHop(const std::string& faceUri, double cost)
121 {
122 NextHop nexthop(faceUri, cost);
123 return nexthop;
124 }
125
Jiewen Tana0497d82015-02-02 21:59:18 -0800126 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600127 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -0800128 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600129 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -0800130 radius, angle);
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800131 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800132 }
133
134 void
135 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
136 {
137 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
138
139 tlv::CoordinateLsa tlvLsa;
140 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
141
142 checkTlvCoordinateLsa(tlvLsa, lsa);
143 }
144
145 void
146 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
147 {
148 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
149
150 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600151 BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta());
Jiewen Tana0497d82015-02-02 21:59:18 -0800152 }
153
154 void
155 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
156 {
157 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
158
159 tlv::NameLsa tlvLsa;
160 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
161
162 checkTlvNameLsa(tlvLsa, lsa);
163 }
164
165 void
166 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
167 {
168 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
169
170 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
171
Nick Gordonf14ec352017-07-24 16:09:58 -0500172 for (const ndn::Name& name : lsa.getNpl().getNames()) {
Jiewen Tana0497d82015-02-02 21:59:18 -0800173 BOOST_CHECK_EQUAL(*it, name);
174 ++it;
175 }
176 }
177
178public:
laqinfand22da512017-05-25 17:29:53 -0500179 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600180 ConfParameter conf;
181 DummyConfFileProcessor confProcessor;
laqinfand22da512017-05-25 17:29:53 -0500182 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