blob: eae64860fcc2ff90a6f37095553c14e5351818c0 [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
Jiewen Tana0497d82015-02-02 21:59:18 -080025#include "nlsr.hpp"
26
27#include "../boost-test.hpp"
28#include "../test-common.hpp"
29
30#include <ndn-cxx/util/dummy-client-face.hpp>
31
32namespace nlsr {
33namespace test {
34
35class PublisherFixture : public BaseFixture
36{
37public:
38 PublisherFixture()
dmcoomes9f936662017-03-02 10:33:09 -060039 : face(std::make_shared<ndn::util::DummyClientFace>())
40 , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050041 , lsdb(nlsr, g_scheduler)
Jiewen Tana0497d82015-02-02 21:59:18 -080042 {
43 }
44
45 void
46 addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
47 {
48 Adjacent adjacency(name, faceUri, cost, Adjacent::STATUS_ACTIVE, 0, 0);
49 lsa.addAdjacent(adjacency);
50 }
51
52 void
53 checkTlvLsaInfo(const tlv::LsaInfo& info, Lsa& lsa)
54 {
55 BOOST_CHECK_EQUAL(info.getOriginRouter(), lsa.getOrigRouter());
56 BOOST_CHECK_EQUAL(info.getSequenceNumber(), lsa.getLsSeqNo());
57 BOOST_CHECK_LE(info.getExpirationPeriod(), ndn::time::milliseconds(0));
58 }
59
60 void
61 checkTlvAdjLsa(const ndn::Block& block, AdjLsa& lsa)
62 {
63 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::AdjacencyLsa);
64
65 tlv::AdjacencyLsa tlvLsa;
66 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
67
68 checkTlvAdjLsa(tlvLsa, lsa);
69 }
70
71 void
72 checkTlvAdjLsa(const tlv::AdjacencyLsa& tlvLsa, AdjLsa& lsa)
73 {
74 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
75
76 std::list<tlv::Adjacency>::const_iterator it = tlvLsa.getAdjacencies().begin();
77
78 for (const Adjacent& adjacency : lsa.getAdl().getAdjList()) {
79 BOOST_CHECK_EQUAL(it->getName(), adjacency.getName());
80 BOOST_CHECK_EQUAL(it->getUri(), adjacency.getConnectingFaceUri());
81 BOOST_CHECK_EQUAL(it->getCost(), adjacency.getLinkCost());
82 ++it;
83 }
84 }
85
86 CoordinateLsa
87 createCoordinateLsa(const std::string& origin, double radius, double angle)
88 {
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060089 CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
Jiewen Tana0497d82015-02-02 21:59:18 -080090 radius, angle);
91
Alexander Afanasyevf9f39102015-12-01 17:43:40 -080092 return lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -080093 }
94
95 void
96 checkTlvCoordinateLsa(const ndn::Block& block, CoordinateLsa& lsa)
97 {
98 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::CoordinateLsa);
99
100 tlv::CoordinateLsa tlvLsa;
101 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
102
103 checkTlvCoordinateLsa(tlvLsa, lsa);
104 }
105
106 void
107 checkTlvCoordinateLsa(const tlv::CoordinateLsa& tlvLsa, CoordinateLsa& lsa)
108 {
109 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
110
111 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicRadius(), lsa.getCorRadius());
112 BOOST_CHECK_EQUAL(tlvLsa.getHyperbolicAngle(), lsa.getCorTheta());
113 }
114
115 void
116 checkTlvNameLsa(const ndn::Block& block, NameLsa& lsa)
117 {
118 BOOST_CHECK_EQUAL(block.type(), ndn::tlv::nlsr::NameLsa);
119
120 tlv::NameLsa tlvLsa;
121 BOOST_REQUIRE_NO_THROW(tlvLsa.wireDecode(block));
122
123 checkTlvNameLsa(tlvLsa, lsa);
124 }
125
126 void
127 checkTlvNameLsa(const tlv::NameLsa& tlvLsa, NameLsa& lsa)
128 {
129 checkTlvLsaInfo(tlvLsa.getLsaInfo(), lsa);
130
131 std::list<ndn::Name>::const_iterator it = tlvLsa.getNames().begin();
132
133 for (const ndn::Name& name : lsa.getNpl().getNameList()) {
134 BOOST_CHECK_EQUAL(*it, name);
135 ++it;
136 }
137 }
138
139public:
dmcoomes9f936662017-03-02 10:33:09 -0600140 std::shared_ptr<ndn::util::DummyClientFace> face;
Jiewen Tana0497d82015-02-02 21:59:18 -0800141 Nlsr nlsr;
142 Lsdb lsdb;
143 ndn::KeyChain keyChain;
144};
145
146} // namespace test
147} // namespace nlsr
dmcoomes9f936662017-03-02 10:33:09 -0600148
149#endif // NLSR_PUBLISHER_FIXTURE_HPP