blob: dd733fa8cbec9a924a16a3cb86089ff5a5355e38 [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
63 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
64 {
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050065 Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
Nick Gordone9733ed2017-04-26 10:48:39 -050066 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080067 }
68
69 void
70 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
71 {
72 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
73 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
74 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
75 }
76
77 void
78 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
79 {
80 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
81
82 tlv::AdjacencyLsa tlvLsa;
83 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
84
85 checkTlvAdjLsa(tlvLsa, lsa);
86 }
87
88 void
89 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
90 {
91 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
92
93 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
94
95 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
96 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -050097 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -080098 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
99 ++it;
100 }
101 }
102
laqinfan35731852017-08-08 06:17:39 -0500103 NextHop
104 createNextHop(const std::string& faceUri, double cost)
105 {
106 NextHop nexthop(faceUri, cost);
107 return nexthop;
108 }
109
Jiewen Tana0497d82015-02-02 21:59:18 -0800110 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600111 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -0800112 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600113 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -0800114 radius, angle);
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800115 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800116 }
117
118 void
119 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
120 {
121 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
122
123 tlv::CoordinateLsa tlvLsa;
124 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
125
126 checkTlvCoordinateLsa(tlvLsa, lsa);
127 }
128
129 void
130 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
131 {
132 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
133
134 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600135 BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta());
Jiewen Tana0497d82015-02-02 21:59:18 -0800136 }
137
138 void
139 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
140 {
141 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
142
143 tlv::NameLsa tlvLsa;
144 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
145
146 checkTlvNameLsa(tlvLsa, lsa);
147 }
148
149 void
150 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
151 {
152 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
153
154 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
155
Nick Gordonf14ec352017-07-24 16:09:58 -0500156 for (const ndn::Name& name : lsa.getNpl().getNames()) {
Jiewen Tana0497d82015-02-02 21:59:18 -0800157 BOOST_CHECK_EQUAL(*it, name);
158 ++it;
159 }
160 }
161
162public:
laqinfand22da512017-05-25 17:29:53 -0500163 ndn::util::DummyClientFace face;
laqinfand22da512017-05-25 17:29:53 -0500164
165 Nlsr nlsr;
166 Lsdb& lsdb;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500167
168 ndn::security::pib::Identity routerId;
laqinfan35731852017-08-08 06:17:39 -0500169 RoutingTable& rt1;
Jiewen Tana0497d82015-02-02 21:59:18 -0800170};
171
172} // namespace test
173} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -0600174
175#endif // NLSR_PUBLISHER_FIXTURE_HPP