blob: aa8034336696447b782e6257d91efdbb3fff712b [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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
laqinfand22da512017-05-25 17:29:53 -050025#include "publisher/lsdb-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>
33
34#include <boost/filesystem.hpp>
35
36using namespace ndn;
Jiewen Tana0497d82015-02-02 21:59:18 -080037
38namespace nlsr {
39namespace test {
40
41class PublisherFixture : public BaseFixture
42{
43public:
44 PublisherFixture()
laqinfand22da512017-05-25 17:29:53 -050045 : face(g_ioService, keyChain, {true, true})
46 , nlsr(g_ioService, g_scheduler, face, g_keyChain)
47 , lsdb(nlsr.getLsdb())
Jiewen Tana0497d82015-02-02 21:59:18 -080048 {
laqinfand22da512017-05-25 17:29:53 -050049 INIT_LOGGERS("/tmp/","TRACE");
50 nlsr.getConfParameter().setNetwork("/ndn");
51 nlsr.getConfParameter().setRouterName("/This/Router");
52 nlsr.initialize();
53 face.processEvents(ndn::time::milliseconds(10));
Jiewen Tana0497d82015-02-02 21:59:18 -080054 }
55
56 void
57 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
58 {
Nick Gordone9733ed2017-04-26 10:48:39 -050059 Adjacent adjacency(name, ndn::util::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
60 lsa.addAdjacent(std::move(adjacency));
Jiewen Tana0497d82015-02-02 21:59:18 -080061 }
62
63 void
64 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
65 {
66 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
67 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
68 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
69 }
70
71 void
72 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
73 {
74 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
75
76 tlv::AdjacencyLsa tlvLsa;
77 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
78
79 checkTlvAdjLsa(tlvLsa, lsa);
80 }
81
82 void
83 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
84 {
85 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
86
87 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
88
89 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
90 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -050091 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -080092 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
93 ++it;
94 }
95 }
96
97 CoordinateLsa
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060098 createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
Jiewen Tana0497d82015-02-02 21:59:18 -080099 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600100 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -0800101 radius, angle);
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800102 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800103 }
104
105 void
106 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
107 {
108 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
109
110 tlv::CoordinateLsa tlvLsa;
111 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
112
113 checkTlvCoordinateLsa(tlvLsa, lsa);
114 }
115
116 void
117 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
118 {
119 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
120
121 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600122 BOOST_CHECK(tlvLsa.getHyperbolicAngle() == lsa.getCorTheta());
Jiewen Tana0497d82015-02-02 21:59:18 -0800123 }
124
125 void
126 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
127 {
128 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
129
130 tlv::NameLsa tlvLsa;
131 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
132
133 checkTlvNameLsa(tlvLsa, lsa);
134 }
135
136 void
137 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
138 {
139 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
140
141 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
142
143 for (const ndn::Name& name : lsa.getNpl().getNameList()) {
144 BOOST_CHECK_EQUAL(*it, name);
145 ++it;
146 }
147 }
148
149public:
laqinfand22da512017-05-25 17:29:53 -0500150 ndn::util::DummyClientFace face;
Jiewen Tana0497d82015-02-02 21:59:18 -0800151 ndn::KeyChain keyChain;
laqinfand22da512017-05-25 17:29:53 -0500152
153 Nlsr nlsr;
154 Lsdb& lsdb;
Jiewen Tana0497d82015-02-02 21:59:18 -0800155};
156
157} // namespace test
158} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -0600159
160#endif // NLSR_PUBLISHER_FIXTURE_HPP